2013-10-26 50 views
1

我正在開發一個新的插件。在這個插件中,用戶可以選擇插件的顯示位置。如何過濾帖子,頁面,檔案和其他頁面?

如果用戶只選擇發佈或存檔頁面,那我該如何找到它? 如果我使用add_filter('the_content','function');

那麼我的插件將顯示所有頁面,但如何在單個類別或歸檔頁面中做到這一點?

回答

1

您可以檢查一個特定的頁面與這些conditonals是顯示器

is_page() //For pages 
is_single //for posts 
is_singular //for posts AND pages 
is_category //for categories 
is_tag() //for tags 
is_404() //for 404 page 

另外,請勿使用匿名函數,當你添加過濾器。 總是使用自定義函數

add_filter ('the_content','my_magic_function'); 

對於模板標籤的完整列表檢查,請訪問: http://codex.wordpress.org/Function_Reference/is_page

+0

非常感謝 – krishnaTORQUE

0

我們使用Conditional Tags

add_filter('the_content', function($content) 
{ 
    is(!is_single()) 
     return $content; 

    return '<p>This is a single post.</p>' . $content; 
}); 

示例代碼需要PHP 5.3+

+0

平均單隻後的頁面? – krishnaTORQUE

+0

是的。這些條件有許多組合,你必須在文檔中挖掘一些以獲得對你有用的東西。 – brasofilo

相關問題