1
{% set query = craft.entries.businessAddress(params).orderBy('Premium desc, distance').limit(12) %}

{% paginate query as pageInfo, pageEntries %}

<div class="row">
        
    {% for entry in pageEntries %}

        <div class="col-lg-4">  

            <div class="DETAILS   {% if premium == 'yes' %}  {% endif %}"> 
            <!--- DETAILS -->
            </div>

        </div>

    {% endfor %}

{% include 'includes/_sect-pagination' %}

</div>

I have the above code, which outputs paginated results of a section ordered by whether they are a STANDARD or PREMIUM entry, then by a distance calculation. Within the entry output an IF statement adds more CSS to the output depending if STANDARD or PREMIUM, all of this works fine, however, id like to add more CSS to the results.

I would like to have the PREMIUM entries output in a separate ROW to the STANDARD entries so the ROWS can have different CSS applied, but still remain part of the total pagnination.

For example, if there are 3 premium and 14 standard,

The first page would be:-

<div class="row premiumrow">
<did class="col-lg-4">PREM ENTRY 1</div>
<did class="col-lg-4">PREM ENTRY 2</div>
<did class="col-lg-4">PREM ENTRY 3</div>
<div class="row standardrow">
<did class="col-lg-4">STANDARD ENTRY 1</div>
<did class="col-lg-4">STANDARD ENTRY 2</div>
<did class="col-lg-4">STANDARD ENTRY 3</div>
<did class="col-lg-4">STANDARD ENTRY 4</div>
<did class="col-lg-4">STANDARD ENTRY 5</div>
<did class="col-lg-4">STANDARD ENTRY 6</div>
<did class="col-lg-4">STANDARD ENTRY 7</div>
<did class="col-lg-4">STANDARD ENTRY 8</div>
<did class="col-lg-4">STANDARD ENTRY 9</div>

Second page would be:-

<div class="row standardrow">
<did class="col-lg-4">STANDARD ENTRY 1</div>
<did class="col-lg-4">STANDARD ENTRY 2</div>

Can anyone say if that is possible within paginated results, if so how?

Any help would be greatly appreciated.

1

Well after a brain melting, I have come up with an answer, im not sure how pretty it is, any comments on how to tidy it up are most welcome.

<!-- get the premium entries and randomize -->
{% set premEntries = craft.entries.section("test").relatedTo(category).Premium('yes').orderBy('RAND()').ids() %}

<!-- get the standard entries and randomize -->
{% set standEntries = craft.entries.section("test").relatedTo(category).Premium('no').orderBy('RAND()').ids() %}

<!-- get the total number of premium entries -->
{% set premCount = craft.entries.section("test").relatedTo(category).Premium('yes').orderBy('RAND()').count() %}

<!-- Divide total premium entries by Pagination per page limit -->
{% set limitTotal = premCount / 12 %}

<!-- Round up the linitTotal, this gives me page the premium entries finish on -->
{% set limitRoundUp = ceil(limitTotal) %}

<1-- This gives me the number of premium entries on the last page they appear -->
{% set limitRoundDown = floor(limitTotal) %}
{% set lim3 = limitRoundDown * 12 %}
{% set lim4 = premCount - lim3 %}


<!-- This merges the 2 sets of entries together into the paginated results -->
{% set allEntries = standEntries |merge(premEntries) %}
{% set posts = craft.entries.id( allEntries ) %}
{% paginate posts.limit(12).orderby('Premium desc') as pageInfo, pageEntries %}     
{% set pageCount = pageInfo.totalPages %}


<!--  This turns the grey background white on page 2 and beyond if there are less that 12 premium entries -->
    <div class="container-fluid greyouter {% if premCount <= 12 %}whiteouter{% endif %}">       
        <div class="container">
                <div class="row">
            
                {% for entry in pageEntries %}
                
                
    <!-- this is the styling for the above, must be inside the FOR statement to be able to register the current page -->    

    
                    {% if pageInfo.currentPage != '1' %}
                        <style>
                            .whiteouter {
                                background-color: #fff;
                                        }
                        </style>
                    {% endif %}
                    
                    
    <!-- this is the styling for if page 1 has no premium entries, it changes the background to white, must be inside the FOR statement to be able to register the current page --> 
    
    
        {% if pageInfo.currentPage == '1' and premCount == '0' %}
            <style>
                .greyouter              {
                background-color: #fff;
                        }
        </style>
        {% endif %}
    <div class="col-lg-4 pb-5"> 
                
        <div class="vendorboximg">
            
        </div>
        
        
    </div>  


<!--  This checks to see if this page is where the premium entries stop, and if this loop is the last premium, if so it adds a new row, no CSS required as backgorund is white anyway -->

    {% if pageInfo.currentPage == limitRoundUp and loop.index == lim4 %}
     </div></div></div><div class="container-fluid pt-5"><div class="container"><div class="row">{% endif %}


{% endfor %}
<!-- Pagination numbers -->
<div style="width:100%">
    {% include 'includes/_sect-pagination' %}
  </div>              

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.