Automatically insert content after each wordpress post

April 7, 2009

Most wordpress blogs automatically displays some text after each post, for exemple to ask readers to subscribe to their rss feed of the blog. This text is very often hardcoded. Fortunately, we can using function.php instead, and be able to manage all in one place when  you’ll switch theme. Simply paste the following code in your functions.php file. By using functions.php, you’ll not have to re-insert this code if you switch themes. function insertFootNote($content) { if(!is_feed() && !is_home()) { $content.=... [Read the full story]

Show related wordpress posts without plugin

March 24, 2009

Displaying related posts is a very great way to help visitors staying longer on your blog. You can use a plugin, but you also can use tags and a custom code to show related posts. This code will display related posts based on the current post tag(s). It must be pasted within the loop.   <?php //for use in the loop, list 5 post titles related to first tag on current post $tags = wp_get_post_tags($post->ID); if ($tags) {   echo 'Related Posts';   $first_tag = $tags[0]->term_id;   $args=array(     ‘tag__in’... [Read the full story]

Get the first image from the wordpress post and display it

February 25, 2009

Most WordPress users are using custom fields to display thumbs on their blog homepage. It is a good idea, but do you know that with a simple php function, you can grab the first image from the post, and display it. You can simply call the function within the loop to display the first image from the post: <?php echo get_first_image() ?> But first, paste this function follow on your functions.php file. function get_first_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output =... [Read the full story]

List wordpress future posts

February 22, 2009

Do you ever wished to be able to use WordPress to list future events? This can be very useful for exemple if you’re using WordPress for a band website and like to list your future shows. Just simply paste this code where you’d like you future posts to be displayed:   <div id="livexpft"> <div id="livexpft_header"><p>Future events</p></div> <?php query_posts('showposts=10&post_status=future'); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div... [Read the full story]

Display post based on custom fields with a custom query

February 20, 2009

Many blogger interested to know how to be able to display posts based on custom fields values. The first thing to do is to create a page template. The code below will display your posts, based on the following condition: Post must have a custom field with key tag and value email. Of course, you can change it in the query to make the code fits your needs. <?php /* Template Name: Custom query */ $querystr = " SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id ... [Read the full story]

Page 4 of 14« First...«23456»...Last »