Modifizierte Version des Recent Posts Plugins

habe den Plugin Recent Posts von Nick Momrik um die optionale Anzeige der Kategorie erweitert.


Hier der PHP Code

PHP:

  1.  

  2. /*

  3. Plugin Name: Recent Posts

  4. Plugin URI: http://mtdewvirus.com/code/wordpress-plugins/

  5. Description: Returns a list of the most recent posts.

  6. Version: 1.07

  7. Author: Nick Momrik

  8. Author URI: http://mtdewvirus.com/

  9. */

  10. /*

  11. parameter description:

  12. $no_posts – sets the number of recent posts to display, DEFAULT: 5

  13. $before – text to be displayed before the link to the recent post, DEFAULT

  14. $after – text to be displayed after the link to the recent post, DEFAULT

  15. $hide_pass_post – whether or not to display password protected posts, DEFAULT true

  16. $skip_posts – allows skipping of a number of posts before showing the number of posts specified with the $no_posts parameter, DEFAULT 0

  17. $show_excerpts – allows the post excerpt to be output after the post title, DEFAULT false

  18. $show_cat – shows category name, DEFAULT true

  19. */

  20.  

  21. function mdv_recent_posts($no_posts = 5, $before =
  22. ‘, $after =
  23. ‘, $hide_pass_post = true, $skip_posts = 0, $show_excerpts = false, $show_cat=true) {
  24.     global $wpdb;

  25.     $time_difference = get_settings(‘gmt_offset’);

  26.     $now = gmdate(“Y-m-d H:i:s”,time());

  27.    

  28.     if (!$show_cat) {

  29.         $request = “SELECT ID, post_title, post_excerpt

  30.             FROM $wpdb->posts

  31.             WHERE post_status = ‘publish’ “;

  32.     } else {

  33.         $request = “SELECT ID, post_title, post_excerpt, category_nicename

  34.             FROM $wpdb->posts a, $wpdb->post2cat b, $wpdb->categories c

  35.             WHERE post_status = ‘publish’ AND a.ID=b.post_id AND b.category_id=c.cat_ID “;

  36.     }

  37.  

  38.     if($hide_pass_post) $request .= “AND post_password =’’ “;

  39.     $request .= “AND post_date_gmt < '$now' ORDER BY post_date DESC LIMIT $skip_posts, $no_posts";

  40.  

  41.     $posts = $wpdb->get_results($request);

  42.     $output = ‘’;

  43.     if($posts) {

  44.         foreach ($posts as $post) {

  45.             $post_title = stripslashes($post->post_title);

  46.             if ($show_cat) $post_category = stripslashes($post->category_nicename);

  47.             $permalink = get_permalink($post->ID);           

  48.             $output .= $before. . $permalink . ‘" rel="bookmark" title="Zum Beitrag: ‘.htmlspecialchars($post_title, ENT_COMPAT)

  49.                         .(($show_cat)?’ – Kategorie: ‘.$post_category : “”)

  50.                         .‘">‘ ;           

  51.             $output .= htmlspecialchars($post_title).(($show_cat)?[$post_category]:“”) . ‘‘;

  52.             if($show_excerpts) {

  53.                 $post_excerpt = stripslashes($post->post_excerpt);

  54.                 $output.=

  55. . $post_excerpt;

  56.             }

  57.             $output .= $after;

  58.         }

  59.     } else {

  60.             $output .= $before . “None found” . $after;

  61.     }

  62.     echo $output;

  63. }

  64.  

<—142f16bf75691b40556ebbceafa88cfb—><—142f16bf75691b40556ebbceafa88cfb—><—142f16bf75691b40556ebbceafa88cfb—><—a7e777fbf6730352706317e8054682ac—>

Kommentar schreiben

Du musst angemeldet sein um einen Kommentar zu schreiben.