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.
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):
That’s all there is to it. The [post-content] shortcode requires a single argument: the ID of the post/page being cloned.
As a bonus, this plugin comes with a second shortcode built in that allows you to display a list of posts or pages. The [post-list] 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
0, the current post will be included in the post list if it matches the rest of the criteria specified.
The [post-content] 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 [post-list] shortcode, however, does output some HTML. By default, it uses the following HTML:
<li class="listed-post"><a href="%permalink%" title="%title%">%title</a></li>
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
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.