[Support request] Local Navigation

Home Forums Support [Support request] Local Navigation

Home Forums Support Local Navigation

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2194039
    Sophia

    Hi there,

    I‘m trying to implement a local navigation to the archive-pages (I got a few of them). The navigation should be on the left sidebar and contain the links to all posts of the taxonomy – so it should be dynamic. Is there any way to do this with GeneratePress?

    Nice regards,
    Sophia

    #2194368
    David
    Staff
    Customer Support

    Hi there,

    just to be clear, on the archive page, you want to list all posts of that same taxonomy term in the sidebar ?

    #2194394
    Sophia

    Yes, exactly – like a index of content of the archive page. And the index changes, when the user moves to another taxonomies archive page.

    #2194450
    David
    Staff
    Customer Support

    Sorry for the questions, but does that not mean you will have duplicate posts effectively? As the archive will be listing the posts, and you will also have them listed in the sidebar ? What am i missing 🙂

    #2206182
    Sophia

    Hi,

    sorry for delated answer. No, I’m not duplicating – I was just wondering if there is a way to display a dynamic taxonomy archives list – so all the posts by taxonomys terms (I’ve got different taxonomies and therefor different archive-pages) as a list anchored to the post-id.
    I would like to place the list in a sticky side bar as a local navigation on this side, because our costumer does not want to display just excerpts but the whole posts on the archive page. So it wouldn’t be very user friendly without the additional list…

    #2206441
    David
    Staff
    Customer Support

    Ok – so you could create your own Shortcode to display the list.
    Try adding this PHP Snippet to your site:

    function db_show_posts_in_category() {
        $string = '';
        $cat = get_queried_object()->term_id;
        $the_query = new WP_Query( array( 
            'cat' => $cat, 
            'posts_per_page' => 5 
        ) ); 
           
        // The Loop
        if ( $the_query->have_posts() ) {
            $string .= '<ul class="category_posts_list">';
            while ( $the_query->have_posts() ) {
                $the_query->the_post();
                    $string .= '<li>';
                    $string .= '<a href="' . get_the_permalink() .'" rel="bookmark">'  . get_the_title() .'</a></li>';    
                }
            } 
        
        $string .= '</ul>';
           
        return $string;
           
        /* Restore original Post Data */
        wp_reset_postdata();
    }
    add_shortcode('show_cat_posts', 'db_show_posts_in_category');

    That will create this shortcode: [show_cat_posts]

    Which you could add to your archive pages using a Hook Element:

    https://docs.generatepress.com/article/hooks-element-overview/

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