WordPress的只显示在文章
问题描述:
我有我的WP功能的问题。我只需要它在博客文章上显示。现在它会显示在其他页面上,例如FrontPage。WordPress的只显示在文章
这是我在functions.php的功能:
function my_sp_function($content) {
$include = FALSE;
$post = FALSE;
if (in_category(array(3, 4, 5, 6, 91, 133))) {
$include = TRUE;
}
if (get_post_type(get_the_ID()) == 'post'){
$post = TRUE;
}
if ($post = TRUE AND $include == TRUE) {
return $content;
}
}
任何人那里知道我做错了什么?
我现在已经使用此代码尝试,它仍然显示在头版上的$内容..
function my_sp_function($content) {
$include = FALSE;
$post = FALSE;
if (in_category(array(3, 4, 5, 6, 91, 133))) {
$include = TRUE;
}
if(is_home() || is_front_page()) {
$include = FALSE;
}
if ($post == TRUE AND $include == TRUE) {
return $content;
}
}
答
如果你想只包括在主页上的功能,你有两个选择 - 只将函数插入到主题中的single.php
模板中,或者当is_single()
为true但is_page()
为false时,首选方法仅将您的函数挂接到the_content
。
function my_sp_function($content) {
$content .= "Some more stuff for the_content!";
return $content;
}
if (is_single() && ! is_page()){
add_filter('the_content', 'my_sp_function');
}
钩子在哪里?你必须以某种方式调用它......这将是关键。 – rnevius 2014-10-26 13:35:17
你只需要echo my_sp_function();在single.php,index.php或其他帖子页面上。你不应该在任何其他模板文件上调用它(如果用在header/footer/sidebar中,使用条件if(is_single()|| in_category($ cat)|| is_category($ cat)|| etc || etc)) 。 – ggdx 2014-10-26 13:39:07
if($ post = TRUE ...'if to($ post == TRUE ...' – 2014-10-26 13:40:47