Featured Post on Wordpress


/ Published in: PHP
Save to your folder(s)

This code goes into the index.php


Copy this code and paste it in your HTML
  1. <?php while (have_posts()) : the_post(); ?>
  2. <!-- EVEN IF YOU'VE GOT PAGEST OF POSTS AFTER THE HOMEPAGE, ONLY THE FIRST POST ON THE FIRST PAGE WILL BE STYLED DIFFERENTLY -->
  3. <?php if (is_paged()) : ?>
  4. <?php $postclass = ('regular'); ?>
  5. <?php else : ?>
  6. <?php $postclass = ($post == $posts[0]) ? 'featured' : 'regular'; ?>
  7. <?php endif; ?>
  8.  
  9. <!-- NOW THAT WE'VE SET UP THE CONDITIONS, LETS CREATE A DIV WITH THE CSS CLASS FED DYNAMICALLY -->
  10. <div class="<?php echo $postclass; ?>">
  11. <!-- THIS IS WHERE ALL THE SCRIPT FOR YOUR POST GOES -->
  12.  
  13. <?php comments_template() ?>
  14. <?php endwhile ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.