tags 1 - Pad the content with

tags (*) title_style: 0 - Display the post as

title

post (*) 1 - Display the post as title:post trunc_more: 0 - Do not truncate post at tag (*) 1 - Truncate post at tag alt_link: Alternate URL for post title link surrounded by apostrophes (Example: 'http://www.site.org' ) Only needed if 2 is specified in link_to_post Default values are noted with an asterisk (*). Version History: 2007 Oct 29: Version 2.0 will only work with the Wordpress 2.3 series 2007 Jul 26: Fixed a bug in the alternate link code that was visible in IE browsers. 2007 Jul 12: Added the trunc_more and alt_link options. 2007 Feb 28: Added the paragraph pad option. This option will add the

tag if the content doesn't have them for paragraph breaks. Title style is now also an option. The title can be formatted as

title

post or title:post. 2007 Feb 26: Permalinks now appear as defined by option in Wordpress settings. 2006 May 05: Added the options of displaying only the post title, content, or excerpt 2006 Jan 28: Cleaned up SQL syntax to avoid problems with future dated posts. */ function get_recent_post($post_category_id,$post_display = 0,$link_to_post = 0, $paragraph_pad = 1, $title_style = 0, $trunc_more = 0, $alt_link = "") { /* These are the global vars wordpress uses for table names in MySQL */ /* $wpdb is the database name */ global $wpdb; /* Get the current time */ $now = current_time('mysql'); /* Set the title style */ if ($title_style == 0) { $title_begin = "

"; $title_end = "

"; $title_only_end = "

"; } else if ($title_style == 1) { $title_begin = ""; $title_end = ": "; $title_only_end = ""; } /* If there is a post category specified, continue... */ if ($post_category_id) { if (($post_display == 1) || ($post_display == 4)) { /* Query the title and excerpt */ $req_post = "SELECT wp_posts.ID, wp_posts.post_title, wp_posts.post_excerpt FROM wp_posts, wp_term_taxonomy, wp_term_relationships WHERE (wp_term_taxonomy.term_id = $post_category_id) AND (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) AND (wp_term_relationships.object_id = wp_posts.ID) AND (wp_posts.post_modified <= '$now') AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.ID DESC LIMIT 1;"; $posts = $wpdb->get_results($req_post); foreach ($posts as $post) { $single_post_id = $post->ID; $single_post_title = $post->post_title; $single_post = $post->post_excerpt; } } else if (($post_display == 0) || ($post_display == 2) || ($post_display == 3)) { /* Query the title and content */ $req_post = "SELECT wp_posts.ID, wp_posts.post_title, wp_posts.post_content FROM wp_posts, wp_term_taxonomy, wp_term_relationships WHERE (wp_term_taxonomy.term_id = $post_category_id) AND (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) AND (wp_term_relationships.object_id = wp_posts.ID) AND (wp_posts.post_modified <= '$now') AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.ID DESC LIMIT 1;"; $posts = $wpdb->get_results($req_post); foreach ($posts as $post) { $single_post_id = $post->ID; $single_post_title = $post->post_title; $single_post = $post->post_content; } } /* If trunc_more is enabled, truncate the post at the tag */ if ($trunc_more == 1) { $post_length = strlen($single_post); $more_position = strpos($single_post,""); $single_post = substr($single_post,0,$more_position); } /* Check for how to display the most recent post */ if (($post_display == 0) || ($post_display == 1)) { /* Return the title and content/excerpt */ $return_recent_post = $title_begin . ""; if ($link_to_post == 1) { /* Link the title to the post's permalink */ $return_recent_post = $return_recent_post . ""; $return_recent_post = $return_recent_post . $single_post_title . "" . $title_end . $single_post; } else if ($link_to_post == 2) { /* Link the title to the alternate link */ $return_recent_post = $return_recent_post . ""; $return_recent_post = $return_recent_post . $single_post_title . "" . $title_end . $single_post; } else { /* Do not link the title to anything */ $return_recent_post = $return_recent_post . $single_post_title . "" . $title_end . $single_post; } } else if ($post_display == 2) { /* Return only the title */ $return_recent_post = $title_begin . ""; if ($link_to_post == 1) { /* Link the title to the post's permalink */ $return_recent_post = $return_recent_post . ""; $return_recent_post = $return_recent_post . $single_post_title . "" . $title_only_end; } else if ($link_to_post ==2) { /* Link the title to the alternate link */ $return_recent_post = $return_recent_post . ""; $return_recent_post = $return_recent_post . $single_post_title . "" . $title_only_end; } else { /* Do not link the title to anything */ $return_recent_post = $return_recent_post . $single_post_title . "" . $title_only_end; } } else if (($post_display == 3) || ($post_display == 4)) { /* Return only the content/excerpt */ $return_recent_post = $single_post; } /* Return the most recent post! */ /* Use the wpautop function to pad with

tags where needed */ if ($paragraph_pad == 1) { $return_recent_post = wpautop($return_recent_post); } return $return_recent_post; } } ?>