Autonav - Child-pages shown with hidden parent-page
Permalink 4 users found helpfulI have a structure like this :
Home - en - - Page#1 - - Page#2 - - - Subpage#1 - - - Subpage#2 - - Page#3 - - hiddenpages - - - hPage#1 - - - hPage#2
The "hiddenpages" is set to 'Exclude from nav'
In autonav i have :
Show pages : second level Sub-pages to show : All Level of subpages : All levels Standard template
The problem is now, that while the sub-pages beneath Page#2 are show correctly, beneath Page#3 i have hPage#1 and hPage#2 shown, even they are not child-pages of Page#3 but child-pages of hiddenpages, an invisible parent-page.
How can i avoid that those child-pages are shown ?
I can't block them all, because i want to use them later as well for other autonavs (show pages beneath a certain page).
Thanks for input on this issue !
Marc-André
edit your "/block/autonav/view.php" (or the custom template you are using). And do the replacement listed below. It's not the most elegant solution, but it's functional.
If you do not have any files in "/block/" simply copy /concrete/block/autonav/view.php to /block/autonav/view.php
lines to replace (starts at line 9 or 10):
foreach($aBlocks as $ni) { $_c = $ni->getCollectionObject(); if (!$_c->getCollectionAttributeValue('exclude_nav')) {
replace with:
foreach($aBlocks as $ni) { $_c = $ni->getCollectionObject(); $ppObj = Page::GetById($_c->getCollectionParentID()); if (!$_c->getCollectionAttributeValue('exclude_nav') && (!$ppObj->getCollectionAttributeValue('exclude_nav') || $_c->getCollectionID() == 1) ) {
Solution courtesy #concrete5 on freenode - JesperDK, Renic, MIRV-, and |ucas.
This solution will hide all descendants of a page that has the "Exclude From Nav" attribute set to true.
$excludedCIDs = array(); // array to reference excluded CIDs foreach($aBlocks as $ni) { $_c = $ni->getCollectionObject(); if ($_c->getCollectionAttributeValue('exclude_nav')) { $childrenArray = $_c->getCollectionChildrenArray(); // Get an array of children cIDs $excludedCIDs = array_merge($childrenArray, $excludedCIDs); $excludedCIDs[] = $_c->getCollectionID(); // Add current cID to excluded array continue; // Move to next page } if (!in_array($_c->getCollectionID(), $excludedCIDs) ) {
Thanks to all the other devs for the other solutions to nice to see alternative methods.
Next time Ill just load Jordans template instead and start from there.
Thread Marked as Helpful :)
I created an exclude_children page attribute,
then under the previous code just tweaked it slightly,
if ($_c->getCollectionAttributeValue('exclude_children')) {
$childrenArray = $_c->getCollectionChildrenArray(); // Get an array of children cIDs
$excludedCIDs = array_merge($childrenArray, $excludedCIDs);
}
This way I can show children of only certain blocks and hide those I do not want to appear, ie blog pages.
Im using both this and code above so that have slightly more granularity.
:doh: I just realised too that this is exactly what Jordanlev's Package does, sometimes I wish that I did research before jumping into the code.
Thanks for your great tips i also this problem, but now i solved by your code with some changing because i have multi language site so thats why, i use:
$_c = $ni->getCollectionObject(); $ppObj = Page::GetById($_c->getCollectionParentID()); if (!$_c->getCollectionAttributeValue('exclude_nav') && (($ni->getLevel() == 0) || !$ppObj->getCollectionAttributeValue('exclude_nav')) ) {
http://www.concrete5.org/marketplace/addons/autonav-exclude-subpage...
I do however find this how autonav including subpages quite infuriating and not really in the sprit of the cms.
I've got the menu embedded in the template like this:
<div class="menu_nav"> <?php $nav = BlockType::getByHandle('autonav'); $nav->controller->orderBy = 'display_asc'; $nav->controller->displayPages = 'top'; $nav->controller->displaySubPages = 'all'; $nav->controller->displaySubPageLevels = 'custom'; $nav->controller->displaySubPageLevelsNum = 1; $nav->render('view'); ?> </div>
but it displays the subpages even though the parents have "exclude from nav" checked.
I couldn't used the plugin "Autonav Exclude Subpages " because my nav is embedded the the template so what I did was use the view from the plugin and added it to the autonav template folder.
<div class="menu_nav"> <?php $nav = BlockType::getByHandle('autonav'); $nav->controller->orderBy = 'display_asc'; $nav->controller->displayPages = 'top'; $nav->controller->displaySubPages = 'all'; $nav->controller->displaySubPageLevels = 'custom'; $nav->controller->displaySubPageLevelsNum = 1; //$nav->render('view'); $nav->render('templates/exclude_subpages'); ?> </div>
hope this helps someone else in the future.
Do note that you can create a new directory on your server here:
YOURSITE/blocks/autonav/templates/
and drop the file in there (your template code would stay the same, C5 knows to look there). This is considered better than dropping it into here:
YOURSITE/concrete/blocks/autonav/templates/
...because if you update the system you'll lose the one inside the concrete directory.
-Jordan
Good to know to use the blocks folder custom files.
I am using a drop-down menu custom template on my blog already, so I can't add on Jordan's custom template.
Any ideas or suggestions to make the blog sub-pages not appear in the main navigation but still in the Date Nav. Or why my blog sub-pages are appearing under another non-parent page in the navigation? (The blog isn't even part of the main navigation)
Thanks for your help as always!
Auto-nav block is working much better now! :)
In my dropdown autonav, I have an Events page and want to hide it's child pages, as I don't want a dropdown full of 20 items. I want to keep the parent page visible though.
1. I tried creating the custom page attribute (check box) with the handle "exclude_subpages_from_nav" and then checked the box under the parent page properties. That didn't work.
2. I looked into your "Autonav Exclude Subpages" add-on but it's not compatible with version 5.6 (It's supposed to come with the package but I can't seem to find it anywhere)
Any clue how I can achieve this?
If you've upgraded a site from an earlier version of C5, though, and have the Autonav Exclude Subpages addon installed, it should still work just fine. If you created the "exclude_subpages_from_nav" attribute and applied it to the top-level page whose children you want excluded, that should do the trick. If not, try clearing your site cache via the C5 dashboard. Also check that the autonav block you're wanting to exclude subpages from actually has that custom template set to it. Also also check your SITEROOT/blocks/autonav/templates directory to see if maybe you overrode something with a different template that doesn't include this functionality?
Hope something in there helps :)
I created the check box attribute exclude_subpages_from_nav the same way I created others such as replace_link_with_first_in_nav and it does appear under the page properties but checking the box has no impact, and the supages for that parent item still appear.
If this functionality is somehow buit into the core of 5.6, then how do we use it? I couldn't find it anywhere. I'm not using any custom templates and I've cleared the Site cache tons of times.
I really appreciate your help.
exclude_subpages_from_nav
(make sure the spelling is correct).
If you're using 5.6 it should just work -- I honestly have no idea why it wouldn't be (if the attribute handle is spelled correctly and you've checked the box for that attribute on a page).
You're checking the box on the parent page, right (the one that has the 30 pages under it -- not one of the 30 pages themselves)?
I'm copying my view.php below - Would you mind looking at it and telling me if this is infact outdated? Where can I get an updated file for view.php? Thanks SO much!!!!!
<script type="text/javascript">
$(document).ready(function () {
$('.nav li').hover(
function () {
//show its submenu
$('ul', this).slideDown(115);
},
function () {
//hide its submenu
$('ul', this).slideUp(115);
}
);
});
</script>
<?php
You say this site is a fresh install of 5.6.0.2? If so, the new template is in concrete/blocks/autonav/view.php
If its an updated site though, it will be in updates/concrete5.6.0.2/blocks/autonav/view.php
Best of luck!
If I have
Parent 1
Parent 2
- Kid 2
- Kid 2b
Parent (hidden)
- Kid 3
- Kid 3b
Kid 3 and 3b are showing underneath Parent 2 (following Kid 2b).
When I choose "relevent" (no kids show at all on ANY Parent and my drop down menu does not work. i must use all/all to make my drop down work) Any ideas?
Also, please note... relevent does not show any children at all.
Settings:
Top Level
Order Ascending
Display Sub Pages ?????? (relevent doesn't work)
Display Sub Page Levels - All
Thanks!!!