Forum Moderators: coopster
<div id="main_content"><a href="<?php bloginfo('url'); ?>"><div id="header">
<?php if ( is_category(america-wants-peace) ) { ;?>
<div id="headercat01">
<?php } elseif ( is_category(world-peace) ){ ;?>
<div id="headercat02">
<?php } elseif ( is_category(religion-peace) ) { ;?>
<div id="headercat03">
<?php } elseif ( is_category(wise-want-peace) ) { ;?>
<div id="headercat04">
<?php } elseif ( is_category(non-violence-solves-problems) ) { ;?>
<div id="headercat05">
<?php } elseif ( is_category(american-militarization) ) { ;?>
<div id="headercat06">
<?php } elseif ( is_category(global-militarization) ) { ;?>
<div id="headercat07">
<?php } elseif ( is_category(war-propaganda) ) { ;?>
<div id="headercat08">
<?php } elseif ( is_category(war-economy-fails) ) { ;?>
<div id="headercat09">
<?php } elseif ( is_category(war-is-hell) ) { ;?>
<div id="headercat10">
<?php } else { ;?>
<div id="header">
<?php } ;?>
<h1></h1>
<div class="description"></div>
</div></a>
the error message is:
Parse error: syntax error, unexpected T_GLOBAL, expecting ')' in /home/peacepai/public_html/test/wp-content/themes/autumn-almanac/header.php on line 38
line 38 is:
<?php } elseif ( is_category(global-militarization) ) { ;?> although I know whatever is wrong with line 38 is wrong with at least half of the other lines.
<?php
if ( is_category(america-wants-peace) )
{ echo '<div id="headercat01">'; }
elseif ( is_category(world-peace) )
{ echo '<div id="headercat02">'; }
...and so on.
}
elseif ( is_category(american-militarization) ) {
echo("<div id=\"headercat06\">");
}
elseif ( is_category(global-militarization) ) {
echo("<div id=\"headercat07\">");
}
elseif ( is_category(war-propaganda) ) {
echo("<div id=\"headercat08\">");
}
elseif ( is_category(war-economy-fails) ) {
echo("<div id=\"headercat09\">");
}
elseif ( is_category(war-is-hell) ) {
echo("<div id=\"headercat10\">");
}
else {
echo("<div id=\"header\">)";
}
?>
[edited by: eelixduppy at 1:53 am (utc) on June 24, 2009]
[edit reason] disabled smileys [/edit]
You are stopping you php if statements so all of those divs are always going to be displayed
You don't HAVE to echo the divs...stopping and starting php is allowed, you should learn that as it's very useful.
If you choose to echo, echo with single quotes if your content has double quotes so you don't have to use escape characters. Why make it messier than you have to?
echo '<div id="headercat01">';
into just php you end up with
<?php if ( is_category(america-wants-peace) ) { ; }elseif{...
that is never going to execute anything.
Stopping and starting php is fine for small applications. Personally when I write anything, I have all of my php separated from my html using templates. If you write anything on a large scale it becomes too hard to debug if you always mixing php and html.
Let me know if you still can't get it working kilanw we were all where you are at one point in our lives.
Afterwards, I changed "is_category" to "the_category" and it brought the error message back. (i've seen both used to call the category from the database).
I also double checked the category "global-militarization". Everything is spelled properly and the category does exist.
The PHP is consistent across the board, I wonder why it's calling specifically THAT LINE, and not one before it?
Andrewsmd+Stoutfiles makes me feel I'm on the right track, but I'd really love to get this figured out. Thanks for your help so far everyone.
(global is some kind of PHP code! that's why error is T_GLOBAL. I changed the slug to world-militarization which takes away that error, then I get an error for unexpected ';' on line 58:
echo("<div id=\"header\">)";
}
?>
So I remove that and it says "unexpected '}' on line 59", so I remove that and it says "unexpected ';' on line 59".
of which there is no semi-colon on line 59.
So my guess is........
else {
echo("<div id=\"header\">)";
}
?>
is wrong in some way shape or form. What I'm trying to tell the PHP is
"if the category is this, call this header image"
but in the last line am trying to tell it
"if it's not one of those ten categories(if it's anything else), call this header image"
So what the hell am I doing wrong?
And to everyone, thanks in advance, I appreciate your help.
I'm using dreamweaver, and the word global was green, that's what tipped me off. So yes, it was highlighted.
I think category is a function? I'm building a wordpress, So what I'm trying to say is "If the category is this, display this header image" (which is set as background image of that div)
I modified my original code from what I saw here:
wordpress.org/support/topic/196979?replies=7
Here is the whole string, as is, now:
</head>
<body><div id="wrapper">
<div id="main_content">
<a href="<?php bloginfo('url'); ?>"><div id="header">
<?php
if ( is_category(america-wants-peace) ) {
echo('<div id=\"headercat01\">');
}
elseif ( is_category(world-peace) ){
echo('<div id=\"headercat02\">');
}
elseif ( is_category(religion-peace) ) {
echo('<div id=\"headercat03\">');
}
elseif ( is_category(wise-want-peace) ) {
echo('<div id=\"headercat04\">');
}
elseif ( is_category(non-violence-solves-problems) ) {
echo('<div id=\"headercat05\">');
}
elseif ( is_category(american-militarization) ) {
echo('<div id=\"headercat06\">');
}
elseif ( is_category(world-militarization) ) {
echo('<div id=\"headercat07\">');
}
elseif ( is_category(war-propaganda) ) {
echo('<div id=\"headercat08\">');
}
elseif ( is_category(war-economy-fails) ) {
echo('<div id=\"headercat09\">');
}
elseif ( is_category(war-is-hell) ) {
echo('<div id=\"headercat10\">');
}
else {
echo('<div id=\"header\">)';
}
?>
<h1></h1>
<div class="description"></div>
</div></a>
and current error message is:
Parse error: syntax error, unexpected ';' in /home/peacepai/public_html/test/wp-content/themes/autumn-almanac/header.php on line 58
Is it possible it's the last line? cause the top is telling it display <div id="header"> then it's saying if the category is any of these then display this corresponding div, then the line is or else if it's not these categories, display <div id="header">
I'm going to guess that doesn't need to be in there twice...
That got my site showing again. Now the header image appears, but not inline with the rest of the site. The 350 pixel height header that's supposed to show at the top of the screen above everything, now appears behind the navigation and other page elements.
Additionally, the intended effect was still not achieved. If I click on a category on the right side (america wants peace... etc.) it still shows the same header image, not the new header image for that category.
So while I think I can maybe(?) fix the first part of the problem with css, I still can't understand why it's not switching out the images...
I'll keep monkeying with it and come back to the post.
Thanks again for helping.
See if that echoes the correct thing on the correct page. Then you will know if it is a php problem or a html/css problem.
I also changed "is_category" to "the_category" and it displayed text to navigate to that category page.
I think it's possible is_category is the wrong command?
As I mentioned before, I pulled it from here
wordpress.org/support/topic/196979?replies=7
[edited by: coopster at 9:10 pm (utc) on June 24, 2009]
[edit reason] no personal urls please TOS [webmasterworld.com] [/edit]
A Category Page
is_category()
When any Category archive page is being displayed.
is_category('9')
When the archive page for Category 9 is being displayed.
is_category('Stinky Cheeses')
When the archive page for the Category with Name "Stinky Cheeses" is being displayed.
is_category('blue-cheese')
When the archive page for the Category with Category Slug "blue-cheese" is being displayed.
is_category(array(9,'blue-cheese','Stinky Cheeses'))
Returns true when the category of posts being displayed is either term_ID 9, or slug "blue-cheese", or name "Stinky Cheeses". Note: the array ability was added at Version 2.5.
in_category('5')
Returns true if the current post is in the specified category id. read more
Note: Be sure to check your spelling when testing, "is" and "in" are a big difference.
See also is_archive() and Category Templates.
There's something wrong with the final statement, though. I want it to display <div id="header"> (the default header) when it's not on one of those 10 categories. As it stands, it is displaying <div id="headercat10"> when it's on a regular category. Here's the whole code:
<a href="<?php bloginfo('url'); ?>"><div id="header">
<?php
if ( is_category(america-wants-peace) ) {
echo("<div id=\"headercat01\">");
}
if ( is_category(world-peace) ) {
echo("<div id=\"headercat02\">");
}
if ( is_category('religion-peace') ) {
echo("<div id=\"headercat03\">");
}
if ( is_category('wise-want-peace') ) {
echo("<div id=\"headercat04\">");
}
if ( is_category(non-violence-solves-problems) ) {
echo("<div id=\"headercat05\">");
}
if ( is_category(american-militarization) ) {
echo("<div id=\"headercat06\">");
}
if ( is_category(world-militarization) ) {
echo("<div id=\"headercat07\">");
}
if ( is_category(war-propaganda) ) {
echo("<div id=\"headercat08\">");
}
if ( is_category(war-economy-fails) ) {
echo("<div id=\"headercat09\">");
}
if ( is_category(war-is-hell) ) {
echo("<div id=\"headercat10\">");
}
else {
echo("<div id=\"header\">");
}
?>
<h1></h1>
<div class="description"></div>
when it's on a top level category, like just peace or green, it should be displaying green naked lady on the top. (like the homepage).
Thanks again.
[edited by: jatar_k at 8:23 pm (utc) on June 25, 2009]
Hence why it is showing the first statement. it's the only "if" statement.
same thing with the echo. No matter which category I click, it shows me "this header should be america-wants-peace"
<?php
if ( is_category(america-wants-peace) ) {
echo('<div id="headercat01">');
echo("we should have the header america-wants-peace");
}
elseif ( is_category(world-peace) ) {
echo('<div id="headercat02">');
echo("we should have the header world-peace");
}
elseif ( is_category(religion-peace) ) {
echo('<div id="headercat03">');
echo("we should have the header religion-peace");
}
elseif ( is_category(wise-want-peace) ) {
echo('<div id="headercat04">');
echo("we should have the header wise-want-peace");
}
elseif ( is_category(non-violence-solves-problems) ) {
echo('<div id="headercat05">');
echo("we should have the header non-violence-solves-problems");
}
elseif ( is_category(american-militarization) ) {
echo('<div id="headercat06">');
echo("we should have the header american-militarization");
}
elseif ( is_category(world-militarization) ) {
echo('<div id="headercat07">');
echo("we should have the header world-militarization");
}
elseif ( is_category(war-propaganda) ) {
echo('<div id="headercat08">');
echo("we should have the header war-propaganda");
}
elseif ( is_category(war-economy-fails) ) {
echo('<div id="headercat09">');
echo("we should have the header war-economy-fails");
}
elseif ( is_category(war-is-hell) ) {
echo('<div id="headercat10">');
echo("we should have the header war-is-hell");
}
else {
echo('<div id="header">');
}
?>
<h1></h1>
Thanks again for all the help
I seem to have got something going with this array. HOWEVER, the main header (not one of the ones to appear under a category, but the one to appear when NOT on those categories) takes FOREVER to load. Is there a simple fix here? Should I have the standard <div id="header"> there somewhere?
<a href="index.php"><?php wp_head(); ?></a>
</head>
<body><div id="wrapper">
<div id="main_content">
<a href="<?php bloginfo('url'); ?>">
<?php
$c = get_query_var('cat');
$cat = get_category ($c);
$headers = array(
'america-wants-peace' => 'headercat01',
'world-peace' => 'headercat02',
'religion-peace' => 'headercat03',
'wise-want-peace' => 'headercat04',
'non-violence-solves-problems' => 'headercat05',
'american-militarization' => 'headercat06',
'world-militarization' => 'headercat07',
'war-propaganda' => 'headercat08',
'war-economy-fails' => 'headercat09',
'war-is-hell' => 'headercat10'
);
$divid = isset($headers[$cat->slug]) ? $headers[$cat->slug] : 'header';
?>
<div id="<?php echo $divid ?>">
<h1></h1>
<div class="description"></div>
</div></a>
?>
<div id="<?php echo $divid ?>">
to
$divid = isset($headers[$cat->slug]) ? $headers[$cat->slug] : 'header';
echo('<div id="{$divid}">');
?>