Wordpress人气竞赛仅跟踪特定类别的帖子

时间:2010-09-23 12:21:16

标签: wordpress wordpress-plugin

我在自托管网站上使用wordpress的人气竞赛。

人气竞赛是否有可能仅跟踪特定类别的帖子?

提前致谢。

1 个答案:

答案 0 :(得分:0)

虽然我在一段时间内没有参与人气竞赛,但我认为这应该有效:

/**
 * Define the categories to be tracked
 */
$GLOBALS['pc_track_cats'] = array(1,3,5,8); // alternately, category slugs can be used as well

/**
 * Check the content each time it is called to see if we're in our target cat
 * if not, remove the popularity-contest filter
 *
 * @param string $the_content
 * @return string
 */
function my_check_pc($the_content) {
    if (!in_category($GLOBALS['pc_track_cats'])) {
        remove_filter('the_content', 'akpc_content_pop');
    }
    return $the_content;
}
add_filter('the_content', 'my_check_pc', 1);

/**
 * Replace the popularity contest filter after the content has been run
 *
 * @param string $the_content
 * @return string
 */
function my_replace_pc($the_content) {
    add_filter('the_content', 'akpc_content_pop');
    return $the_content;
}
add_filter('the_content', 'my_replace_pc', 9999);