Using a new attribute to display a page in a pagelist
Permalink 2 users found helpfulWhat I need to do is make another nav at the top which makes the contact link more prominent. So I have created a checkbox attribute called prominent_checkbox, added this to my contact page, removed is_featured from this page and have styled up my new menu so that it indeed makes the contact button more prominent.
My only problem is that I don't know where to start with the filtering as described on this page:http://www.concrete5.org/documentation/developers/pages/searching-a...
Here is what I have written so far:
<div id="prominent_contact"> <div id="prominent_contact_inner"> <?php Loader::model('page_list'); $pl = new PageList(); $pl->filterByAttribute($attributeKeyHandle, $value, $comparison); $pl->sortByDisplayOrder(); $pages = $pl->get($itemsToGet = 100, $offset = 0); ?> </div> </div>

Let it be known to all C5 members that YOU ARE THE MAN!!!
Thanks dude - this worked perfectly
Is that critical piece of information available anywhere in the documentation? I've seen it used in Andrew Embler's example for "Building a Single-Page Powered Editing Interface for concrete5 Pages" but he doesn't explain what it is or why it is needed.
He also uses $pagelist->sortBy() which seems to be another undocumented function.
Correct me if I'm wrong, but it seems that concrete5 documentation is not complete, it's more of an introduction to the possibilities of what can be done using concrete5.
For more in depth details, would it be true to say that the best bet at the moment is either to study the codebase itself in detail, or to post in the forums and hope for the help of a c5 guru such as yourself who has already gone through that step?
For the page list object, though, glancing at the functions available in concrete/models/page_list.php can be useful for seeing what's available.
Feel free to PM me if you aren't getting good responses to forum posts for programming questions like this.
-Jordan
Coming back to it now for a second look. Nothing much seems to have changed, at least as far as the documentation goes, but this time I think I'll make more use of the forums. Speedy replies from concrete5 gurus is a major plus in concrete5's favour.
Wondering if you can help me? I'm putting together a site & the guys who run it want to have two Main Navs - I've called them #nav1 & #nav2 and have styled them all up to display how I want them to and thought it would be as simple as using the code that you supplied to me the last time to get it to work - as it worked so well the last time.
It's displaying the links I want it to display alright, but not giving me any styling on them. Just plain text links.
Have you got any ideas?
Thanks in advance,
Steve
Using firebug I've worked out that the CSS that I as using to style the main nav which is an Autonav block won't work with styling the second nav as it's a page_list. The autonav uses <ul> while the Page_list doesn't.
I reckon I probably need to call in a custom template when I'm calling in the second Nav Bar.
Do you know how to make the custom template come in with the rest of the call and style it or should it just style automatically?
Or am I talking complete nonsense :-)
Wherever it is, can't you just change its html so it matches the way the autonav block spits out its html? Like instead of <div id="prominent_contact"> just put <ul class="nav"> around it, then each item instead of just echo'ing "<a href=...", also echo a list item like "echo '<li><a href=...'"
Does that make sense to you?
This is what the code looks like at the minute & this is what the navs display as:
<div id="navs"> <div id="nav1" class="grid_8"> <?php $bt = BlockType::getByHandle('autonav'); $bt->controller->displayPages = 'top'; $bt->controller->orderBy = 'display_asc'; $bt->controller->displaySubPages = 'all'; $bt->controller->displaySubPageLevels = 'custom'; $bt->controller->displaySubPageLevelsNum = '1'; $bt->render('templates/main_menu'); ?> </div><!-- nav1 ends --> <div id="nav2" class="grid_4"> <?php Loader::model('page_list');
But I then changed it based on your comment above to this:
<div id="nav2" class="grid_4"> <ul class="nav2"> <?php Loader::model('page_list'); $nh = Loader::helper('navigation'); $pl = new PageList(); $pl->filterByNavTwo(1); //<--this is the critical piece -- note the function name is a "CamelCase" version of your attribute name. $pl->sortByDisplayOrder(); //$pl->sortByMultiple('p1.cParentID ASC, p1.cDisplayOrder ASC'); //<--this might work better for sorting if the pages are scattered throughout the site $pagelist = $pl->get(); foreach ($pagelist as $p) { echo '<li><a href="' . $nh->getLinkToCollection($p) . '">' . htmlspecialchars($p->getCollectionName()) . '</a></li>'; } ?></ul> </div><!-- Nav2 ends -->
& it's perfect.
Thanks Jordan, again you are a life saver.