Hi,
could anyone support on the displaying subcategories on the category page dinamically using query? I tried a lot of combinations and watched tutorials, but cannot do that.
Hi,
could anyone support on the displaying subcategories on the category page dinamically using query? I tried a lot of combinations and watched tutorials, but cannot do that.
Hi @slekstut,
I’ll try and add some archive related dynamic values so one can access them more easily, as they should be available.
In the meantime, might I propose:
And your shortcode:
// Function to retrieve the term ID of the current category
function get_current_category_id()
{
$current_category = get_queried_object();
// Check if the current category is an instance of WP_Term
if ($current_category instanceof WP_Term) {
$category_id = $current_category->term_id;
return $category_id;
}
}
// Register shortcode and associate it with the 'get_current_category_id' function
add_shortcode('cc_current_term_id', 'get_current_category_id');
@Louis thanks for your suggestion. I am set parameters as you provided. But cannot insert short code. Paragraph in query template is not cwicly block with settings. How and where to insert the shortcode?
I guess shortcode should be as shown in docs:
Hi @slekstut,
You’ll want to add the shortcode code I provided above using a code snippet plugin such as Code Snippets – WordPress plugin | WordPress.org.
Cheers,
Hi @slekstut,
I see that @Louis has already answered this. Just in case you need more information, I put together a tip, to give you a overview of the different ways you can add your shortcode definition and any other custom code:
I hope this makes it clearer.
Thanks for your support. But I cannot get why it is not working? I did shortcode with wpcodebox plugin. Published the code. Enabled. But in editor I cannot add any element to query template. Or it’s not the way to do it?
Somehow I made it work. I think because added more taxonomies in the query editor (as per image below). Editor shows all subcategories but in the preview page it shows okay. When I enter another category page, subcategories are correct.
Thanks again!
Any ideas how to make that subcategories a links dynamically redirecting to subcategory page?