Beantin webbkommunikation

Beantin Beta Blog

Experiments, investigations, and tests of web things
January 13, 2012

Exclude categories from home page and RSS in Pagelines

For The Beantin Index that I launched earlier this week, there are posts that contain ratings and then there are blog posts. The main focus of the site are the ratings, so I didn’t want blog posts appearing on the home page, and I wanted two separate RSS feeds.

Here’s what I did…

This article was really useful, but it needed some extra tinkering to work it to work with Pagelines.

Exclude categories from home page

here’s the function added to functions.php – i’ve put cat=-24 in order to exlude my “blog” category. You need to find out your own category id.

// exclude blog category from front page loop
function exclude_blog_cat() {
global $query_string;
if (is_home()) {
  query_posts($query_string.'cat=-24');
  }
}

Elsewhere in functions.php i added the following Pagelines hook:

add_action('pagelines_before_theloop', 'exclude_blog_cat');

Removing from recent posts widget

This doesn’t stop the pages appear in the “recent posts” widget, so I installed the WP PHP widget plugin so I could put some PHP code into a wordpress widget (the default text widget doesn’t run PHP)

Into the PHP widget I put the following code to make my own “recent posts” widget:

<ul>
<?php
$recentPosts = new WP_Query();
$recentPosts->query('showposts=5&cat=-24');
?>
<?php while ($recentPosts->have_posts()) :
    $recentPosts->the_post(); ?>
  <li><a href="<?php the_permalink() ?>"
  rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>

Excluding from RSS feed

Finally, I needed to exclude the category from the main RSS feed, and add a feed of it’s own – the info at the end of the Brightscape blog post was enough to sort out that combined with the following hook and code to make sure the 2nd RSS feed appeared in the header:

add_action('wp_head', 'insert_rss'); function insert_rss() { ?>
<link rel="alternate" type="application/rss+xml" title=
  "<?php bloginfo('name'); ?> Feed" href="<?php
  bloginfo('rss2_url'); ?>" />
<link rel="alternate" type="application/rss+xml" title=&
  quot;<?php bloginfo('name'); ?> Blog Feed" href="
  http://feeds.feedburner.com/BeantinIndexBlog" />
<?php }
Related Posts Plugin for WordPress, Blogger...

Tags

Filed under Configuration, Wordpress.

Tags: , , ,

Theme Beantin created by James Royal-Lawson. Privacy Policy