Extend Wordpress functionality with shortcodes
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:
<?php function widget($atts){ global $wp_widget_factory; 'class' => FALSE // the widget's PHP class name, required ), $atts)); // make sure the user doesn't XSS us (wpmu) $class = wp_specialchars($class); //check if the class exists // if it doesn't, then try to add WP_Widget_ in front of the class name, and check again return '<p>'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'<strong>'.$class.'</strong>').'</p>'; else: $class = $wp_class; endif; endif; // checking for other attributes, other than "class" foreach($atts as $att=>$val): if ($att!="class") $instance[wp_specialchars($att)]=wp_specialchars($val); endforeach; $id = $class; // name the selector id as the PHP class name // this is the css class, not the PHP class name $classname = $wp_widget_factory->widgets[$class]->widget_options['classname']; // if doesn't exist, name it as the id (class name) if(!$classname) $classname = $id; // change the id to the widget id parameter, if set // output to php buffer, because there's not get_the_widget function in wp // display the widget ','after_widget' => ' ','before_title' => ' ','after_title' => ' ')); // store the buffer output in a variable // display it return $output; } 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:
<?php function queryposts($atts){ 'category_id' => '', 'category_name' => '', 'tag' => '', 'day' => '', 'month' => '', 'year' => '', 'count' => '5', 'author_id' => '', 'author_name' => '', 'order_by' => 'date', ), $atts)); $output = ''; // create the query string if ($category_id != '') $query[] = 'cat=' .$category_id; if ($category_name != '') $query[] = 'category_name=' .$category_name; if ($tag != '') $query[] = 'tag=' . $tag; if ($day != '') $query[] = 'day=' . $day; if ($month != '') $query[] = 'monthnum=' . $month; if ($year != '') $query[] = 'year=' . $year; if ($count) $query[] = 'posts_per_page=' .$count; if ($author_id != '') $query[] = 'author=' . $author_id; if ($author_name != '') $query[] = 'author_name=' . $author_name; if ($order_by) $query[] = 'orderby=' . $order_by; // backup the $post variable so it doesn't mess it up if called again $backup = $post; while ($posts->have_posts()): $posts->the_post(); // copy here the post layout from your theme's index.php file -- this is just a example ?> endwhile; $post = $backup; // restore the original $post wp_reset_query(); // store the buffer output in the $output variable return $output; } add_shortcode('query', 'queryposts'); // add the shortcode...
Example:
[query category_name="Uncategorized" count=15]
This theme looks really nice by the way!!!
this theme is very nice,but how i can downlaod it…
this theme is very nice,
thx for Extend Wordpress functionality with shortcodes
Colin, have you figured out how to fix this problem?
I’ve updated from version 1.5 to 2.02. and I also have the same problem. I noticed that the checkbox for this option has been turned off so I turned it back on. I realized that you also have to select ‘featured’ articles that should then display.
I have a problem in that the “Maximum number of posts to display” is pre-set to 1 and is greyed out so I cannot change the number. The featured articles do not rotate for me, even when I select multiple featured articles.
I have an additional problem where I no longer have an admin page for Ads. My admin page titles are like this:
Design | Content | Navigation | SEO | | Advanced | User CSS |
Notice that there are two ‘||’ between SEO and Advanced.
If I copy and paste the entire row of links I actually get | SEO | Ads | Advanced, but I cannot see it to click on it..
Thanks for sharing..
Yes this is a problem, In mystique that even after putting ad codes I don’t know where they goes?
Amazing Theme….Finally I feel that I got the right one…Thank You!!
thanks for this theme.
may be can you help me. I did make the installation of the version 1.21 in my web site http://www.spicegirlsbrasil.com and i saw the post thumbnail gallery in the top of the working…really nice. but now i did make the installation in my new web site http://www.programasexappeal.com.br and is not working!!!!! I am not sure if is the version or some setting that i need set up.