Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • I combined several posts/fixes from the forum and the following works for me!

    Limitation to category works
    Page/Post fix is included.

    <?php
    /*
    Plugin Name: Customizable Post Listings
    Version: 1.1
    Plugin URI: https://www.coffee2code.com/wp-plugins/
    Author: Scott Reilly
    Author URI: https://www.coffee2code.com
    Description: Display Recent Posts, Recently Commented Posts, Recently Modified Posts, Random Posts, and other post listings using the post information of your choosing in an easily customizable manner. You can narrow post searches by specifying categories and/or authors, among other things. Changes made by Adam.

    */

    /*
    Copyright (c) 2004 by Scott Reilly (aka coffee2code)

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
    files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy,
    modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
    IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    */

    //
    // ************************ START TEMPLATE TAGS ******************************************************************
    //

    function c2c_get_recent_posts ($num_posts = 5,
    $format = ”

    • %post_date%: %post_URL%
    • “,
      $categories = ”, // space separated list of category IDs — leave empty to get all
      $orderby = ‘date’,
      $order = ‘DESC’, // either ‘ASC’ (ascending) or ‘DESC’ (descending)
      $offset = 0, // number of posts to skip
      $date_format = ‘m/d/Y’, // Date format, php-style, if different from blog’s date-format setting
      $authors = ”, // space separated list of author IDs — leave empty to get all
      $include_passworded_posts = false)
      {
      global $wpdb, $tablecomments, $tableposts, $tableterm_relationships, $tableterm_taxonomy;
      if ($add_recent_comment_to_sql && !isset($tablecomments)) $tablecomments = $wpdb->comments;
      if (!isset($tableterm_relationships)) $tableterm_relationships = $wpdb->term_relationships;
      if (!isset($tableterm_taxonomy)) $tableterm_taxonomy = $wpdb->term_taxonomy;
      if (!isset($tableposts)) $tableposts = $wpdb->posts;
      if ($order != ‘ASC’) $order = ‘DESC’;
      if (‘max_comment_date’ == $orderby) { $add_recent_comment_to_sql = 1; }
      else {
      if ($orderby != ‘rand()’) $orderby = “$tableposts.post_$orderby”;
      $add_recent_comment_to_sql = 0;
      }
      $include_sticky_posts = true;

      $now = current_time(‘mysql’);
      if ($add_recent_comment_to_sql) $sql = “SELECT $tableposts.*, MAX(comment_date) AS max_comment_date FROM $tablecomments, $tableposts “;
      else $sql = “SELECT DISTINCT * FROM $tableposts “;
      if ($categories) {
      $sql .= “LEFT JOIN $tableterm_taxonomy ON ($tableterm_relationships.term_taxonomy_id = $tableterm_taxonomy.term_taxonomy_id) LEFT JOIN $tableterm_relationships ON ($tableposts.ID = $tableterm_relationships.object_id)”;
      $cats = explode(‘ ‘, $categories);
      }
      $sql .= “WHERE $tableposts.post_date <= ‘$now’ AND ( $tableposts.post_status = ‘publish’ AND $tableposts.post_type = ‘post’ “;
      if ($include_sticky_posts) $sql .= “OR $tableposts.post_status = ‘sticky’ “;
      $sql .= “) “;
      if (!$include_passworded_posts) $sql .= “AND $tableposts.post_password = ” “;
      if ($add_recent_comment_to_sql) $sql .= “AND $tableposts.ID = $tablecomments.comment_post_ID AND $tablecomments.comment_approved = ‘1’ “;
      if ($categories) {
      $first = 1;
      $sql .= “AND ( “;
      foreach ($cats as $cat) {
      if ($first) $first = 0;
      else $sql .= “OR “;
      $sql .= “$tableterm_relationships.term_taxonomy_id = ‘$cat’ “;
      }
      $sql .= “) “;
      }
      if ($authors) {
      $auths = explode(‘ ‘, $authors);
      $first = 1;
      $sql .= “AND ( “;
      foreach ($auths as $author) {
      if ($first) $first = 0;
      else $sql .= “OR “;
      $sql .= “$tableposts.post_author = ‘$author’ “;
      }
      $sql .= “) “;
      }
      if (‘modified’ == $orderby) $sql .= “AND $tableposts.post_modified_gmt <= ‘$now’ “;
      $sql .= “GROUP BY $tableposts.ID ORDER BY $orderby $order”;
      if ($num_posts) $sql .= ” LIMIT $offset, $num_posts”;
      $posts = array();
      $posts = $wpdb->get_results($sql);
      if (empty($posts)) return;
      return c2c_get_recent_handler($posts, $format, $date_format);
      } //end function c2c_get_recent_posts()

      function c2c_get_random_posts($num_posts = 5,
      $format = ”

    • %post_date%: %post_URL%
    • “,
      $categories = ”, // space separated list of category IDs — leave empty to get all
      $order = ‘DESC’, // either ‘ASC’ (ascending) or ‘DESC’ (descending)
      $offset = 0, // number of posts to skip
      $date_format = ‘m/d/Y’, // Date format, php-style, if different from blog’s date-format setting
      $authors = ”, // space separated list of author IDs — leave empty to get all
      $include_passworded_posts = false)
      {
      return c2c_get_recent_posts($num_posts, $format, $categories, ‘rand()’, $order, $offset, $date_format, $authors, $include_passworded_posts);
      } //end function get_random_post()

      function c2c_get_recently_commented ($num_posts = 5,
      $format = ”

    • %comments_URL%
      %last_comment_date%
      %comments_fancy%
    • “,
      $categories = ”, // space separated list of category IDs — leave empty to get all
      $order = ‘DESC’, // either ‘ASC’ (ascending) or ‘DESC’ (descending)
      $offset = 0, // number of posts to skip
      $date_format = ‘m/d/Y h:i a’, // Date format, php-style, if different from blog’s date-format setting
      $authors = ”, // space separated list of author IDs — leave empty to get all
      $include_passworded_posts = false)
      {
      return c2c_get_recent_posts($num_posts, $format, $categories, ‘max_comment_date’, $order, $offset, $date_format, $authors, $include_passworded_posts);
      } //end function get_recently_commented()

      function c2c_get_recently_modified ($num_posts = 5,
      $format = ”

    • %post_URL%
      Updated: %post_modified%
    • “,
      $categories = ”, // space separated list of category IDs — leave empty to get all
      $order = ‘DESC’, // either ‘ASC’ (ascending) or ‘DESC’ (descending)
      $offset = 0, // number of posts to skip
      $date_format = ‘m/d/Y’, // Date format, php-style, if different from blog’s date-format setting
      $authors = ”, // space separated list of author IDs — leave empty to get all
      $include_passworded_posts = false)
      {
      return c2c_get_recent_posts($num_posts, $format, $categories, ‘modified’, $order, $offset, $date_format, $authors, $include_passworded_posts);
      } //end function c2c_get_recently_modified()

      //
      // ************************ END TEMPLATE TAGS ********************************************************************
      //

      function c2c_comment_count ($post_id) {
      global $wpdb, $tablecomments;
      if (!isset($tablecomments)) $tablecomments = $wpdb->comments;
      return $wpdb->get_var(“SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = ‘$post_id'”);
      } //end function c2c_comment_count()

      function c2c_get_recent_tagmap ($posts, $format, $tags, $date_format) {
      if (!$tags) return $format;
      global $authordata, $post;

      //– Some things you might want to configure —–
      $excerpt_words = 6; // Number of words to use for %post_excerpt_short%
      $excerpt_length = 50; // Number of characters to use for %post_excerpt_short%, only used if $excerpt_words is 0
      $idmode = ‘nickname’; // how to present post author name
      $comment_fancy = array(‘No comments’, ‘1 Comment’, ‘%comments_count% Comments’);
      //– END configuration section —–

      if (!$date_format) $date_format = get_settings(‘date_format’);

      // Now process the posts
      $orig_post = $post; $orig_authordata = $authordata;
      foreach ($posts as $post) {
      $text = $format;
      $comment_count = ”;
      $authordata = ”;
      $title = ”;

      // If want last_comment information, then need to make a special db request
      $using_last_comment = 0;
      foreach ($tags as $tag) {
      if (strpos($tag, ‘last_comment’) !== false) { $using_last_comment = 1; break; }
      }
      if ($using_last_comment) {
      global $wpdb, $tablecomments, $comment;
      if (!isset($tablecomments)) $tablecomments = $wpdb->comments;
      $comment = $wpdb->get_row(“SELECT * FROM $tablecomments WHERE comment_post_ID = ‘$post->ID’ AND comment_approved = ‘1’ ORDER BY comment_date DESC LIMIT 1”);
      }

      // Perform percent substitutions
      foreach ($tags as $tag) {
      switch ($tag) {
      case ‘%comments_count%’:
      if (!$comment_count) { $comment_count = c2c_comment_count($post->ID); }
      $new = $comment_count;
      break;
      case ‘%comments_fancy%’:
      if (!$comment_count) { $comment_count = c2c_comment_count($post->ID); }
      if ($comment_count < 2) $new = $comment_fancy[$comment_count];
      else $new = str_replace(‘%comments_count%’, $comment_count, $comment_fancy[2]);
      break;
      case ‘%comments_url%’:
      $new = get_permalink() . “#postcomment”;
      break;
      case ‘%comments_URL%’:
      if (!$title) { $title = the_title(”, ”, false); }
      $new = ‘‘.$title.’‘;
      break;
      case ‘%last_comment_date%’:
      $new = mysql2date($date_format, $comment->comment_date);
      break;
      case ‘%last_comment_id%’:
      $new = $comment->comment_ID;
      break;
      case ‘%last_comment_url%’:
      $new = get_permalink().’#comment-‘.$comment->comment_ID;
      break;
      case ‘%last_commenter%’:
      $new = apply_filters(‘comment_author’, $comment->comment_author);
      break;
      case ‘%last_commenter_URL%’:
      $author = apply_filters(‘comment_author’, $comment->comment_author);
      $new = ‘comment_author_url).'” title=”Visit ‘.$author.’\’s site”>’.$author.’‘;
      break;
      case ‘%post_author%’:
      if (!$authordata) { $authordata = get_userdata($post->post_author); }
      $new = the_author($idmode, false);
      break;
      case ‘%post_author_count%’:
      $new = get_usernumposts($post->post_author);
      break;
      case ‘%post_author_posts%’:
      if (!$authordata) { $authordata = get_userdata($post->post_author); }
      $new = ‘ID, $authordata->user_nicename).'” title=”‘;
      $new .= sprintf(__(“Posts by %s”), htmlspecialchars(the_author($idmode, false))).'”>’.stripslashes(the_author($idmode, false)).’
      ‘;
      break;
      case ‘%post_author_url%’:
      if (!$authordata) { $authordata = get_userdata($post->post_author); }
      if ($authordata->user_url)
      $new = ‘user_url.'” title=”Visit ‘.the_author($idmode, false).’\’s site”>’.the_author($idmode, false).’‘;
      else
      $new = the_author($idmode, false);
      break;
      case ‘%post_content%’:
      $new = apply_filters(‘the_content’, $post->post_content);
      break;
      case ‘%post_date%’:
      $new = mysql2date($date_format, $post->post_date);
      break;
      case ‘%post_excerpt%’:
      $new = apply_filters(‘the_excerpt’, get_the_excerpt());
      break;
      case ‘%post_excerpt_short%’:
      $new = ltrim(strip_tags(apply_filters(‘the_excerpt’, get_the_excerpt())));
      if ($excerpt_words) {
      $words = explode(” “, $new);
      $new = join(” “, array_slice($words, 0, $excerpt_words));
      if (count($words) > $excerpt_words) $new .= “…”;
      } elseif ($excerpt_length) {
      if (strlen($new) > $excerpt_length) $new = substr($new,0,$excerpt_length) . “…”;
      }
      break;
      case ‘%post_id%’:
      $new = $post->ID;
      break;
      case ‘%post_modified%’:
      $new = mysql2date($date_format, $post->post_modified);
      break;
      case ‘%post_title%’:
      if (!$title) { $title = the_title(”, ”, false); }
      $new = $title;
      break;
      case ‘%post_url%’:
      $new = get_permalink();
      break;
      case ‘%post_URL%’:
      if (!$title) { $title = the_title(”, ”, false); }
      $new = $new = ‘‘.$title.’‘;
      break;
      }
      $text = str_replace($tag, $new, $text);
      }
      echo $text . “\n”;
      }
      $post = $orig_post; $authordata = $orig_authordata;
      return;
      } // end function c2c_get_recent_tagmap()

      function c2c_get_recent_handler ($posts, $format = ”, $date_format = ”) {
      if (!$format) { return $posts; }

      // Determine the format of the listing
      $percent_tags = array(
      “%comments_count%”, // Number of comments for post
      “%comments_fancy%”, // Fancy reporting of comments: (see get_recent_tagmap())
      “%comments_url%”, // URL to top of comments section for post
      “%comments_URL%”, // Post title linked to the top of the comments section on post’s permalink page
      “%last_comment_date%”, // Date of last comment for post
      “%last_comment_id%”, // ID for last comment for post
      “%last_comment_URL%”, // URL to most recent comment for post
      “%last_commenter%”, // Author of last comment for post
      “%last_commenter_URL%”, // Linked (if author URL provided) of author of last comment for post
      “%post_author%”, // Author for post
      “%post_author_count%”, // Number of posts made by post author
      “%post_author_posts%”, // Link to page of all of post author’s posts
      “%post_author_url%”, // Linked (if URL provided) name of post author
      “%post_content%”, // Full content of the post
      “%post_date%”, // Date for post
      “%post_excerpt%”, // Excerpt for post
      “%post_excerpt_short%”, // Customizably shorter excerpt, suitable for sidebar usage
      “%post_id%”, // ID for post
      “%post_modified%”, // Last modified date for post
      “%post_title%”, // Title for post
      “%post_url%”, // URL for post
      “%post_URL%”, // Post title linked to post’s permalink page
      );
      $ptags = array();
      foreach ($percent_tags as $tag) { if (strpos($format, $tag) !== false) $ptags[] = $tag; }
      return c2c_get_recent_tagmap($posts, $format, $ptags, $date_format);
      } //end function c2c_get_recent_handler()

      ?>

    Thread Starter kopas

    (@kopas)

    This is not exactly what i want. The _blank just opens a window with a random size and location on screen. The window should be centered and with a specific size! In normal HTML i would include some piece of JavaScript code into the original window that would open the new centered popup but with wordpress i have no idea how to accomplish this.

    I encounter the same problem when upgrading to 2.2. I have not touched any file with dreamweaver or frontpage.

    Are you trying to activate the widget plugin? It is not needed anymore. The widget code is already build into wordpress from version 2.2

    I tried the proposed solution but still my db tables are not created. Any hints or tips on how to proceed next?

    Thread Starter kopas

    (@kopas)

    Solved my problem.. It was caused by an incomplete ftp transfer. Strange thing is that is happend 2 or 3 times and and another ftp client (FlashFxp) solved my issue!

Viewing 6 replies - 1 through 6 (of 6 total)