Parallax wordpress theme. How can i get dynamically the page ID's to display their own sub-menus?
I'm creating a wordpress theme with parallax features and html5, the home has all the main pages and two different kind of navigations.
Main one, is the navigation for parent pages. So I have About, Projects and Contact.
But each one of this pages has child pages. About page has one child that is below it, but as i cannot access from the main menu, each page that has childs or subpages has the second type of menu.
Also projects, has different pages: "Projects" (main), "Design" (child), Consulting (child), etc.
The second menu that is placed on the right of the page as rounded buttons lists the parent "about" and the child "about 2".
I already figured it out a way to li开发者_如何学Pythonst those and to make the links behave with scroll to (parallax behavior)
But, the way that i have hardcodes the parent page. What i would like to do is to find a way to get dinamically the page ID so it won't be hardcoded, but as the theme works as a only one page site, it's making me get troubles.
Here is the code that i have, could anyone help me to find a way so the code is going to identify the ID of each current page to list the main and the children pages ?
As you see $parent = 13;
is hardcoded, and also it includes $pages = get_pages('hierarchical=0&include=13') ;
with the id hardcoded too. So all the pages are showing the same. I know i can create a conditional with is_page for each hardcoding it, but the idea is to make it dynamic.
Any help will be great!
THanks,
<?php
$parent = 13;
$args= array(
'parent' => $parent,
'hierarchical' => 0
);
$pages = get_pages('hierarchical=0&include=13') ;
foreach ( $pages as $page ) {
$new_title = str_replace( " ", "", strtolower( $page->post_name ) );
echo '<li><a href="#' . $new_title . '" title="' . $page->post_title . '">' . $page->post_title . '</a></li>';
}
$child_page_pages = get_pages($args);
foreach ( $child_page_pages as $page ) {
$new_title = str_replace( " ", "", strtolower( $page->post_name ) );
echo '<li><a href="#' . $new_title . '" title="' . $page->post_title . '">' . $page->post_title . '</a></li>';
}
?>
To get post parent page ID's you can use get_post_ancestors( $post )
it should return the parent ID.
$ReturnParents = get_post_ancestors($post->ID);
Another method you can try is the global $post
.
global $post;
global $wp_query;
$thePostID = $wp_query->post->ID;
$myParent = $post->post_parent;
echo "I am post ". $thePostID . " and my parent is " . $myParent;
精彩评论