Forum

Thread tagged as: Question, Installation

Show the latest 3 articles in footer excluding the the one showing (example link...

Hi,

Please see this link: https://sedna.uksrv.co.uk/~poole/news-detail.php?s=driving-in-europe

This is a separate list and detail page functionality and on the detail page, I need the latest 3 articles excluding the one showing to appear in the footer.

Could you help?

Jack Linwood

Jack Linwood 0 points

  • 6 years ago
Michael Wilkinson

Michael Wilkinson 6 points
Registered Developer

Hi Jack

I'm assuming (hoping!) you're using the official blog app for this. If so, you could call the perch_blog_custom() function with your template as an argument to return 3 news items.

If you didn't want the current article in the list then there a few ways of doing that. I think the easiest way would be to grab the id of the entry and assign the value to a Perch variable, then check for that value in the template so you can ignore it. Or, in a layout file, you could return the output to a php array, loop through it and manipulate it.

Hope that helps with a couple of options to look at.

Thanks, Michael

Thanks for this Michael!

Although I am not using the Blog app and have already started with just a simple list and detail page.

Is there any way of doing it like this?

Plus I'm a major novice with perch, is there any way you can provide code?

Thanks again.

Michael Wilkinson

Michael Wilkinson 6 points
Registered Developer

Hi Jack

I'm guessing, but if you have the master-detail setup, then you probably have something like this, but I have added the extra bit:

<?php
    perch_content_create('News', array(
        'template'  => 'news_detail.html',
        'multiple'  => true,
        'edit-mode' => 'listdetail',
    ));
?>

<?php
  if (perch_get('s')) {
       // Detail mode
        PerchSystem::set_var('slug', perch_get('s')); // the variable 'slug' is now available in the template
    perch_content_custom('News', array(
       'template'   => 'news_detail.html',
       'filter' => 'news_slug',
       'match' => 'eq',
       'value' => perch_get('s'),
       'count' => 1,
    ));
  } 
  else {
   // List mode
    perch_content_custom('News', array(
      'template' => 'news_list.html',
    ));
  }

Then in your template (news_detail.html), you can use the <perch:if> for the variable sent (I'm assuming 'title' is what matches the slug):

<perch:if id="title" match="eq" value="{slug}">
<perch:else />
   ***** This bit would return the three that are not the one sent in *****
</perch:if>

Without seeing what your template is for the actual news item, it's a bit tricky. I would urge you to install the blog app though and convert what you have. It wouldn't take very long to do and you'd have the functionality all ready to go. Then, you could do what you're after easily and also have all the other blog bts available to you.

Hope that helps a little more though.

Thanks, Michael

It doesn't need to be that complicated to exclude the item you're currently on, I do this

perch_content_custom('News', array(
'page' => '/page.php',
'template' => 'template.html',
'sort' => 'date',
'sort-order' => 'DESC',
'filter' => 'slug',
'match' => 'neq',
'value' => perch_get('s'),
'count' => 3,
));

So that will grab the latest 3 items, but filter them to make sure the slug doesn't match the current result.

Obviously just match the date & slug to the ID's in your template

Michael Wilkinson

Michael Wilkinson 6 points
Registered Developer

Dexter beat me to it! He is right though, that is a better way.

Thumbs up Dexter!

So sorry for the late reply, but this worked great.

Thanks to the both of you!