ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Pagination always shows the same posts.

June 07, 2012 1:44pm

Subscribe [2]
  • #1 / Jun 07, 2012 1:44pm

    ehime

    6 posts

    In order for me to correctly put in pagination, I’ve had to make two seperate loops,
    unfortunetly it shows the same two products over and over, regardless of page. How
    can I fix this?

    <section id="{embed:chan}" class="product-content">
       <div class="wrap">
    
        <hgroup>
         <h1>{embed:title}</h1>
    
         {embed="products/.sub-nav"}
    
        </hgroup>
    
        <ul class='list-column-3'>
        {exp:channel:entries channel="{embed:chan}" category="{embed:cat_id}" status="{embed:stat}" limit="{embed:limt}" paginate="bottom"}
    
         <li>
          <article>
    
           {if no_results}No Products in this Channel, check channel info?{/if}
           {if product_blurb_image}{product_blurb_image}{/if}
    
           <h1>{title}</h1>
           {product_blurb}
          
          </article>
          <a href="http://{comment_url_title_auto_path}class=red-btn">Learn More</a>
         </li>
      
         {!-- The below is needed for a true 3 column layout --}
         {switch="||</ul><ul class='list-column-3'>"}
    
        {/exp:channel:entries}
        </ul>
    
    
        <ul class="product-pager">
        {exp:channel:entries channel="{embed:chan}" category="{embed:cat_id}" status="{embed:stat}" limit="{embed:limt}" paginate="bottom"}
            {paginate}
                {pagination_links}
    
                       {previous_page}
            <li><a href="http://{pagination_url}%22class=%22prev" class="prev ir"> </a></li>
                       {/previous_page}
    
                       {page}
                              <li><a href="http://{pagination_url}" class="{if current_page}curr{/if}">{pagination_page_number}</a></li>
                       {/page}
    
                       {next_page}
            <li><a href="http://{pagination_url}%22class=%22next" class="next ir"> </a></li>
                       {/next_page}
    
                {/pagination_links}
            {/paginate}
        {/exp:channel:entries}
        </ul>
    
        <div class="clear"></div>  
    
       </div>
      </section><!--/{embed:chan}-->

    EDIT

    This works, but I can’t close the last UL tag when there are no pages (no content), or there is only one page =(

    <section id="{embed:chan}" class="product-content">
        <div class="wrap">
    
         <hgroup>
          <h1>{embed:title}</h1>
    
          {embed="products/.sub-nav"}
    
         </hgroup>
    
         <ul class='list-column-3'>
         {exp:channel:entries channel="{embed:chan}" category="{embed:cat_id}" status="{embed:stat}" limit="{embed:limt}" paginate="bottom"}
    
          <li>
           <article>
    
            {!-- I could put the closing </ul> here, but then it'd only show if there was nadda' --} 
    
            {if no_results}No Products in this Channel, check channel info?{/if}
            {if product_blurb_image}{product_blurb_image}{/if}
    
            <h1>{title}</h1>
            {product_blurb}
           
           </article>
           <a href="http://{comment_url_title_auto_path}class=red-btn">Learn More</a>
          </li>
       
          {!-- The below is needed for a true 3 column layout --}
          {switch="||</ul><ul class='list-column-3'>"}
    
             {paginate}
    
           {!-- Close last "list-column-3" open "product-pager" --} 
           </ul><ul class="product-pager">
                 {pagination_links}
    
                        {previous_page} <li><a href="http://{pagination_url}%22class=%22prev" class="prev ir"> </a></li> {/previous_page}
    
                        {page} <li><a href="http://{pagination_url}" class="{if current_page}curr{/if}">{pagination_page_number}</a></li> {/page}
    
                        {next_page} <li><a href="http://{pagination_url}%22class=%22next" class="next ir"> </a></li> {/next_page}
    
                 {/pagination_links}
           </ul>
    
           {!-- This shoulld work, but doesn't --}
           {if "{total_pages}" == 1} </ul> {/if}
    
             {/paginate}
    
         {/exp:channel:entries}
    
         <div class="clear"></div>  
    
        </div>
       </section><!--/{embed:chan}-->
  • #2 / Jun 07, 2012 2:13pm

    Manoj Thomas

    185 posts

    Does something like this work? I moved the pagination code inside your first loop and got rid of the second loop.

    <section id="{embed:chan}" class="product-content">
       <div class="wrap">
    
        <hgroup>
         <h1>{embed:title}</h1>
    
         {embed="products/.sub-nav"}
    
        </hgroup>
    
        
        {exp:channel:entries channel="{embed:chan}" category="{embed:cat_id}" status="{embed:stat}" limit="{embed:limt}" paginate="bottom"}
    
        {if count == '1'}<ul class='list-column-3'>{/if}
    
         <li>
          <article>
    
           {if no_results}No Products in this Channel, check channel info?{/if}
           {if product_blurb_image}{product_blurb_image}{/if}
    
           <h1>{title}</h1>
           {product_blurb}
          
          </article>
          <a href="http://{comment_url_title_auto_path}class=red-btn">Learn More</a>
         </li>
      
         {!-- The below is needed for a true 3 column layout --}
         {switch="||</ul><ul class='list-column-3'>"}
    
        {if count == total_results}</ul>{/if}
    
    
    
            {paginate}
            <ul class="product-pager">
    
                {pagination_links}
    
                       {previous_page}
            <li><a href="http://{pagination_url}%22class=%22prev" class="prev ir"> </a></li>
                       {/previous_page}
    
                       {page}
                              <li><a href="http://{pagination_url}" class="{if current_page}curr{/if}">{pagination_page_number}</a></li>
                       {/page}
    
                       {next_page}
            <li><a href="http://{pagination_url}%22class=%22next" class="next ir"> </a></li>
                       {/next_page}
    
                {/pagination_links}
    
           </ul>
            {/paginate}
    
    
    
        {/exp:channel:entries}
        
    
    
        <div class="clear"></div>  
    
       </div>
      </section><!--/{embed:chan}-->
  • #3 / Jun 07, 2012 4:58pm

    ehime

    6 posts

    Actually I gave up and used some php =P
    I’m a quiter, I know 😉

    I did something similar with moving inside the first loop and losing the
    second, which seemed to be the main issue anyway. Won’t lie, yours is a
    lot more semantic.

    <?php $i=0; ?> {!-- Start incrementation --}
       <section id="{embed:chan}" class="product-content">
        <div class="wrap">
    
         <hgroup>
          <h1>{embed:title}</h1>
    
          {embed="products/.sub-nav"}
    
         </hgroup>
    
         <ul class='list-column-3'>
         {exp:channel:entries channel="{embed:chan}" category="{embed:cat_id}" status="{embed:stat}" limit="{embed:limt}" paginate="bottom"}
         <?php $i++; ?> {!-- Increment --}
    
          <li>
           <article>
    
            {!-- I could put the closing </ul> here, but then it'd only show if there was nadda' --} 
    
            {if no_results}No Products in this Channel, check channel info?{/if}
            {if product_blurb_image}{product_blurb_image}{/if}
    
            <h1>{title}</h1>
            {product_blurb}
           
           </article>
           <a href="http://{comment_url_title_auto_path}class=red-btn">Learn More</a>
          </li>
       
          {!-- The below is needed for a true 3 column layout --}
          {switch="||</ul><ul class='list-column-3'>"}
    
             {paginate}
    
           {!-- Close last "list-column-3" open "product-pager" --} 
           </ul><ul class="product-pager">
                 {pagination_links}
    
                        {previous_page} <li><a href="http://{pagination_url}%22class=%22prev" class="prev ir"> </a></li> {/previous_page}
    
                        {page} <li><a href="http://{pagination_url}" class="{if current_page}curr{/if}">{pagination_page_number}</a></li> {/page}
    
                        {next_page} <li><a href="http://{pagination_url}%22class=%22next" class="next ir"> </a></li> {/next_page}
    
                 {/pagination_links}
           </ul>
    
             {/paginate}
    
         {/exp:channel:entries}
    
         {!-- Because this is so screwed up that you can't say if --} 
         {!-- !paginate, use php to count the totals and ad an end UL --}
         <?php echo ($i<{embed:limt})?'</ul>':'';?> 
    
         <div class="clear"></div>  
    
        </div>
       </section><!--/{embed:chan}-->
  • #4 / Jun 08, 2012 3:35pm

    Dan Decker

    7338 posts

    Hi ehime,

    It looks like you and Manjo sorted this one out, but is there anything else I can do?

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases