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.

Display div and entry only if there's a current entry?

September 15, 2007 11:36pm

Subscribe [1]
  • #1 / Sep 15, 2007 11:36pm

    csavannah

    27 posts

    I’m working on a blog and I’d like a site news bar to appear at the top of it, but I want it only to appear if theres news. I’ve the weblog for it to only display one entry, but I’m not sure how cause the div and entry to appear only if there’s a current entry. Naturally I’d either set an entry to expire or expire it manually.

    The code I have is this:
    {exp:weblog:entries weblog="sitenews" orderby="date" status="open" sort="desc" limit="1" show_expired="no"
    show_future_entries="no" disable="categories|custom_fields|member_data|pagination|trackbacks"}
    {if count =="1"}
    <div id=“header”>


    <div id=“sitenewsbar”>

    Site News {current_time format="%M. %j%S, %Y:"} 


    {body}
    {/exp:weblog:entries}

    </div>
    {/if}

    But all that does is show Site News {body}

    Any suggestions on how to get this done?

  • #2 / Sep 16, 2007 12:07am

    chrispiciullo

    69 posts

    Hey Brandon,

    Remove custom_fields from the disable= bit of your entries tag.  That’ll bring back the actual content of your “site news” posts.

    Chris

  • #3 / Sep 16, 2007 3:55am

    julianps

    175 posts

    If I understand you right, can you use a conditional; so that the complete tag (inc HTML) only appears when there’s something to show?

    {exp:weblog:entries weblog="sitenews" orderby="date" status="open" sort="desc" limit="1" show_expired="no" 
    show_future_entries="no" disable="categories|custom_fields|member_data|pagination|trackbacks"} 
    <!-- {if count =="1"} -->
    <div id="header"> 
    
    {if body}
         <div id="sitenewsbar"> 
                  Site News {current_time format="%M. %j%S, %Y:"}
                  {body}
         </div><!-- s//itenewsbar -->
    {/if}
    </div><!-- h//eader -->
    
    {/exp:weblog:entries} 
    
    <!-- /div -->
    <!-- {/if} -->

    You can set expire dates in any number of ways, not least when you create the article in the first place.

    JiF

  • #4 / Sep 16, 2007 10:10am

    csavannah

    27 posts

    Cool, a combination of both suggestions solved the problem. Need to turn custom_fields back on AND check for the presence of {body}. Thanks guys!

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

ExpressionEngine News!

#eecms, #events, #releases