Modifizierte Version des Recent Posts Plugins
habe den Plugin Recent Posts von Nick Momrik um die optionale Anzeige der Kategorie erweitert.
PHP:
<- /*
- Plugin Name: Recent Posts
- Plugin URI: http://mtdewvirus.com/code/wordpress-plugins/
- Description: Returns a list of the most recent posts.
- Version: 1.07
- Author: Nick Momrik
- Author URI: http://mtdewvirus.com/
- */
- /*
- parameter description:
- $no_posts – sets the number of recent posts to display, DEFAULT: 5
- $before – text to be displayed before the link to the recent post, DEFAULT
- $after – text to be displayed after the link to the recent post, DEFAULT
- $hide_pass_post – whether or not to display password protected posts, DEFAULT true
- $skip_posts – allows skipping of a number of posts before showing the number of posts specified with the $no_posts parameter, DEFAULT 0
- $show_excerpts – allows the post excerpt to be output after the post title, DEFAULT false
- $show_cat – shows category name, DEFAULT true
- */
- function mdv_recent_posts($no_posts = 5, $before = ‘
- ‘
, $after = ‘ ‘, $hide_pass_post = true, $skip_posts = 0, $show_excerpts = false, $show_cat=true) { - global $wpdb;
- $time_difference = get_settings(‘gmt_offset’);
- $now = gmdate(“Y-m-d H:i:s”,time());
- if (!$show_cat) {
- $request = “SELECT ID, post_title, post_excerpt
- FROM $wpdb->posts
- WHERE post_status = ‘publish’ “;
- } else {
- $request = “SELECT ID, post_title, post_excerpt, category_nicename
- FROM $wpdb->posts a, $wpdb->post2cat b, $wpdb->categories c
- WHERE post_status = ‘publish’ AND a.ID=b.post_id AND b.category_id=c.cat_ID “;
- }
- if($hide_pass_post) $request .= “AND post_password =’’ “;
- $request .= “AND post_date_gmt < '$now' ORDER BY post_date DESC LIMIT $skip_posts, $no_posts";
- $posts = $wpdb->get_results($request);
- $output = ‘’;
- if($posts) {
- foreach ($posts as $post) {
- $post_title = stripslashes($post->post_title);
- if ($show_cat) $post_category = stripslashes($post->category_nicename);
- $permalink = get_permalink($post->ID);
- $output .= $before. ‘ . $permalink . ‘" rel="bookmark" title="Zum Beitrag: ‘.htmlspecialchars($post_title, ENT_COMPAT)
- .(($show_cat)?’ – Kategorie: ‘.$post_category : “”)
- .‘">‘ ;
- $output .= htmlspecialchars($post_title).(($show_cat)?” [$post_category] “:“”) . ‘‘;
- if($show_excerpts) {
- $post_excerpt = stripslashes($post->post_excerpt);
- $output.= ‘
- ‘ . $post_excerpt;
- }
- $output .= $after;
- }
- } else {
- $output .= $before . “None found” . $after;
- }
- echo $output;
- }








Diese Inhalt ist unter einer Creative Commons-Lizenz lizenziert.