In de kolom rechts naast elke pagina staat de “Navigatie”. Dit blok toont hyperlinks naar de moederpagina, de zusterpagina’s en/of de kinderen van de huidige pagina.
Deze navigatie heb ik geprogrammeerd in PHP, gebruik makend van de WordPress standaardfuncties. De functie is opgenomen in functies.php van het subthema.
De source-code van de functie:
<?php
function display_current_page_menu()
{
/* This functions displays a vertical navigation menu for the
current page, containing:
- a link to its direct parent (not the grandparents)
- links to its siblings (pages having the same parent)
- the title of the current page (not linkable)
- links to its direct childs (not the grandchilds)
By Henk Arendse (www.henkarendse.nl); 19-nov-2013.
*/
global $post;
$link_format = "<div class='%s'><a href='%s'>%s</a></div>";
if ($post->post_parent) {
// current page is sub-page.
// get its parent page; print a link to the parent.
$parent = get_post($post->post_parent);
echo (sprintf($link_format,
"spm-parent", //css class
get_page_link( $parent->ID ),
$parent->post_title ));
// get sibling pages
$siblings = get_pages( array(
'hierarchical' => 0,
'parent' => $post->post_parent,
'sort_column' => 'menu_order',
'sort_order' => 'asc' ) );
// print current page and its siblings
foreach( $siblings as $sibling ) {
// skip empty pages
$content = $sibling->post_content;
if ( ! $content ) continue;
if ($sibling->ID == $post->ID) {
// disply currrent page
echo ("<div class='spm-current'>"
. $post->post_title
. "</div>");
// get childeren of current page
$children = get_pages( array(
'hierarchical' => 0,
'parent' => $post->ID,
'sort_column' => 'menu_order',
'sort_order' => 'asc' ) );
foreach( $children as $child){
// skip empty page
$content = $child->post_content;
if ( ! $content ) continue;
// display link to child
echo (sprintf($link_format,
"spm-child", // css class
get_page_link( $child->ID ),
$child->post_title ));
} //foreach child
} else {
// display link to sibling
echo (sprintf($link_format,
"spm-sibling", // css class
get_page_link( $sibling->ID ),
$sibling->post_title ));
}
} // foreach sibling
} else { // current page is not a sub-page.
// get childeren of current page
$children = get_pages( array(
'hierarchical' => 0,
'parent' => $post->ID,
'sort_column' => 'menu_order',
'sort_order' => 'asc' ) );
// print the page title of the current page (not linkable)
// or link to home if no children
if ($children)
echo ("<div class='spm-parent'>"
. $post->post_title
. "</div>");
else
echo (sprintf($link_format,
"spm-parent", //css class
home_url(),
"Home" ));
foreach( $children as $child){
// skip empty page
$content = $child->post_content;
if ( ! $content ) continue;
// display link to child
echo (sprintf($link_format,
"spm-sibling", // css class
get_page_link( $child->ID ),
$child->post_title ));
} // foreach chilld
}
}
?>