PHP Code / Wordpress Syntax Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
OnlineD
Forum Newbie
Posts: 5
Joined: Thu Mar 17, 2011 5:54 am

PHP Code / Wordpress Syntax Problem

Post by OnlineD »

I am new to PHP and new to Wordpress so have a steep learning curve ahead of me.

I have what appears to be a simple issue I just can not crack. All I have trying to do is show a page title or not depening on the page within a Wordpress I am looking at. I am using the is_home statement so it should be simple but I am getting an error, I suspect because my syntax is incorrect. This is what I am trying to do

Code: Select all

<?php
if ( is_home() ) {
 // If this is the home I do not want to show anything
} else {
 // If this is not the home page then I want to show the page title.
}
?>
I tried it like this but then got the error

Code: Select all

<?php
if ( is_home() ) {
} else {
<h2><?php the_title(); ?></h2>
}
?>
It seems like it should be easy but can anyone give me a steer on this.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: PHP Code / Wordpress Syntax Problem

Post by Darhazer »

Code: Select all

<?php
if ( is_home() ) {
} else {
?><h2><?php the_title(); ?></h2><?php
}
?>
OnlineD
Forum Newbie
Posts: 5
Joined: Thu Mar 17, 2011 5:54 am

Re: PHP Code / Wordpress Syntax Problem

Post by OnlineD »

Many hanks

is_home did not work for some reason, but I got it working using this syntax with is_front_page
OnlineD
Forum Newbie
Posts: 5
Joined: Thu Mar 17, 2011 5:54 am

Re: PHP Code / Wordpress Syntax Problem

Post by OnlineD »

I now have a similar problem b ut this time I need to put in two extra PHP elements

Code: Select all

<?php
if ( is_front_page() ) {
<link rel="stylesheet" href="<?php bloginfo("template_url"); ?>/style_home.css" type="text/css" media="screen" />
} else {
?><link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<?php
}
?>
But I am getting an error after the first if call. Again this is a syntax thing I think.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: PHP Code / Wordpress Syntax Problem

Post by Darhazer »

When you are writting HTML code, you have to close PHP first

Code: Select all

<?php
if ( is_front_page() ) { ?>
<link rel="stylesheet" href="<?php bloginfo("template_url"); ?>/style_home.css" type="text/css" media="screen" />
<?php } else {
?><link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<?php
}
?>
or you have to use xhp
Post Reply