WordPress.org

Ready to get started?Download WordPress

Forums

Custom Taxonomies Menu Widget
[resolved] How to Hide Taxonomy Titles (9 posts)

  1. iftomkins
    Member
    Posted 3 years ago #

    Hi! Great plugin. Thanks so much for releasing it. I'm trying to figure out right now how to hide the taxonomy titles, and just display the content list of the taxonomy. Any tips?

    http://wordpress.org/extend/plugins/custom-taxonomies-menu-widget/

  2. iftomkins
    Member
    Posted 3 years ago #

    Found a solution to only display items contained within a given hierarchical taxonomy, while hiding the taxonomy titles and hierarchy. (Perhaps this could be a future addition to the widget setup?)

    At line 156,

    I added this line:
    'hierarchical' => '0',
    And changed this line
    'title_li' => $custom_taxonomy->labels->name, // Tax nice name
    to this line
    'title_li' => '',

    Here's the entire chunk of code before and after.

    Before:

    $args_list = array(
    'taxonomy' => $custom_taxonomy->name, // Registered tax name
    'title_li' => $custom_taxonomy->labels->name, // Tax nice name
    'include' => implode(',', (array)$instance['include_' . $custom_taxonomy->name]),
    'orderby' => $instance['orderby'],
    'show_count' => $instance['show_count'],
    'order' => $instance['order'],
    'echo' => '0'
    );

    After:

    $args_list = array(
    'taxonomy' => $custom_taxonomy->name, // Registered tax name
    'title_li' => '',
    'hierarchical' => '0',
    'include' => implode(',', (array)$instance['include_' . $custom_taxonomy->name]),
    'orderby' => $instance['orderby'],
     'show_count' => $instance['show_count'],
    'order' => $instance['order'],
    'echo' => '0'
     );

    *All the parameters to the wp_list_categories function (which is what I changed) are listed here: http://codex.wordpress.org/Template_Tags/wp_list_categories

  3. studiograsshopper
    Member
    Plugin Author

    Posted 3 years ago #

    Hi,

    Good suggestion! I'll add this as an option in a future version.

    I haven't tested your code, but just to clarify:

    1. You don't always want to show the hierarchical structure of the taxonomy terms?

    2. You would like the option to not display the taxonomy title?

    Thanks!

  4. iftomkins
    Member
    Posted 3 years ago #

    Hi!

    To answer your questions: 1. It's not that I don't want to show the hierarchy itself, it's just that sometimes I only want to show the children of a parent taxonomy, and making the hierarchy parameter = '0' seems to display only the children. 2. Yes, I would like to be able to hide the title of the taxonomy. Here is an illustrative example:

    Before: I had a hierarchical custom taxonomy like this (by default, the plugin shows all of the below):
    -Topics
    --Subtopic
    ---Child of Subtopic
    ---Child of Subtopic
    ---Child of Subtopic

    Goal: My goal was to show only the Children of a single Subtopic, so it looks like this:

    -Child of Subtopic
    -Child of Subtopic
    -Child of Subtopic

    Changing this line
    'title_li' => $custom_taxonomy->labels->name, // Tax nice name
    to this line
    'title_li' => '',

    results in this:

    -Subtopic
    --Child of Subtopic
    --Child of Subtopic
    --Child of Subtopic

    Then, adding this line
    'hierarchical' => '0',
    results in this:

    -Child of Subtopic
    -Child of Subtopic
    -Child of Subtopic

    Success!

    Future Goal: I would also like, in a different location, to display only the Subtopics, but not their children, so it would look like this:

    -Subtopic
    -Subtopic
    -Subtopic

    I think I could get your plugin to do this, but I'm not sure how to configure the plugin to run differently in two different instances of the widget (since I still want to display only the Children of Subtopics in a couple other places). So I'm exploring a direct solution in the Codex. If you have any tips on how I could make the plugin run by one set of parameters in one widget instance and by another set of parameters in another, do let me know! :)

  5. studiograsshopper
    Member
    Plugin Author

    Posted 3 years ago #

    Thanks for the feedback.

    For the first two goals, I think these are useful and I'll add these as options.

    For your last point, you can already pick and choose terms within the taxonomy. Won't being able to suppress the taxonomy name then give you what you want?

  6. studiograsshopper
    Member
    Plugin Author

    Posted 3 years ago #

    I should have added - you can run multiple instances of the widget, each with a different configuration.

  7. iftomkins
    Member
    Posted 3 years ago #

    Yes! You are correct. With the two above parameter changes, just de-selecting all the children of the subtopics in the widget configuration, with the subtopics selected, allows for just the list of subtopics.

    However, because I decided to customize and show the list of subtopics only on certain pages conditionally, I'm using the following code inside of a widget. The code was taken from here http://codex.wordpress.org/Template_Tags/wp_list_categories#Display_Terms_in_a_custom_taxonomy

    <?php
    
    $taxonomy     = 'topics';
    $orderby      = 'name';
    $depth        = '1';
    $show_count   = 0;      // 1 for yes, 0 for no
    $pad_counts   = 0;      // 1 for yes, 0 for no
    $hierarchical = 1;      // 1 for yes, 0 for no
    $title        = 'Topics';
    
    $args= array(
      'taxonomy'     => $taxonomy,
      'depth'        => $depth,
      'orderby'      => $orderby,
      'show_count'   => $show_count,
      'pad_counts'   => $pad_counts,
      'hierarchical' => $hierarchical,
      'title_li'     => $title
    );
    ?>
    
    <?php
    
    wp_list_categories( $args );
    
    ?>

    Thanks again for your plugin! :)

  8. studiograsshopper
    Member
    Plugin Author

    Posted 3 years ago #

    For info, I've just released version 1.1 which adds the two options you mentioned originally:

    - Show/Hide hierarchy
    - Show/Hide taxonomy titles

    Thanks for the useful suggestions! :-)

  9. iftomkins
    Member
    Posted 3 years ago #

    Great news!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic