Display the loop using wordpress shortcode
September 23, 2009
The loop is the easiest way to display WordPress posts, perfect for those sites who are using WordPress as a CMS. But we can create a shortcode that will make post displaying simpler. Use this shortcode below to create a loop on a page, post or sidebar. Just use template tags and html like you would in a normal loop to create your layout. The sample below displays an unordered list with titles and links to the post. Just paste code in your functions.php file. Or if you want, you can use it in a plugin. // The Loop /* *... [Read the full story]
Disable WordPress automatic formatting on posts using a shortcode
June 23, 2009
If you often display code snippets on your WordPress blog, you know how bad WordPress automatic formatting can be. With this shortcode you can disable it on a portion of text. Add the following function to your themes functions.php file: function formatter_shortcode($content) { $new_content = ''; $pattern_full = '{(\[raw\].*?\[/raw\])}is’; $pattern_contents = ‘{\[raw\](.*?)\[/raw\]}is’; $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($pieces as $piece) { if... [Read the full story]
Add private notes to WordPress posts
May 15, 2009
Sometimes, you may need to leave a private note (e.g. only visible to admin) to a post, but there’s no built-in solution in WordPress to do it. Here’s the code you need to add to your functions.php file: add_shortcode( 'note', 'live_note' ); function live_note( $atts, $content = null ) { if ( current_user_can( 'publish_posts' ) ) return '<div class="note">'.$content.'</div>'; return ''; } Once done, simply add the following shortcode in your posts: [note] This is a note that only someone can... [Read the full story]
Using wordpress shortcodes to show members-only content
May 14, 2009
This tutorial will cover three methods for setting up shortcodes to use in your posts and pages that will allow you to hide or show content depending on who’s viewing it. Content for users that are not logged in Many people want to focus on hiding content from this group of users, but you want to start by showing them content. Most traffic to your site will likely be through non-logged in users, so make sure you give this group of people something. Open your theme’s functions.php file in your favorite text editor. Add... [Read the full story]
Display the last image attached to post using shortcode
January 20, 2009
First, you have to paste the following code in your functions.php file, in order to create the shortcode. function sc_postimage($atts, $content = null) { extract(shortcode_atts(array( "size" => 'thumbnail', "float" => 'none' ), $atts)); $images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . get_the_id() ); foreach( $images as $imageID => $imagePost ) $fullimage = wp_get_attachment_image($imageID, $size, false); $imagedata = wp_get_attachment_image_src($imageID,... [Read the full story]



















