Jump to content

Featured Page


Rich Torres
 Share

Recommended Posts

Hello there fellow PW people,

I am looking to feature a different page every week on the home page. I am building this web site, but not maintaining the content. I wanted some thing like a checkbox that would turn a page into a 'featured' page. this checkbox could only be used by one page at any given time. So if another page is chosen as featured, it would have to lose this value.

I am kind of at a loss where to start. I have done some searching, but perhaps my keywords are not allowing something I am looking for to pop up.

Thanks in advance!

Rich Torres

Link to comment
Share on other sites

How about something like this?

  • Create a Checkbox field called featured, add it to a template
  • Hook into Page::savedField, return if field name is not 'featured'
  • Check if $page ($page = $event->arguments(0)) has $page->featured=1
  • Perform a $pages->find("featured=1, id!=$page")
  • Iterate over those pages and set featured=0

Now one potential problem that comes to my mind is that as you're iterating over these pages, the hook will be called over and over. Setting $event->cancelHooks = true before you do the iteration should cancel subsequent hooks, but I haven't tried it.

 

  • Like 1
Link to comment
Share on other sites

I'm an idiot... page reference field on home page... all those duckduckgo searches... wasted :'(:lol:

abdus, thank you for such a hasty reply. I will make note of this, as I am sure this will help me further my understanding. I am sure this info will come in useful in the near future.

Link to comment
Share on other sites

There should be at most 1 page with featured=1, but $pages->find() returns PageArray, you'd have to iterate over it but it's just semantics. 

What I'm interested is how you'd get a hook to run just once and stop further hooks from getting triggered inside that hook.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...