At work a few months ago, I needed a lightweight “News” feature for a site we were developing. The news articles needed to behave just like regular blog posts, in that they should have a news archive page in reverse chronological order. I also needed a widget that would display the latest news items in a sidebar. Rather than using just a category to exclude or include posts based on context, I elected to make a simple plugin that would add a News custom post type (CPT) through a plugin. That’s how the News-CPT plugin was born.
This approach has a couple of big advantages over other methods. Using a custom post type instead of a category means that I don’t have to filter the News articles from regular lists post, like on the homepage, and in recent posts lists in sidebars. Adding the custom post type through a plugin means that you can change themes without having to remember to copy the CPT code from one themes’s files to another. Once you activate the plugin, the News post type will remain available, no matter how many themes you try.
The plugin also supplies basic single-news.php and archive-news.php templates to get you started styling those pages. All you have to do to customize those pages is make copies of those pages into your theme’s directory and modify them to your heart’s content. The plugin will use your customized template files first, and only fall back on its basic files if a custom version doesn’t exist in your theme folder.
You can download my plugin from the WordPress plugin repository at http://wordpress.org/plugins/news-cpt/. There is more complete documentation there.
4 thoughts on “News-CPT Plugin for WordPress”
Hi Van Jesse,
Do you have examples of the news pages in action?
We implemented it on our site but the formatting is not good but we have not updated the PHP pages yet.
Are there services that could help us with the formatting?
The plugin was originally developed for this site, http://www.boatsmangillmorewagner.com/news/. The PHP templates there were customized to work with their business theme, which is a child theme of Genesis.
You can see how to format the templates for your site at the News CPT FAQ page. Look under the heading What’s the easiest way to create my own custom version of the news templates?.
The way the templates work is pretty standard, so a developer who is familiar with WordPress themes developer should be able to help you with it.
Thanks for trying the plugin.
I need to return the news post to standard post, is there an easier way to do this instead of re-typing out the posts again?
You can make all the
/newsinto regular old “posts” by changing their post_type field in your database from news to post.
(The only caveat is that if you have any “News” items with the exact same URL, after the “/news” part, as an existing part, you will need to change those news items’ name fields, too. Otherwise, WordPress will be confused about which post to display, if they are both in the “post” type.)
Comments are closed.