• Resolved do77

    (@do77)


    Hi,

    I want to style single posts of category 1 different than those of category 2. In the function reference I read that this can be achieved with in_category() so I added the tag to my single.php file within the loop. However, now it says I have an unexpected error ‘<‘ on line 36.

    Here is my code:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <?php if ( in_category( 'news' )) {
    
    <h1><?php the_title(); ?></h1>
    <div class="single"><?php the_content(__('Read more', ''));?></div>
    
    } else {
    
    <h1><?php the_title(); ?></h1>
    <div>A lot of code including custom fields and an if statement if a user is logged in etc. </div>
    
    }
    ?>

    Any idea what I am doing wrong? Would appreciate your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • make sure to close and open your php tags anytime the code switches to and from html code:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <?php if ( in_category( 'news' )) { ?>
    
    <h1><?php the_title(); ?></h1>
    <div class="single"><?php the_content(__('Read more', ''));?></div>
    
    <?php } else { ?>
    
    <h1><?php the_title(); ?></h1>
    <div>A lot of code including custom fields and an if statement if a user is logged in etc. </div>
    
    <?php }
    ?>
    Thread Starter do77

    (@do77)

    That was it! Thank you so much alchymyth!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problems with in_category()’ is closed to new replies.