Two useful shortcodes, that you can add to your functions.php file (if you’re not using the Mystique theme):

Allowing the user to insert a arbitrary widget inside posts:

  1. <?php
  2. function widget($atts){
  3. global $wp_widget_factory;
  4. extract(shortcode_atts(array(
  5. 'class' => FALSE // the widget's PHP class name, required
  6. ), $atts));
  7. // make sure the user doesn't XSS us (wpmu)
  8. $class = wp_specialchars($class);
  9. //check if the class exists
  10. if (!is_a($wp_widget_factory->widgets[$class], 'WP_Widget')):
  11. // if it doesn't, then try to add WP_Widget_ in front of the class name, and check again
  12. $wp_class = 'WP_Widget_'.ucwords($class); // capitalize 1st letter
  13. if (!is_a($wp_widget_factory->widgets[$wp_class], 'WP_Widget')):
  14. $wp_class = 'WP_Widget_'.ucwords(strtolower($class));
  15. if (!is_a($wp_widget_factory->widgets[$wp_class], 'WP_Widget')):
  16. return '<p>'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'<strong>'.$class.'</strong>').'</p>';
  17. else:
  18. $class = $wp_class;
  19. endif;
  20. endif;
  21. // checking for other attributes, other than "class"
  22. $instance = array();
  23. foreach($atts as $att=>$val):
  24. if ($att!="class") $instance[wp_specialchars($att)]=wp_specialchars($val);
  25. endforeach;
  26. $id = $class; // name the selector id as the PHP class name
  27. // this is the css class, not the PHP class name
  28. $classname = $wp_widget_factory->widgets[$class]->widget_options['classname'];
  29. // if doesn't exist, name it as the id (class name)
  30. if(!$classname) $classname = $id;
  31. // change the id to the widget id parameter, if set
  32. if(isset($instance['widget_id'])) $id= $instance['widget_id'];
  33. // output to php buffer, because there's not get_the_widget function in wp
  34. // display the widget
  35. the_widget($class, $instance, array('widget_id'=>'arbitrary-instance-'.$id,'before_widget' => '
  36. ','after_widget' => '
  37. ','before_title' => '
  38. ','after_title' => '
  39. '));
  40. // store the buffer output in a variable
  41. $output = ob_get_contents();
  42. // display it
  43. return $output;
  44. }
  45. add_shortcode('widget','widget'); // registers the shortcode

To use this add in your posts for example:
[widget  class="calendar"]
A more detailed explanation here.

Display certain posts  inside pages:

  1. <?php
  2. function queryposts($atts){
  3. extract( shortcode_atts( array(
  4. 'category_id' => '',
  5. 'category_name' => '',
  6. 'tag' => '',
  7. 'day' => '',
  8. 'month' => '',
  9. 'year' => '',
  10. 'count' => '5',
  11. 'author_id' => '',
  12. 'author_name' => '',
  13. 'order_by' => 'date',
  14. ), $atts));
  15. $output = '';
  16. $query = array();
  17. // create the query string
  18. if ($category_id != '') $query[] = 'cat=' .$category_id;
  19. if ($category_name != '') $query[] = 'category_name=' .$category_name;
  20. if ($tag != '') $query[] = 'tag=' . $tag;
  21. if ($day != '') $query[] = 'day=' . $day;
  22. if ($month != '') $query[] = 'monthnum=' . $month;
  23. if ($year != '') $query[] = 'year=' . $year;
  24. if ($count) $query[] = 'posts_per_page=' .$count;
  25. if ($author_id != '') $query[] = 'author=' . $author_id;
  26. if ($author_name != '') $query[] = 'author_name=' . $author_name;
  27. if ($order_by) $query[] = 'orderby=' . $order_by;
  28. ob_start(); // output to buffer
  29. // backup the $post variable so it doesn't mess it up if called again
  30. $backup = $post;
  31. $posts = new WP_Query(implode('&',$query));
  32. while ($posts->have_posts()): $posts->the_post();
  33. // copy here the post layout from your theme's index.php file -- this is just a example ?>
  34. endwhile;
  35. $post = $backup; // restore the original $post
  36. wp_reset_query();
  37. // store the buffer output in the $output variable
  38. $output = ob_get_contents();
  39. return $output;
  40. }
  41. add_shortcode('query', 'queryposts'); // add the shortcode...

Example:
[query category_name="Uncategorized" count=15]