Forum

Thread tagged as: Question

Apply featured attribute to one item at a time

Hi guys, I'm just building a site using Perch that has a portfolio section. I've followed the video guide in the docs and so far everything is working great, however I'm just trying to figure out the best way of having a 'Featured' project which I'll output using a different template.

I'd like the 'Feature' attribute to only be applied to one portfolio item at a time, i.e. if the editor applies Featured to a new project it removes it from the previous item that had it. Is that possible? What would I use to do that? Categories?

Thanks.

Alan Charlesworth

Alan Charlesworth 0 points

  • 5 years ago
Simon Clay

Simon Clay 127 points

Hi Alan, I don't think there is a way to force only 1 item to be featured at a time. However, there are a few of things we can do to make it work pretty well:

1) Firstly add a 'Featured Project' checkbox, I've added 'help' to encourage the editor to try to keep to just 1 featured project:

<perch:content id="featured_project" type="checkbox" label="Featured Project" value="Featured Project" suppress="true" help"Please ensure only 1 project should be marked as Featured at any time" />

2) Use count with perch_content_custom to only show 1 featured project. So even if more than one are marked as 'Featured' only one will show:

<?php
    perch_content_custom('Projects', array(
        'page'=>'/portfolio/index.php',
        'template'=>'_featured_project.html',
        'count'=>1
    )); 
?>

3) In 'Region Options' uncheck 'Edit all on one page' to show the Projects in listdetail mode (rather than singlepage) and add in featured_project to the 'Item list column IDs' (along with the _title and perhaps image). This will show the editor at a glance the item(s) that have been marked as 'Featured'.

I hope that helps.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think Simon has covered everything!

Simon Clay

Simon Clay 127 points

:) thanks boss.

Hi Simon, thanks for that. That sounds like the perfect solution actually! I'll give that a blast!