Skip to main content
added 91 characters in body
Source Link
Brad Bell
  • 67.6k
  • 6
  • 75
  • 145

I have this this code -

    {% for entry in craft.entries.section('news').first() %}
    <div class="container" id="featured-news">
        <div class=col-md-6>
            <h2 class="news-title">{{ entry.title }}</h2>
            <h3 class="news-date">{{ entry.postDate.format('F d, Y') }}</h3>
        
            <p>
                {{ entry.body }}
            </p>
        </div>
    
        <img class="col-md-4" src="images/pic-block-pic1.jpg" style="float:right;">
    
        <div class="col-xs-12" >
            <a href="{{ entry.url }}" style="float:right; padding: 20px 0px 20px 0px">READ FULL STORY...</a>
        </div>
    </div>
{% endfor %}

I thought the .first().first() would pick up just the first news story, however it is returning the same container several times.

I then want to return all other entries elsewhere, so what should I include in my code below to do this -

        <div class="imgOverview">
        <ul>
            {% for entry in craft.entries.section('news').find() %}
            <li>
                <div><img src="images/pic-block-pic1.jpg" alt=""><div class="imgOverviewOverlay"><a href="{{ entry.url }}"><span>{{ entry.title }}<small>{{ entry.postDate.format('F d, Y') }}</small></span></a></div></div>
            </li>
            {% endfor %}    
        </ul>
    </div>

I have this this code -

    {% for entry in craft.entries.section('news').first() %}
<div class="container" id="featured-news">
    <div class=col-md-6>
        <h2 class="news-title">{{ entry.title }}</h2>
        <h3 class="news-date">{{ entry.postDate.format('F d, Y') }}</h3>
        <p>
        {{ entry.body }}
        </p>
    </div>
    <img class="col-md-4" src="images/pic-block-pic1.jpg" style="float:right;">
    <div class="col-xs-12" >
    <a href="{{ entry.url }}" style="float:right; padding: 20px 0px 20px 0px">READ FULL STORY...</a>
    </div>
</div>
{% endfor %}

I thought the .first() would pick up just the first news story, however it is returning the same container several times.

I then want to return all other entries elsewhere, so what should I include in my code below to do this -

        <div class="imgOverview">
        <ul>
            {% for entry in craft.entries.section('news').find() %}
            <li>
                <div><img src="images/pic-block-pic1.jpg" alt=""><div class="imgOverviewOverlay"><a href="{{ entry.url }}"><span>{{ entry.title }}<small>{{ entry.postDate.format('F d, Y') }}</small></span></a></div></div>
            </li>
            {% endfor %}    
        </ul>
    </div>

I have this this code -

{% for entry in craft.entries.section('news').first() %}
    <div class="container" id="featured-news">
        <div class=col-md-6>
            <h2 class="news-title">{{ entry.title }}</h2>
            <h3 class="news-date">{{ entry.postDate.format('F d, Y') }}</h3>
        
            <p>
                {{ entry.body }}
            </p>
        </div>
    
        <img class="col-md-4" src="images/pic-block-pic1.jpg" style="float:right;">
    
        <div class="col-xs-12" >
            <a href="{{ entry.url }}" style="float:right; padding: 20px 0px 20px 0px">READ FULL STORY...</a>
        </div>
    </div>
{% endfor %}

I thought the .first() would pick up just the first news story, however it is returning the same container several times.

I then want to return all other entries elsewhere, so what should I include in my code below to do this -

<div class="imgOverview">
    <ul>
        {% for entry in craft.entries.section('news').find() %}
            <li>
                <div><img src="images/pic-block-pic1.jpg" alt=""><div class="imgOverviewOverlay"><a href="{{ entry.url }}"><span>{{ entry.title }}<small>{{ entry.postDate.format('F d, Y') }}</small></span></a></div></div>
            </li>
        {% endfor %}    
    </ul>
</div>
Source Link

How do I get just the first entry with a 'for' loop?

I have this this code -

    {% for entry in craft.entries.section('news').first() %}
<div class="container" id="featured-news">
    <div class=col-md-6>
        <h2 class="news-title">{{ entry.title }}</h2>
        <h3 class="news-date">{{ entry.postDate.format('F d, Y') }}</h3>
        <p>
        {{ entry.body }}
        </p>
    </div>
    <img class="col-md-4" src="images/pic-block-pic1.jpg" style="float:right;">
    <div class="col-xs-12" >
    <a href="{{ entry.url }}" style="float:right; padding: 20px 0px 20px 0px">READ FULL STORY...</a>
    </div>
</div>
{% endfor %}

I thought the .first() would pick up just the first news story, however it is returning the same container several times.

I then want to return all other entries elsewhere, so what should I include in my code below to do this -

        <div class="imgOverview">
        <ul>
            {% for entry in craft.entries.section('news').find() %}
            <li>
                <div><img src="images/pic-block-pic1.jpg" alt=""><div class="imgOverviewOverlay"><a href="{{ entry.url }}"><span>{{ entry.title }}<small>{{ entry.postDate.format('F d, Y') }}</small></span></a></div></div>
            </li>
            {% endfor %}    
        </ul>
    </div>