[Support request] Drop Down Menu

Home Forums Support [Support request] Drop Down Menu

Home Forums Support Drop Down Menu

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #846192
    kunal

    Hi David and Tom,

    I have some secondary navigation categories. What I would like to do have a box (almost like a Table of Contents box), that goes under the title of the category.

    The link that I provided is an illustration of what I would like to do

    GeneratePress 2.2.2
    #846789
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Should be pretty easy.

    1. Create a new Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
    2. Set the hook to after_archive_description
    3. Check the Execute PHP checkbox.
    4. Add this as your content:

    <?php
    	$current_cat = get_queried_object();
    	$args = array( 'child_of' => $current_cat->term_id );
    	$categories = get_categories( $args );
    	
    	if ( ! empty( $categories ) ) {
    		echo '<p>Find out more:</p>';
    		echo '<ul>';
    			foreach ( $categories as $category ) {
    				echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></li>';
    			}
    		echo '</ul>';
    	}
    ?>

    5. In the Display Rules, set it to “Post Category Archive”.

    #846954
    kunal

    Hi Tom, thanks for the reply… .but… still no luck! I put the code as above, and still no output. Only the environmental category has a child category, so only this category archive page should have an output, but there is no output of the children categories?
    thanks Tom!
    Kunal

    https://venture-engineering.com/environmental-site-assessments-edmonton/phase-1-esa-edmonton/update-1/

    #847030
    Tom
    Lead Developer
    Lead Developer

    Ah, you’re using a Page Hero instead of the standard archive description.

    In that case, you need to create a shortcode:

    add_shortcode( 'subcat_links', function() {
        ob_start();
        
        $current_cat = get_queried_object();
        $args = array( 'child_of' => $current_cat->term_id );
        $categories = get_categories( $args );
    	
        if ( ! empty( $categories ) ) {
            echo '<p>Find out more:</p>';
            echo '<ul>';
            foreach ( $categories as $category ) {
                echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></li>';
            }
            echo '</ul>';
        }
    
        return ob_get_clean();
    } );

    Then add the shortcode to the Header Element in the Elements area:

    [subcat_links]

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