I am developing a single page site within WordPress, that contains multiple sections. These sections are pages in WordPress.
In my index.php
I loop through all pages within WordPress and add them to the index file - front page with a custom loop.
Loop through all pages
<?php
$args = array('post_type' => 'page', 'orderby' => 'menu_order', 'posts_per_page' => -1);
$loop = new WP_Query($args);
?>
<?php if ($loop) : while ($loop->have_posts()) : $loop->the_post(); ?>
<?php $slides = get_field('flexslider'); ?>
<?php
if ($slides) {
get_template_part( 'templates/slideshow' );
} else {
get_template_part( 'templates/parallax' );
}
?>
<?php endwhile; ?>
<?php endif; ?>
MENU
Because I developing a single page layout, I should modify the basic WordPress navigation to output the right menu links specific for this type of layout. So the normal output (I removed the id
and class
attributes to focus on the right thing) should be replaced for a hashtag and the slug of the page.
Basic menu link markup:
<li id="" class=""><a href="http://prachtelectronica.nl/wordpress/?page_id=10" class="menu-link main-menu-link">Lightning</a></li>
Modified menu link (what I wish):
<li id="" class=""><a href="#lightning" class="menu-link main-menu-link">Lightning</a></li>
I use the following WordPress function to build a menu:
<?php wp_nav_menu( array(
'theme_location' => 'primary-menu',
'menu' => 'primary-menu',
'container' => 'nav',
'container_id' => 'primary-navwrapper',
'menu_id' => 'listnav',
));
?>
I would like that the position of each section (page) will be determine by the menu order that is set in Appearance > Menu
, so the customer has only three thing to do when creating a new section (page). (1) Create a page, (2) add the page to the menu (3) and order it inside the menu structure.
I already using the menu_order
property inside my page loop (as you can see above) to display the pages inside the index.php
file. The order of the menu is used to position the sections (pages) in the right order.
One extra option for the pages is that the user can add a custom template to a page by selecting the template ads
inside the WP editor. Pages that make use of this template named, "ads", should be displayed in index.php as a section, but not appears as a menu item in the list of menu item, because these sections are not relevant for the primary content.
I hope there is a solution for my wish. If you have any questions, please let me know it in the comments below. For now, thanks in advance.