Solved

wordpress - is parent page

Posted on 2011-03-16
4
987 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
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
meb_santoso earned 250 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 250 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 look for a specific file type in a local or remote server directory using PHP.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now