Post Loops: legacy information (LiveCanvas 3 only)

Legacy information (LiveCanvas 3 "only")

Here's what the section code looks like:

So at the heart of this solution there's a shortcode: lc_get_posts

The shortcode is just a sort of wrapper to the get_posts function which is the best way to pull data from WP without having unwanted side effects. Is just simple and trivial code.

It has a lot of parameters. Here is complete listing with their default values as well:

Query-related parameters

These parameters control which posts will be called from the shortcode.
Geeks will like that these are the same that the get_posts function handles.

posts_per_page => 10
offset => 0
category =>
category_name =>
orderby => date
order => DESC
include =>
exclude =>
meta_key =>
meta_value =>
post_type => post
post_mime_type =>
post_parent =>
author =>
post_status => publish
suppress_filters => true

Output-related parameters

These parameters control the way posts are displayed - it's a handy way to control their layout.

output_view => lc_get_posts_default_view
The name of the function which shall be used for displaying posts. A custom callback function can be used so you can have full control on how the posts will look like. If you do use a custom callback, the following  parameters are ignored.

output_wrapper_class =>
Name of CSS class which will wrap the whole post list

output_link_class =>
Name of CSS class which will be used for the link

output_heading_tag => h2
Heading tag to use for the article title

output_hide_elements =>
Used for hiding post elements - it defaults to none - but you can list here one or more comma separated elements chosen from this set: title, author, datetime, featured, excerpt, category, comments, clearfix

output_date_format=>

Date format attribute (From v 3.10 onwards)

output_featured_image_before =>
Set to 1 to have the featured image before the post title

output_featured_image_format => thumbnail
Useful to set each  post's featured image format

output_featured_image_class => attachment-thumbnail img-responsive alignleft
Useful to set each  post's image wrapper class

Extending and Customizing the View of your Posts

Dynamic Post Loop Templating

Custom Callback function

In order to have maximum control over the generated markup, you can use your own custom callback templating function.

This can be useful to do if you want to show posts in a carousel, as an example,  or in a special widget that needs a precise HTML syntax.

You'll just need to add a simple function to your codebase, defining how retrieved posts are "printed".

A working example of this is inside this micro plugin, which is meant to be your starter point: Custom Posts Display (download here).

All the plugin does is  to define the lc_get_posts_mycustom_view function.

After activating the plugin, edit via code editor your post loop.

Just add this parameter to the get_posts shortcode:

output_view="lc_get_posts_mycustom_view"

You will see that the post loop is shown as a linear set of posts, with uppercase titles.

Now duplicating/editing/hacking the PHP function in the plugin, you can have your posts rendered exactly how you want.