Using a new attribute to display a page in a pagelist

Permalink 2 users found helpful
I have a problem I can't get my head around. I currently have my main menu which I've used to list the main products & services that my client offers. I've used the is_featured attribute to create a secondary nav above this which contains Home, About, etc. and this works perfectly.

What 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>

PassionForCreative
 
jordanlev replied on at Permalink Best Answer Reply
jordanlev
<div id="prominent_contact">
<div id="prominent_contact_inner">
<?php
Loader::model('page_list');
$nh = Loader::helper('navigation');
$pl = new PageList();
$pl->filterByProminentCheckbox(1); //<--this is the critical piece -- note the function name is a "CamelCase" version of your attribute name. If the attribute name was "my_example_attribute", you'd use $pl->filterByMyExampleAttribute(1) instead
$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 '<a href="' . $nh->getLinkToCollection($p) . '">' . htmlspecialchars($p->getCollectionName()) . '</a>';
}
?>
</div>
PassionForCreative replied on at Permalink Reply
PassionForCreative
Jordanlev,

Let it be known to all C5 members that YOU ARE THE MAN!!!

Thanks dude - this worked perfectly
bevegan replied on at Permalink Reply
@jordanlev,

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?
jordanlev replied on at Permalink Reply
jordanlev
Yes, the c5 documentation is woefully incomplete (especially for programmers). In some cases, reading through the core code is useful, but sometimes it leads you down a dark path of "too much information" -- I've actually learned more from looking at how the various blocks and packages are built (both the built-in ones and free ones from the marketplace). And of course the forums too.

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
bevegan replied on at Permalink Reply
Thanks, Jordan. Sage advice. I stumbled down the path of 'too much information' when I first took a look at concrete5 about a year ago. At that time, I got swamped in code and gave up on it. Seemed to be too much effort to get beyond just the very basics.

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.
PassionForCreative replied on at Permalink Reply
PassionForCreative
Hi Jordan,

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
jordanlev replied on at Permalink Reply
jordanlev
If the links are being displayed then the code is working properly. You need to create or alter your CSS to make those links look different (which isn't really something I can explain in a forum -- using CSS to style websites is a huge topic, and it completely depends on the design you're going for anyway so there's never a "correct answer" or anything like that).
PassionForCreative replied on at Permalink Reply
PassionForCreative
Thanks Jordan. I had a feeling you would say something like that. it's definitely something to do with my code.

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 :-)
jordanlev replied on at Permalink Reply
jordanlev
I think I understand what you're saying, but I don't understand how you've structured your code. Where exactly do you have that code that's posted above in this forum thread?

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?
PassionForCreative replied on at Permalink Reply 1 Attachment
PassionForCreative
Hi Jordan,

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.