Viewing 3 replies - 1 through 3 (of 3 total)
  • 1. How is $single not accurate in your examples? The first link is to the second page of a sub-category. This is not a single post page, but a category page displaying one post.

    What you probably want is a way of redirecting to an individual post when a paged category listing has only one entry, but I don’t know of a hack or plugin that would accomplish this.

    2. You may want to use the newer conditional function: if(is_single())

    3. The next/previous_post() tags display links only on single post pages, when run from The Loop. Testing on $single or is_single() pretty much accomplishes what you’re after.

    In the old days, $single was (I believe!) set if there was only one result from the DB lookup — thus a category query that returned a single item would be $single. It looks like is_single() now returns true only if the query is one that CAN only return one result, and not whether or not the query actually DID return only one result. Personally, I see that as a bit of a ‘bug’, since if an internal search results in a single query, the old old code used to just result in the one post displaying.

    HOWEVER, you can look at $wp_query->post_count to see what the last query returned, and base upon that instead. I’ve had to do stuff like that myself recently — I don’t like it, but it works.

    -d

    Thread Starter dannyman

    (@dannyman)

    <i>What you probably want is a way of redirecting to an individual post when a paged category listing has only one entry, but I don’t know of a hack or plugin that would accomplish this.</i>

    That would be neat, but I must walk before I can fly. Thank you, Kafkaesqui for the is_single() advice.

    -danny

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘$single not always accurate — suggestions?’ is closed to new replies.