xDroid's Blog

WordPress简单定制

又是一篇只有历史意义的文章了。

首页隐藏特定分类的文章

index.php
修改前:

<?php if ( have_posts() ) : ?>

修改后:

<?php if ( have_posts() ) : query_posts($query_string .'&amp;cat=-*');?>

侧边栏“最新发布”中隐藏特定分类的文章

widgets/class-wp-widget-recent-posts.php
修改前:

$r = new WP_Query( apply_filters( 'widget_posts_args', array(
    'posts_per_page' => $number,
    'no_found_rows' => true,
    'post_status' => 'publish',
    'ignore_sticky_posts' => true
) ) );

修改后:

$r = new WP_Query( apply_filters( 'widget_posts_args', array(
    'posts_per_page' => $number,
    'no_found_rows' => true,
    'post_status' => 'publish',
    'ignore_sticky_posts' => true,
    'cat' => '-*'
) ) );

侧边栏隐藏特定的目录

widgets/class-wp-widget-categories.php
修改前:

$cat_args['title_li'] = '';

修改后:

$cat_args['title_li'] = '';
$cat_args['exclude'] = '*';

修改feed显示的分类

function custom_rss_feed_content($content) {
    if(is_feed()) {
        $output = '欢迎访问 http://blog.xdrd.me';
        $content = $content . $output ;
    }
    return $content;
}
//add_filter('the_content','custom_rss_feed_content');
function exclude_cat_feed($query) {
    if(is_feed()) {
        $query->set('cat','-*'); //排除ID为 * 的分类
        return $query;
    }
}
add_filter('pre_get_posts', 'exclude_cat_feed');

以上*是对应分类的tag_id。
在这里写下来免得自己忘记了。