[Help] Get current page id base on page title
-
Hi everyone,
I’d like to list all child pages of the current browsing page. But my URL is: https://www.domain.com/pageTitle
I googled it and found the code which works with this type of URL: https://www.domain.com/?page_id=123
I tried to use
the_title();
to get the current page title and tried to convert it to string, then use theget_page_by_title();
to get the page ID.
But it doesn’t work.This is my code:
<!-- List child pages only --> <?php //$this_page_title = the_title(); $this_page_title = 'the_title()'; $this_page_id = get_page_by_title($this_page_title); if($post->post_parent) $children = wp_list_pages("depth=1&title_li&child_of=.$this_page_id->ID&echo=0"); else $children = wp_list_pages("depth=1&title_li&child_of=.$this_page_id->ID&echo=0"); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php } ?> <!-- // End list -->
Please help me!
Thanks in advanced!
PS: I don’t know what differences between
.$this_page_id
,.$this_page_id.
and$this_page_id
. Please explain.(sorry if my english bad ^^)
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘[Help] Get current page id base on page title’ is closed to new replies.