Support » Fixing WordPress » Single post with it’s own category posts listed

  • I’ve searched through the forums, and no one (as far as I can tell) has exactly asked how to do what I’m trying to do.

    I’m putting together a WordPress site that is meant to be used as a gallery of sorts (using an image associated with each post). The posts would each fall under one of about six categories. I have been able to figure out how to set up a category template page for each of the categories, and I know how to produce a list of all the category’s posts on that template page.

    I use this bit of code:
    $posts = get_posts('numberposts=4&offset=1&category=1');
    foreach($posts as $post) :
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>

    What I would like to be able to do is to have the viewer see each post, and on the side have that list of posts from the same category. Does that make sense?

    So, for instance, we could have a category called “Displays”. That category title is in the sidebar. A visitor would click on “Displays”, and the category page comes up. On that category page is a list of all the posts that are about Displays. Then, they could click on one of the post titles, and the full post would appear. However, I still want them to have access to that post list that was on the category page.

    Is there a way to use the same code as above, but have it somehow figure out the category the post on that same page is? If that is possible, then it would be a simple change to the single.php/archive.php files.

    In case you think this is really odd, I’m trying to do this in order to provide navigation that is not chronologically based. My goal is to end up with a site that doesn’t have “previous” or “next” anywhere on it. I’m using WP as a CMS, more or less, and coming up with a totally custom template. I’m not a PHP jockey, so if I seem to need some hand holding, that’s why.

    Thank you in advance for any and all help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • This is kindof iffy, I’m not sure about the exact conditions of what you want to do. However, at the very least this’ll probably give you an idea of what you can do.

    Clicky here for the example.

    Thanks Noel! I’m going to try to see if it does what I need it to do.

    Any other thoughts out there?


    I’m trying to figure out where the code should go, specifically. Would it go onto the archive.php page after the loop? I realize you don’t know my exact situation, but if you could hazard a guess I would be very grateful.

    Also, should that first line of code open with

    <?php if ( is_category( )) instead of just if ( is_category( ))?

    Like I said, I’m not the greatest coder, so thank you for help!

    Well, let’s say you were using Kubrick (for the sake of example). You’d open up its sidebar.php and if you wanted to add it before Archives, it’d look something like this.

    Also, the <?php ?> stuff is really dependent on where in the template you place it and the coding style of the theme’s author.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Single post with it’s own category posts listed’ is closed to new replies.