Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

At the moment I'm trying to figure out why this snippet is not working basically I want to display a div id for different categories. I'm using the following.

 <?php if (in_category( array('6,14,15,13') )) { ?>
 <div id="eatheader">

 <?php } elseif (in_category( array('7,11,12,10,9') )) { ?>
 <div id="goheader">

 <?php } elseif (in_category( array('4,16,17,18,19') )) { ?>
 <div id="playheader">

 <?php } elseif (in_category( array('3,22,21,26') )) { ?>
 <div id="shopheader">

 <?php } elseif (in_category( array('5') )) { ?>
 <div id="talkheader">

 <?php } else { ;?>
 <div id="defaultheader">

 <?php } ?>

But this is not working I'm getting the following error message:

Parse error: syntax error, unexpected $end in /home/test/public_html/project/wp-content/themes/project/category.php on line 75

Line 75 is the

<?php get_footer(); ?>

Any help would be awesome, thanks!

share|improve this question
    
the posted code does not create an error - search somewhere else in your template. –  Michael Jul 14 '12 at 9:33
add comment

1 Answer

up vote 1 down vote accepted

The unnecessary semi-colon is probably causing the error. <?php } else { ;?> should be <?php } else { ?>. Try this:

<?php if (in_category( array(6,14,15,13) )) { ?>
<div id="eatheader">

<?php } elseif (in_category( array(7,11,12,10,9) )) { ?>
<div id="goheader">

<?php } elseif (in_category( array(4,16,17,18,19) )) { ?>
<div id="playheader">

<?php } elseif (in_category( array(3,22,21,26) )) { ?>
<div id="shopheader">

<?php } elseif (in_category(5)) { ?>
<div id="talkheader">

<?php } else { ?>
<div id="defaultheader">

<?php } ?>

As you can see, I've also modified <?php } elseif (in_category( array('5') )) { ?> to <?php } elseif (in_category(5)) { ?> as you are specifying just one category.

The same code can be rewritten to this (just in case it's useful to you—more readable and understandable):

<?php

    if ( in_category( array( 6,14,15,13 ) ) ) {
        echo '<div id="eatheader">';
    }

    elseif ( in_category( array( 7,11,12,10,9 ) ) ) {
        echo '<div id="goheader">';
    }

    elseif ( in_category( array( 4,16,17,18,19 ) ) ) {
        echo '<div id="playheader">';
    }

    elseif ( in_category( array( 3,22,21,26 ) ) ) {
        echo '<div id="shopheader">';
    }

    elseif ( in_category( 5 ) ) {
        echo '<div id="talkheader">';
    }

    else {
        echo '<div id="defaultheader">';
    }

?>
share|improve this answer
    
the 'same code can be rewritten' will lead to an error message because it mixes html and php code. –  Michael Jul 14 '12 at 9:35
    
@Michael Yeah, right. Don't know what I was thinking... thanks for the headsup though, corrected. :) –  its_me Jul 14 '12 at 11:48
    
thanks for the correction ;-) –  Michael Jul 14 '12 at 12:49
    
Thanks works perfectly! –  savunit Jul 16 '12 at 21:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.