I have a news page (/news). You can open an article (i.e. /news/test-article) which uses the same listing template, but has an accordion open with content for that article (javascript/push state magic).

In the event someone goes directly to /news/{slug} I want to make sure that article is the top one in the list.

Is it possible to go i.e.

$criterea = craft()->elements->getCriteria(ElementType::Entry);
$criterea->section = 'news';
$criterea->order = 'postDate desc';
$criterea->ids = [$startArticle->id, {magically fall back to default sorting!}];
$criterea->fixedOrder = true;

Or am I going to have to futz with the array manually after the search?



Isn't news/test-article just an example of news/{slug}? And is this for a plugin (hence the PHP) or a template (hence the templating tag for your question)?

Perhaps what you want to do is start by grabbing the slug from the URL and getting the entry you're after:

{% set entry = craft.entries.section('news').slug(craft.request.lastSegment).first %}
// output

Use that to display the first entry, then get the rest of the news entries but filter out the active:

{% set otherEntries = craft.entries.section('news').id('not ' ~ entry.id) %}
{% for otherEntry in otherEntries %}
    // output
{% endfor %}

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.