• Resolved richarduk

    (@richarduk)


    I’m linking to a single post in the standard template i.e. single.php

    Single.php needs to contain a loop that shows all the posts from the category ‘oranges’.

    I shall use something like if is_single('17') then show all the posts from category ‘oranges’

    Can anyone tell me how to do this loop that shows all the posts from the category ‘oranges’?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi

    The file is called SINGLE.php for a reason – it is designed to show a single post. What you want to do is done in WP using a category page.

    Please read these for approaches to accomplishing what you want:
    http://codex.ww.wp.xz.cn/Template_Hierarchy

    http://codex.ww.wp.xz.cn/Pages

    http://codex.ww.wp.xz.cn/Template_Tags/query_posts

    If what you want is comments after each post on the category page, you can paste the comment logic from single.php into your custom template.

    Thread Starter richarduk

    (@richarduk)

    🙂

    Thanks for your reply.

    For those that want to know how to get multiple posts on a single.php type page, it’s very, very easy.

    The first line and the last line do the stuff, the rest is just an example Loop inbetween

    <?php if (is_single('990')) {?>
    
    <?php query_posts('showposts=200&cat=71&order=ASC'); ?>   
    
    <?php if (have_posts()) : ?>    
    
    <?php while (have_posts()) : the_post(); ?>
    
    <div class="<?php echo $oddpost; ?>" id="post-<?php the_ID(); ?>"> 
    
    <?php if ( comments_open() ) : ?>
    
    <span class="number-of-comments"> <?php comments_popup_link('', '1 Comment', '%  Comments', 'comment-link', 'Sorry, no further comments on this post'); ?></span> 
    
    <?php endif; ?>
    &nbsp;
    
    </div>         <?php /* COMMENT   end <div class="post"> END COMMENT */?>
    
    <?php endwhile; ?>
    
    <?php /* COMMENT
    Wordpress has finished fetching all the posts.  The Loop doesn't finish until     <?php endif; ?>   END COMMENT */?>
    
    <?php else : ?>
    
    <?php /* If no posts were found  then  do all the stuff between here and the final      <?php endif; ?>       below,  such as displaying an apology or a search form.    */?>
    
    <h2 class="not-found">Sorry! </h2>
    <p class="not-found">No posts were found - try something else
    
    <form method="get" id="search-form-not-found" action="<?php bloginfo('home'); ?>/">
    <fieldset>
    <input type="text" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="search-input-not-found" />
    <input type="submit" id="search-submit-not-found" value="Search" />
    </fieldset>
    </form>
    
    <?php /* This displays an apology and a search form if no posts were found. Delete it or just have a line of text if you want  */?>
    
    <?php endif; ?>     
    
    <?php /* End of The Loop  */?> 
    
     <?php }  ?>

    You’ll need to create a unique single page to carry this code, otherwise none of your other posts will show (because they won’t be the single post with an id of 990)

    You’ll have to mess around, but basically in single.php you need to send different categories of posts to different single pages.

    So in single.php we need to put something like this:

    <?php
    
    if (in_category(80)) {include(TEMPLATEPATH . '/single-oranges.php');}  
    
    elseif (in_category(90)) {include(TEMPLATEPATH . '/single-lemons.php');}  
    
    else {include(TEMPLATEPATH . '/single-plums.php');}   /* Default template to use if  post is not in one of categories above */
    
    ?>

    @richarduk: WP is a powerful and flexible application which can pretty much be tweaked to show anything or everything. BUT as stvwlf said above, WP’s single.php is a WP template set up to show a simgle post. Multiple posts (excerpts or full content) could much easily have been implemented with:

    archive.php – The archive template. Used when a category, author, or date is queried. Note that this template will be overridden by category.php, author.php, and date.php for their respective query types.

    per http://codex.ww.wp.xz.cn/Theme_Development#Anatomy_of_a_Theme

    Thread Starter richarduk

    (@richarduk)

    I’m aware of that.

    This was a specific request for a specific purpose. I appreciate your help, and I know that it’s impossible to tell if I’m a newbie or not, but there was reasoning behind the apparent madness.

    The category page led to single posts. One of those single posts listed excerpts from another category.

    It was necessary to do it this way.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Multiple posts on single.php?’ is closed to new replies.