can’t use the page_test method to check pagination

I’ve tried to follow the example for Testing for paginated Pages but i don’t know why it isn’t working. i put it in the single.php file for post detection. i don’t know why the page_test is broken. example code here:

<?php
get_header();
?>

    <div id="content" class="narrowcolumn" role="main">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
            <h2><?php the_title(); ?></h2>
            <div style="margin-top:5px">
<div style="padding:5px; float:left; margin-right:50px;"><fb:share-button href="<?php the_permalink(); ?>" class="url" type="button_count"></fb:share-button></div>

        <?php    
        $page_test = $wp_query->get( 'paged' );
        if ( ! $page_test || $page_test < 2 ) {

            something here...

            <?php } else { ?>

            another here...

            <?php } ?>

Related posts

Leave a Reply

2 comments

  1. You need to either add global $wp_query;

    global $wp_query;
    $page_test = $wp_query->get( 'paged' );
    

    or use get_query_var();

    $page_test = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
  2. the above solution i tried already.

    Never mind, i solved it, even i don’t know why. if some body knows…:
    this:

    // not working
        $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : false;
        if ( $paged === false ) {
    

    didn’t worked, but this:

    // works
        $paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : false;
        if ( $paged === false ) {
    

    did work. the difference is “page” instead of “paged”. i don’t know why everywhere i looked i’ve found the code with “paged” and it didn’t worked (even it the conditional tags page in the codex!), but here, in a simple topic i found it.

    nevertheless, it is solved.