Customizing the News Page

There are a number of developers who want to use WordPress as an aggregated news source - this is the number one reason I created the News Page. The News Page template is pretty easy to understand, and consequently easy to modify.

Each column in the News Page is defined in the stylesheet - here’s the breakdown of each column in the page_news.php file:

  • News Section #1 is defined as <div id=”newspageleft”>
  • News Section #2 is defined as <div id=”newspagemiddle”>
  • News Section #3 is defined as <div id=”newspageright”>

By default, the code written for each of these three columns is the same - the code is calling to publish the excerpt of the latest post in category ID #1. I did it that way because on every WordPress install there will always be a category ID #1, and always an initial post.

However the beauty of the Revolution theme is how customizable it is, and how simple it is to change things around. I’ll break down each section to make it easier to customize. The following code defines the image that’s in each column:

<img src="<?php bloginfo('template_url'); ?>/images/np-1.jpg" alt="<?php bloginfo('name'); ?>" />

The code below is really the heart of the news page. This is where you can define which category you want to pull, and how many posts you want to show:

<?php $recent = new WP_Query("cat=1&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<b><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></b>
<?php the_excerpt(__('Read more'));?><div style="clear:both;"></div>
<?php endwhile; ?><br />

The code that says “cat=1″ is the category that is being pulled, where 1 is the category ID #, and then the “showposts=1″ is where you can define how many posts of that category you want to show.

Lastly, there is a list at the bottom of each column that currently shows the previous post titles of the category you are specifying. The code below acts in the same way as mentioned above, the only exception is that the post content isn’t shown:

<ul>
<?php $recent = new WP_Query("cat=1&showposts=5"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>