WordPress hack: Use includes in your posts or pages

The first step is to paste the following code in your function.php file:

function digwp_includeContentShortcode($atts) {

  $thepostid = intval($atts[postidparam]);
  $output = '';

  query_posts("p=$thepostid&post_type=page");
  if (have_posts()) : while (have_posts()) : the_post();
    $output .= get_the_content($post->ID);
  endwhile; else:
    // failed, output nothing
  endif;
  wp_reset_query();

  return $output;

}

Once done, you can use the shortcode in your posts or pages, with the following syntax:

[digwp_include postidparam=XXXX]

postidparam is the ID of the post you want to include.

Credits goes to Chris Coyier for this awesome shortcode!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

WordPress hack: Use includes in your posts or pages

Leave a Reply

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