• I mainly post to my blog once a day at most, and when I search for a specific day (or use the calendar widget to navigate through my archives) I often only get one post returned. When that happens I’d like to just display the full content of the post rather than a (one-item) list of post titles.

Viewing 3 replies - 1 through 3 (of 3 total)
  • then .. you need to count the number of posts returned.

    $numposts = (count($posts));

    and you need to tell WP what to do with that number:

    if ($numposts == 1 ) { display content; }
    
    else { display something else; }
    Thread Starter lorenholmes

    (@lorenholmes)

    thanks whooami, but i’m still a little lost. what is the array returned when a search is performed, and is it different than what is returned from a click on a link in the calendar widget?

    is there already a function that will count the number of elements in the array or do i need to create one?

    i think i know what i need to do but WP is a complex application and i’m new to it, so i don’t yet know where to look for the things i need.

    You are over complicating things ??

    take a look at index.php in the defualt theme. Im going to cut out the normal post display stuff for simplicities sake and because the normally used pastebin.com appears to be broke.

    We have the normal stuff at the top:

    <?php get_header(); ?>
    <div id="content" class="narrowcolumn">
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    After that, we are in the loop. So lets count the posts returned, and then do something with them.

    <?php $numposts = (count($posts)); ?>
    <?php if ($numposts == 1 ) :?>

    <– One post returned.

    This is the point at which you decide what you want to show using all the normal template tags. Stuff like this:

    <div class="onepost" id="post-<?php the_ID(); ?>">

    and so on …

    then we put in the else statement :

    <?php else : ?>

    Here, we tell WP what to do if more than one post was returned. This would be where you would do alternate styling.

    ie,

    <div class="morethanonepost" id="post-<?php the_ID(); ?>">

    after that, we close the if statement that we added:

    <?php endif; ?>

    and the rest is back to the normal stuff within index.php that closes the loop, adds the navigation, sidebar, footer, etc..

    <?php endwhile; ?>
    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('&laquo; Previous Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Next Entries &raquo;') ?></div>
    </div>
    <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.
    
    <?php include (TEMPLATEPATH . "/searchform.php"); ?>
    <?php endif; ?>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    does that help?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘if search or archives return a single post display content not title’ is closed to new replies.