• Hi,

    Ive been trying to get a page that lists:

    1. all child categories from a certain category ID
    2. per child category the category description
    3. per child category the amount of posts in it
    4. per child category the last 2 posts below the description
    5. per child category the last post date
    6. per child category the amount of comments on the posts in that category

    That last one is giving me a hard time… can’t get it to work.

    Here is the code I use… could use some fresh eyes.
    (don’t mind syntax please clean up is needed).

    <?php $categories =  get_categories('child_of=225');
    
    foreach  ($categories as $category) {
    
        //Display the sub category information using $category values like $category->cat_name
        echo '<div class="row clearfix">';
        echo '<div class="col1"><div class="inner"><h2>'.$category->name.'</h2>';
        echo '<p>'.$category->description.'</p>';
        echo '<p class="recent"><strong>Meest recent:</strong></p>';
        echo '<ul class="recentlist">';
    
        foreach (get_posts('posts_per_page=2&cat='.$category->term_id) as $post) {
            setup_postdata( $post );
            $my_date = mysql2date("D j M Y - H:i", $post->post_date);
    
            echo '
    <li><a>ID).'">'.get_the_title().'</a></li>
    ';
        }
    
        echo '';
    
        echo '</div></div>'; //end .col1 .inner
    
        echo '<div class="col2">'.$category->count.'</div>';
    
        echo '<div class="col3">COMMENT COUNT MAGIC MUST TAKE PLACE</div>'; //comment count here!
    
        echo '<div class="col4">'.$my_date.'</div></div>';
    
    } ?>

    And a screenshot to visualise the stuff.

    Cheers,
    Paul

Viewing 1 replies (of 1 total)
  • Thread Starter kortschot

    (@kortschot)

    Edit:

    Fix in the setup_postdate, was in the wrong foreach:

    <?php $categories =  get_categories('child_of=225');
    
    foreach  ($categories as $category) {
    
        setup_postdata( $post );
        $my_date = mysql2date("D j M Y - H:i", $post->post_date);
    
        //Display the sub category information using $category values like $category->cat_name
        echo '<div class="row clearfix">';
        echo '<div class="col1"><div class="inner"><h2>'.$category->name.'</h2>';
        echo '<p>'.$category->description.'</p>';
        echo '<p class="recent"><strong>Meest recent:</strong></p>';
        echo '<ul class="recentlist">';
    
        foreach (get_posts('posts_per_page=2&cat='.$category->term_id) as $post) {
    
            echo '<li><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></li>';
        }
    
        echo '</ul>';
    
        echo '</div></div>'; //end .col1 .inner
    
        echo '<div class="col2">'.$category->count.'</div>';
    
        echo '<div class="col3">X</div>'; //comment count here!
    
        echo '<div class="col4">'.$my_date.'</div></div>';
    
    } ?>

    The comment count is still an issue though.

Viewing 1 replies (of 1 total)
  • The topic ‘Category overview page with comment counts’ is closed to new replies.