0

I have in my concrete5 (LATEST) few composers (Blogs, news and more).
I want, via php code to query the database and retrieve list of composers entries.
On top of that, one of the news composers Fields is boolean - DisplayOnHomePage.

What I want to do is to show on the home page list of news (title and image) that was marked as DisplayOnHomePage=true.
Is there any official API to do that?

If there isn't, is there any other way to do it?

Thanks!

SexyMF
  • 10,657
  • 33
  • 102
  • 206

1 Answers1

0

What I would suggest is using the pagelist, (block or model)

This allows you to filter pages by any number of things, including attributes.

$pl = new Pagelist();
$pl->ignoreAliases();
$pl->filterByPath('/some/page');
$pl->filterByCollectionTypeHandle('some_handle');
$pl->filterByDisplayOnHomePage();
$pages = $pl->get($numofitems);

There are a ton of things that you can filter by, the only things you really need for this to work is the first and last line of that code.

Just so you know, thats using the model, not the block.

After you do that, $pages is an array of page objects.

Mike

Mnkras
  • 300
  • 1
  • 7
  • Questions, how would he define the method filterByDisplayOnHomePage?; Is some_handle means the page type?, thanks – SexyMF May 14 '12 at 05:42
  • filterByDisplayOnHomePage() is a "magic method" -- the page list class will automatically provide a method that is the CamelCase version of the attribute_handle (although I think it only does this if you've checked the "Field available in Dashboard Page Search." box for it in the dashboard attributes page). – Jordan Lev May 14 '12 at 18:11
  • @Mnkras, do you need to pass 1 into the filterByDisplayOnHomePage method (e.g. $pl->filterByDisplayOnHomePag(1);) ? – Jordan Lev May 14 '12 at 18:11
  • Nope, it will by default filter by if the value is true, (its a basic if statement basically) – Mnkras May 18 '12 at 22:56