If more than X number of entries show this instead of that
Posted: 14 January 2009 09:58 AM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  362
Joined  03-07-2006

Hi all, I’m finding it hard to come up with a solution to this.

Put simply I want to show something when there are more than 4 entries and something else when there are less. But I can’t seem to do it.

The code I want to show if there are less than 4 entries contains 2 weblog entries and some conditionals (not sure if this is relevant but it seems to complicating things… to me anyway) and the other code just has one entries tag.

Here is the full code…

If total results is more than 4 show this…
       
       

<ul>
                
                
{exp:weblog:entries weblog="{section}" disable="member_data|pagination|trackbacks" sort="asc"}
                
<li>
                    <
h2>{product-name}{if products-info}<a class="info" href="/products/info/{url_title}/{categories}{category_id}{/categories}"><img src="/images/info.gif" width="21" height="21" alt="Info" /></a>{/if}</h2>
                
                    <
p>{exp:imgsizer:size src="{product-img}" width="200" alt="{product-name}"}</p>
                
{product-summary}
                
</li>
                
{/exp:weblog:entries}
            
</ul>

       
otherwise show this…

       

<div id="sliderwrap">
                <
div id="slider">
                    <
ul class="navigation">
                        
{exp:weblog:entries weblog="{section}" disable="member_data|pagination|trackbacks" sort="asc"}
                        
<li><a href="#{url_title}"><span>{product-name}</span></a></li>
                        
{/exp:weblog:entries}
                    
</ul>
                    <
div class="scroll-top">
                        <
div class="scroll">
                            <
div class="scrollContainer">
                                
{exp:weblog:entries weblog="{section}" disable="member_data|pagination|trackbacks" sort="asc"}
                                {if no_results}{redirect
="404"}{/if}
                                
                                
                                
<div class="panel" id="{url_title}">
                                    <
h2>{product-name}{if products-info}<a class="info" href="/products/info/{url_title}/{categories}{category_id}{/categories}"><img src="/images/info.gif" width="21" height="21" alt="Info" /></a>{/if}</h2>
                                    <
p class="scrollimg">{exp:imgsizer:size src="{product-img}" width="200" alt="{product-name}"}</p>
                                    
{product-summary}
                                    
<div class="relblock">
                                        <
h2 class="relatedheading">You might also be interested in&hellip;</h2>
                                        <
ul class="related">
                                            <
li><a href="#"><img src="/images/img52x52-1.jpg" width="52" height="52" alt="" /></a>
                                                <
h3><a href="#">26" Cinema Display</a></h3>
                                            </li>
                                            <li><a href="
#"><img src="/images/img52x52-2.jpg" width="52" height="52" alt="" /></a>
                                                
<h3><a href="#">IOmega 250BG HD</a></h3>
                                            </
li>
                                            <
li><a href="#"><img src="/images/img52x52-3.jpg" width="52" height="52" alt="" /></a>
                                                <
h3><a href="#">Mini Display cable</a></h3>
                                            </
li>
                                        </
ul>
                                    </
div>
                                </
div>
                                
{/exp:weblog:entries}

                            
</div>
                        </
div>
                    </
div>
                </
div>
            </
div><!-- end slider -->
            <
div class="slidebase"></div>

       

Any suggestions welcome!

Thanks

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 14 January 2009 10:08 AM   [ Ignore ]   [ # 1 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  9254
Joined  04-15-2006

Hiya,

As you haven’t shown the tag that you are using where you are getting the 4 or less results from then I am taking a guess here but I think your best bet on all of this would be to use embedded templates so you would end up with something like this :

{exp:weblog:entries weblog="default_site"}
{if total_results
> "4"}
{embed
="embed-one"}
{if
:else}
{embed
="embed-two"}
{
/if}
{
/exp:weblog:entries}

The template embed-one would contain the information that you want to use when there are more than 4 results and the embed-two template would contain the code to spit out when you have less than 4.

Hope that helps a bit.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 14 January 2009 10:54 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  362
Joined  03-07-2006

Hmm its kinda working. But its looping the contents and if I add limit=“1” then it doesn’t work.

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 14 January 2009 11:45 AM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  9254
Joined  04-15-2006

Oops sorry about that, try this instead :

{exp:weblog:entries weblog="default_site"}

{if total_results
> "4" AND count == "1"}
{embed
="embed-one"}
{if
:else}
{embed
="embed-two"}
{
/if}

{
/exp:weblog:entries}

Hopefully that should work correctly?

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 14 January 2009 12:45 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  362
Joined  03-07-2006

Hmm no thats showing both.. The smaller code once and the larger twice!?

Would you mind having a look if I PM you a login? I’m stumped!

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 14 January 2009 12:49 PM   [ Ignore ]   [ # 5 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  9254
Joined  04-15-2006

This perhaps?

{exp:weblog:entries weblog="default_site"}

{if total_results
> "4" AND count == "1"}
{embed
="embed-one"}
{if
:elseif total_results < "4" AND count == "1"}
{embed
="embed-two"}
{
/if}

{
/exp:weblog:entries}

You can send me a login if you want to but I may not be able to take a look right away as I am having to borrow my Wife’s computer as mine is in the shop and she needs it in a bit. If you send it over if no-one else helps though then I will take a look no problem.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 14 January 2009 01:00 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  362
Joined  03-07-2006

Thats cracked it! Thanks so much

Mike

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 14 January 2009 01:19 PM   [ Ignore ]   [ # 7 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  299
Joined  04-12-2008

Maybe there’s a problem with the if else, i’ve run into some strange things using if else with count and total results.

What if you try

{exp:weblog:entries weblog="default_site"}

{if total_results
> "4"}
    {embed
="embed-one"}
{
/if}

{if total_results
< "4"}
    {embed
="embed-two"}
{
/if}

{
/exp:weblog:entries}

EDIT: Already seen that problem’s solved wink

 Signature 

Designchuchi | Twitter

URL Field Extension
Required Category Extension
DC FreeForm GeoIP Extension
DC Template Manager

Profile
 
 
Posted: 14 January 2009 04:43 PM   [ Ignore ]   [ # 8 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  9254
Joined  04-15-2006
Mikee Bee - 14 January 2009 01:00 PM

Thats cracked it! Thanks so much

Mike

Hi Mike,

No problem at all. Sorry but I posted the first answer too quickly before I actually thought it all through first. Will definitely try not to do that again wink

Glad it’s all working for you now though.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 77572 Total Logged-in Users: 36
Total Topics: 101562 Total Anonymous Users: 17
Total Replies: 544412 Total Guests: 257
Total Posts: 645974    
Members ( View Memberlist )
Newest Members:  Mark2009Idril616tonybernardcarterstarksColeJLinskitnealsemperjrawhallshiusbozzly