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.

How to only show headline if there are content

November 10, 2008 7:36pm

Subscribe [2]
  • #1 / Nov 10, 2008 7:36pm

    ayza

    71 posts

    Hi all,

    I have a h3 headline that only should be displayed if there are content in the list that follow.

    I’ve put the <ul> tag outside of the weblog entries tag in order for them not to repeat for each list item.

    <h3>Läs mer</h3>
    <p><ul><br />
     {exp:weblog:entries weblog="hjalptexter"  related_categories_mode="on" custom_fields="off" member_data="off" disable="member_data|pagination|trackbacks"}    <br />
    <li><a href="http://{path=">{title}</a></li><br />
    {/exp:weblog:entries}    <br />
    </ul>

    Any ideas? I’m bushed tonight.

    / Ayza

  • #2 / Nov 10, 2008 8:47pm

    vosSavant

    380 posts

    Here’s what I’d do:

    {exp:weblog:entries weblog="hjalptexter"  related_categories_mode="on" custom_fields="off" member_data="off" disable="member_data|pagination|trackbacks" limit="1"}<h3>Läs mer</h3>{/exp:weblog:entries}

    Notice the limit=“1” parameter. This means your H3 tag will only display once no matter how many entries you have in that weblog, but won’t display at all if it’s empty.

    Then you can add the <ul> underneath and repeat your weblog query to display the actual entries, if there are any.

  • #3 / Nov 11, 2008 3:21am

    Ingmar

    29245 posts

    Here’s what I’d do:

    {exp:weblog:entries weblog="hjalptexter" related_categories_mode="on" 
    custom_fields="off" member_data="off" disable="member_data|pagination|trackbacks"}    
    
       {if count == "1"}
          <h3>Läs mer</h3>
    <p>      <ul><br />
       {/if}</p>
    
    <p>      <li><br />
             <a href="http://{path=">{title}</a><br />
          </li></p>
    
    <p>   {if count == total_results}<br />
          </ul><br />
       {/if}<br />
    {/exp:weblog:entries}

  • #4 / Nov 11, 2008 12:49pm

    vosSavant

    380 posts

    Ingmar,

    Without testing this myself, it looks like the above code would only display the H3 tag if there was exactly one entry in the weblog. Is that correct?

    If so, would you instead do this:

    {if count > 0}<h3>Läs mer</h3>{/if}
  • #5 / Nov 11, 2008 12:55pm

    ayza

    71 posts

    Thanks Ingmar and vosSavant!

  • #6 / Nov 11, 2008 12:57pm

    Ingmar

    29245 posts

    No, that is not correct. It would display it only if the current entry was the first one, ie once. {count} is incremented by one on every repetition of the loop.

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

ExpressionEngine News!

#eecms, #events, #releases