WordPress.org

Ready to get started?Download WordPress

Forums

In a list of terms show the posts in a current term next to it(current term) (5 posts)

  1. nookaround
    Member
    Posted 2 years ago #

    With this code parent term page lists all the child terms and the child term page lists all of the posts in current term, and the single page lists a big flat list of terms(hierarchical).

    Now,

    The parent term page is fine.

    When it's child term page, i want to list all child terms( not showing with this code ) + the posts in current term( showing ).

    And when it's single post, i want to list the same as child term page.

    $term = get_queried_object();
            $tax = 'ntp_package_type';
            $parents = $term->parent;
            $term_id = $term->term_id;
    
            if($parents == 0){
                wp_list_categories( array (
                                'taxonomy'  => 'ntp_package_type',
                                'pad_counts'=> 0,
                                'title_li'  => '',
                                'child_of'  => $term_id,
                                )
                );
            }
            elseif (is_tax($tax, $term->name)){
    
                $args = array(
                        'post_type' => 'ntp_package',
                        $tax => $term->name,
                );
                $wp_query = new WP_Query($args);
                if( $wp_query->have_posts() ):
                while ( $wp_query->have_posts() ) : $wp_query->the_post();
                echo "<p><a>".$post->post_title."</a></p>";
                endwhile;
                endif;
    
            }
            elseif (is_single()){
    
            }

    It is for a sidebar sub nav. is it a right way to do? I'd really appreciate any help.

  2. Andrew
    Forum Moderator
    Posted 2 years ago #

    Can you wrap code using Backticks or the (code) button above your post?

  3. nookaround
    Member
    Posted 2 years ago #

    Hey i tried it says, "Post is too old", what's that?

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    Hey i tried it says, "Post is too old", what's that?

    Users can edit a post for up to 60 minutes from the time of submission. After that, the post can only be edited by a moderator.

    I edited your post so that the code is formatted correctly.

  5. nookaround
    Member
    Posted 2 years ago #

    @keesiemeijer Thank you.

    have you read the question?
    i just need to concatenate the result of wp_list_categories to the is_tax() result.

    when i assign wp_list_categories to a variable and echo it outside the if ($parents == 0 ) it produces null.

    is there any way i can achieve this submenu.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags