Tag Groups Shortcodes

Below, you’ll find a detailed guide on how to add the Tag Groups Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Tag Groups Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Tag Groups Plugin and the shortcodes it provides:

Plugin Icon
Tag Groups is the Advanced Way to Display Your Taxonomy Terms

"Tag Groups is an advanced WordPress plugin to display your taxonomy terms effectively. It simplifies and enhances the organization and presentation of your tags, making your site more user-friendly."

★★★★☆ (47) Active Installs: 4000+ Tested with: 6.3.2 PHP Version: 7.2
Included Shortcodes:
  • [tag_groups_cloud]
  • [tag_groups_accordion]
  • [tag_groups_alphabet_tabs]
  • [tag_groups_info]
  • [tag_groups_tag_list]
  • [tag_groups_alphabetical_index]

Tag Groups [tag_groups_cloud] Shortcode

The Tag Groups Cloud shortcode is a powerful tool in the TagGroups plugin. It generates a tag cloud where tags are grouped by their assigned tag group. This shortcode is customizable with various attributes, allowing for a personalized display. It can also return an array instead of outputting the HTML, useful for developers.

Shortcode: [tag_groups_cloud]

Examples and Usage

Basic example – A shortcode that generates a cloud of tags grouped by their respective groups. By default, it will display all groups and tags.

[tag_groups_cloud]

Advanced examples

Display a tag cloud with tags from a specific group. Here, we specify the group ID as a parameter to the shortcode. For example, to display tags from the group with ID 2:

[tag_groups_cloud id=2]

Display a tag cloud with a limit on the number of tags. Here, we specify the ‘amount’ parameter to limit the number of tags displayed. For example, to display only 10 tags:

[tag_groups_cloud amount=10]

Display a tag cloud with tags from multiple groups. Here, we specify multiple group IDs separated by commas. For example, to display tags from the groups with IDs 2, 3, and 5:

[tag_groups_cloud id="2,3,5"]

Combine different parameters to display a customized tag cloud. For example, to display 10 tags from the groups with IDs 2, 3, and 5:

[tag_groups_cloud id="2,3,5" amount=10]

PHP Function Code

In case you have difficulties debugging what causing issues with [tag_groups_cloud] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'tag_groups_cloud', array( $object_TagGroups_Shortcode_Tabs, 'tag_groups_cloud' ) );

Shortcode PHP function:

                    function tag_groups_cloud( $atts = array(), $return_array = false )
    {
        return ( new TagGroups_Shortcode_Tabs() )->tag_groups_cloud( $atts, $return_array );
    }
                    

Code file location:

tag-groups/tag-groups/include/helpers/class.shortcode_statics.php

Tag Groups [tag_groups_accordion] Shortcode

The Tag Groups Accordion shortcode is a dynamic tool in PHP that enables the creation of an accordion-style layout for tags. The shortcode uses the TagGroups_Shortcode_Accordion class to group tags in an expandable and collapsible format. This enhances website navigation, making it user-friendly.

Shortcode: [tag_groups_accordion]

Examples and Usage

Basic Example – This shortcode is used to display a tag group in an accordion format. It doesn’t require any parameters by default.

[tag_groups_accordion /]

Advanced Examples

Displaying a tag group in an accordion format with specified group IDs. In this case, only the groups with IDs 1, 2, and 3 will be displayed.

[tag_groups_accordion include="1,2,3" /]

Displaying a tag group in an accordion format with a specified amount of tags per group. Here, only the first 10 tags of each group will be displayed.

[tag_groups_accordion amount=10 /]

Combining multiple parameters. This example displays the groups with IDs 1, 2, and 3, showing only the first 10 tags of each group, and orders the tags by their count in descending order.

[tag_groups_accordion include="1,2,3" amount=10 orderby="count" order="DESC" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [tag_groups_accordion] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'tag_groups_accordion', array( $object_TagGroups_Shortcode_Accordion, 'tag_groups_accordion' ) );

Shortcode PHP function:

                    function tag_groups_accordion( $atts = array() )
    {
        return ( new TagGroups_Shortcode_Accordion() )->tag_groups_accordion( $atts );
    }
                    

Code file location:

tag-groups/tag-groups/include/helpers/class.shortcode_statics.php

Tag Groups [tag_groups_alphabet_tabs] Shortcode

The Tag Groups Alphabet Tabs shortcode is used to display tags in an alphabetical tabbed format. It provides a highly customizable way to organize your tags. It supports numerous attributes like active, adjust_separator_size, amount, append, and many more to fine-tune the display.

Shortcode: [tag_groups_alphabet_tabs]

Parameters

Here is a list of all possible tag_groups_alphabet_tabs shortcode parameters and attributes:

  • active – Specifies the initially active tab.
  • adjust_separator_size – Adjusts the size of the separator between tags.
  • amount – Controls the number of tags to display.
  • append – Adds a string at the end of each tag link.
  • assigned_class – Specifies a CSS class for the assigned tags.
  • do_not_cache – Disables caching of the tags.
  • collapsible – Allows tabs to be collapsible.
  • custom_title – Sets a custom title for the tags.
  • custom_title_zero – Sets a custom title for tags with zero count.
  • custom_title_plural – Sets a custom title for plural tags.
  • delay – Delays the display of the tabs.
  • div_class – Assigns a CSS class for the div.
  • div_id – Sets a unique ID for the div.
  • exclude – Excludes specified tags from the list.
  • exclude_letters – Excludes specified letters from the list.
  • exclude_terms – Excludes specified terms from the list.
  • hide_empty – Hides tags with zero posts.
  • ignore_accents – Ignores accents in tags.
  • include – Includes only specified tags in the list.
  • include_letters – Includes only specified letters in the list.
  • include_terms – Includes only specified terms in the list.
  • largest – Sets the font size for the most used tags.
  • link_append – Appends a string to each tag link.
  • link_target – Sets the target of the tag links.
  • locale – Sets the localization of the tags.
  • min_max_per_letter – Adjusts font sizes per letter.
  • mouseover – Controls mouseover effect on tabs.
  • order – Sets the order of the tags.
  • orderby – Sets the parameter to order the tags by.
  • prepend – Adds a string at the beginning of each tag link.
  • remove_filters – Removes filters from the tags.
  • separator – Sets a separator between the tags.
  • separator_size – Sets the size of the separator.
  • show_tag_count – Displays the count of the tags.
  • smallest – Sets the font size for the least used tags.
  • source – Specifies the source of the tags.
  • tags_post_id – Sets the post ID for the tags.
  • taxonomy – Sets the taxonomy of the tags.
  • threshold – Sets the minimum number of posts for a tag to appear.
  • ul_class – Assigns a CSS class for the unordered list.

Examples and Usage

Basic example – Displaying alphabet tabs using the default settings.

[tag_groups_alphabet_tabs /]

Advanced examples

Displaying alphabet tabs with custom parameters. Here, we are setting the ‘active’ parameter to 1, ‘amount’ to 10, and ‘collapsible’ to true. This means that the first tab will be active, only 10 tabs will be displayed, and the tabs will be collapsible.

[tag_groups_alphabet_tabs active=1 amount=10 collapsible=true /]

Using the shortcode to exclude certain letters from the alphabet tabs. Here, we are excluding the letters ‘A’, ‘B’, and ‘C’.

[tag_groups_alphabet_tabs exclude_letters="A,B,C" /]

Using the shortcode to include only certain letters in the alphabet tabs. Here, we are including only the letters ‘X’, ‘Y’, and ‘Z’.

[tag_groups_alphabet_tabs include_letters="X,Y,Z" /]

Using the shortcode to display alphabet tabs in descending order and ordered by name.

[tag_groups_alphabet_tabs order="DESC" orderby="name" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [tag_groups_alphabet_tabs] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'tag_groups_alphabet_tabs', array( $object_TagGroups_Shortcode_Alphabet_Tabs, 'tag_groups_alphabet_tabs' ) );

Shortcode PHP function:

                    function tag_groups_alphabet_tabs( $atts = array() ) {

      $this->init();
      
      $this->shortcode_id = 'tag_groups_alphabet_tabs';

      $this->set_attributes( shortcode_atts( array(
        'active' => -1,
        'adjust_separator_size' => true,
        'amount' => 0,
        'append' => '',
        'assigned_class' => null,
        'do_not_cache' => false,
        'collapsible' => null,
        'custom_title' => null,
        'custom_title_zero' => null,
        'custom_title_plural' => null,
        'delay' => true,
        'div_class' => 'tag-groups-cloud',  // tag-groups-cloud preserved to create tab functionality
        'div_id' => '',
        'exclude' => '',
        'exclude_letters' => '',
        'exclude_terms' => '',
        // 'hide_empty_tabs' => false, // doesn't make sense here
        'hide_empty' => true,
        'ignore_accents' => false,
        'include' => '',
        'include_letters' => '',
        'include_terms' => '',
        'largest' => 22,
        'link_append' => '',
        'link_target' => '',
        'locale'  => '',
        'min_max_per_letter' => 1, // option to assign post counts to font sizes for each letter separately; here different than Alphabetical Tag List because we don't see all tab contents simultaneously
        'mouseover' => null,
        'order' => 'ASC',
        'orderby' => 'name',
        'prepend' => '',
        'remove_filters' => 1,
        'separator' => '',
        'separator_size' => 12,
        'show_tag_count' => true,
        'smallest' => 12,
        'source' => 'shortcode',
        'tags_post_id' => -1,
        'taxonomy' => implode( ',', TagGroups_Taxonomy::get_enabled_taxonomies() ),
        'threshold' => 0, // minimum number of posts, total (independent of groups)
        'ul_class' => ''
      ), $atts ) );

      /**
       * Don't set it as default in extract( shortcode_atts() ) because the block sends an empty string
       */
      if ( empty( $this->attributes->html_id ) ) {

        $this->attributes->html_id = 'tag-groups-cloud-alphabet-tabs-' . uniqid();

      }

      /**
      * Keep always jQuery UI class to produce correct output
      */
      if ( ! in_array( 'tag-groups-cloud', array_map( 'trim', explode( ' ', $this->attributes->div_class ) ) ) ) {

        $this->attributes->div_class .= ' tag-groups-cloud';

      }

      if ( $this->attributes->delay ) {

        $this->attributes->div_class .= ' tag-groups-cloud-hidden';
        
      }

      $div_id_output = $this->attributes->html_id ? ' id="' . TagGroups_Shortcode_Statics::sanitize_html_classes( $this->attributes->html_id ) . '"' : '';

      $div_class_output = $this->attributes->div_class ? ' class="' . TagGroups_Shortcode_Statics::sanitize_html_classes( $this->attributes->div_class ) . '"' : '';

      if ( is_array( $atts ) ) {

        asort( $atts );

      }

      /**
       * Call this before creating the cache key
       */
      $this->get_post_id();

      $this->cache_key = md5( 'alphabet_tabs' . serialize( $atts ) . serialize( $this->attributes->tags_post_id ) );

      // check for a cached version (premium plugin)
      $html = apply_filters( 'tag_groups_hook_cache_get', false, $this->cache_key );

      if ( $html ) {

        $html = $this->finalize_html( $html, $div_id_output, $div_class_output, $atts );

        return $html;

      }


      $this->check_attributes();

      $this->get_taxonomies();

      $this->get_tags();
      
      $this->make_include_array();

      $this->maybe_add_post_tags_or_groups();


      $this->html_tabs = array();

      $this->html_tags = array();


      $ul_class_output = $this->attributes->ul_class ? ' class="' . TagGroups_Shortcode_Statics::sanitize_html_classes( $this->attributes->ul_class ) . '"' : '';


      // apply sorting that cannot be done on database level
      if ( 'natural' == $this->attributes->orderby || 'random' == $this->attributes->orderby || $this->attributes->threshold ) {

        $this->sort();
        
      }

      /**
      * Extract the alphabet
      */
      $this->extract_alphabet();

      $this->include_exclude_letters();

      $this->sort_alphabet();

      $html = '';

      /*
      *  render the tabs
      */
      $this->make_tabs_HTML();

      /*
      *  render the tab content
      */
      $this->determine_min_max_alphabet();

      $this->make_tags_HTML();

      /*
      * assemble tabs
      */
      $html .= '<ul' . $ul_class_output . '>' . implode( "\n", $this->html_tabs ) . '</ul>';

      /*
      * assemble tags
      */
      $html .= implode( "\n", $this->html_tags );

      if (  ! $this->attributes->do_not_cache ) {

        // create a cached version (premium plugin)
        do_action( 'tag_groups_hook_cache_set', $this->cache_key, $html );

      }


      $html = $this->finalize_html( $html, $div_id_output, $div_class_output, $atts );

      return $html;

    }
                    

Code file location:

tag-groups/tag-groups/include/helpers/class.shortcode_statics.php

Tag Groups [tag_groups_info] Shortcode

The Tag Groups Info shortcode is used to display tag group information. It fetches details like the number of tags, group ID, taxonomy, target, and link pattern. It also supports caching for premium users. The shortcode allows customization of HTML id and class. It can render information for all groups, a specific group, or multiple groups. It also provides the option to not cache the output.

Shortcode: [tag_groups_info]

Parameters

Here is a list of all possible tag_groups_info shortcode parameters and attributes:

  • do_not_cache – if set to true, the output will not be cached
  • info – determines the type of tag group information to display
  • group_id – specifies the tag groups to show; ‘all’ for all groups, comma-separated IDs for specific groups
  • html_id – sets the ID attribute of the output HTML element
  • html_class – sets the class attribute of the output HTML element
  • taxonomy – specifies the taxonomy to which the tags belong
  • target – sets the target attribute of the links in the output
  • link_pattern – determines the URL structure of the links in the output

Examples and Usage

Basic example – Display the number of tags for all groups

[tag_groups_info info="number_of_tags" group_id="all" /]

Advanced examples

Display the number of tags for a specific group with an ID of 5

[tag_groups_info info="number_of_tags" group_id="5" /]

Display the number of tags for multiple groups with IDs 2, 3 and 4, and add a custom HTML class

[tag_groups_info info="number_of_tags" group_id="2,3,4" html_class="my-custom-class" /]

Display the number of tags for a specific group with an ID of 3, and open the links in a new tab

[tag_groups_info info="number_of_tags" group_id="3" target="_blank" /]

Display the number of tags for all groups, add a custom HTML class and ID, and use a custom link pattern

[tag_groups_info info="number_of_tags" group_id="all" html_id="my-id" html_class="my-class" link_pattern="{name}" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [tag_groups_info] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'tag_groups_info', array( $object_TagGroups_Shortcode_Info, 'tag_groups_info' ) );

Shortcode PHP function:

                    function tag_groups_info( $atts = array() )
        {
            $this->init();
            global  $tag_group_groups ;
            $this->shortcode_id = 'tag_groups_info';
            if ( is_array( $atts ) ) {
                asort( $atts );
            }
            $cache_key = md5( 'tag_groups_info' . serialize( $atts ) );
            // check for a cached version (premium plugin)
            $html = apply_filters( 'tag_groups_hook_cache_get', false, $cache_key );
            if ( $html ) {
                return $html;
            }
            extract( shortcode_atts( array(
                'do_not_cache' => false,
                'info'         => 'number_of_tags',
                'group_id'     => 'all',
                'html_id'      => '',
                'html_class'   => '',
                'taxonomy'     => null,
                'target'       => '_self',
                'link_pattern' => '{slug}',
            ), $atts ) );
            
            if ( !empty($div_id) ) {
                $id_string = ' id="' . $html_id . '"';
            } else {
                $id_string = '';
            }
            
            
            if ( !empty($html_class) ) {
                $class_string = ' class="' . $html_class . '"';
            } else {
                $class_string = '';
            }
            
            $this->get_taxonomies();
            
            if ( 'all' == $group_id ) {
                $term_groups = $tag_group_groups->get_group_ids_by_position();
                $output = $this->render_table(
                    $id_string,
                    $class_string,
                    $term_groups,
                    $info,
                    $target,
                    $link_pattern
                );
            } elseif ( strpos( $group_id, ',' ) !== false ) {
                $term_groups = array_map( 'intval', explode( ',', $group_id ) );
                $output = $this->render_table(
                    $id_string,
                    $class_string,
                    $term_groups,
                    $info,
                    $target,
                    $link_pattern
                );
            } else {
                $output = $this->render_one(
                    $id_string,
                    $class_string,
                    (int) $group_id,
                    $info,
                    $target,
                    $link_pattern
                );
            }
            
            if ( !$this->attributes->do_not_cache ) {
                // create a cached version (premium plugin)
                do_action( 'tag_groups_hook_cache_set', $this->cache_key, $html );
            }
            return $output;
        }
                    

Code file location:

tag-groups/tag-groups/include/helpers/class.shortcode_statics.php

Tag Groups [tag_groups_tag_list] Shortcode

The Tag Groups shortcode ‘tag_groups_tag_list’ is used to generate a list of tags grouped by their assigned categories. This shortcode is highly customizable with attributes like ‘amount’, ‘column_count’, ‘order’, and ‘orderby’ to control the display. It fetches the tags from the database and sorts them based on the assigned attributes. The ‘tag_groups_tag_list’ shortcode also includes caching functionality to improve performance.

Shortcode: [tag_groups_tag_list]

Parameters

Here is a list of all possible tag_groups_tag_list shortcode parameters and attributes:

  • add_premium_filter – Determines if a premium filter should be added.
  • amount – Specifies the number of tags to display.
  • append – Additional text appended to the tag list.
  • assigned_class – CSS class for the assigned tags.
  • column_count – The number of columns in the tag list.
  • column_gap – The space between columns in the tag list.
  • custom_title – Custom title for the tag list.
  • custom_title_zero – Title displayed when there are no tags.
  • div_class – CSS class for the tag list container.
  • div_id – Unique ID for the tag list container.
  • do_not_cache – Determines if the tag list should not be cached.
  • exclude – Excludes certain tags from the list.
  • group_in_class – Group tags in a specific CSS class.
  • groups_post_id – Post ID to get the tag groups from.
  • h_level – HTML heading level for the title.
  • header_class – CSS class for the tag list title.
  • hide_empty_content – Hide tag list if there are no tags.
  • hide_empty – Hide tags that have no posts associated with them.
  • include – Only include certain tags in the list.
  • keep_together – Keep tag groups together in the list.
  • largest – Font size for the largest tag.
  • link_append – Text appended to each tag link.
  • link_target – The target of the tag links.
  • not_assigned_name – Name for tags not assigned to a group.
  • order – Order of the tags in the list (ASC or DESC).
  • orderby – Field to order the tags by.
  • prepend – Text prepended to each tag in the list.
  • remove_filters – Remove filters from the tags.
  • show_not_assigned – Show tags not assigned to any group.
  • show_all_groups – Show all tag groups, regardless of posts.
  • show_tag_count – Show the number of posts for each tag.
  • smallest – Font size for the smallest tag.
  • source – Source of the tags (shortcode).
  • tags_div_class – CSS class for the tags container.
  • tags_post_id – Post ID to get the tags from.
  • taxonomy – Taxonomy to get the tags from.
  • threshold – Minimum number of posts a tag must have to be included.

Examples and Usage

Basic example – Display a list of tags grouped by their assigned categories. The list will be arranged in ascending order by name.

[tag_groups_tag_list order="ASC" orderby="name" /]

Advanced examples

Display a list of tags grouped by categories with a custom title. The list will be arranged in ascending order by name and the tags will be displayed in two columns with a gap of 10px.

[tag_groups_tag_list order="ASC" orderby="name" column_count=2 column_gap="10px" custom_title="My Custom Title" /]

Display a list of tags grouped by categories excluding certain tags. The list will be arranged in ascending order by name, the tags will be displayed in two columns with a gap of 10px and the tags with ids 5, 10 and 15 will be excluded.

[tag_groups_tag_list order="ASC" orderby="name" column_count=2 column_gap="10px" exclude="5,10,15" /]

Display a list of tags grouped by categories including certain tags only. The list will be arranged in ascending order by name, the tags will be displayed in two columns with a gap of 10px and only the tags with ids 1, 2 and 3 will be included.

[tag_groups_tag_list order="ASC" orderby="name" column_count=2 column_gap="10px" include="1,2,3" /]

Display a list of tags grouped by categories with a custom title and showing the tag count. The list will be arranged in ascending order by name, the tags will be displayed in two columns with a gap of 10px and the count of posts associated with each tag will be shown.

[tag_groups_tag_list order="ASC" orderby="name" column_count=2 column_gap="10px" custom_title="My Custom Title" show_tag_count=true /]

PHP Function Code

In case you have difficulties debugging what causing issues with [tag_groups_tag_list] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'tag_groups_tag_list', array( $object_TagGroups_Shortcode_Tag_List, 'tag_groups_tag_list' ) );

Shortcode PHP function:

                    function tag_groups_tag_list( $atts = array() )
        {
            $this->init();
            $this->shortcode_id = 'tag_groups_tag_list';
            $this->set_attributes( shortcode_atts( array(
                'add_premium_filter'  => 0,
                'amount'              => 0,
                'append'              => '',
                'assigned_class'      => null,
                'column_count'        => 2,
                'column_gap'          => '10px',
                'custom_title'        => null,
                'custom_title_zero'   => null,
                'custom_title_plural' => null,
                'div_class'           => 'tag-groups-tag-list',
                'div_id'              => '',
                'do_not_cache'        => false,
                'exclude'             => '',
                'exclude_terms'       => '',
                'group_in_class'      => 0,
                'groups_post_id'      => -1,
                'h_level'             => 3,
                'header_class'        => '',
                'hide_empty_content'  => false,
                'hide_empty'          => true,
                'include'             => '',
                'include_terms'       => '',
                'keep_together'       => 1,
                'largest'             => 12,
                'link_append'         => '',
                'link_target'         => '',
                'not_assigned_name'   => 'not assigned',
                'order'               => 'ASC',
                'orderby'             => 'name',
                'prepend'             => '',
                'remove_filters'      => 1,
                'show_not_assigned'   => false,
                'show_all_groups'     => false,
                'show_tag_count'      => true,
                'smallest'            => 12,
                'source'              => 'shortcode',
                'tags_div_class'      => 'tag-groups-tag-list-tags',
                'tags_post_id'        => -1,
                'taxonomy'            => implode( ',', TagGroups_Taxonomy::get_enabled_taxonomies() ),
                'threshold'           => 0,
            ), $atts ) );
            /**
             * Don't set it as default in extract( shortcode_atts() ) because the block sends an empty string
             */
            if ( empty($this->attributes->html_id) ) {
                $this->attributes->html_id = 'tag-groups-tag-list-' . uniqid();
            }
            $div_id_output = ( $this->attributes->html_id ? ' id="' . TagGroups_Shortcode_Statics::sanitize_html_classes( $this->attributes->html_id ) . '"' : '' );
            $div_class_output = ( $this->attributes->div_class ? ' class="' . TagGroups_Shortcode_Statics::sanitize_html_classes( $this->attributes->div_class ) . '"' : '' );
            $div_column_output = ( empty($this->attributes->column_count) ? '' : ' style="column-count:' . (int) $this->attributes->column_count . '; column-gap:' . $this->attributes->column_gap . '"' );
            if ( is_array( $atts ) ) {
                asort( $atts );
            }
            /**
             * Call this before creating the cache key
             */
            $this->get_post_id();
            $this->cache_key = md5( 'tag_list' . serialize( $atts ) . serialize( $this->attributes->tags_post_id ) . serialize( $this->attributes->groups_post_id ) );
            // check for a cached version (premium plugin)
            $html = apply_filters( 'tag_groups_hook_cache_get', false, $this->cache_key );

            if ( $html ) {
                $html = $this->finalize_html(
                    $html,
                    $div_id_output,
                    $div_class_output,
                    $div_column_output,
                    $atts
                );
                return $html;
            }

            $this->check_attributes();
            $this->get_taxonomies();
            $this->get_tags();
            $this->make_include_array();
            $this->maybe_add_post_tags_or_groups();
            // apply sorting that cannot be done on database level
            if ( 'natural' == $this->attributes->orderby || 'random' == $this->attributes->orderby || $this->attributes->threshold ) {
                $this->sort();
            }
            $html = $this->make_html();
            $html = $this->finalize_html(
                $html,
                $div_id_output,
                $div_class_output,
                $div_column_output,
                $atts
            );
            return $html;
        }
                    

Code file location:

tag-groups/tag-groups/include/helpers/class.shortcode_statics.php

Tag Groups [tag_groups_alphabetical_index] Shortcode

The Tag Groups Alphabetical Index shortcode is used to create an alphabetical index of tags. It provides customization options like column count, gap, and sorting order. This shortcode generates an index with tags assigned to letters. It supports multiple taxonomies, tag sizes, and allows to include or exclude specific tags/letters.

Shortcode: [tag_groups_alphabetical_index]

Parameters

Here is a list of all possible tag_groups_alphabetical_index shortcode parameters and attributes:

  • amount – number of tags to display
  • append – additional string to add to each tag
  • assigned_class – custom CSS class for the tags
  • do_not_cache – if true, the output will not be cached
  • column_count – number of columns for the tag display
  • column_gap – space between the columns
  • custom_title – custom title for the tag group
  • div_class – CSS class for the outer div of the tag list
  • div_id – unique identifier for the tag list div
  • exclude – tags to exclude from the list
  • h_level – heading level for the tag group title
  • hide_empty – if true, tags without posts will be hidden
  • include – specific tags to include in the list
  • largest – font size for the most frequently occurring tags
  • order – sorting order of the tags, either ‘ASC’ or ‘DESC’
  • orderby – parameter to sort the tags by
  • show_tag_count – if true, the number of posts for each tag will be displayed
  • smallest – font size for the least frequently occurring tags
  • taxonomy – taxonomies to include in the tag list

Examples and Usage

Basic example – Display tags in an alphabetical index with default parameters.

[tag_groups_alphabetical_index /]

Advanced examples

Display tags in an alphabetical index with a specific amount, custom title, and a column count of 3.

[tag_groups_alphabetical_index amount=10 custom_title="My Custom Title" column_count=3 /]

Display tags in an alphabetical index excluding certain letters and terms, and changing the order to descending.

[tag_groups_alphabetical_index exclude_letters="Q,X,Z" exclude_terms="term1, term2" order="DESC" /]

Display tags in an alphabetical index with a custom div class and id, and a column gap of 20px.

[tag_groups_alphabetical_index div_class="my-custom-class" div_id="my-custom-id" column_gap="20px" /]

Display tags in an alphabetical index with a specific taxonomy and showing tag count.

[tag_groups_alphabetical_index taxonomy="post_tag" show_tag_count=true /]

PHP Function Code

In case you have difficulties debugging what causing issues with [tag_groups_alphabetical_index] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'tag_groups_alphabetical_index', array( $object_TagGroups_Shortcode_Alphabetical_Index, 'tag_groups_alphabetical_index' ) );

Shortcode PHP function:

                    function tag_groups_alphabetical_index( $atts = array() ) {

      $this->init();
      
      $this->shortcode_id = 'tag_groups_alphabetical_index';

      $this->set_attributes( shortcode_atts( array(
        'amount' => 0,
        'append' => '',
        'assigned_class' => '',
        'do_not_cache' => false,
        'column_count'  => 2,
        'column_gap'  => '10px',
        'custom_title' => null,
        'custom_title_zero' => null,
        'custom_title_plural' => null,
        'div_class' => 'tag-groups-alphabetical-index',
        'div_id' => '',
        'exclude' => '',
        'exclude_letters' => '',
        'exclude_terms' => '',
        'h_level' => 3,
        'header_class' => '',
        'hide_empty' => true,
        // 'hide_empty_content' => false, // doesn't make sense here
        'ignore_accents' => false,
        'include' => '',
        'include_letters' => '',
        'include_terms' => '',
        'keep_together' => 1,
        'largest' => 12,
        'link_append' => '',
        'link_target' => '',
        'locale'  => '',
        'min_max_per_letter' => 0, // option to assign post counts to font sizes for each letter separately
        'order' => 'ASC',
        'orderby' => 'name',
        'prepend' => '',
        'remove_filters' => 1,
        'show_tag_count' => true,
        'smallest' => 12,
        'source' => 'shortcode',
        'tags_div_class' => 'tag-groups-alphabetical-index-tags',
        'tags_post_id' => -1,
        'taxonomy' => implode( ',', TagGroups_Taxonomy::get_enabled_taxonomies() ),
        'threshold' => 0, // minimum number of posts, total (independent of groups)
      ), $atts ) );


      /**
       * Don't set it as default in extract( shortcode_atts() ) because the block sends an empty string
       */
      if ( empty( $this->attributes->html_id ) ) {

        $this->attributes->html_id = 'tag-groups-alphabetical-index-' . uniqid();

      }

      $div_id_output = $this->attributes->html_id ? ' id="' . TagGroups_Shortcode_Statics::sanitize_html_classes( $this->attributes->html_id ) . '"' : '';

      $div_class_output = $this->attributes->div_class ? ' class="' . TagGroups_Shortcode_Statics::sanitize_html_classes( $this->attributes->div_class ) . '"' : '';

      $div_column_output = empty( $this->attributes->column_count ) ? '' : ' style="column-count:' . (int) $this->attributes->column_count .'; column-gap:' . $this->attributes->column_gap .'"' ;

      if ( is_array( $atts ) ) {

        asort( $atts );

      }

      /**
       * Call this before creating the cache key
       */
      $this->get_post_id();

      $this->cache_key = md5( 'tag_alphabetical_index' . serialize( $atts ) . serialize( $this->attributes->tags_post_id ) );

      // check for a cached version (premium plugin)
      $html = apply_filters( 'tag_groups_hook_cache_get', false, $this->cache_key );

      if ( $html ) {

        $html = $this->finalize_html( $html, $div_id_output, $div_class_output, $div_column_output, $atts );

        return $html;

      }

      $this->check_attributes();

      $this->get_taxonomies();

      $this->get_tags();

      $this->make_include_array();

      $this->maybe_add_post_tags_or_groups();

      // apply sorting that cannot be done on database level
      if ( 'natural' == $this->attributes->orderby || 'random' == $this->attributes->orderby || $this->attributes->threshold ) {

        $this->sort();
        
      }


      /**
      * Extract the alphabet
      */
      $this->extract_alphabet();

      $this->include_exclude_letters();

      $this->sort_alphabet();


      $this->make_headings_HTML();

      /*
      *  render the tab content
      */
      $this->determine_min_max_alphabet();

      $html = $this->add_tags_HTML();


      if (  ! $this->attributes->do_not_cache ) {

        // create a cached version (premium plugin)
        do_action( 'tag_groups_hook_cache_set', $this->cache_key, $html );

      }

      $html = $this->finalize_html( $html, $div_id_output, $div_class_output, $div_column_output, $atts );

      return $html;

    }
                    

Code file location:

tag-groups/tag-groups/include/helpers/class.shortcode_statics.php

Conclusion

Now that you’ve learned how to embed the Tag Groups Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *