Prerequisites:
To use news shortcodes, you must publish your news items as posts in WordPress. Shortcodes do not display WordPress pages. Additionally, if you want to output separate news feeds that are specific to certain topics, you must create the appropriate categories (Manage > Categories), and apply them to your news posts.
Overview
Use news shortcode anywhere on your website where you want to output a news feed from the posts you publish in WordPress. Use it to display the most recently-posted news items on your home page. You can use it on a main page for a specific topic within your site and only display the most recent news posts from a category. The shortcode has been designed to allow for maximum flexibility.
Shortcode uses a special type of tag that begins and ends with square brackets — [ ]. Customized attributes are specified inside the brackets. The shortcode for news posts can be as simple as entering this:
[bu_list_news structure=”title”]
Where you have entered this shortcode, WordPress will return a list of news posts showing the title of the post, and the title links to the full news page. The format uses the unordered list tag with HTML classes of “news_list” and “category_{{category_id}}.” Each list item will also have an HTML class of “post-{{post_id}}.”
Example output would look something like this:
<ul class="news_list category_0">
<li class="post-45">News Post Title</li>
<li class="post-46">News Post Title</li>
<li class="post-48">News Post Title</li>
<li class="post-51">News Post Title</li>
<li class="post-57">News Post Title</li>
</ul>
… where “0” is the category ID (“0” means all categories), and “45,” “46,” “48,” “51,” and “57” are the individual news post IDs.
News Shortcode Attributes
You have several optional attributes you can use in the shortcode to customize the type of output you get from WordPress. Each attribute has a default value, but you can change those default values for even more flexibility.
Attributes | Default Value | Description |
---|---|---|
category | All | Post category ID that the listing will come from (“All” or “0” denotes all categories) |
number | 5 | Maximum number of posts |
structure* | title:date:excerpt | The components and order of components that are output for each post. Possible values include, but are not limited to: title, date, excerpt, author, and tag. |
excerpt_length | 12 | Number of words output in the excerpt |
more_link | [ More ] | Text label for the link that points to the post |
age_cap | 6 | Cutoff point for the search in months |
random | 0 | Randomize listing on page load using Javascript: 1 is on and 0 is off |
random_pool_size** | 10 | Number of posts to choose from |
thumb_size | 65 | Size in pixels for width/height of the thumbnail or name of image size. If numeric, size in pixels for width/height of the thumb. If string, a specific thumb size (e.g. ‘thumbnail’, ‘medium’, ‘full’). |
date_format | F j, Y | Date format |
*To provide flexibility in the order of components and control over which components are output, the structure attribute has a specific syntax. Currently, there are five components that can be output: title, date, excerpt, author, and thumbnail. An editor can specify what components are output and where they are listed.
**When using the random_pool_size attribute, the number specified must be equal to or greater than the maximum number of posts available in the selected category.
For example: [bu_list_news structure=”title:excerpt”] would output the news post title, followed by the excerpt.
If your shortcode’s structure syntax has an error, the shortcode will fail and output this error:
ERROR: The structure attribute for the shortcode is not defined properly.
Each component has specific HTML markup you can use to style your output with CSS.
Component | Markup |
---|---|
date | <span class="date">{{date}}</span> |
title | <h4 class="news_post_title"><a href="{{permalink}}">{{post_title}}</a></h4> |
excerpt | <p class="excerpt">{{content}}... <a ref="{{permalink}}">{{more_link}}</a></p> |
author | <p class="author">By {{firstname}} {{lastname}}</p> |
thumbnail*** | <div class="thumbnail"> {{thumbnail}} </div> |
***Using the thumbnail component in news shortcode requires activation of the headline thumbnail plugin. Please see Using the Headline Thumbnail for more information.
Examples
The shortcode system is very flexible and customizable using the various attributes listed above. Here are some examples:
- What you want: A list of 5 most recent news posts in category #32, and just the news post title.
Shortcode:
[bu_list_news category="32" number="5" structure="title"]
- What you want: A list of 10 news posts from category #63, displayed in random order, with date, title, and author (in that order).
Shortcode:
[bu_list_news category="63" number="10" random="1" structure="date:title:author"]
- What you want: A list of 6 most recent news posts in category #44 displaying the title and a 25-word excerpt.
Shortcode:
[bu_list_news category="44" number="6" structure="title:excerpt" excerpt_length="25"]
- What you want: A list of 7 most recent news posts in category #17 but display nothing older than 2 months.
Shortcode:
[bu_list_news category="17" number="7" age_cap="2"]
- What you want: A list of 10 most recent news posts in category #25, displaying date, title, excerpt, and an 80×80 pixel thumbnail image.
Shortcode:
[bu_list_news category="25" number="10" structure="thumbnail:date:title:excerpt" thumb_size="80"]
How to Determine a Category ID
The news shortcode is easy to use, but it does require that you figure out what “category ID” you want to use in your output. The easiest way to determine the ID for the category you want to use is:
- Go into the WordPress editor to News Posts and then select Categories.
- Click on the name of the category you want.
- That takes you to the Edit Category page. Here, just look for the number at the end of the URL. That is the Category ID number.