Skip Navigation

[Resolved] Hierarchical custom taxonomy links in a Custom HTML widget

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to use the custom shortcode get_taxonomy_items to display links to hierarchical term archives in a Custom HTML widget, but the term links appear before the widget instead of inside the widget.

Solution: When used in a Custom HTML widget, this custom shortcode must be modified as shown:

/* modifica per categorie personalizzate */
function get_taxonomy_items_func($atts){
extract( shortcode_atts( array(
'taxonomy_name' => '',
), $atts ) );
$args = array(
'taxonomy' => $taxonomy_name,
'hierarchical' => 1,
'title_li'=>0
);
ob_start();
wp_list_categories( $args );
return ob_get_clean(); 
}
add_shortcode('get_taxonomy_items', 'get_taxonomy_items_func');

Then insert this code in the Custom HTML widget:

<ul class="widget_categories">
    [get_taxonomy_items taxonomy_name="tribunali"]
</ul>

Relevant Documentation: @https://toolset.com/forums/topic/how-to-create-a-view-which-displays-taxonomy-as-proper-indented-hierarchy/#post-368307

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by fulvioT 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#624040
taxonomies.png

Hi,

I am trying to insert a personal taxonomy into a widget.
I follow your instruction at https://toolset.com/forums/topic/how-to-create-a-view-which-displays-taxonomy-as-proper-indented-hierarchy/#post-368307

And create a html widget text with the following code

[get_taxonomy_items taxonomy_name="tribunali"]

But when I open a page the taxonomy elements appears outside the widget see screenshot.

Can I solve it?

thanks
fulvio

#624082

The shortcode provided in the other ticket does not create the white pane for you, it only creates the text links. If you want to add the white background, you can copy the markup from the other category widget on the page. Place the entire contents in the HTML widget:

<aside id="ts-tribunali-hierarchy-1" class="widget inner-padding widget_categories">
  <h2 class="widget-title">Tribunali</h2>
  <div>
    <ul>[get_taxonomy_items taxonomy_name="tribunali"]</ul>
  </div>
</aside>

This will apply the same styles you can see in the Categorie Generali widget.

#624152
elements.png

Hi,

I try to follow your instruction but the result is the same, the elements are out-of-panel.

May be I don't clear: my elements are Milano, Totino that are show before the title and out-of-panel

thanks
fulvio

#624333

Can I look in your wp-admin area to see how you have this widget configured? Please provide login credentials in the private reply fields here.

#624413

Okay I see the problem. I made an adjustment in the functions.php file, adding ob_start() and ob_get_clean():

/* modifica per categorie personalizzate */
function get_taxonomy_items_func($atts){
extract( shortcode_atts( array(
'taxonomy_name' => '',
), $atts ) );
$args = array(
'taxonomy' => $taxonomy_name,
'hierarchical' => 1,
'title_li'=>0
);
ob_start();
wp_list_categories( $args );
return ob_get_clean(); 
}

Then in the HTML widget I modified the code to inherit the other category link formatting:

<ul class="widget_categories">
	[get_taxonomy_items   taxonomy_name="tribunali"]
</ul>

Please check now.

#624536

thanks for all

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.