Forum

Thread tagged as: Question

Pagination in the footer of a blog post

When I page through "related posts" in the example below the main post disappears because of how pagination works. Can I page through these while keeping the main post in place?

Example: https://cl.ly/431U3B1w0A3v

Danny Turley

Danny Turley 0 points

  • 4 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

The link is dead. We need your template to be able to offer help.

Hi Racehl,

The post.php

    <section class="blog">
      <div class="container">
        <div class="row">

        <!-- calls the template to style Case Studies. -->
        <div class="col-lg-8 col-lg-push-2">

                <?php perch_blog_post($post_slug); ?>

        </div>

        </div>
        <div class="row">
        <div class="col-lg-8 col-lg-push-2">
        <h3 class="m-b-20">Related Case Studies</h3>

          <div class="row">

            <?php  
            $categories = perch_blog_post_categories(perch_get('s'), array( 'skip-template'=>true, ));  if (count($categories)) { $cat_slugs = array(); foreach($categories as $cat) { $cat_slugs[] = $cat['catSlug']; }  
            perch_blog_custom(array( 'paginate' => true, 'filter' => 'postSlug', 'match' => 'neq', 'value' => perch_get('s'), 'sort-order'=> 'RAND', 'count'=> 2, 'template'=> 'related_posts.html', 'section'=> 'case-studies', 'set' => 'case-studies' )); }  
            ?>


        </div>
      </div>
      </div>      
     </section>

And related_posts.html template

<div class="col-lg-6 m-t-20 m-b-20">

 <perch:if exists="image">
    <div class="blog-img_cover">
        <div class="blog-img_thumb" style="background-image: url(<perch:blog id="image" type="image" crop="true" />);border-radius:10px;"></div>
    </div>
</perch:if>

<div class="article-info"> 
<h4 class="fs-20 m-t-20"><a href="<perch:blog id="postURL" />" rel="bookmark" class="entry-title"><perch:blog id="postTitle" /></a></h4>
<perch:blog id="excerpt" type="textarea" textile="true" words="15" append="..."/> 
<a class="fs-16 btn btn-rounded btn-bordered btn-complete bold" type="button" href="<perch:blog id="postURL" />">Read more</a>
</div> 

</div> 

<perch:after>
    </div>
     <perch:if exists="paging">
        <div class="paging">
            Page <perch:blog id="current_page" /> of <perch:blog id="number_of_pages" />
            <perch:blog id="page_links" encode="false" />
            <perch:if exists="not_first_page">
                <a href="<perch:blog id="prev_url" encode="false" />">Previous</a>
            </perch:if>
            <perch:if exists="not_last_page">
                <a href="<perch:blog id="next_url" encode="false" />">Next</a>
            </perch:if>
        </div>
    </perch:if>
</perch:after> 
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you have two sets of results and only want to page through one, set a custom pagination variable on the other.

perch_blog_custom([
    'pagination-var' => 'bananas',
]);