Display Posts Shortcode
[resolved] Custom Template (5 posts)

  1. Jason Judge
    Posted 3 years ago #

    This is a great tag for selecting posts of all types. However, so far as I can see, it just displays a listing, i.e. titles, maybe an image.

    Is there any way to throw each post that is selected, at a custom template? For example, I have different post types that I need to pass through different summary templates, because they are, well, different post types and each need their own special handling.

    Is this possible? I certainly hope so :-)

    -- Jason


  2. Daniel Bachhuber
    Hand Built
    Posted 3 years ago #

    I dig this idea too. What's the simplest implementation of it? How would it work for you?

  3. Bill Erickson
    Plugin Author

    Posted 3 years ago #

    Are you asking if different uses of the shortcode (querying different types of content) can be displayed in different ways?

    First, you have a quite a few display options in the shortcode itself, like include_date, include_excerpt...

    But there's also an output filter you can use to customize the actual output. For instance, if you're listing upcoming events, you might want to include the event date and location. Use the 'display_posts_shortcode_output' filter to modify what is output. Example: http://www.billerickson.net/code/display-posts-shortcode-additional-fields/

    You could add your own attributes to the shortcode and use that to determine how it is customized in the output filter. For instance, [display-posts template="event"]. In your output filter, check if ( isset( $atts['template'] ) && 'event' == $atts['template'] ), then do whatever customizations you'd like to it.

    Is that what you were looking for, or something else?

  4. Jason Judge
    Posted 3 years ago #

    Yes, that looks spot-on. So that I understand it correctly, so long as that filter returns *something*, then that return content will replace the entire summary for that post?

    The way I want to use it, is to display products from a WooCommerce shop. To do that, we have a function we can call up to display a single product, which uses customised formatting (through templates) so we would not want any of the output generated by this plugin. If that is how this filter works, then that is exactly what we are looking for.

    -- Jason

  5. Bill Erickson
    Plugin Author

    Posted 3 years ago #

    Yes, that's exactly how it works. You're able to filter the entire output of the post listing.

    You're also able to customize the outer wrapper. By default it is a ul (and the listings are li's). This can be changed to an ol or div.

    [display-posts wrapper="div"]

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Display Posts Shortcode
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.