WordPress.org

Ready to get started?Download WordPress

Forums

Corretly using conditional tags (1 post)

  1. veevee
    Member
    Posted 6 years ago #

    I'm working the navigation for my site, and have been struggling to get it to function the way I want. Right now I'm using

    <?php
     global $post;
     $myposts = get_posts('numberposts=1&offset=0&category=6');
     foreach($myposts as $post) :
     setup_postdata($post);
     ?>
    	<li>
    	<a href="<?php the_permalink() ?>" rel="bookmark">Prints</a>
    	</li>
    
     <?php endforeach; ?>

    to display a link to the most recent post of a specific category. I wanted to set a conditional statement, so that if you are in that category, the link turns into static text of a different color. I tried modifying the above statement to be:

    <?php
     global $post;
     $myposts = get_posts('numberposts=1&offset=0&category=4');
     foreach($myposts as $post) :
     setup_postdata($post);
     ?>
    
    <?php
    
    if (is_category()) {
          	echo "<ul style="color: fuchsia;">Drawings</ul>";
    } else {
    	echo "<li><a href=""
    	<?php the_permalink() ?>;
    	echo " rel="bookmark">Drawings</a></li>";
    }
    ?>
    <?php endforeach; ?>

    But I keep getting parse errors. I can't figure it out, would love some help if any one knew the correct syntax.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.