Expand the most recent (last) post of a category list

Note : the following code snippet requires advanced WordPress developer skills. There's no guarantee that this snippet works as is with the latest version of our themes, and with the latest version of WordPress. That's why you need to always test any code snippets in a staging environment before implementing it in a production site.

Howdy Customizr developer,

The following is a quick snippet that will expand (meaning show the full content instead of the excerpt) the last published post of a category list.

As usual, I will try to show you the safest way to code this with the use of a child theme and a filter in  the functions.php file. You don’t want to modify the core, do you? 😉


Which filter?

We need first to identify what filter we want to hook our code to.

  1. Click on Customiz’it and enable the DEVELOPERS TOOLTIPS option in Dev tools section, save and go to front page.
  2. Display a category list on your website and find the tip located in any post excerpt, click on it and display the filter to use
  3. the filter to use in this case is :  ‘tc_post_list_content’


Which context?

Now we need to determine in which context we are going to filter the original function. In this example, the post content will be expanded in the following conditions :

1) We are displaying a category list : this can be check easily with the WordPress boolean  is_category() .

2) We are displaying the first post of the list (meaning the last published one): this seems to be a little more tricky but in fact very simple! The global $wp_query object has a useful (but quite unknown) property :  $wp_query->current_post . It simply gives the index of the loop, starting from 0. So in our case, we just want to check if this index is == 0 to expand. Cool uh?

3) We are displaying of post with no particular format (aside, image, link,…) : a standard post. When a post has no specific format defined, then the WordPress function get_post_format()  will return false .


The code


And that should do the trick.

As always, you are more than welcome to give a feedback/url if you have implement this snippet in your website!



Related Snippets you may also like

5 thoughts on “Expand the most recent (last) post of a category list

  • Esther Lee

    Never mind. Solved. Two things:
    The function names don’t match

    ‘expand_most_recent_post’ should be ‘expand_last_post’, yes?

    I also stripped out all of the conditionals except for

    and it works now.

    • Nicolas Post author

      Hi Esther, congratulations for finding the answer yourself!
      And thanks for the correction : you are right, the filter callback and the function did not match, it is fixed now.


      • Esther Lee

        Cool. Hey, while we’re on the subject — I looked thru the FAQ but couldn’t find the answer — is there a way to also include the comments form after said expanded current post? Basically what I want to achieve is: “Front page” contains current post, expanded, with comments; sidebar only lists posts after that (or current post in sidebar link is disabled, since it’s on the front page). Thanks!

  • Esther Lee

    Hi Nicolas,

    Thanks for the Bootstrap-based theme. I’m fairly new to WordPress but reasonably adept with HTML5/CSS3. I have had a fairly easy time styling Customizr using a Child Theme to match my brand, but I’m dreadful when it comes to sussing out PHP.

    I tried following your instructions (which got muddy right around trying to figure out which filter (I tried the “functions.php” and then the “tc_post_list_content” function inside of “class-content-post_list.php” but then my posts failed to render at all. Also not clear whether to copy into my child theme or modify and replace, and how/where to do all this.

    Please help. I’ve spent several hours on this and must concede defeat.

Comments are closed.