Categories

Posted in: Newsmag
Post count: 7

Wondered if you could possibly help with my particular problem. I have created a parent category “Council”, with a child category “Council Meetings”, and a child category coming off that “Council Documents”.

Question – How can I stop “Council Documents” appearing in “Council” and “Council Meetings” category pages ?

Post count: 9544

Technically you can’t very easily … since they are child categories and designed to show the child and child’s child.

Not a theme issue.

In theory, you could create a custom template for the two parent categories with custom loop to EXCLUDE the nth child category in results, but likely need to get programmer to help you with that.

Might want to read up on the WordPress docs/codex on how categories work — as it’s common with all themes as that is part of WP and not the theme.

See – https://codex.wordpress.org/Taxonomies

  • This reply was modified 10 years by simchris.
Post count: 6535

Hi @BradfordZone

As @Chris said you will need some custom code to exclude the posts from a child category to appear on main category page.

function exclude_categories() {
	$excluded = array( 'categoy_id' );
	if (is_category(parent_category)){
		set_query_var( 'category__not_in', $excluded );
	}
}
add_filter( 'pre_get_posts', 'exclude_categories' );

You need to replace the categoy_id with the id of the category which you want to exclude and also replace the parent_category with the id of the parent category like in this example: http://screencast.com/t/TaWyHKFniVI To get the category id follow this link: http://screencast.com/t/rs9qiFg9 You have to place your code in functions.php file.

Hope this help.
Thanks!

  • This reply was modified 10 years by Andrei L..
Post count: 7

Thanks for that. As a work around removing the child categories and making them main categories. Is it possible to choose which Categories appear just below the menu bar on each main category page – Thus making it appear the categories are connected – even though they are not ?

Post count: 6535

Hi

I am not sure I understand your request correct but if you want to remove a category from subcategory list: http://screencast.com/t/LES2Qh2aL7z on category page, then you can modify this function: http://screencast.com/t/jkuNplHh and add this parameter

'exclude' => 'category-id'

To get the category id follow this link: http://screencast.com/t/Qt4EfcIZv
If this is not what you mean please provide more details.
Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)
The forum ‘Newsmag’ is closed to new topics and replies.