• Resolved Drew

    (@drewrockshard)


    Hello,

    I have issues with query_post for limiting the post on the homepage. I only want 1 post on the homepage, and I know you would normally use the is_home() conditional tag, but right now I’m just wanting to get this to work, I can do that part later.

    I have looked all over the forums, and have not been able to find something that actually worked. If I run this code, and in the options for reading I have the “At most show” value of 10, so that when someone searches or clicks on a tag, they will get 10 posts per page, but on the homepage (when I use the is_home() conditional) it will only show the current post. Of course, this is not working whatsoever, it is just using the value in the Reading Options (current value of 10).

    `<?php query_posts(‘showposts=1’); ?>
    <?php if ( $posts ) : foreach ( $posts as $post ) : start_wp(); ?>
    <div class=”post”>
    <h2>” title=”Permalink: <?php the_title(); ?>”><?php the_title(); ?></h2>
    <?php the_content(“Continue reading ” . the_title(”, ”, false)); ?>
    <?php post_updated(‘M j, Y’, 24, ‘<p class=”updated”>Updated: ‘, ‘</p>’); ?>
    </div> <!– close post –>`

    If someone could help me out, that would be great! Thanks in advanced.

    Drew

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Drew

    (@drewrockshard)

    Alright this seems to be resolved. It appears that I was using the old version of The Loop:

    <?php if ( $posts ) : foreach ( $posts as $post ) : start_wp(); ?>

    And should have been using the new version:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    NOTE: There are also different closing parts of The Loop, so make sure you use the following closing for the new The Loop:

    <?php endwhile; else: ?>
    <p><?php _e(‘Sorry, no posts matched your criteria.’); ?></p>
    <?php endif; ?>

    For those who might have this issue, check you Loop! 🙂

    jbbrwcky

    (@jbbrwcky)

    Why not use something like this:
    <?php $my_query = new WP_query('showposts=1'); ?>

    ?

    This way you don’t need to bother with the ‘show how many posts’ options in the Admin page, like you mentioned. You used query_posts, I just don’t think you need to.

    Thread Starter Drew

    (@drewrockshard)

    True. Maybe I shall do so 😀

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘query_post (single post on homepage) not working’ is closed to new replies.