• Hi,

    I hope someone can help me with this problem as i’ve been trying for days..
    I cant get my paging works well inside single page (custom post)

    I created a WP site with custom post type UI.

    == Structure ==
    Custom post type UI : mypost
    Custom taxonomy: mycategory
    Terms in “mycategory” : cat1

    == What i wanna do ==
    This’s the result i wanna have.

    <div class=left>
    <!-- All posts in the same term -->
    <p>Post1</p>
    <p>Post2</p>
    <p>Post3</p>
    </div>
    <div class=right>
    <!-- contents of the post when clicked -->
    <p>the_contents() for Post1</p>
    </div>

    My URL is https://domain/cat1/post1-title
    I created a single-cat1.php for this.

    The_contents()for post1 is easy

    <?php if(have_posts() ): while(have_posts()) : the_post(); ?>
    <p><?php esc_html(the_content()); ?>
    <?php endwhile; endif; ?>

    BUT i cant get my left menu works well..

    Method 1

    <?php
    $args = array(
        'post_type' => 'mypost',
        'post_per_page' => '2',
        'tax_query' => array(
            array(
                'taxonomy' => 'mycat',
                'field'    => 'slug',
                'terms'    => "cat1",
            )
        )
    );
    $loop = new WP_Query($args);
    while($loop->have_posts()) : $loop->the_post();
    ?>
    <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
    
    <p><?php previous_posts_link('PREV'); ?></p>
    <p><?php next_posts_link('NEXT'); ?></p>

    The previous_posts_link & next_posts_link shows nothing.

    Method 2

    <?php
    $t = array_shift(get_the_terms($post->ID, 'mycat'));
    $tposts = get_posts('post_type=mypost&posts_per_page=2&taxonomy=mycat&term=cat1');
    foreach($tposts as $tp) :
    ?>
    <p><a href="<?php echo get_permalink($tp->ID); ?>"><?php echo esc_html($tp->post_title); ?></a></p>
    <?php endforeach; ?>
    
    <p><?php previous_posts_link('PREV'); ?></p>
    <p><?php next_posts_link('NEXT'); ?></p>

    The PREV or NEXT link is supposed to be paging for the left menu (list of posts within same term).

    Would appreciate if anyone could help.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to display post lists in the same term with paging’ is closed to new replies.