2011-04-05 53 views
0

我不确定这是否可行,但我有一个问题想要得到解答。我所做的是在特定页面上进行自定义循环。这个循环中的项目有很多类别,我已经设置了一个功能来在单个页面上显示这些类别。但是,从一些特定页面中,我只想显示一个静态类别,而不是所有可能的类别。有没有一种方法来检查的前一页和应用基础上的东西,有点像这样:在显示WordPress内容之前有条件检查前一页

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

显然还没有一个previous_page_is标签,但有东西,我可以做到这一点会模仿这种功能?

谢谢,托马斯

回答

0

我意识到这是3年前问的,但是当我在寻找同样的东西时,我发现了这篇文章 - 我找到了我想要的答案,所以我会在这里发布它。感谢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 

} 
相关问题