前两天,异想天开,然后给自己的blog上加了个“涂鸦”分类,把临时想到的乱七八糟的东西放在里面。结果收到了“退订威胁”。其实,当天我就注意到了,只是没想到如何解决。威胁的力量是无穷的……当然,想想tiny的“微尘程序员网站”上布满了垃圾,也确实非常内疚。
上网搜索了一下,在美女Lisa Sabin Wilson的网站上找到个解决方案,但好像在我这里不管用。想了想,修改了一下/wp-includes/目录里面的feed-rss2.php文件,搞定!
其实就是修改一下feed-rss2.php文件中的while loop中的内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <?php while( have_posts()) : the_post(); ?> <?php if (in_category(36)) :?> <!-- exclude category id=36 from feed rss2 --> <?php else : ?> <item> <title><?php the_title_rss() ?></title> <link><?php the_permalink_rss() ?></link> <comments><?php comments_link(); ?></comments> <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate> <dc:creator><?php the_author() ?></dc:creator> <?php the_category_rss() ?> <guid isPermaLink="false"><?php the_guid(); ?></guid> <?php if (get_option('rss_use_excerpt')) : ?> <description><![CDATA[<?php the_excerpt_rss() ?>]]></description> <?php else : ?> <description><![CDATA[<?php the_excerpt_rss() ?>]]></description> <?php if ( strlen( $post->post_content ) > 0 ) : ?> <content:encoded><![CDATA[<?php the_content() ?>]]></content:encoded> <?php else : ?> <content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded> <?php endif; ?> <?php endif; ?> <wfw:commentRss><?php echo get_post_comments_feed_link(); ?></wfw:commentRss> <?php rss_enclosure(); ?> <?php do_action('rss2_item'); ?> </item> <?php endif; ?> <!-- exclude category id=36 from feed rss2 --> <?php endwhile; ?> |
其中的2~4行,以及28行是后填进去的。从此之后,我的rss 2.0 feed输出的时候,不再输出“涂鸦”这个分类里的文章。
至于其它类型的feed,原理应该一样,可以分别修改wp-includes目录中的以下文件:
- feed.php
- feed-atom.php
- feed-atom-comments.php
- feed-rdf.php
- feed-rss.php
- feed-rss2.php
- feed-rss2-comments.php



{ 7 comments… read them below or add one }
您最近的feed确实比较杂的说
不过个人认为还能接受
算是还挺有趣吧
使用类似http://www.lixiaolai.com/?feed=rss2&cat=-1的地址可以把类为1的文章去掉,配合feedsky用不需要修改源代码。
to zhang: 美女Lisa Sabin Wilson给的方案也是这样的,不知道我这里为什么不行?
哈哈,老大你还真自律
to tinyfool: 那是。
看了一下,我感觉你蛮适合用用 twitter 这样的 microblog, 另外国内也有克隆品, 或 tumblelog 也是适合你的, 比如 tumblr 或 soup.io
暂时没有在feed去除某分类的需求