Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Tabbed posts categories with pagination

Discussion in 'Misc WordPress Requests' started by Kristis, Jan 24, 2018.

  1. Kristis

    Guest

    Tabbed posts categories with pagination, by Kristis

    Currently, I have a blog page with looped posts categories tabs and posts block in each category.

    Now pagination is working not separately on each category tab.

    My problem is that I can’t figure out how to use pagination on each category tab and have the user be able to select the page on that tab and stay on that tab.

    I’m using page-navi plugin for pagination.

    Thank you for any help!

    index.php

    <?php if ( is_home() ) : ?>
    <div id="primary" class="content-area <?php echo ( get_theme_mod( 'nikkon-blog-full-width', false ) ) ? sanitize_html_class( 'content-area-full' ) : ''; ?>">
    <?php else : ?>
    <div id="primary" class="content-area">
    <?php endif; ?>

    <div class="tab-content clearfix">
    <?php
    $categories = get_categories( array( 'orderby' => 'term_id', 'order' => 'ASC',) );

    $i=0;
    $_active = '';
    foreach ( $categories as $category ) {
    $_active = ($i == 0 ? ' active' : '');
    echo "\n";
    echo sprintf('<div class="tab-pane%s" id="%s">',
    $_active, str_replace( ' ', '-', strtolower( $category->cat_name ) )
    );
    echo "\n";
    $_loop = new WP_Query( array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'cat' => $category->term_id,
    'paged' => $paged
    ) );

    echo "\n";
    echo '<main id="main" class="site-main" role="main">';
    echo "\n";

    get_template_part( '/templates/titlebar' );

    if ( $_loop->have_posts() ):

    echo "\n<!--//**************** BEGIN POSTS ***************************//-->\n";

    //original:
    // <div class="blog-blocks-wrap blog-blocks-wrap-remove blog-columns-three blog-style-postblock">
    //echo ( get_theme_mod( 'nikkon-blog-layout' ) == 'blog-blocks-layout' ) ? '<div class="blog-blocks-wrap blog-blocks-wrap-remove blog-columns-three ' . sanitize_html_class( $blog_style ) . '">' : '';
    echo '<div class="blog-blocks-wrap blog-columns-three blog-style-postblock">';

    // original:
    // <div class="blog-blocks-wrap-inner">
    //echo ( get_theme_mod( 'nikkon-blog-layout' ) == 'blog-blocks-layout' ) ? '<div class="blog-blocks-wrap-inner">' : '';
    echo '<div>';

    while ( $_loop->have_posts() ) : $_loop->the_post();

    get_template_part( 'templates/contents/content' );

    endwhile;

    echo ( get_theme_mod( 'nikkon-blog-layout' ) == 'blog-blocks-layout' ) ? '<div class="clearboth"></div></div>' : '';

    echo ( get_theme_mod( 'nikkon-blog-layout' ) == 'blog-blocks-layout' ) ? '</div>' : '';

    echo "\n<!--//**************** END POSTS ***************************//-->\n";

    else:

    get_template_part( 'templates/contents/content', 'none' );

    endif;

    echo "\n";
    echo '</main>';

    echo "\n";
    echo '</div>';
    echo "\n";
    $i++;
    }
    ?>
    </div>

    <!-- posts pagination -->
    <?php wp_pagenavi(); ?>

    category.php

    <section id="post-nav">
    <div class="nav-container">
    <div class="nav-flexy">
    <div class="nav-flexy_item">
    <ul id="post-tabs" class="nav nav-tabs">
    <?php
    $categories = get_categories( array(
    'orderby' => 'term_id',
    'order' => 'ASC'
    ) );
    $i=0;
    foreach( $categories as $category ) {
    $_name = $category->name;
    $_href = str_replace(' ','-',strtolower($_name));
    if ($i == 0) {
    echo sprintf('<li class="active"><a href="#%s" data-toggle="tab">%s</a></li>',
    esc_attr( $_href ), esc_html( $_name ) );
    } else {
    echo sprintf('<li><a href="#%s" data-toggle="tab">%s</a></li>',
    esc_attr( $_href ), esc_html( $_name ) );
    }
    echo "\n";
    $i++;
    }
    ?>
    </ul>
    </div>
    </div>
    </div>
    </section>

    Tabbed posts categories with pagination
     
    #1

Share This Page

Monarch Social Sharing Plugin