• Hi All,

    I’m trying to dynamically build a table of contents (TOC) for each “issue” of a magazine site I’m working on. The TOC will only be listed on the “cover” article of the issue.

    The way I’m constructing it is to have each issue be in the category “Volumes” and then have each issue number be a separate child category of “Volumes”.

    The problem I’m having is that while I can determine the category of each issue by using cat_is_ancestor_of I don’t know how to put that information then into the get_posts query to list only the specific “issue” category that the TOC is a part of.

    Below is the code I’ve cobbled together. Any help would be appreciated

    A.

    <?php
    foreach((get_the_category()) as $childcat) {
    if (cat_is_ancestor_of(25, $childcat)) { ?>
    
    <?php
    $args = array( 'numberposts' => 5, 'order'=> 'DSC', 'category' => 'echo $childcat->cat_name' );
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :  setup_postdata($post); ?>
    <div>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><i><?php the_title(); ?></i></a>   
    
    </div>
    <?php endforeach; ?>
    <?php }} ?>
  • The topic ‘Listing Posts in Same Category as Parent Post’ is closed to new replies.