Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to display the current page number in the site. I want it to be conditional though so that it doesn't show up on the home/front page. Using the code below, the page number is being displayed at all.

<?php 
    $pageNumber = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if(!is_front_page()) {
        echo "<div class='page-count'><?php echo '&ndash; $pageNumber &ndash;'; ?></div>";
    }
?>
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You want to use is_paged which checks if the current page number is 2 or above (and returns true if it is). is_front_page checks 'if the main page is a posts or a Page'.

You've also used incorrect syntax (changed from a double quote to a single quote, and used <?php inside a string being echoed).

Untested, but the following should do what you want:

<?php 
    $pageNumber = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if(is_paged()) {
        echo "<div class='page-count'> &ndash;".$pageNumber." &ndash;</div>";
    }
?>
share|improve this answer
    
Thanks, Stephen! is_paged() was the function I was looking for! –  Tony Mar 12 '12 at 1:33
add comment

as get_query_var('paged') returns empty on the first page, this might work as well (untested):

<?php
  if( get_query_var('paged') ) echo "<div class='page-count'> &ndash;".get_query_var('paged')." &ndash;</div>";
?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.