2

I have a script that uses query to determine if a particular entry is open or closed. based on that entry, it then displays a list of blog entry excerpts. if that particular entry id has a status of closed, it displays the list with one category hidden. Otherwise it shows all categories.

Everything on this works fine except for the pagination. I cannot get it to appear inside the conditional, and when it is outside of the conditional, it just shows the same few blog excerpts on every page.

Below is my code:

{exp:query sql="SELECT status FROM exp_channel_titles WHERE entry_id = '46'"}
            {if status == 'closed'}
                {exp:channel:entries channel="blog" disable="member_data" limit="3" paginate="bottom" order_by="desc" category="not 4"}
                    {if no_results}
                        <p>No results available</p>
                    {/if}
                    <div class="entry"><article>
                        <div class="header"><header>
                            <hgroup>
                                <h2 class="category">{categories}{category_name}{/categories}</h2>
                                <h1>{title}</h1>
                            </hgroup>
                            <p><span class="date">{entry_date format="%F %d, %Y"}</span> / <span class="author">{author}</span></p>
                        </header></div> <!-- /.header -->
                        {if blog_image}
                            <p><img src="{blog_image}" alt="{title}"></p>
                        {/if}
                        {blog_excerpt}
                        <a href="{url_title_path='blog/entry'}" class="more">read more &gt;</a></p>
                    </article></div> <!-- /.entry -->

                    <div class="moreEntries">
                        {paginate}
                            {if previous_page}
                                <a href="{auto_path}" class="prev">&lt;  Newer Posts</a>    |  
                            {/if}
                            {if next_page}
                                <a href="{auto_path}" class="next">Older Posts  &gt;</a>
                            {/if}
                        {/paginate}
                    </div> <!-- /.moreEntries -->
                {/exp:channel:entries}
            {if:else}
                {exp:channel:entries channel="blog" disable="member_data" limit="3" paginate="bottom" order_by="desc"}
                    {if no_results}
                        <p>No results available</p>
                    {/if}
                    <div class="entry"><article>
                        <div class="header"><header>
                            <hgroup>
                                <h2 class="category">{categories}{category_name}{/categories}</h2>
                                <h1>{title}</h1>
                            </hgroup>
                            <p><span class="date">{entry_date format="%F %d, %Y"}</span> / <span class="author">{author}</span></p>
                        </header></div> <!-- /.header -->
                        {if blog_image}
                            <p><img src="{blog_image}" alt="{title}"></p>
                        {/if}
                        {if event_location}
                            <p><strong>{event_location}</strong><br>
                            {blog_month} {blog_day}, {blog_year} - {blog_event_time}}</p>
                        {/if}
                        {blog_excerpt}
                        <a href="{url_title_path='blog/entry'}" class="more">read more &gt;</a></p>
                    </article></div> <!-- /.entry -->

                    <div class="moreEntries">
                    {paginate}
                            {if previous_page}
                                <a href="{auto_path}" class="prev">&lt;  Newer Posts</a>    |  
                            {/if}
                            {if next_page}
                                <a href="{auto_path}" class="next">Older Posts  &gt;</a>
                            {/if}
                        {/paginate}
                    </div> <!-- /.moreEntries -->
                {/exp:channel:entries}
            {/if}
        {/exp:query}

Thanks for any help you can offer!

1 Answer 1

2

You're running into variable collision. Since both the Query and Channel modules use the {paginate} tags, the outer-most module (Query) is winning the battle.

The solution is to embed your Channel Entries loops.

{exp:query sql="SELECT status FROM exp_channel_titles WHERE entry_id = '46'"}
    {if status == 'closed'}
        {embed="_embeds/loop1"}
    {if:else}
        {embed="_embeds/_loop2"}
    {/if}
{/exp:query}

Then your two chunks of code go into templates located at _embeds/loop1 and _embeds/loop2 respectively (use your own naming conventions of course).

I should also point out:

  • order_by="desc" does nothing. You're probably thinking of orderby, but that parameter accepts a field name, not a sort order ... what I think you want is sort="desc", which you can omit anyway, because that is the default sort. :)
  • <div class="moreEntries"> should be within your {paginate} loop, otherwise you'll end up with <div class="moreEntries"></div> at the end of every entry in the loop, followed by your pagination links outside of the final moreEntries division.
2
  • Thanks that helps me out a ton! And thanks for the two extra tips, always good to keep me on my toes!!
    – prosborne
    Jan 15, 2013 at 22:18
  • Though I did not test it myself, I don't think {embed} is required here. It should be enough just to place {paginate}{/paginate} inside each tag pair.
    – Yuri Salimovskiy
    Jan 16, 2013 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.