• Resolved Joshuwar

    (@joshuwar)


    Hi, I’m trying to get wordpress to display posts from seperate parent categories on a category page.

    For example, the main category could be ‘John’ (a child category of ‘artists’, for example), and on this category page, I want seperate lists of posts associated with his name, like ‘News About John’ (posts in both ‘John’ category and in ‘News’ category) or ‘Pictures by John’ (posts in both ‘John’ and ‘Pictures’) or whatever.

    I’ve been fiddling with this intention for ages, and I’ve arrived at code which works some of the time. This is pretty confusing for me (I’m still learning php). Here’s what I’ve got…

    <?php
    $pictures = 11;
    $news = 6;
    $biography = 7;
    ?>
    
    <?php
    $category = get_the_category(); //get all categories for this post
    echo 'first category is ' . $category[0]->cat_ID;
    ?>
    
    <?php query_posts(array('category__and' => array($category[0]->cat_ID,$biography))); ?>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <h2 class="medtitle"><?php the_title(); ?></h2>
    
    <?php the_content(); ?>
    
    <?php endwhile; endif; ?>
    
    <h3>News About This Person:</h3>
    
    <?php query_posts(array('category__and' => array($category[0]->cat_ID,$news))); ?>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <h2><?php the_title(); ?></h2>
    
    <?php the_content(); ?><br />
    
    <?php endwhile; endif; ?>
    
    <h3>Pictures by this Person:</h3>
    
    <?php query_posts(array('category__and' => array($category[0]->cat_ID,$pictures))); ?>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
    
    <?php the_excerpt() ?>
    
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">Read More</a>
    
    <?php endwhile; endif; ?>

    What seems to happen is that sometimes the ‘first category’ thing seems to misfire and think that it’s on another category (ie. the parent of the category which the page is). I’m totally at a loss with it, so any assistance with the above, or new directions, or anything at all, would be massively appreciated.

    Also if you think you can help but I’ve been a bit inarticulate, I will try to explain better.

    Thanks!

    J

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Getting category posts from different parents on a category page’ is closed to new replies.