Documentation:UBC Content Management System/CLF Theme/Loop
|Welcome to the support documentation for the
UBC CMS Service.
|UBC Collab Theme|
[loop] is a very powerful shortcode that allows you to customize the type of content to display. With this shortcode you can do anything mentioned here. For more information on what kind of parameters are possible in the query parameter please see: WP Query Parameters.
You can place the shortcode anywhere in the site.
Note: You must activate the Loop Shortcode plugin to use the shortcode
- query - the query that you want to retrieve from the database see some possibilities here.
- rss - the url of the feed that you want to display,
- view - choose one (full, archive, list) or create your own.
- pagination - by default pagination is false, only works with the query and not the rss.
- num - used in conjunction with the rss to display a limited set of item,
- error - what to display if there is no results can be found
- author - filters posts by author name or for the current logged in user, use: author="current_user" #
'# for current user comments, use the [user_comments] shortcode
Examples of Loop Usage
Please find below several examples of [loop] usage.
The following line placed in the main content area of the frontpage will display the latest 5 posts on the frontpage of the site:
[loop query="posts_per_page=5" view="archive"]
The following line placed in the main content area of the frontpage will display the latest 5 posts on the frontpage of the site, with pagination enabled to navigate to older posts:
[loop query="posts_per_page=5" pagination="true" view="archive"]
To combine parameters in the query, use the ampersand character ('&'). The following line displays 5 posts from the category SampleCategory:
[loop query="posts_per_page=5&category_name=SampleCategory" view="archive"]
Here is how the outcome looks on the website:
You can use the following attributes for the view parameter:
Below is another example of [loop] usage:
[loop query="category_name=Conference"] [link_with_content] [the_excerpt] by [the_author] - Date: [last-updated] [/loop]
You can use the following parameters within the [loop] shortcode: *[the_content] *[permalink] *[the_excerpt] *[the_author] *[the_title] *[the_date] (post publish date, but one date per page, see http://codex.wordpress.org/Function_Reference/the_date) *[the_time] (to display the date with multiple posts with the same date, use [the_time format='F j, Y']) *[last-updated] *[the_post_thumbnail] *[categories] *[tags] *[cf field_name] (where 'field_name' is the name of a custom field in the query. The value of the custom field will be displayed) *[link_with_content] *Documentation:UBC Content Management System/CLF Theme/List of currently available shortcodes
Note: Some parameters require the "More Template Tag Shortcodes" plugin to be activated. (e.g., the [the_content] tag).
This example pulls all posts in the category "Conference" and displays the title, permalink, author, date and excerpt and thumbnail image if available.
You can also sort by custom field. For example:
[loop query="posts_per_page=5&category_name=newsandevents&meta_key=event_date&orderby=meta_value&order=asc" view="archive"]
You can also use loop shortcode with pages.
For example, if you wish to dynamically pull a list of pages that use custom field 'color', regardless of the value of that custom field, you might do it with the help of a shortcode that looks like this:
[loop query="posts_per_page=5&post_type=page&meta_key=color" view="list"]
To return all the posts in the February 2011, use the time parameters (see http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters)
[loop query="year=2011&monthnum=2" view=archive]
To return posts with future publishing dates in similar fashion as upcoming events use this:
The loop query above will show future and published posts in ascending order. If you wanted to only show future posts delete publish from post_status.