WordPress.org

Ready to get started?Download WordPress

Forums

Select comment text instead of post (2 posts)

  1. vanleeuwen1974
    Member
    Posted 7 years ago #

    Hello folks,

    In my sidebar.php I am using the List recent comments and posts-plugin, which shows the latest comments in the sidebar.

    This plugin exists of the following tag in the sidebar <?php bdp_comments(); ?> and the following php file:

    <?php
    /*
    Plugin Name:bdp-comments
    Plugin URI:http://www.ozpolitics.info/blog/?page_id=164#comments
    Description:List recent comments and posts - hacked from the WordPress core
    Version:1.0.3
    Author:Bryan Palmer (palmer.bryan@gmail.com)
    Author URI:http://www.ozpolitics.info/
    
    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.
    */
    
    function bdp_comments($howmany='3', $before='<li>', $after='</li>') {
    
    	global $wpdb;
    
    	$sql = 	"SELECT comment_author, comment_author_url, comment_ID, " .
    		"comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' " .
    		"ORDER BY comment_date_gmt DESC LIMIT $howmany";
    
    	if ( $comments = $wpdb->get_results($sql) )  {
    		foreach ($comments as $comment) {
    			echo "$before";
    			if($comment->comment_author_url) {
    				echo '<a href="' .$comment->comment_author_url. '"  rel="nofollow">';
    			}
    			echo "$comment->comment_author";
    			if($comment->comment_author_url) {
    				echo '</a>';
    			}
    			echo " on <a href='" . get_permalink($comment->comment_post_ID) .
    				'#comment-' . $comment->comment_ID . "'>" .
    				get_the_title($comment->comment_post_ID) . "</a>$after\n";
    		}
    	}
    }
    
    function bdp_posts($howmany='5', $before='<li>', $after='</li>') {
    
    	global $wpdb;
    
    	$today = current_time('mysql', 1);
    
    	$sql =	"SELECT ID, post_title FROM $wpdb->posts WHERE " .
    		"post_status='publish' AND post_date_gmt<'$today' AND post_type='post' " .
    		"ORDER BY post_date DESC LIMIT $howmany";
    
    	if ( $recentposts = $wpdb->get_results($sql) )  {
    		foreach ($recentposts as $post) {
    			echo "$before<a href='" .get_settings('siteurl'). "?p=$post->ID'>$post->post_title</a>$after";
    		}
    	}
    }
    
    ?>

    This plugin displays who has posted the comment on which post. I however would like to show the text of the latest comment instead of which post. I think the query on the database has to be changed in the php file. Can somebody help me with this?

    Thanks.

    Marcel van Leeuwen

  2. vanleeuwen1974
    Member
    Posted 7 years ago #

    Anybody???

Topic Closed

This topic has been closed to new replies.

About this Topic