2

I'm creating a newspaper style website. The homepage is made up of 'editions', each date should have a homepage with all the articles selected for that edition. I figure the best way to do this is with Playa.

I have a channel for articles, videos and graphics (listings in structure).

I've also created a channel for the editions (which is a listing in Structure), and using Playa you can select which articles, videos and graphics should be selected for that edition.

{exp:channel:entries channel="editions" dynamic="no" limit="1" show_future_entries="yes" start_on="{current_time format="%Y-%m-%d 00:00"}" stop_before="{current_time format="%Y-%m-%d 23:59"}"}

{home_main_article} (Playa field)
<h2>{title}</h2>
<div class="author">by {author} on {entry_date format="%d-%m-%Y"}</div>
<p>{article_content}</p>
{/home_main_article}
{/exp:channel:entries}

My issue is this: Articles created on dates that don't match the date the edition was created, don't show up. Even with show_future_entries="yes" set, they still don't show. This may be because of the home channel is set to only show the edition for that day... Essentially articles, videos and graphics should be able to be created on any day and linked to any edition, that edition should show the entry content.

  • Did you test your theory by removing start_on="{current_time format="%Y-%m-%d 00:00"}" stop_before="{current_time format="%Y-%m-%d 23:59"}" from the channel tag? – Anna_MediaGirl Apr 4 '13 at 2:14
  • If I remember correctly removing that still didn't show the entries. I had to add show_future_entries="yes" on the Playa field. – Paul Redmond Apr 4 '13 at 9:31
2

indeed the parts can be related with playa, the main edition could be fetched with year="" month="" and day="". you'ld need some logic with segment_n conditionals and preload_replace or switchee to check if the segments where filled in.


Edit: examples added

Preload_replace

You can use {preload_replace:varname="value"} to set a variable that is instantly replaced in the entire template. Because it is instantly replaced, a second preload replace will not find any variable {varname} left in the template. However, simple segment conditionals are parsed earlier so we can use that to our advantage.

Say you have year in segment_4 then you can check if segment_4 is empty and set a preload variable accordingly.

{if segment_4==''}
  {preload_replace:p_year="{current_time format='%Y'}"}
{/if}
{preload_replace:p_year="{segment_4}"}

# if segment_4 is empty then {p_year} will hold the current year,
# otherwise it will hold the value from segment_4

You can then set the channel:entries parameter year="{p_year}" and similar for month="" and day="".

Switchee

Another approach i have used somewhere, is using switchee on
variable="{segment_4}/{segment_5}/{segment_6},
in combination with a crazy regular expression on the case value=""
to filter correct date ranges (only for year and month in this case).

{exp:switchee variable="{segment_3}/{segment_4}/{segment_5}" parse="inward"}
  {case value="#[12][0-9][0-9][0-9]/([0][1-9]&#124;[1][0-2])/#"}
    // show archive year="{segment_3}" month="{segment_4}"
  {/case}
  ... other cases
{/exp:switchee}
| improve this answer | |
  • When I used year="" month="" and day="" on the main edition it didn't bring in the results from Playa. But, I've found that adding show_future_entries="yes" on the Playa field itself will work fine. Can you elaborate on preload_replace or switchee with an example? Many thanks. – Paul Redmond Apr 3 '13 at 16:08
  • added preload_replace and switchee examples. – GDmac Apr 23 '13 at 7:58
0

I got it working using:

{exp:channel:entries channel="editions" dynamic="no" limit="1" show_future_entries="yes" url_title="{freebie_2}"}

   {home_articles show_future_entries="yes"}
     {title}
   {/home_articles}

{/exp:channel:entries}

The url structure is website.dev/edition/2013-04-01 (title of the edition)

| improve this answer | |

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.