Navigation to Multiple Sections Within a Page

Permalink
I am working on a theme for a client that features horizontal scrolling, so it's like there's several pages within the same page. There is a navigation menu that takes you to each section on the page.

However, I need to know how to make it so that the site editor will be able to add sections (each with a custom name) on their own, by adding a page attribute.

PineCreativeLabs
 
glockops replied on at Permalink Reply
glockops
You could do this by having a different area for each section. So duplicate the "Add to Main" code and have Main 2, Main 3, etc.

Then for your navigation, you can have an attribute that links to the sections, something like "Name for Area 1", "Name for Area 2".

Finally your navigation would check to see if there are blocks in the area, and if so display the corresponding area name (set by the attribute) - if no attribute was set, you could give it a default value.

Untested code, may need tweaked.
<?php // Declare your section areas
$section1 = new Area('Section 1');
$section2 = new Area('Section 2');
$section3 = new Area('Section 3');
?>
<?php // Make your navigation ?>
<ul class="your-navigation">
<?php // Show navigation is in edit mode or if the area has blocks
 if($c->isEditMode() || $c->getTotalBlocksInArea($section1) > 0) { 
 // retrieve custom area name from attributes
$nav1 = ($c->getAttribute('handle_for_section1')) ? $c->getAttribute('handle_for_section1') : 'Enter default value here';
?>
<li><a href="#section1"><?=$nav1?></a></li>
<?php } // End if ?>
<?php // Repeat the above for each section you have, changing the section names and handles where needed ?>


Hope that helps!

Reference:http://www.concrete5.org/documentation/developers/pages/areas/...