1

On my site I want to add a section just below Navigation and above-content (from where posts starts to show up on front page) which would show a panel where I can put any BREAKING NEWS (not always, whenever I want) with its excerpt and image. That panel should stretch with max-width.

I want to pull that BREAKING NEWS from a specific category say - category_breaking.

Is it possible? If yes, then how?

Thanks for the help.

I want to achieve exactly like this - (https://i.sstatic.net/1jYuh.png)

1 Answer 1

2

It's certainly possible, and is a common thing to do with WordPress:

<?php
  $q = new WP_Query('category_name=category_breaking'); // query that gets all posts in category "category_breaking"
  if( $q->have_posts() ) : // if there are posts returned by query...
    echo "<div id='breaking_news'>"; // start the breaking news section
    while( $q->have_posts() ) : $q->the_post(); // start looping through query results
      echo "<div class='bn_post'>"; // single breaking news post start
      echo "<h2>".get_the_title()."</h2>"; // display breaking news post title
      if(has_post_thumbnail()) // if post has featured image set...
      {
        the_post_thumbnail(); // then display featured image
      }
      echo "</div>"; // close single breaking news post
    endwhile;
    echo "</div>"; // close breaking news section
  endif;
?>
2
  • Well, you made it sound so simple. I would be applying that asap and would let you know. :)
    – vajrasar
    Commented Aug 21, 2012 at 20:30
  • well, after using your help and forking it a bit with the help of various forums. I came to wrap it up with what I need. Thanks. This is the final code I used, which is working fine. dpaste.com/hold/790904
    – vajrasar
    Commented Aug 24, 2012 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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