Page 1 of 1

PHP Code / Wordpress Syntax Problem

Posted: Tue Mar 22, 2011 8:22 am
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.

Re: PHP Code / Wordpress Syntax Problem

Posted: Tue Mar 22, 2011 9:06 am
by Darhazer

Code: Select all

<?php
if ( is_home() ) {
} else {
?><h2><?php the_title(); ?></h2><?php
}
?>

Re: PHP Code / Wordpress Syntax Problem

Posted: Tue Mar 22, 2011 9:48 am
by OnlineD
Many hanks

is_home did not work for some reason, but I got it working using this syntax with is_front_page

Re: PHP Code / Wordpress Syntax Problem

Posted: Sun Mar 27, 2011 1:35 pm
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.

Re: PHP Code / Wordpress Syntax Problem

Posted: Sun Mar 27, 2011 3:59 pm
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