Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

wordpress - is parent page

Posted on 2011-03-16
4
Medium Priority
?
1,047 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

604 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