Site logo

[Support request] How can I show my custom post type categories

Home Forums Support [Support request] How can I show my custom post type categories

Home Forums Support How can I show my custom post type categories

  • This topic has 1 reply, 2 voices, and was last updated 3 years ago by David.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2566220
    Jaume

    Hi, I created a custom post type called Directory with its own categories. All fine.

    But now, I need to show the categories in my home page, as shown in this image: https://postimg.cc/ykLvKBRP. I don’t need to show the posts but the categories.

    I tried to use the loop, but I cannot find the way to tell the lopp to show the categories.

    Any idea on how to achieve this?

    Thank you.

    Raquel

    #2566528
    David
    Staff
    Customer Support

    Hi there,

    the Query Loop will only return posts at this time.
    We will be adding other content types to GB Pro in the future.

    If you want to get the taxonomy terms, you can use a PHP Snippet to create your own shortcode:

    function custom_taxonomy_terms_shortcode( $atts ) {
        $atts = shortcode_atts( array(
            'taxonomy' => '',
        ), $atts );
    
        $terms = get_terms( array(
            'taxonomy' => $atts['taxonomy'],
            'hide_empty' => false,
        ) );
    
        $output = '<ul class="tax-grid">';
    
        foreach ( $terms as $term ) {
            $term_link = get_term_link( $term );
    
            if ( is_wp_error( $term_link ) ) {
                continue;
            }
    
            $output .= '<li class="tax-grid-item"><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>';
        }
    
        $output .= '</ul>';
    
        return $output;
    }
    add_shortcode( 'custom_taxonomy_terms', 'custom_taxonomy_terms_shortcode' );
    

    This doc explains adding PHP: https://docs.generatepress.com/article/adding-php/

    Then you can add the list your page with this shortcode: [custom_taxonomy_terms taxonomy="your_taxonomy_name"]

    It will require some CSS to make it into a grid.
    Which I can provide if you can share a link to the page where the list is displayed

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.