WordPress.org

Ready to get started?Download WordPress

Forums

List other posts from current category (6 posts)

  1. HejGustav
    Member
    Posted 6 years ago #

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

    How to do?

    Gustav

  2. momoblack
    Member
    Posted 5 years ago #

    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

  3. Dunkkan
    Member
    Posted 5 years ago #

    Here there's some interesting info :

    a thread -> http://wordpress.org/support/topic/179755?replies=1
    another -> http://wordpress.org/support/topic/189282?replies=7

    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)

  4. Dunkkan
    Member
    Posted 5 years ago #

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

    Forget the links and spread the word !

    http://playground.ebiene.de/400/related-posts-by-category-the-wordpress-plugin-for-similar-posts/

    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 -->
    		<?php
    		if (have_posts()) :
    		while (have_posts()) :
    	      the_post();
    		?>
    		<?php the_title(); ?>
    		<?php the_content(); ?>
    		<?php endwhile;
    		endif;
    		?>
    
    <!-- YOU WILL ADD HERE THE PROVIDED CODE
    once the plugin is installed -->
    
    <?php
    related_posts_by_category(
      array(
        '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.

  5. nadiaa
    Member
    Posted 5 years ago #

    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
    and
    2) once I have the current categories, how do I omit certain ones?

  6. brainycat
    Member
    Posted 5 years ago #

    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.

    $categories=get_categories('');
    foreach ($categories as $cat)
    {
        if (is_category($cat->cat_ID)) ||
        (is_category($cat->cat_ID) != $unwanted_cat_ID)
        {
            get_the_image()
        }
    }

Topic Closed

This topic has been closed to new replies.

About this Topic