<?php echo get_the_title($root_page_id);?>
Thread Starter
ajcke
(@ajcke)
That does the trick. On the home page it this code displays the latest post title. I would probably need some type of if statement to detect the homepage and display the site title. What code could I use for that?
Thread Starter
ajcke
(@ajcke)
And one more thing. When a post page is displayed the code displays the post title. How could this code display the site title instead of the post title?
<?php $page_title = ( empty( $post->ancestors ) ) ? get_bloginfo('name') : get_the_title(end( $post->ancestors )); ?>
<h2><?php echo $page_title ; ?></h1>
Thread Starter
ajcke
(@ajcke)
I tried the following code to resolve the homepage issue. It gave my site the white screen of death and if I remove the code I can’t get my site back.
<?php
if ( is_home() ) {
<h1><?php bloginfo('name'); ?></h1>
} else {
<?php $root_page_id = ( empty( $post->ancestors ) ) ? $post->ID : end( $post->ancestors ); ?>
<h1><?php echo get_the_title($root_page_id);?></h1>
}
?>
[Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
<?php
if ( is_home() ) {
?><h1><?php bloginfo('name'); ?></h1><?php
} else {
$root_page_id = ( empty( $post->ancestors ) ) ? $post->ID : end( $post->ancestors ); ?>
<h1><?php echo get_the_title($root_page_id);?></h1>
}
?>
Thread Starter
ajcke
(@ajcke)
I’m banging my head over this one. I get a white screen with the following code. I don’t see any issues with it.
<?php
if ( is_home() ) {
// This is a homepage
<h1>Homepage</h1>
} else {
// This is not a homepage
<h1>Not Homepage</h1>
}
?>
Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
You aren’t closing off your PHP or stringifying the HTML.
Why aren’t you using the code I suggested?
Why do you keep changing on your own?
Thread Starter
ajcke
(@ajcke)
I tried, but my site displays a white screen with the if statement code. Can you post an example of what it should look like? Is ?> not properly closing the php?
I already did twice, see above.
Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
Go with Rajesh’s example.
Thread Starter
ajcke
(@ajcke)
Rajesh your first snippet of code works perfectly. I’m not sure why it wasn’t displaying correctly…user error!