Another quest in my WordPress life is the perfect list view for posts, events or articles. I simply like it simple, beautiful, well-thought and flawless responsive, and I rarely come across these attributes out-of-the-box. The plugin List Category Posts by Fernando Briano brought me closer to my dream, and with a bit of template coding and CSS the perfect post list view was accomplished (the described work was done with version 0.71 of the plugin).

The List Category Posts Shortcode

The basic shortcode to generate a list view of all your posts is simply [catlist]. It will display a simple unordered list with the titles of the articles:

wordpress_perfect-blog-event-article-list-view-01

Next we want to activate the thumbnails and the excerpt by using [catlist thumbnail=yes excerpt=yes].

wordpress_perfect-blog-event-article-list-view-02

Not the most beautiful article list by default, I agree, and we could easily start beautifying the outcome with CSS, but there are also changes in the basic structure that need to be done to achieve our vision of a perfect post list. Fortunately, the plugin comes with an easy to adapt template system.

Creating our own Post List Template

The plugin looks for own templates in a folder called list-category-posts placed in the child-theme folder, e.g. wp-content\themes\child-theme\list-category-posts\perfectlist.php. You can download the folder with the file to copy it into your child-theme folder. I left all the various orginal comments in the file and added mine, while the following code is a reduced version to keep the article clearer. If you want to reproduce the applied changes, compare the downloaded file perfectlist.php with the default.php of the plugin to see the differences.

Let’s understand a bit what the template does and in which parts I adapted it:

$lcp_display_output is the string which will gather all the information.
$lcp_display_output .= $this->get_something($post); are the successive lines that add the different elements that can be activated in the shortcode, as a category link or a conditional title. The functions get_something deliver a whole block of information and can pass on certain variables to influence their output. Read the whole instructions and the comments in the file for a complete overview.

Next opens our loop that will catch the information for each single post. We will use a DIV container with a class .postlist instead of an UL list. For the moment, since we cannot check if the shortcode option thumbnail is set to yes, we have to work with different templates, so we assign the extra class .withthumb for an easier CSS formatting. If the post has a featured image, we open a span with a .thumbmagic class as a container for our padding-trick method and call the thumbnail through $lcp_display_output .= $this->get_thumbnail($post);. In case the post doesn’t have a featured image set, we can define a placeholder image, or simply delete or comment this line to keep an empty space.

We use H3 for our title, and P for content or excerpt. The posts_morelink is wrapped in the class .morelink so we can easily text-align: right the Read more text. This is all we have to do to prepare the HTML stucture to fit our needs. To view our list with our own template, we need to call it in the shortcode and at this occassion we also add the read more link:

[catlist thumbnail=yes excerpt=yes posts_morelink="Read more..." template=perfectlist]

The CSS Styling

Let’s go for some basic styling. The margin-left of the .lpc-container needs to be set according to the desired image width plus a bit of space between image and text. At the moment we use the WordPress thumbnail size of 150px plus 20px space. The overflow: auto takes care that the floating images will stay in the box even if the excerpt text is very little.

wordpress_perfect-blog-event-article-list-view-04

Positioning magic

The list could be done with the WordPress-generated thumbnails, but to become independent in our choice of sizes, I integrated a wonderful technique that I found during my quest for the perfect calendar. With this padding-bottom trick we can create an equal cropping of bigger images, opening the way to display medium or large images of landscape or portrait format in any size and landscape or portrait endformat we want. Sounds amazing? It is! Let’s have a look at the CSS code. We float the .thumbmagic image container, so it doesn’t drive out the text. The display– and positioning parameters are part of the padding-bottom trick. The width we can freely choose to define the endformat of our thumbnails, and with the padding-bottom we assign our desired height.

Now, with the .thumbmagic img we define whether a 100% height with an auto width, if we want to use a portrait endformat, or 100% width with an auto height, if we want to use a landscape endformat. We also set a min-width or min-height for the case of images with a lower ratio than our choosen proportions to not leave a white space. The rest is part of the trick as you can read in detail in the above mentioned calendar post.

Since we have chosen an image width of 200px, we need to set the .lcp-container from above CSS to 220px instead of 170px. Furtheron the image resolution is not enough, and to increase the image quality we will use the medium size instead of the thumbnail size by extending our shortcode with the thumbnail_size attribute: [catlist thumbnail=yes thumbnail_size=medium excerpt=yes posts_morelink="Read more..." template=perfectlist]

wordpress_perfect-blog-event-article-list-view-05

Sidenote: I want to mention that, despite the free choice of sizes, it can still be preferable to use the thumbnail size and increase its dimensions in the media settings accordingly (most likely you will need to regenerate the thumbnails after changing the settings, e.g. with the plugin Force Regenerate Thumbnails). Why? Because only the “official” WordPress thumbnail size can be edited directly in WordPress to customize the cropping of the images that would look strange with automated cropping, e.g. a cut-off head.

Responsive magic

Last but not least, it should look good also on mobile devices, and my ideal was to move the thumbnail above the centered title, excerpt and read more link. This is achieved with the following CSS code:

wordpress_perfect-blog-event-article-list-view-06

Card View

As an addition we can also easily create a card view. For the moment I don’t know a way to transmit attributes through the shortcode, which would be most easy to use, so we need to work with a second template file, in which the class cardview is added to the postlist-div. You find it also in the downloaded folder from the template chapter. Call it in your article like this for example: [catlist thumbnail=yes thumbnail_size=large excerpt=yes posts_morelink="Read more..." template=cardview]

Now we only need to add these lines of CSS:

wordpress_perfect-blog-event-article-list-view-07

Multi-colum

As we see, it is a bit big and to keep the maximum width in a nice format and use the space better, we will integrate a multi-column solution to round it up. We start with a 2-column approach:

What happens there? Our postlist boxes start to float and are reduced to 48% width so two are floating lovingly next to each other. Then we assign the remaining 4% space to every second box (2n) starting with the very first one (+1), helping them to not become too attached to each other. To assure that every couple starts perfectly aligned in the new row, we now need to address again every second one but starting only with the third box (the first one in the second row) to clear the float of the first couple. That’s the basic mechanism wrapped in a bit of poetry. In the end we can wrap our lovely couples in a media query so below a certain resolution they stand on their own again.

wordpress_perfect-blog-event-article-list-view-08

Responsiveness

With the media query we already installed a basic responsiveness, but why not going further. Let’s start with a three-column layout on desktop screens, reducing into a two-column on tablets and one-column on phones:

wordpress_perfect-blog-event-article-list-view-09

And what if we don’t want thumbs?

Easy, we just choose the nothumb template file which you also find in the downloaded folder by using this shortcode:

wordpress_perfect-blog-event-article-list-view-10

Pagination

The plugin also comes with a pagination function, and the following CSS takes care that it also looks nice:

Conclusion

Quite nice, I simply love it. This is the end of the story for the moment, a long quest to my perfect list view for posts, events and articles. You can use the same CSS formats e.g. in the template system of the Events Manager, styling your events in this way as I did for the calendar of the ATMAN Yoga Federation. You can apply it to the blog- and archive pages. The only cherries missing on top would be to pass on if thumbnail is set to yes and choose the card view through the shortcode itself, in this way getting along with just one template file, so if anyone has a clue, let me know in the comments. I hope you enjoyed the trip and wish you a lot of fun with this wonderful plugin and its possibilities. Big thanks to its creator Fernando Briano.

And here once again the complete CSS code for your own perfect postlist. Simply copy into some custom CSS option of your theme or the style.css of your child-theme, and together with the downloaded template files and the correct shortcodes you are ready to go. Post your website in the comments, I would love to see the code in action elsewhere.