WordPress.org

Ready to get started?Download WordPress

Forums

Coercing wp_query to be single (3 posts)

  1. dmwlff
    Member
    Posted 8 years ago #

    Hi all. I'm excited about getting in to wordpress.

    I'm trying to make modifications to my index page so that I can show only my latest entry and the comments for that entry.

    I'd like to use a bunch of the functions that require that is_single() return true. If I understand correct, I read here that is_single() doesn't test for lists of length 1, so that a list of one is just a different data type from a single post. (NB that the title of the post is misleading but there's good information in it.)

    I'm happy to write the code that will transform a list to single (and make it available) but I need a pointer or two. Can anyone get me going in the right direction?

    Thanks!
    Adam Wolff

  2. Kafkaesqui

    Posted 8 years ago #

    If you add these two lines somewhere before The Loop, even just after the <body> tag should work, any single page functionality you need will be available:

    <?php
    query_posts('showposts=1');
    $wp_query->is_single = true;
    ?>

    I'd recommend making what modifications you're after to your theme's home.php template rather than the index.php, since index.php is the default for all other template types. If your theme does not have one, copy index.php (and name it home.php). Or alternatively, change the code above to:

    <?php
    if(is_home()) {
    query_posts('showposts=1');
    $wp_query->is_single = true;
    }
    ?>

  3. dmwlff
    Member
    Posted 8 years ago #

    Rocklin! That did it.

Topic Closed

This topic has been closed to new replies.

About this Topic