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.

Is there a method of doing this? Can I use PHP to say if(URL=page/2/) { } or something like that within my template?

Essentially, I want an ad to appear in my sidebar when a user clicks 'Older Entries' and Wordpress directs them to "myblog.com/page/2/".

I'm pretty sure I know how to accomplish this with JQuery, but I was wondering if there was a way through PHP, and without a plugin.

Thanks WPA

share|improve this question
    
So you want to hardcode every exception? Sorry, this is bad style. If I were you, I'd write a small plugin that uses custom fields to do this dynamically. –  Raphael Jan 20 '12 at 22:04

2 Answers 2

up vote 0 down vote accepted

PHP has the $_SERVER[] variable, you can use this to get just about anything contained in the URL, you'll probably want to look at PATH_INFO as a launching point. You can use strpos() (or, if you want to have better results, preg_match()) to check whether or not the string you get from $_SERVER[] contains the desired string.

share|improve this answer
    
This is way too low-level. –  Raphael Jan 20 '12 at 22:03
    
I agree that it's not the best method, but it answers exactly what the OP asked for, specifically a PHP only solution for checking the url for the paged parameter. –  m0r7if3r Jan 20 '12 at 22:14
    
Why not propose the best method? ;) The problem with your solution (besides all matters of style) is that it assumes a specific URL format. Even if pretty URL format never changes, access via ugly URLs is always possible and has to be dealt with specifically if you do it like you propose. –  Raphael Jan 20 '12 at 22:55
    
Yes, but yours does not stick to the question. Agree to disagree. –  m0r7if3r Jan 20 '12 at 23:40
    
All I see is one person used template tags provided by The Loop, and one person used plain PHP and was more courteous. Gets the rep... –  RCNeil Jan 21 '12 at 1:20

You can use function is_page to identify the page, for example like that:

if ( is_page('mypage') ) { ... }

The function apparently accepts page IDs, titles and slugs.

Note the documentation about its behaviour w.r.t The Loop.

In order to check the page number, use this:

$paged = $wp_query->get( 'paged' );
if ( !empty($paged) && $paged >= 2 ) { ... }
share|improve this answer

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.