?
Solved

wordpress - is parent page

Posted on 2011-03-16
4
Medium Priority
?
1,040 Views
Last Modified: 2012-05-11
How do I change the below code to say...

if parent page is ...

instead of if page is ...

<?php if (is_page(array('my-knowledge' ,'clients', 'skills'))) { ?>
      
                                    <h1 class="entry-title"><?php the_title(); ?></h1>

                              <?php } else { ?>
0
Comment
Question by:petewinter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
meb_santoso earned 1000 total points
ID: 35160607
wait... what ?
what do you want to do exactly?

from what I can understand you want to do something like this:

IF the parent page IS one of these pages: my knowledge, clients, or skills
THEN display the title from the child page
ELSE display whatever

is that correct?

if so, you can do the following (among 1000 other ways to do it)
-. get current post's parent
-. cross check the current page's parent ID against the predefined IDs
-. return true or false
-. use the return value to do whatever you need to do

# make a function first, put in functions.php

function is_child($pageID) { 
	global $post; 
	if( is_page() && ($post->post_parent==$pageID) ) {
               return true;
	} else { 
               return false; 
	}
}

Open in new window


# do some checking

<?php
if(is_child(123) || is_child(456) ) {
echo "This is a child page of some parent";
} else {
echo .....etc.........
?>

Open in new window

0
 
LVL 31

Assisted Solution

by:gwkg
gwkg earned 1000 total points
ID: 35173926
Didn't test this...

$find = array('my-knowledge' ,'clients', 'skills')
if (in_array($post->post_parent,$find)) {
    <h1 class="entry-title"><?php the_title(); ?></h1>
<?php } else { ?>
0
 
LVL 31

Expert Comment

by:gwkg
ID: 35173930
semi-colon after the first line
0
 

Author Closing Comment

by:petewinter
ID: 35180796
many thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question