Post Content Shortcodes Demo

This is an example page showing how the [post-content] shortcode works. Below this text is the [post-content] shortcode, but when viewing this page, you will instead see the content of the Post Content Shortcodes page. For purposes of this demonstration, I have added a horizontal rule above and below the content of the original page; but those are not part of the shortcode itself.


Post Content Test #1

Below, I am using the following shortcode: [post-list post_type=”page” orderby=”menu_order” order=”asc”]

No posts could be found that matched the specified criteria.


Post Content Test #2

Below, I am using the following shortcode: [post-list post_type="post" orderby="date" order="desc"]


Post Content Test #3

Below, I am using the following shortcode: [post-content id=456]

For those of you that haven’t seen it, Ron Rennick wrote an amazing plugin for us at University of Mary Washington that lets us manage all of our documents (PDF, Word, Excel, etc.) from a single site in our WordPress network; and then insert links to those documents from within any other site in the network. The plugin handles revisioning the documents, and ensures that a single permalink always leads to the latest and greatest version of the document.

Just in case you’re wondering, yes, the Document Repository plugin is completely compatible with multisite (duh!) and with multi-network setups of WordPress.

In our particular situation, there were a handful of additional tweaks I wanted to make to the plugin, though. They weren’t really within Ron’s purview to make, since they didn’t effect the overall utility or performance of the plugin; I just wanted to make things a little cleaner and easier to use in our installation.

Therefore, I wrote up a simple mu-plugin (you could choose to use any or all of this code in a mu-plugin, or just paste it into your theme’s functions.php file; the code is completely modular).

The functions in that code make the following changes:

  1. Remove the Posts, Media, Links, Pages and Gravity Forms* menus from the admin menu on the site we’re using for the Document Repository. We will be using the Document Repository all by itself on that site, and all posts and pages will be handled on other sites in the network, so we didn’t want anything else cluttering up the admin area and confusing our users.
  2. Adjust the capabilities for users on the Documents site. In our case, we didn’t want WordPress “authors” to be able to “publish” documents (we only want them to be able to save them in pending or draft status; waiting for another user to actually approve and publish the documents). We also didn’t want WordPress editors to be able to edit the taxonomy values, so we took that capability away from them.
  3. Remove the Quick Press dashboard widget. Since we won’t be using standard posts on our Documents site, we didn’t want users to be confused into thinking that they could quick-press a document. Therefore, we just removed it.
  4. Remove the “Insert Gravity Form*” button from the Upload/Insert area about the document editor. Since the permalinks for all documents redirect to the documents themselves, there was no reason whatsoever for a user to ever try to insert a Gravity Form* into the body/description of a document post. To reduce confusion, we simply removed that button from the Upload/Insert area above the editor when someone is editing a document post.

As I said above, each of the functions is completely modular, so if you would like to add one or more of these features to the Document Repository plugin, please feel free to copy and paste the appropriate function(s).

View the Code

*Gravity Forms is a premium plugin used to create and manage Web-based forms.

**As a side note, this Document Repository plugin should not at all be confused with my List Attachments Shortcode plugin (I was asked about this earlier this week). They have completely and totally different functionality. The Document Repository plugin manages documents/downloadable items from a central site. Each Document is a separate post on that site. The List Attachments Shortcode plugin simply displays a list of any items that have been attached to a single post/page.


Post Content Test #4

Below, I am using the following shortcode: [post-content id=308]

On a few of the sites I manage, there has been a need to display the content of one post or page within another post or page. In some cases, it make sense to simply redirect the duplicate (or “clone”) to the original using a plugin like “Page Links To”. In other cases, though, the clone needs to be an actual clone of the original, presented as a separate page with the same content. In some fringe cases, it’s even necessary to display the content of multiple pages within a single page (for instance, in one case, there was a site with pages for “past”, “present” and “future” information about the organization; and they wanted another page with the “past” and “present” information displayed together).

Of course, you could simply copy the content of the first page and paste it into a new page, but that can get awfully messy rather quickly when you start to edit the content of one or the other.

That’s where this plugin comes in. By including a simple shortcode within the post editor, WordPress will automatically retrieve the content of the original post or page and display it in the current post or page.

Usage

To display the content of a page or post, you simply need to know the ID of that post. Then, use a shortcode like the following (for this example, let’s say the ID of the post we want to clone is 25):

As of this point, I am releasing the List Attachments Shortcode plugin into the WordPress repository. As a result, I’ve included a proper WordPress plugin readme file, as well as the text of the GPLv2 license with the download.

There was only one change to the code between this version and the previous version; but it’s a rather major one. The links generated by the first version of the plugin were empty. This newer version corrects that.

The usage is still the same as the first version.

Download the List Attachments Shortcode plug-in for WordPress.

That’s all there is to it. The

No posts could be found that matched the specified criteria.

shortcode requires a single argument: the ID of the post/page being cloned.

Bonus

As a bonus, this plugin comes with a second shortcode built in that allows you to display a list of posts or pages. The

shortcode does not require any arguments at all. If no arguments are passed to it, it will use the following defaults:

  • numberposts => -1
  • offset => 0
  • category => null
  • orderby => post_title
  • order => asc
  • include => null
  • exclude => null
  • meta_key => null
  • meta_value => null
  • post_type => ‘post’
  • post_mime_type => null
  • post_parent => null
  • post_status => ‘publish’
  • exclude_current => true

The first 13 arguments shown are the standard arguments used with the get_posts() function in WordPress. One thing to note is the fact that the numberposts argument is set to -1 by default for this shortcode, where it is normally set to 5 in other WordPress usage.

The last argument shown in the list is custom for this plugin. When set to true, the exclude_current argument will keep the current post from being shown in the post list. When set to false, "false" or 0, the current post will be included in the post list if it matches the rest of the criteria specified.

Output

The

No posts could be found that matched the specified criteria.

shortcode simply outputs the content of the post. It does not add any extra HTML code to the output. It does, however, use apply_filters( ‘the_content’ ) on the content of the post to make sure that any shortcodes in the original page are processed, and that any necessary formatting is applied.

The

shortcode, however, does output some HTML. By default, it uses the following HTML:

<ul class="post-list">
<li class="listed-post"><a href="%permalink%" title="%title%">%title</a></li>
</ul>

There are some filters available within the plugin that can alter the HTML generated by the shortcode. Those filters are as follows:

  • post-content-shortcodes-open-list – filters the opening ‘<ul>’ tag
  • post-content-shortcodes-open-item – filters the opening ‘<li>’ tag
  • post-content-shortcodes-item-link-open – filters the opening ‘<a>’ tag. Three parameters are available with this filter. The constructed ‘<a>’ tag is sent as the first parameter, the permalink is the second and the title attribute is the third. The ‘the_permalink’ filter is applied to the permalink before it is sent or used, and the ‘the_title_attribute’ filter is applied to the title attribute before it is sent or used.
  • post-content-shortcodes-item-link-close – filters the closing ‘</a>’ tag
  • post-content-shortcodes-close-item – filters the closing ‘</li>’ tag
  • post-content-shortcodes-close-list – filters the closing ‘</ul>’ tag

To Do

Following are some known issues or features that will possibly be fixed/added in future releases:

  • Attachments are not carried over from the original post (so the featured image, gallery shortcodes, etc. are not used in the clone).
  • Pages cannot currently be shown in hierarchical order.

We have reached the end of the content for the Post Content Shortcodes page and are now back to the content of this demo page.

 

8 thoughts on “Post Content Shortcodes Demo

  1. Pingback: Post Content Shortcodes 0.1a | Ten-321 WordPress Plug-Ins

  2. Rob

    In an unpublished draft page, I’m using the following to display a list of posts:
    [post-list]
    and the posts appear alphabetically

    What would be the shortcode for the posts to appear in order of publication?
    i.e. latest post at the top of the list

    Thanks for a great tool

    Reply
  3. GW

    Have an issue… been trying to use posts on the homepage… however, I just want certain info to show… I think shortcodes is the way… in each post theres:
    1. Picture
    2. Text
    3. ShareThis Buttons
    How can I omit the text… or better yet… how can I show the picture and let’s say the first 2 lines of text with the ShareThis Buttons
    Thanks

    Reply
  4. Sirbols

    Hi Curtiss,
    Congratulations for this great plugin. You made my job was easier.

    I need your help.
    The shortcode:
    [post-list show_excerpt=1 show_title=false category="Categoryname"] is creating two columns to show the post included in the category.
    Is there any way to have only one Column?

    Reply
    1. Curtiss Grymala Post author

      Yes. You should be able to override the default styles by adding the following CSS to your site (if you are using a custom theme, you can add it to your theme’s stylesheet; otherwise, you can either add it using the JetPack Custom CSS module, or, if your theme supports any custom head code, you can add it there).

      body .post-list.with-excerpt {
      column-count: 1;
      column-gap: 0;
      column-rule: none;
      -webkit-column-count: 1;
      -webkit-column-gap: 0;
      -webkit-column-rule: none;
      -moz-column-count: 1;
      -moz-column-gap: 0;
      -moz-column-rule: none;
      -o-column-count: 1;
      -o-column-gap: 0;
      -o-column-rule: none;
      }

      Reply
  5. Thomas

    Hi all!

    I’m using the plugin to list headlines and excerpt on a front page, all the shortcode atributes works fine for me (sorting, numer of posts etc) except show_image=false. I don’t want to see any image that may be in a post, but even though I’ve tried both show_image=false and show_image=0 it’s still showing.

    Any ideas?

    Reply
    1. Curtiss Grymala Post author

      Unfortunately, there’s nothing in the plugin that would remove images that are embedded within the post. The “show_image” parameter just determines whether the “Featured Image” should be shown or not. You could potentially get around this by manually setting an excerpt for each post, in which case, if you tell the plugin to show the excerpt, it should show that manual excerpt rather than creating an automatic excerpt from the post content.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *