• 0
Sign in to follow this  
Followers 0

Filtering categories on homepage

Question

Posted · Report post

Hello, I am trying to filter out categories on the homepage with the following action:

//Removes certain categories from home page based on category id
	add_action('pagelines_inside_top_theloop' ,'filter_cats');
	function filter_cats(){
		if (is_home()){
			$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; //fixes pagination
			$args = array(
				'cat'=> '-43',
				'paged'=> $paged
			);
			query_posts($args);
		  }
	}

The code is placed in the base theme's functions.php file, but nothing happens. Can someone have a look to see if the code is correct? Thanks Tuan

Share this post


Link to post
Share on other sites

7 answers to this question

  • 0

Posted · Report post

Hi Tuan, Is this supposed to be an Action or a Filter ?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Danny, I'm not sure. I found this on the forum which says it was suppose to filter out specific categories on the homepage. However, it doesn't work. Hoping the get some help with it. Thank

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Did you get the code from PageLines Framework support or PlatformPro support. They each have their own hooks. To check if "pagelines_inside_top_theloop" is the proper hook, activate the PageLines Action Map plugin on your site and look to see if the hook exists on the home page. (And according to one of the links below, it appears [i]incorrect[/i].) Next, just guessing here but you probably want a filter, not an action, so you should change that. Info for learning more about hooks: http://api.pagelines.com/hooks/ http://www.pagelines.com/wiki/Glossary#Highlight http://www.pagelines.com/wiki/PageLines_Themes

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Sorry, I'm more than green when it comes to php. If I change the hook in the code above, do you think it will work then?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Hi tuanma, If coding isn't your thing, have you tried the Special Recent Post plug-in ? It allows you to use specific options to show only posts from category X and then provides you with a shortcode which you can then add to your Homepage content area. I think using this plug-in would be the best course of action. I have provided you with a link to the plug-in below. http://wordpress.org/extend/plugins/special-recent-posts/

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

HI Tuan, This could solve your problem, if you are still looking for a piece of code to exclude categories. Replace the code you pasted in here with the following (in your child theme's functions.php): [code] function exclude_category( $query ) { if ( $query->is_home ) { $query->set( 'cat', '-1' ); } } add_action( 'pre_get_posts', 'exclude_category' ); [/code] Keep in mind that when using "is_home" you are referring to the blog page. If you have a static page set as Home in Setting>Reading you should replace "is_home" with "is_front_page". Of course, don't forget to replace "-1" with whatever category ID you want to exclude. Good luck!

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

@Anthalis, Thanks for sharing, Let us know @tuanma if this resolves your issue.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0