Support » Fixing WordPress » List other posts from current category

  • I want to show a list of other posts in the current category when I view a single post.

    How to do?


Viewing 5 replies - 1 through 5 (of 5 total)
  • This is exactly what I want to do. I have looked through the plugins and widgets and have found a lot of variations, but not this. I think it is a few lines of code at most, something like this:

    <?php echo get_posts(get_the_category()); ?>

    I don’t really know php or the template tags, but this is what it might look like in other languages.

    Is there a plugin or widget that already does this? If not, and somebody has the code, I can plug it in. thank you

    Here there’s some interesting info :

    a thread ->
    another ->

    In the first one, the person forgot to close the php, so you must add at the end of the code that :

    <?php endforeach; ?>
    <?php endforeach; ?>

    (yes, two times)

    The second thread, I’ve not tried it out (I’m going to)

    Sorry, I was à la dérive before I found this true gem.

    Forget the links and spread the word !

    Download and install.
    Then, paste the code shown in the site anywhere in your template : after the loop, in sidebar.php, in the footer, where you want.

    I did it after my loop :

    <!-- THIS IS MY MINIMALIZED POST for showing purposes -->
    		if (have_posts()) :
    		while (have_posts()) :
    		<?php the_title(); ?>
    		<?php the_content(); ?>
    		<?php endwhile;
    once the plugin is installed -->
        'orderby' => 'post_date',
        'order' => 'DESC',
        'limit' => 5,
        'echo' => true,
        'before' => '<li>',
        'inside' => '&raquo; ',
        'outside' => '',
        'after' => '</li>',
        'rel' => 'nofollow',
        'type' => 'post',
        'message' => 'no matches'

    Read carefully the code. In “limit” don’t hesitate to change the number of posts to display.

    I’m enjoyin an ultrafast, hyper-neat, super-short never-error hypra-related posts plugin with it 🙂

    And my loop is a chaotic disaster, so this one is pure warranty.

    Hope this helps.

    Hi there, I have been through all the above options, and none quite work for me. On an individual post page, I want to display all other posts from the same category, but also with the option to exclude certain categories.

    I am only displaying thumbnails, and so the available plugins don’t work for me as they are not flexible enough.

    I currently have

    <?php $my_query = new WP_Query('category_name='. $category->term_id); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
      <li><?php get_the_image( 'default_size=thumbnail&amp;width=65&amp;height=65' ); ?></li>
    <?php endwhile; ?>

    However this displays all thumbnails, not current category.

    1) how do I alter the above code to show current categories only
    2) once I have the current categories, how do I omit certain ones?

    To test for current category, I’ve used this loop (I modified my original loop with the logical ‘OR’ so you can exclude a specific category. Add another operator for each subsequent category you want to exclude.

    foreach ($categories as $cat)
        if (is_category($cat->cat_ID)) ||
        (is_category($cat->cat_ID) != $unwanted_cat_ID)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘List other posts from current category’ is closed to new replies.