Showing the post password form for excerpts in WordPress

June 27, 2009

Many WordPress themes show excerpts on the front page and other archive-type views. When viewing a password-protected post, this message is displayed: There is no excerpt because this is a protected post. While this is fine for many scenarios, it may not be the most helpful piece of text for the average Internet user. Instead of showing the message, we’ll replace it with a password form. Replacing the no excerpt text with a password form WordPress comes packaged with a neat function called get_the_password_form() that... [Read the full story]

Get tags based on the wordpress category

June 27, 2009

Althought WordPress allow you to do lots of things by default, but how to retrieve tags based on the category? Just paste following code wherever you need to display the list of tags that are specific to a particular category. Note: You can replace the category name on line two.   <?php query_posts('category_name=wordpress'); if (have_posts()) : while (have_posts()) : the_post();         $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { $all_tags_arr[] = $tag -> name; //USING... [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 (preg_match($pattern_contents,... [Read the full story]

Custom RSS feeds in WordPress

June 12, 2009

RSS feeds are very useful and very popular. WordPress creates RSS feeds by default, but how to create your own, custom RSS Feed? If you need a custom RSS feed, like for example, a feed indexing only somes categories and tags, or if you redirected all WordPress RSS feeds to Feedburner but still want to be able to get a category feed, there’s an easy solution though, just follow these steps: create a custom page template within your theme that serves out the feed (code below) create a new page (which can be blank),... [Read the full story]

get wordpress custom fields outside the loop

June 12, 2009

Custom fields are very useful and are used on many WordPress blogs. But how to easily get custom fields values outside the loop? To display a custom field value outside the loop, simply use the following code. Don’t forget to replace Myfield on line 4 by the name of the custom field you want to display.   <?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'MyField', true); ?>  Read More →