Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to get for two parents
Old 01-27-2011, 07:38 AM How to get for two parents
asmalik12's Avatar
Extreme Talker

Posts: 173
Name: Abdullah Saleem
Trades: 0
Hi,

Here is the code for posting on the pages with parent page '283' in Wordpress.

PHP Code:
<?php
if (283 == $post->post_parent) {
echo 
'this post has a parent of 283';
}
?>
I wanna use this code for another page with different parent '1048'. How can I do that? Also, It's not working on parent page, I wanna use it on parent page too .
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
asmalik12 is offline
Reply With Quote
View Public Profile Visit asmalik12's homepage!
 
 
Register now for full access!
Old 01-27-2011, 09:51 AM Re: How to get for two parents
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I wanna use this code for another page with different parent '1048'
Change the hardcoded '283' to '1048'

Quote:
Also, It's not working on parent page, I wanna use it on parent page too
To do what?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-27-2011, 10:49 AM Re: How to get for two parents
asmalik12's Avatar
Extreme Talker

Posts: 173
Name: Abdullah Saleem
Trades: 0
Hey dude, I wanna show it on 1041, 1048, 1132 page's child pages.

Secondly, When I use this It doesn't show in parent page....
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam

Last edited by asmalik12; 01-27-2011 at 12:47 PM..
asmalik12 is offline
Reply With Quote
View Public Profile Visit asmalik12's homepage!
 
Old 01-27-2011, 01:25 PM Re: How to get for two parents
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
PHP Code:
<?php
if ($post->post_parent == 1041) || ($post->post_parent == 1048)  || ($post->post_parent == 1132
   {
   echo 
'this post has a parent of '.$post->post_parent;
   }
?>
Not tested
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-27-2011, 06:28 PM Re: How to get for two parents
Average Talker

Posts: 16
Name: Filip Filipov
Location: Bulgaria
Trades: 0
Hi @asmalik12,
why not just use switch
PHP Code:
switch ($post->post_parent) {
  case 
283:
    echo 
'this post has a parent of 283';
    break;
  case 
1048:
    echo 
'this post has a parent of 1048';
    break;
  
// more ...

__________________

Please login or register to view this content. Registration is FREE
- IP Address Lookup. Domain Lookup. Geolocation by IP or Doomain Name

Please login or register to view this content. Registration is FREE
- Check PageRank, Alexa Rank, Backlinks, Indexed Pages, ...
primecode is offline
Reply With Quote
View Public Profile Visit primecode's homepage!
 
Old 01-27-2011, 09:01 PM Re: How to get for two parents
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
(a) don't hard code any numbers! if ($post->post_parent) {echo "parent is " $$post->post_parent;} (b) doesn't make sense to attempt this on the parent page -- think about the name of the value you're looking at! There must be a similar variable holding the parent's identity.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 01-28-2011, 09:43 AM Re: How to get for two parents
asmalik12's Avatar
Extreme Talker

Posts: 173
Name: Abdullah Saleem
Trades: 0
Quote:
Originally Posted by chrishirst View Post
PHP Code:
<?php
if ($post->post_parent == 1041) || ($post->post_parent == 1048)  || ($post->post_parent == 1132
   {
   echo 
'this post has a parent of '.$post->post_parent;
   }
?>
Not tested
Not Working... But That's what I want ( Use the stuff once like 'this post has a parent of' )

Quote:
Originally Posted by primecode View Post
Hi @asmalik12,
why not just use switch
PHP Code:
switch ($post->post_parent) {
  case 
283:
    echo 
'this post has a parent of 283';
    break;
  case 
1048:
    echo 
'this post has a parent of 1048';
    break;
  
// more ...

I don't wanna use to post echo value twice. I wanna use same stuff for both page's child pages.

Quote:
Originally Posted by PaulW View Post
(b) doesn't make sense to attempt this on the parent page -- think about the name of the value you're looking at! There must be a similar variable holding the parent's identity.
That's all what I want, but it should come in only one php tag which also includes page's child pages.
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
asmalik12 is offline
Reply With Quote
View Public Profile Visit asmalik12's homepage!
 
Old 01-28-2011, 12:03 PM Re: How to get for two parents
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
Quote:
I don't wanna use to post echo value twice. I wanna use same stuff for both page's child pages.
That won't echo the special content twice. When a case hits a matched value, it breaks. So the first time it would echo the alternate content, it would stop the case loop.

chrishirst's or primecode's case should work provided you are in the loop.

If this is in the function file then you need to make $post global.
(http://codex.wordpress.org/Conditional_Tags)

Can I offer a suggestion? If this is a page that will display alternate content from your standard page template - AND - you will be adding more sub-pages in the future you can always make a custom page template.

Then you could simply select this template when making any number of pages in the future RATHER than having to go back and edit the template code to add another page parent ID to the conditional check each time.

A custom template might be easier in the long run.
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
Old 01-29-2011, 07:12 AM Re: How to get for two parents
asmalik12's Avatar
Extreme Talker

Posts: 173
Name: Abdullah Saleem
Trades: 0
@racer x : I like your idea for creating new template. But how can I proceed?

Will it require to create every file function.php, page.php, single.php e.t.c. or just one file say wcpage.php and add my page.php code with the stuff I wanna add in current page.php?
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
asmalik12 is offline
Reply With Quote
View Public Profile Visit asmalik12's homepage!
 
Old 01-29-2011, 07:36 AM Re: How to get for two parents
asmalik12's Avatar
Extreme Talker

Posts: 173
Name: Abdullah Saleem
Trades: 0
Finally, done it... after some modifications... But racer x, don't forget to answer my last question regarding creating new template.

PHP Code:
<?php

   
if ( is_page('1041') || 1041 == $post->post_parent || 1048 == $post->post_parent || 1132 == $post->post_parent
        {
        echo 
'Stuff goes here';
        }
?>
When, I first tried chrishirst's code, I mistakenly removed ;.
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam

Last edited by asmalik12; 01-29-2011 at 07:38 AM..
asmalik12 is offline
Reply With Quote
View Public Profile Visit asmalik12's homepage!
 
Old 01-29-2011, 03:37 PM Re: How to get for two parents
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
There are many tutorials on this, though, the simplest way is to:
1. copy your current page.php file and paste into a new file.
2. At the top of the new file add:
PHP Code:
<?php
/*
Template Name: Custom Page 1
*/
?>
3. Then you can just modify the code in this new file as needed.

To use the template, simply select it from the Page Template options list in the right column of the edit page area.

Some reminders:
1. This is only for Pages, not Posts.
2. Any number of pages can select this template.
3. Be careful not to title it similar to page-contact-me.php.(eg: preceding with "page-") Doing so will make WP look for a page in your database titled exactly "contact me".(or the slug)

Alternately, you "can" title the custom page the same as a page slug in the database as mentioned above. However, going this route, you will not need to add the template name in comments at the top. These types of templates will be assigned automatically to the matching page and NOT allow the options for other pages to use them.

Official resource:
http://codex.wordpress.org/Pages

There are also some non-native WP functions for finding a subpage at http://www.mattvarone.com/wordpress/...page-function/

Last edited by racer x; 01-29-2011 at 03:38 PM..
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
Reply     « Reply to How to get for two parents
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.64415 seconds with 12 queries