EllisLab text mark
Advanced Search
     
If No Pagination Problem
Posted: 17 August 2012 11:54 PM   [ Ignore ]
Joined: 2010-10-29
144 posts

I need {if no pagination} or the equivalent there of.

Example:

<ul>
{exp:channel:entries limit="10"}<li>{title}</li>{/exp:channel:entries}
{paginate}
</ul>
{pagination_links}
{
/paginate} 

The above is great if I have enough items to create paging.
Sometimes I don’t have enough items, and as you can see if that is the case with the above code I will loose my closing “ul”

Is there a solution?

I am running EE 2.5.2
I have AB Pagination at my finger tips too.

 
Posted: 18 August 2012 07:05 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-20
1046 posts

Couple of things you can do - first, your pagination should be contained inside your entries loop.  And then within the entries loop itself, you can open and close the unordered list with conditionals, like so:

{exp:channel:entries limit="10"}
{if count 
== "1"}<ul>{/if}
<li>{title}</li>
{if total_results}</ul>{/if}
{paginate}
{pagination_links}
{
/paginate}
{
/exp:channel:entries} 

You can take it a step further by adding a simple conditional to the pagination as well, so pagination formatting, etc. is applied only if there is more than one page of results, particularly important if you wrap a div around the pagination links to target them for styling ...

{exp:channel:entries limit="10"}
{if count 
== "1"}<ul>{/if}
<li>{title}</li>
{if total_results}</ul>{/if}
{paginate}
{if total_pages 
"1"}
{pagination_links}
{
/if}
{
/paginate}
{
/exp:channel:entries} 

Hope that helps.

 Signature 

+++

QB Marketing
Vision + Design
url: http://www.qbmarketing.com

 
Posted: 18 August 2012 08:01 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2010-10-29
144 posts

There seems to be a problem with your example.
A channel with 5 entries returns this.

<ul><li>title</li>
</
ul>

<
li>title</li>
</
ul>

<
li>title</li>
</
ul>

<
li>title</li>
</
ul>

<
li>title</li>
</
ul

If you can get your method to work, great, how ever I am a little concerned that there isn’t an {if pagination} variable or more straight forward method native to EE.
I have suggested to EE to include such a solution with no response a while back - http://ellislab.com/forums/viewthread/218201/

Something where you could declare what is to loop inside the channel entries would help too, then you could have non looping code in the channel entry tag.

Any who I look forward to getting this one solved, it has been an ongoing problem for me which I would love to resolve.

Thanks for your help so far John.

 

 
Posted: 18 August 2012 12:14 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-20
1046 posts

Crap - sorry i missed an element. It would be:

{exp:channel:entries limit="10"}
{if count 
== "1"}<ul>{/if}
<li>{title}</li>
{if count == total_results}</ul>{/if}
{paginate}
{if total_pages 
"1"}
{pagination_links}
{
/if}
{
/paginate}
{
/exp:channel:entries} 

Note the change to the fourth line - should be if count == total_results rather than just if total_results.  They the list will close after last entry returned by the loop.

 Signature 

+++

QB Marketing
Vision + Design
url: http://www.qbmarketing.com

 
Posted: 18 August 2012 12:18 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-20
1046 posts

No, there’s no “if paginate” that I’m aware of, but the same effect can be drawn by using the conditional I included in my example:

{paginate}
{if total_pages 
"1"}
your stuff here
{
/if}
{
/paginate} 

It has the same effect - if you put everything inside that conditional, nothing gets returned if there is no page 2.  Not perfect, but it works.

 Signature 

+++

QB Marketing
Vision + Design
url: http://www.qbmarketing.com

 
Posted: 18 August 2012 09:00 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2010-10-29
144 posts

Thanks again.
I can get things to work in the simplified example.
But when I transfer it to my real template where I am using Expresso Store I can not.

Do you know if Store would throw a spanner in this solution?

Would you be open to seeing my CP?

 
Posted: 19 August 2012 09:23 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-20
1046 posts

Truthfully I don’t know how Expresso Store might affect pagination, though I thought Store still treated all content as entries and would therefore still follow the general EE entries loop model.  Have you tried contacting the Expresso Store team with the question?  I understand they provide pretty solid support.

 Signature 

+++

QB Marketing
Vision + Design
url: http://www.qbmarketing.com

 
Posted: 19 August 2012 07:34 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Joined: 2010-10-29
144 posts

Fair enough.
Frustrated there isn’t an if no results or no pagination tag pair.

 
Posted: 20 January 2013 08:49 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Joined: 2011-04-14
6 posts

I appreciate that this post started last year, however, I was looking for a way to get a {if no_pagination} style conditional to work today and stumbled across the following solution:

Within the channel entries tag, add the following code:

{if count==1}
 {if paginate 
== ''}
  Your content here
 {
/if} 
{
/if} 

I’m running 2.5.3.

Hope this helps.

 
Posted: 20 January 2013 09:16 AM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Joined: 2011-04-14
6 posts

I am so sorry. Sadly, I spoke too soon. I’ve discovered the above doesn’t work after all.

However, I am not one to give up. I found the following solution does work.

As you will need to define the limit paramater to invoke the pagination, we can use this with the absolute_results variable to show content if there is no pagination.

So, in the following example I have a limit of 15 entries set on my channel entries tag:

{if absolute_results 15}
 {if count 
== 1}
  Your content here
 {
/if} 
{
/if} 

I’m pretty sure this works.