I loaded wordpress page titles in top of my theme using get_pages()
function like a navigation menu:
<ul>
<?php $pages = get_pages('child_of=0&parent=0&echo=0');
foreach($pages as $page){
echo '<li class=pages id=menu_'.$page->ID.' >';
echo $page->title;
echo '</li>';
}
?>
</ul>
Note:
- that the printed
page titles
doesn't have link to the page. - and all
<li>
tags have sameclass=pages
- and each
<li>
tag has anid
related to current$page->ID
and I've used Jquery
for call a function to show children of each page on click of each <li>
tag with 2 last character of id
attribute like below:
<script type=text/javascript>
$(document).ready(function(){
$('.pages').click(function(){
var id = $(this).attr('id');
id = id.substring(5,7);
$('body').append(<?php get_pages('child_of=id&echo=1'); ?>);
});
});
</script>
Bu It doesn't work, it seems the PHP block code
called when page loaded.
Please help me to call the wordpress get_pages
function on click event of each <li>
to load children of pages.