Skip to main content
deleted 2 characters in body
Source Link

I've answered my own question with some more reading and some messing around...

I had to run a 'foreach' that cycles through the given post's comments within the main loop.

The following code looks at all the comments for each post that passes through the loop and checks for a specific string in the comments' content. Depending on if $mystring$findme is matched, a specific HTML ID is written to the div. At a glance, one can see which posts contain specific content in their comments. Party on.

<?php
if( have_posts() ) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('col-md-6 box');?>>
<div class="post-box article"  

<?php

$comments = get_comments( array( 'number' => 99, 'post_id' => get_the_ID() ) );

if(get_comments_number()==0) : ?>
        id="pendingcomment"
<?php else : 

    foreach($comments as $comm) :
        
        $mystring = get_comment_text( $comm );
        $findme   = 'CHANGES!';
        $pos = strpos($mystring, $findme);
    
        if($pos == true) : ?>
            id="notapprovedcomment"
        <?php elseif($pos == false) : ?>
                id="approvedcomment"
        <?php endif; 

    endforeach;
endif; ?>
>

The code could no doubt be cleaner, but is functional. Hope someone finds this useful one day.

I've answered my own question with some more reading and some messing around...

I had to run a 'foreach' that cycles through the given post's comments within the main loop.

The following code looks at all the comments for each post that passes through the loop and checks for a specific string in the comments' content. Depending on if $mystring is matched, a specific HTML ID is written to the div. At a glance, one can see which posts contain specific content in their comments. Party on.

<?php
if( have_posts() ) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('col-md-6 box');?>>
<div class="post-box article"  

<?php

$comments = get_comments( array( 'number' => 99, 'post_id' => get_the_ID() ) );

if(get_comments_number()==0) : ?>
        id="pendingcomment"
<?php else : 

    foreach($comments as $comm) :
        
        $mystring = get_comment_text( $comm );
        $findme   = 'CHANGES!';
        $pos = strpos($mystring, $findme);
    
        if($pos == true) : ?>
            id="notapprovedcomment"
        <?php elseif($pos == false) : ?>
                id="approvedcomment"
        <?php endif; 

    endforeach;
endif; ?>
>

The code could no doubt be cleaner, but is functional. Hope someone finds this useful one day.

I've answered my own question with some more reading and some messing around...

I had to run a 'foreach' that cycles through the given post's comments within the main loop.

The following code looks at all the comments for each post that passes through the loop and checks for a specific string in the comments' content. Depending on if $findme is matched, a specific HTML ID is written to the div. At a glance, one can see which posts contain specific content in their comments. Party on.

<?php
if( have_posts() ) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('col-md-6 box');?>>
<div class="post-box article"  

<?php

$comments = get_comments( array( 'number' => 99, 'post_id' => get_the_ID() ) );

if(get_comments_number()==0) : ?>
        id="pendingcomment"
<?php else : 

    foreach($comments as $comm) :
        
        $mystring = get_comment_text( $comm );
        $findme   = 'CHANGES!';
        $pos = strpos($mystring, $findme);
    
        if($pos == true) : ?>
            id="notapprovedcomment"
        <?php elseif($pos == false) : ?>
                id="approvedcomment"
        <?php endif; 

    endforeach;
endif; ?>
>

The code could no doubt be cleaner, but is functional. Hope someone finds this useful one day.

Source Link

I've answered my own question with some more reading and some messing around...

I had to run a 'foreach' that cycles through the given post's comments within the main loop.

The following code looks at all the comments for each post that passes through the loop and checks for a specific string in the comments' content. Depending on if $mystring is matched, a specific HTML ID is written to the div. At a glance, one can see which posts contain specific content in their comments. Party on.

<?php
if( have_posts() ) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('col-md-6 box');?>>
<div class="post-box article"  

<?php

$comments = get_comments( array( 'number' => 99, 'post_id' => get_the_ID() ) );

if(get_comments_number()==0) : ?>
        id="pendingcomment"
<?php else : 

    foreach($comments as $comm) :
        
        $mystring = get_comment_text( $comm );
        $findme   = 'CHANGES!';
        $pos = strpos($mystring, $findme);
    
        if($pos == true) : ?>
            id="notapprovedcomment"
        <?php elseif($pos == false) : ?>
                id="approvedcomment"
        <?php endif; 

    endforeach;
endif; ?>
>

The code could no doubt be cleaner, but is functional. Hope someone finds this useful one day.