?
Solved

WordPress Pagination Question: Determining page of a post (i.e. $paged > 1)

Posted on 2011-03-24
10
Medium Priority
?
534 Views
Last Modified: 2012-05-11
Greetings,

In this code snippet the author is dynamically rendering the Title tag based on things like what page the user is on.

I understand (i.e. can run to the codex and figure out) ... most all of it except this little nugget:

if ($paged>1) ....

Apparently nowhere in the theme is a variable $paged being set!?!  

1. Is this some global variable deep in the innards of a WordPress function (cuz, i cant find it)?
2. Is this a variable created by the theme author (cuz, I cant find where $page is set in his code, either)
3. I understand in theory that this code deals with pagination. Correct?

Full code snippet below, please illuminate: I'm green.

sleeper
<?php
		      if (function_exists('is_tag') && is_tag()) {
		         single_tag_title("Tag Archive for &quot;"); echo '&quot; - '; }
		      elseif (is_archive()) {
		         wp_title(''); echo ' Archive - '; }
		      elseif (is_search()) {
		         echo 'Search for &quot;'.wp_specialchars($s).'&quot; - '; }
		      elseif (!(is_404()) && (is_single()) || (is_page())) {
		         wp_title(''); echo ' - '; }
		      elseif (is_404()) {
		         echo 'Not Found - '; }
				 
		      if (is_home()) {
		         bloginfo('name'); echo ' - '; bloginfo('description'); }
		      else {
		          bloginfo('name'); 
			  }
			  
		      if ($paged>1) {
		         echo ' - page '. $paged; }
		   ?>

Open in new window

0
Comment
Question by:the_sleeper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
10 Comments
 
LVL 23

Accepted Solution

by:
jeremyjared74 earned 2000 total points
ID: 35212874
It is saying if there is Greater than 1 page then use the pagination that is built into WordPress.
0
 

Author Comment

by:the_sleeper
ID: 35212978
So $paged is a built in WordPress variable? All I can find in the codex is this (under wp_query) :

"paged (int) - number of page. Show the posts that would normally show up just on page X when using the "Older Entries" link.".

thanks
0
 

Author Comment

by:the_sleeper
ID: 35212985
or is $paged simply a parameter of the WP_Query object. If so, how is calling it without something like

$paged = WP_QUery( 'paged ' )

what am i missing?

sleeper

0
Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

 
LVL 23

Expert Comment

by:jeremyjared74
ID: 35213153
OK, I was wrong. I looked a little deeper and found that was an attempt by a commenter at Perishable Press trying to add the page number to the end of the title. At first it appeared to be a pagination tag, you can find similar here: http://codex.wordpress.org/Conditional_Tags

The article that I found which referenced the tag you have is here:
http://perishablepress.com/press/2008/07/21/how-to-generate-perfect-wordpress-title-tags-without-a-plugin/

The WordPress Trac on the subject (2 years old):
http://core.trac.wordpress.org/ticket/9104
. It appears that it wasn't successful. Maybe it got dropped and deemed useless.



0
 

Author Comment

by:the_sleeper
ID: 35213461
Yeah, I was watched Chris Coyier's video training @ Lynda.com (also just bought the book).
I see the post you were referring to, but I still don't get where that $paged variable is coming from.
0
 

Author Comment

by:the_sleeper
ID: 35213583
I must be dense....

Just scanned the book "Digging into WordPress" and it's here again (and again - with no explanation of this $paged variable) .

Book states:

By using a strategic set of conditional tags in the “header.php” file for your theme, it is possible to address search-engine behavior for virtually all types of pages, thereby enabling you to fine-tune the indexing and crawling of your site’s content.

To see how this is done, consider the following code:

...and there on the first line is a conditional check of the variable $paged..?

<?php if(is_home() && (!$paged || $paged == 1) || is_single()) { ?>
<meta name="googlebot" content="index,archive,follow,noodp" />
<meta name="robots" content="all,index,follow" />
<meta name="msnbot" content="all,index,follow" />
<?php } else { ?>
<meta name="googlebot" content="noindex,noarchive,follow,noodp" />
<meta name="robots" content="noindex,follow" />
<meta name="msnbot" content="noindex,follow" />
<?php } ?>

Open in new window


@jeremyjared74: It is saying if there is Greater than 1 page then...  

I get that part...

@jeremyjared74: ...use the pagination that is built into WordPress.

This is the part I don't get ...are you saying that  the variable $paged is built into WordPress, cuz in the context of these examples, it must be ... so why cant I find anything on it in the codex?

I don't get it...  

sleeper
0
 

Author Comment

by:the_sleeper
ID: 35213599
Did some more digging and discovered that yes - WordPress does use Global Variables and this $paged thingy is one of them. Check this out...

http://codex.wordpress.org/User:CharlesClarkson/Global_Variables

0
 

Author Comment

by:the_sleeper
ID: 35213644
Funny...

here http://codex.wordpress.org/User:CharlesClarkson/Global_Variables you will read this...

Undefined Global Variables

The following variables are global in scope, but do not have a definition here yet. You can help by adding a definition for these global variables.

... and in this list is this (among others)

$page (unknown)
$page_cache (unknown)
$paged (unknown)
$pagenow (unknown)
$pages (unknown)

Oh well. @jeremyjared74, you were right on with the "built in" comment, but it was bugging me that I didn't understand why you were right.

...now I get it. But it would have been nice if the reference book(s) explain that little nugget (or better yet, talked about the Global Variables in some detail)

sleeper
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 35215390
The $paged tag is in use, it was the specific if ($paged>1) that I had a hard time finding documentation on. I don't think this was ever "part of" the WordPress core tags, but more of a hack by a user.
0
 

Author Comment

by:the_sleeper
ID: 35218284
Thanks for all your help, jeremyjared74

stay close... lot more learning to go :)

sleeper
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part I (http://www.experts-exchange.com/Web_Development/Blogs/WordPress/A_8410-Getting-Started-In-WordPress-Part-I.html), I introduced you to the powerful WordPress backend, the WordPress administrative Dashboard.  In Part II, I will introduce yo…
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
Suggested Courses
Course of the Month7 days, 22 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question