mistafro Posted March 23, 2011 Share Posted March 23, 2011 I have a wordpress site that has a ribbon graphic on the index page posts that are in the category "features", it works great when it's like this: <?php //for better seo, we use alt and titles in h query_posts('category_name=features&showposts=4'); while(have_posts()):the_post(); $attrs = array( 'src' => $src, 'class' => "", 'alt' => get_the_title(), 'title' => get_the_title(), );?> <!-- Blog entry --> <div class="blog_entry"> <!-- inside --> <div class="inside"> <!-- Thumbnail --> <div class="thumbnail"> <a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_post_thumbnail('blogsmall', $attr );?></a> </div> <!-- /Thumbnail --> <!-- Resume --> <div class="resume"><div class="featured_banner2"></div> <h3 class="cufon"><a href="<?php the_permalink();?>"><?php the_title();?></a></h3> <p class="bigline"><?php the_excerpt();?></p> <br> <?php if(function_exists('the_ratings')) { the_ratings(); } ?> </div> <!-- /Resume --> but when going to the category view it doesn't work to just add the <div class="featured_banner2"></div> as all post types get the ribbon. So I am trying to use a PHP if statement to only apply that featured_banner2 div line to posts with the category name of "features" I am a total php newbie, so far I tried this but it obviously is not right, I am trying though! lol: <!-- Resume --> <div class="resume"> <?php if ( in_category( 'features' )) { <div class="featured_banner2"></div> } endif;?> <h3 class="cufon"><a href="<?php the_permalink();?>"><?php the_title();?></a></h3> <p class="bigline"><?php echo get_the_excerpt();?></p> </div> <!-- /Resume --> Quote Link to comment Share on other sites More sharing options...
MrXHellboy Posted March 23, 2011 Share Posted March 23, 2011 if ( in_category( 'features' )) { ?><div class="featured_banner2"></div><?php } Quote Link to comment Share on other sites More sharing options...
mistafro Posted March 23, 2011 Author Share Posted March 23, 2011 Hi, thanks. I haven't tried this yet but is that all the code I need? The php looks strange to me as I usually see it start like <?php Quote Link to comment Share on other sites More sharing options...
MrXHellboy Posted March 23, 2011 Share Posted March 23, 2011 you want to parse a HTML division. You could you something like if ( in_category( 'features' )) { echo '<div class="featured_banner2"></div>'; } But PHP is faster parsing HTML instead of print HTML time after time. Quote Link to comment Share on other sites More sharing options...
mistafro Posted March 23, 2011 Author Share Posted March 23, 2011 Both of these don't work. Quote Link to comment Share on other sites More sharing options...
MrXHellboy Posted March 23, 2011 Share Posted March 23, 2011 Its not the php, try to ad the category slug in this in_category() function Quote Link to comment Share on other sites More sharing options...
mistafro Posted March 23, 2011 Author Share Posted March 23, 2011 The slug is there "features" I get the text for the div echoing out on the page but for all of the categories, not just featured. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.