Displaying categories
-
Hello, here is what I’m looking for
Which kind of code would I need to use in this kind of situtation?
I would like to show few categories on one page others on second page, how could choose which categories are posted on a page and which are hided on that same page?
-
Hi, i am not really sure what you are looking for? Would you like to hide some of the categories in a shortcode, widget, in [adverts_add] categories dropdown or somewhere else?
It would be great if you could describe your issue in more details maybe with some screenshot which would explain it.
Hi Greg! Sorry being unclear 🙂
Basically I want to show all but one categories on one page and that one category missing from that page would be shown on other page.
Was I clear enough now? 🙂
Cheers
Ville
Hi, hmm so if i understand correctly you are looking to display the Ads from all categories except one in the [adverts_list]?
If so then you can do that by adding the code below in your theme functions.php file
add_filter( 'shortcode_atts_adverts_list', 'my_adverts_list_category_exclude_atts', 10, 3 ); function my_adverts_list_category_exclude_atts( $out, $pairs, $atts ) { if( ! isset( $atts["_category_exclude"] ) ) { $atts["_category_exclude"] = null; } $out["_category_exclude"] = $atts["_category_exclude"]; return $out; } add_filter( "adverts_list_query", "my_adverts_list_category_exclude", 10, 2 ); function my_adverts_list_category_exclude( $args, $params ) { if( isset( $params["_category_exclude"] ) ) { if( ! isset( $args["taxonomy"] ) || ! is_array( $args["taxonomy"] ) ) { $args["tax_query"] = array(); } $args["tax_query"][] = array( 'taxonomy' => 'advert_category', 'field' => 'term_id', 'terms' => $params["_category_exclude"], 'operator' => 'NOT IN', ); } return $args; }Then you can use the adverts_list as
[adverts_list _exclude_category="1000"] [adverts_list category="1000"]The first shortcode will display Ads from all categories except the category with ID = 1000 and the second snippet will display only Ads assigned to category 1000.
The thing is, on first level I want to list categories, not adverts.
Sorry, but i have no idea what you are trying to do? If you want to list the top categories only then you can create a page from wp-admin / Pages / Add New panel and either list there all categories you want to show manually or use the [adverts_categories show=”top”] shortcode and hide the one category you do not want to show using CSS
well yes, that css code I have been trying to ask how to hide certain categories from a page. so can you provide css how to do that?
Go to wp-admin / Appearance / Customize / Additional CSS panel and add there the code below
.adverts-flexbox-item.adverts-category-slug-CATEGORY-SLUG { display: none !important }where CATEGORY-SLUG is an actual slug of a category you want to hide.
Isn’t this code is hiding category for good? I said in the beginning that I’m going to show all but one category on a one page and then I would like to show that one category on other page. So this is wrong way to hide category?
so I try find code which would be something like this, but obviously this is not working.
Meaning of code would print categories to page and exclude that one category which would be named on code. Is there something like this ?
[adverts_categories _exclude_category=”category_name”]
Sorry, but at this point i cannot help you with this. I literally have no idea what you are trying to accomplish and what the result should look like? Can you add some screenshot which would explain it more clearly?
The _exclude_category param accepts category ID (an integer), not the category name.
I try once more to explain with more details I hope.
1. There is 11 categories on our site
2. I want to hide one of those categories on that page which is listing categories
3. I want to show that one hided category on other page
Call it dividing to two sections if you will
1. ok
2. i understand you are displaying the categories using [adverts_categories show=”top”] shortcode and want to hide one of the items? If so then you can do that with the CSS code i pasted in one of previous messages
.adverts-flexbox-item.adverts-category-slug-CATEGORY-SLUG { display: none !important }3. so you want to show there a [adverts_categories] shortcode with just one box?
yes that code is working but doesn’t it disable the category from the whole site, can it be shown anymore on other page?
and yes that one hided category I want to show on its own page, all the other categories are for certain group of people and that one category is for another group of people.
So shouldn’t there be some kind of code like this on the page instead?
[adverts_list _exclude_category="1000"]? but instead of adverts there would be categories and there would be that one category which would be taken off ?I know I made things tricky for you but I salute you for the help so far and beyond 🙂
Cheers!
Disabling a single category page (or rather having it somewhat visible and somewhat hidden) might not really be possible as far as i know.
thank you for the effort, got myself workaround with using button and link to wanted category.
The topic ‘Displaying categories’ is closed to new replies.