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.

conditionals challenge - custom pagination

July 29, 2008 6:14pm

Subscribe [1]
  • #1 / Jul 29, 2008 6:14pm

    jducka1

    12 posts

    I am trying to create a kind of paginated list of products. I have multiple categories.  In each category I have between 5 and 25 products.  My client wants to allow the user to click through a paginated list of products, only showing 3-4 products at a time.  For each view of the list (each set of 3 or 4 products), the client wants to be able to control which product appears on which list (page 1 of the list, page 2, etc.). 

    To this end, I have created a custom field called “page_no.” Entries with a page_no value of “p1” display on page 1, with a ‘next’ arrow to display entries assigned to page_no “p2.”  Page 2 displays the entries with a page_no value of “p2” and a ‘next’ arrow to display the list of entries with the value “p3.”  But I only want to show the ‘next’ arrow if page 3 isn’t empty—i.e., only if they are entries in the current category that have a page_no of “p3” (in this case). 

    SO—how do I write a conditional for the Page 2 menu that says: only show the arrow to the next page if there IS a next page (i.e., if there are entries in the current category that have page_no == “p3”).  As it is currently written I am hardcoding the ‘next’ arrow for each page (i.e., I am repeating the code below for each of the up to 5 pages of products). 

    Here is my code (minus my efforts to make the ‘next’ arrow conditional):

    <!-- PAGE 2 PRODUCT LIST -->
    {exp:query sql="SELECT cat_id FROM exp_category_posts WHERE  entry_id = '{segment_3}'"}
    {exp:weblog:entries weblog="default_site" dynamic="off" orderby="custom_sort" search:page_no="p3" category="{cat_id}"}
    <li><a href="http://{path=h1/product/{entry_id}}">{related_entries id="title_image"}_{title_image_file}{/related_entries}</a></li>
    {/exp:weblog:entries}
    {/exp:query} 
    <a href="http://...page1…">prev.gif</a>
    <! -- only show this if there are entries on the next page -->
    <a href="http://...page3…">next.gif</a>

    Help?

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

ExpressionEngine News!

#eecms, #events, #releases