1

Could anyone help me with that php script, I'm very new to php and having troubles with making this code to work

 $current = $post->ID;
  $parent = $post->post_parent;
  $grandparent_get = get_post($parent);
  $grandparent = $grandparent_get->post_parent;
  if ($root_parent = get_the_title($grandparent) !== $root_parent = get_the_title($current)) {echo ' <a href="get_permalink($grandparent)">get_the_title($grandparent)</a>';}else {echo '<a href="get_permalink($parent)">get_the_title($parent)</a>';}

The last bit from 'if doesnt work i guess there is some syntax problem

Many thanks,

2
  • no but my output is get_the_title($parent) which should be title of the page wrapped in a href Commented Mar 18, 2011 at 11:19
  • There is a lot wrong with this, if you are planning on doing any more edits with WP code, I suggest read some PHP basics. Commented Mar 18, 2011 at 11:28

1 Answer 1

1

Variable does not parsed if they are quoted with single quote.

There are many way to parse them but I am posting one of them try below code

echo " <a href=\"get_permalink($grandparent)\">get_the_title($grandparent)</a>";}
else {echo "<a href=\"get_permalink($parent)\">get_the_title($parent)</a>";}

OR

echo  '<a href="'.get_permalink($grandparent).'">'.get_the_title($grandparent).'</a>';}
else {echo '<a href="'.get_permalink($parent).'">'.get_the_title($parent).'</a>';}
Sign up to request clarification or add additional context in comments.

2 Comments

<?php $current = $post->ID; $parent = $post->post_parent; $grandparent_get = get_post($parent); $grandparent = $grandparent_get->post_parent; if ($root_parent = get_the_title($grandparent) !== $root_parent = get_the_title($current)) {echo '<a href="'.get_permalink($grandparent).'">'.get_the_title($grandparent).'</a>';}else {echo '<a href="'.get_permalink($parent).'">'.get_the_title($parent).'</a>';} ?> That is what i have now and for some reason it breaks page, sorry for being pain
@jmysona: If it helped accept the answer by clicking on the right arrow besides the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.