steveonz
Member
Posted 5 months ago #
Hi,
I am using wordpress as our CMS for our companies website.
We have about 5-10 pages which we want to insert the same call to action content in.
How can I create a shortcode that will allow me to embed the content from a post into a page?
Thanks
Steven.
Inside your shortcode handling function or method (http://codex.wordpress.org/Shortcode_API) you would have to create a custom WP_Query object (http://codex.wordpress.org/Class_Reference/WP_Query) like this
function myCustomShortcodeHandler( $atts ){
$CustomQuery = new WP_Query( array( 'post__in' => array( 1, 2, 3 ) ) ); // Insert YOUR post IDs here
wp_reset_query();
foreach( $CustomQuery->posts as $Post ) {
/**
* $Post->ID
* $Post->post_title
* $Post->post_excerpt
* $Post->post_content
* ...
*/
}
return;
}
add_shortcode( 'myCustomShortcode', 'myCustomShortcodeHandler' );
steveonz
Member
Posted 5 months ago #
Thanks, but how do I use this shortcode?
bcworkz
Member
Posted 5 months ago #
To use shortcodes, using the page or post editor, enter the tag name inside square brackets wherever you want the shortcode output to occur. Specifically for your situation using Chris' example, using the page editor, type [myCustomShortcode] where your want the posts 1, 2, & 3 to appear on your page.