Getting the Dynamic Listing-Category-Name

Hello.

I am struggling trying to get the dynamic title from the listing_category taxonomy - As seen on the demosite here Design & Graphics – TaskHive

I have redesigned the header section to fit more with the overall style of my site, and now I need to display the listing-category name dynamically, depending on the current selected category.

When I try to insert the listing-category-header.php with the get_template_part function, I get an error.

Any suggestions how to get it to work - I might have the wrong approach all together.

Thank you!

Please post the error message and I’ll try to help, maybe one of the variables used in the category header is not defined.

( ! ) Fatal error: Uncaught Error: Call to a member function get_item_count() on null in public\wp-content\plugins\hivepress\templates\listing-category\view\listing-category-item-count.php on line 5
( ! ) Error: Call to a member function get_item_count() on null in public\wp-content\plugins\hivepress\templates\listing-category\view\listing-category-item-count.php on line 5

When you insert the listing category header as a template part, please try passing the listing_category object to the template context in the same way listinghive/class-theme.php at master · hivepress/listinghive · GitHub

1 Like

Thanks a bunch. I am very early in learning to code, so I get it that the information havent been gathered yet, and im trying to echo something that hasnt been prepared.

I did the same with the view of single blog post, but then it worked. (Get the post-header.php), but then I guess the information was available from some core WordPress code.

I will try to figure it out.

1 Like

Been trying alot of things, but I’m just a few months in trying to learn.

So after trying alot of stuff, and then chewing on what you wrote some more, I ended up with trying these two attempts. Can you give me any guidance?

<?php 
                $output .= hivetheme()->template->render_part(
                    'hivepress/listing-category/view/page/listing-category-header',
                    [
                        'listing_category' => \HivePress\Models\Listing_Category::query()->get_by_id( get_queried_object() ),
                    ]
                );

                    get_template_part('hivepress/listing-category/view/page/listing-category-header', $output);

and this

get_template_part('hivepress/listing-category/view/page/listing-category-header',
                    [
                        'listing_category' => \HivePress\Models\Listing_Category::query()->get_by_id( get_queried_object() ),
                    ]
                );

Thank you in advance :slight_smile:

Please try this one:

                 echo hivetheme()->template->render_part(
                    'hivepress/listing-category/view/page/listing-category-header',
                    [
                        'listing_category' => \HivePress\Models\Listing_Category::query()->get_by_id( get_queried_object() ),
                    ]
                );

I shall once I get home from vacation:-) thank you very much

1 Like

Havent gotten home to try it yet, but another, related question.

When using hivepress tags, you can create custom tags and when clicked, sort it by the tag in a similar fashion as listing categories.

Is there a way to get the current filtrered tag into the heading aswell?

Thank you

It should work this way for the Tag pages by default, here’s an example writing – JobHive If you mean filtering by tags they are not displayed because in search context there may be multiple filters (e.g. category, custom attribute filters) so there’s no page title.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.