1

I'm working on a new website for my student radio station but I've stumbled into a few key bugs which are stopping us from advertising the new site.

It's live right now over on Stormfm.com, you'll be able to see the problems for yourselves there.

The up coming shows section is supposed to display the next 3 shows, however there's a bug with it's limit, to get the section to display at least 3 shows I had to raise the limit to 30, this then means up to 30 shows display. I've copied the code below.

{% for entry in craft.entries.section('shows').order('showTime').limit(30)
    if entry.showDay.contains('now'|date('N')) and entry.showTime > 'now'|date('H:i') %}


  <div class="flex-box mobile">
    <a class="link-block w-inline-block" href="{{ entry.url }}">
      <div class="up-coming-image" style="background-image:url({{ entry.showImage[0].url }}); background-size:cover;" >
        <div class="up-coming-fade" data-ix="fademouse">
          <div>{{ entry.showTime }} - {{ entry.showLength }}</div>
          <h4 class="up-coming-heading">{{ entry.Title }}</h4>
          <div>With {{ entry.hostname.first().title }} </div>
        </div>
        <div class="image-btn">&gt;</div>
      </div>
    </a>
  </div>

{% endfor %}

Also I want to display what the current show on air is, originally I was going to use a similar code to the above, limit it to 1 and have it minus an hour but I can't seem to work out how to do that. For the short term I can flip the greater than to less than, however this then displays only the closest show and I can't else out into a default display if nothing is currently timetabled as on air.

I hope this all makes sense and would appreciate any help you might be able to provide!

Tom

1
  • I've made some changes on the websites, by limiting to 17 I can display 4 up coming shows, sort term thats great but I have a feeling its just going to throw up glitches later, any advice on the proper way to do this?
    – Tom Qwen
    Commented Nov 6, 2017 at 13:56

1 Answer 1

4

What you do, is this:

  • Get 30 items from the database, ordered by showTime
  • Then, you filter them with the if-attribute in the for-statement

This means, that you could get anywhere from 0 to 30 results. What you want to do, is make sure the filtering happens within the element query. I did not test this (not sure about the time criteria part), but something like this should work:

{% for entry in craft.entries
    .section('shows')
    .order('showTime')
    .search('showDay:*' ~ now |date('N') ~ '*')
    .showTime('>= ' ~ now |date('H:i'))
    .limit(3) %}
6
  • Unfortunately moving the limitation to the end doesn't have an effect, weirdly more than 3 still display.
    – Tom Qwen
    Commented Nov 6, 2017 at 16:53
  • It’s not really about the position of the limit(), it’s about having the extra criteria in your query. You can set the limit to 3, if you do it this way.
    – Paul
    Commented Nov 6, 2017 at 16:56
  • The order of criteria does not really matter.
    – Paul
    Commented Nov 6, 2017 at 16:57
  • Okay, I've not used search yet so it's thrown me. I'm being returned this Error Message... Arguments must be separated by a comma. Unexpected token "name" of value "N" ("punctuation" expected with value ",").
    – Tom Qwen
    Commented Nov 6, 2017 at 17:07
  • Just a little Syntax error search('showDay:"*"' ~ now |date('N') ~ '"*"') I would suggest you to read the docs about how to search entries in craft Commented Nov 6, 2017 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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