开发者

Conditional check for previous page before showing content in WordPress

I'm not sure if this is possible, but I have a question that I would like to get answered. What I have done is made a custom loop on certain pages. The items in this loop have many categories, and I have setup a function to display those categories on the single page. However, from a few particular pages, I just want a static category to be displayed instead of all the possible categories. Is there a way to check the previous page and apply something based on that, kind of like this:

if (is_single() && previous_page_is('about')) { 
//stuff here
}

Obviously there is not a previous_page_is tag, but is there something that I can d开发者_如何学JAVAo that would mimic this functionality?

Thanks, Thomas


I realise this was asked 3 years ago but I found this post while I was searching for the same thing - I found the answer so figured I would post it here. With thanks to http://zoerooney.com/blog/tutorials/using-the-referring-page-in-wordpress/

// use the WordPress tag wp_get_referer to assign the referring URL to the variable $referer
$referer = wp_get_referer();

// check if the URL is a specific one
if ( $referer == "whatever-the-full-about-page-url-is" ) {

  // if it is, do something

} else {

  // if it isn't, do something else

}


I think you could use $_SERVER['HTTP_REFERER'] ( http://www.php.net/manual/en/reserved.variables.server.php ) and then if it is needed use get_posts or get_page to retrieve the page that as this slug..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜