Plugin Directory

Changeset 461508


Ignore:
Timestamp:
11/10/2011 09:27:07 PM (14 years ago)
Author:
teo7
Message:

Graphical mode (color bars)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-popular-posts-tool/trunk/wp-popular-posts-tool.php

    r395546 r461508  
    55Description: Enables you to automatically display most commented posts, either by category or tag. Optional: You can choose manually the category or tag you want to display its most commented posts. It has a widget to add it easily to your sidebar. See this plugin in action in http://teofiloisrael.com
    66Author: Teofilo Israel Vizcaino Rodriguez
    7 Version: 2.0.1
     7Version: 2.1
    88Author URI: http://teofiloisrael.com
    99Demo URI: http://teofiloisrael.com
     
    2121     * Prints the list of popular posts
    2222     */
    23     function ti_popular_posts($num, $my_id=0, $begin='<ul>', $end='</ul>', $pre='<li>', $suf='</li>'){
     23    function ti_popular_posts($num, $my_id=0, $begin='<ul>', $end='</ul>', $pre='<li>', $suf='</li>', $mode=0){
    2424        global $wpdb;
    2525        if($my_id==0):
     
    3939
    4040        $myposts = $wpdb->get_results($querystr, OBJECT);
    41         echo $begin;
     41       
     42        if($mode==0) echo $begin;
     43        $postCount = 0;
     44        $maxPostComments = 0;
     45        $colors = array('red', 'orange', 'yellow', 'green', 'blue');
    4246        foreach($myposts as $post) {
    43             echo $pre;
    44             ?><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title ?></a><?php
    45             echo '<br />' . $post->comment_count . ' '; _e('comments');
    46             echo $suf;
    47         } echo '<li><small style="color:#666666; font-size:9px;"><a style="color:#666666; font-size:9px;" href="http://teofiloisrael.com/plugin-popular-posts-tool/">Popular posts Tool</a> for Wordpress by <a style="color:#666666; font-size:9px;" href="http://teofiloisrael.com/">Teofilo Israel</a></small></li>';
     47            if($mode==0) echo $pre;
     48            switch($mode){
     49                case 0://Normal mode, with comment count
     50                default:   
     51                    ?><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title ?></a><?php
     52                    echo '<br />' . $post->comment_count . ' '; _e('comments');
     53                    break;
     54                case 1://Graphical mode
     55                    if($postCount==0) $maxPostComments = $post->comment_count;
     56                    $width = $post->comment_count / $maxPostComments * 100 / 2;
     57                    ?><table>
     58                        <tr style="height:40px">
     59                            <td style="width:<?php echo ($post->comment_count / $maxPostComments * 100); ?>px;
     60                            background-color:<?php if($postCount < 5){echo $colors[$postCount];}else{echo 'blue';}; ?>"></td>
     61                            <td style="width:<?php echo 200 - $width;?>px;padding-left:6px">
     62                                <a href="<?php echo get_permalink($post->ID); ?>">
     63                                    <?php echo $post->post_title ?>
     64                                </a><?php echo $post->comment_count . ' '; _e('comments');?>
     65                            </td><?php
     66                        ?>
     67                        </tr>
     68                      </table>   
     69                        <?php
     70                        $postCount++;
     71                    break;
     72            }
     73            if($mode==0) echo $suf;
     74        } //echo '<li><small style="color:#666666; font-size:9px;"><a style="color:#666666; font-size:9px;" href="http://teofiloisrael.com/plugin-popular-posts-tool/">Popular posts Tool</a> for Wordpress by <a style="color:#666666; font-size:9px;" href="http://teofiloisrael.com/">Teofilo Israel</a></small></li>';
    4875        echo $end;
    4976    }
     
    100127    ?>
    101128    <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php echo esc_html__('Title'); ?>: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
    102     <p><label for="<?php echo $this->get_field_id('itemsQuantity'); ?>"><?php echo esc_html__('Number of items to show:'); ?>: <input class="widefat" id="<?php echo $this->get_field_id('itemsQuantity'); ?>" name="<?php echo $this->get_field_name('itemsQuantity'); ?>" type="text" value="<?php echo attribute_escape($itemsQuantity); ?>" /></label></p> 
    103     <p><label for="<?php echo $this->get_field_id('catId'); ?>"><?php echo esc_html__('Id of the cateogory or tag (leave it blank for automatic detection):'); ?>: <input class="widefat" id="<?php echo $this->get_field_id('catId'); ?>" name="<?php echo $this->get_field_name('catId'); ?>" type="text" value="<?php echo attribute_escape($catId); ?>" /></label></p><?php
     129    <p><label for="<?php echo $this->get_field_id('itemsQuantity'); ?>"><?php echo esc_html__('Number of items to show'); ?>: <input class="widefat" id="<?php echo $this->get_field_id('itemsQuantity'); ?>" name="<?php echo $this->get_field_name('itemsQuantity'); ?>" type="text" value="<?php echo attribute_escape($itemsQuantity); ?>" /></label></p> 
     130    <p><label for="<?php echo $this->get_field_id('catId'); ?>"><?php echo esc_html__('Id of the cateogory or tag (leave it blank for automatic detection)'); ?>: <input class="widefat" id="<?php echo $this->get_field_id('catId'); ?>" name="<?php echo $this->get_field_name('catId'); ?>" type="text" value="<?php echo attribute_escape($catId); ?>" /></label></p><?php
    104131    }
    105132}
     
    108135 * Use this function if you want to use the plugin directly from the code
    109136 */
    110 function ti_popular_posts($num, $my_id=0, $begin='<ul>', $end='</ul>', $pre='<li>', $suf='</li>'){
    111     WpPopularPostsTool::ti_popular_posts($num, $my_id, $begin, $end, $pre, $suf);
     137function ti_popular_posts($num, $my_id=0, $begin='<ul>', $end='</ul>', $pre='<li>', $suf='</li>', $mode=0){
     138    WpPopularPostsTool::ti_popular_posts($num, $my_id, $begin, $end, $pre, $suf, $mode);
    112139}
    113140   
Note: See TracChangeset for help on using the changeset viewer.