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.

Is this the best way to dynamically change a headline?

September 19, 2011 8:14am

Subscribe [1]
  • #1 / Sep 19, 2011 8:14am

    tomjeatt

    19 posts

    I was just after a bit of advice. What I’m doing with the code below is testing to see if there are any entries marked as sticky. If not, then the two

    tags on the page are ‘Latest news’ and ‘Other news.’ If there is a sticky entry then the <h2> tags become ‘Featured news’ and ‘Latest news.’ The way in which I’ve done it requires making three requests to the database though, and I’m concerned that this will affect the response time. Is there a more efficient way to do it?
    <section class="latest-news">
        {exp:channel:entries channel="news" orderby="date" limit="1" disable="pagination" dynamic="no"}
        <h2>{if sticky == 'y'}Featured news{if:else}Latest news{/if}</h2><p> <br />
        <article class="{categories limit="1"}{category_url_title}{/categories}"><br />
            <header><br />
                </p><h3>{title}</h3>
    <p>            <time datetime="{entry_date format="%Y-%m-%dT%H:%i:%s%Q"}">{entry_date format="%n%S %F %Y"}</time><br />
            </header><br />
            {news_content}<br />
        {/exp:channel:entries}<br />
        </article><br />
    </section><br />
    <section class="other-news"><br />
        {exp:channel:entries channel="news" disable="pagination" dynamic="no" limit="1"}<br />
        </p><h2>{if sticky == 'y'}Latest news{if:else}Other news{/if}</h2><p> <br />
        {/exp:channel:entries}<br />
        {exp:channel:entries channel="news" offset="1" orderby="date" limit="4" disable="pagination" dynamic="no"}<br />
        <article class="{categories limit="1"}{category_url_title}{/categories}"><br />
            <header>                    <br />
                </p><h3>{title}</h3>
    <p>            <time datetime="{entry_date format="%Y-%m-%dT%H:%i:%s%Q"}">{entry_date format="%n%S %F %Y"}</time><br />
            </header><br />
            {news_summary}<br />
            <br />
                <a href="#">Read more</a><br />
            <br />
        </article><br />
        {/exp:channel:entries}<br />
    </section> <!-- /#other-news -->

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

ExpressionEngine News!

#eecms, #events, #releases