• Hi everyone,

    I’m trying to find an answer for an issue that I have been having for a while now, and unfortunately I have not found any solutions for my problem. What I am trying to accomplish is to show related posts of a subcategory that is being called in a sub-child page. Here’s the navigation hierarchy:

    Parent page: Projects
    Child page: Hospitality
    Sub-child page(s): X, Y, Z

    ————-
    PROJECTS
    –Hospitality
    —-X
    —-Y
    —-Z
    ————-

    I have the navigation hierarchy configured where the child page name has its own category name (parent category), and the sub-child page has its own category name (child category). I want to be able to show posts of a specific parent category in the child page, and posts of a specific child category in the sub-child page. I managed to display the posts of the child page the way I want it to be, but am having difficulty with displaying specific posts of the child category in the sub-child page.

    Here’s the specific code I’m working on for my child category page:

    backticks

    <?php $orig_post = $post;
    global $post;
    $categories = get_the_category($post->ID);
    if ($categories) {
    $category_ids = array();
    foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;

    $args=array(
    ‘category__in’ => $category_ids,
    ‘post__not_in’ => array($post->ID),
    ‘posts_per_page’=> -1, // Number of related posts that will be shown.
    ‘caller_get_posts’=>1,
    ‘orderby’ => rand
    );

    $my_query = new wp_query( $args );
    if( $my_query->have_posts() ) {
    echo ‘<div id=”related_posts”><h3>Related Projects</h3>

      ‘;
      while( $my_query->have_posts() ) {
      $my_query->the_post();?>

    <div class=”pleft”>
    <h3>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_title(); ?></h3>
    <div class=”relatedthumb”>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_post_thumbnail(); ?></div>
    <div class=”relatedcontent”>

    </div>
    </div>
    <?
    }
    echo ‘
    </div>’;
    }
    }
    $post = $orig_post;
    wp_reset_query(); ?>

    backticks

    I’ve seen the code way too many times and am just tired… Would love the fresh eyes and assistance!

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter Zion Eye Media

    (@onefunkybluesman)

    UGH such a goofball… here’s the code:

    <?php $orig_post = $post;
    global $post;
    $categories = get_the_category($post->ID);
    if ($categories) {
    $category_ids = array();
    foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
    
    $args=array(
    'category__in' => $category_ids,
    'post__not_in' => array($post->ID),
    'posts_per_page'=> -1, // Number of related posts that will be shown.
    'caller_get_posts'=>1,
    'orderby' => rand
    );
    
    $my_query = new wp_query( $args );
    if( $my_query->have_posts() ) {
    echo '<div id="related_posts"><h3>Related Projects</h3>
    
        ';
        while( $my_query->have_posts() ) {
        $my_query->the_post();?>
    
        <div class="pleft">
        <h3>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></h3>
        <div class="relatedthumb">" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></div>
        <div class="relatedcontent">
    
        </div>
        </div>
        <?
        }
        echo '
    
    </div>';
    }
    }
    $post = $orig_post;
    wp_reset_query(); ?>
Viewing 1 replies (of 1 total)

The topic ‘Showing related sub-subcategory posts’ is closed to new replies.