Solved

wordpress - is parent page

Posted on 2011-03-16
4
1,008 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The viewer will learn how to count occurrences of each item in an array.

770 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