• 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

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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;
    }
    ?>

    Thread Starter dmwlff

    (@dmwlff)

    Rocklin! That did it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Coercing wp_query to be single’ is closed to new replies.