1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

wordpress popular posts with thumbnail

Discussion in 'WordPress' started by cinigallery, Apr 10, 2012.

  1. #1
    i wanted to show wordpress popular posts with thumbnail.I tried the following code




    <ol id="popular_posts">
    <?php
    $pp = new WP_Query('orderby=comment_count&posts_per_page=5'); ?>
    <?php while ($pp->have_posts()) : $pp->the_post(); ?>
    <li><div class="pop_image"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(60,60)); ?></a></div><a class="pop_link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    <div style="clear: both;"></div>
    <?php endwhile; ?>
    </ol>




    But showing the error


    Fatal error: Call to undefined function the_post_thumbnail() in /home/user/public_html/wp-content/themes/demo/lsidebar.php on line 79
     
    cinigallery, Apr 10, 2012 IP
  2. AlohaThemes.com

    AlohaThemes.com Active Member

    Messages:
    128
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #2
    Make sure you are using the latest version of WP. If you are using a 2.xx, this function may not be in the core installation and will give you that error.

    Hope that helps :)

    - Scott
     
    AlohaThemes.com, Apr 10, 2012 IP
  3. cinigallery

    cinigallery Greenhorn

    Messages:
    63
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    16
    #3
    iam using WordPress 3.3.1.
     
    cinigallery, Apr 10, 2012 IP
  4. adbox

    adbox Well-Known Member

    Messages:
    906
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    155
    Digital Goods:
    1
    #4
    Is this for a widget?

    I use this for all my blogs . I add it too the theme's functions.php file. ... not this is for recent posts not popular posts but I'm sure it can be modified.


    class Recentposts_thumbnail extends WP_Widget {
    
        function Recentposts_thumbnail() {
            parent::WP_Widget(false, $name = 'Sight Recent Posts');
        }
    
        function widget($args, $instance) {
            extract( $args );
            $title = apply_filters('widget_title', $instance['title']);
            ?>
                <?php echo $before_widget; ?>
                <?php if ( $title ) echo $before_title . $title . $after_title;  else echo '<div class="widget-body clear">'; ?>
    
                <?php
                    global $post;
                    if (get_option('rpthumb_qty')) $rpthumb_qty = get_option('rpthumb_qty'); else $rpthumb_qty = 5;
                    $q_args = array(
                        'numberposts' => $rpthumb_qty,
                    );
                    $rpthumb_posts = get_posts($q_args);
                    foreach ( $rpthumb_posts as $post ) :
                        setup_postdata($post);
                ?>
    
                    <a href="<?php the_permalink(); ?>" class="rpthumb clear">
                        <?php if ( has_post_thumbnail() && !get_option('rpthumb_thumb') ) {
                            the_post_thumbnail('mini-thumbnail');
                            $offset = 'style="padding-left: 65px;"';
                        }
                        ?>
                        <span class="rpthumb-title" <?php echo $offset; ?>><?php the_title(); ?></span>
                        <span class="rpthumb-date" <?php echo $offset; unset($offset); ?>><?php the_time(__('M j, Y')) ?></span>
                    </a>
    
                <?php endforeach; ?>
    
                <?php echo $after_widget; ?>
            <?php
        }
    
        function update($new_instance, $old_instance) {
            $instance = $old_instance;
            $instance['title'] = strip_tags($new_instance['title']);
            update_option('rpthumb_qty', $_POST['rpthumb_qty']);
            update_option('rpthumb_thumb', $_POST['rpthumb_thumb']);
            return $instance;
        }
    
        function form($instance) {
            $title = esc_attr($instance['title']);
            ?>
                <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('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 $title; ?>" /></label></p>
                <p><label for="rpthumb_qty">Number of posts:  </label><input type="text" name="rpthumb_qty" id="rpthumb_qty" size="2" value="<?php echo get_option('rpthumb_qty'); ?>"/></p>
                <p><label for="rpthumb_thumb">Hide thumbnails:  </label><input type="checkbox" name="rpthumb_thumb" id="rpthumb_thumb" <?php echo (get_option('rpthumb_thumb'))? 'checked="checked"' : ''; ?>/></p>
            <?php
        }
    
    }
    add_action('widgets_init', create_function('', 'return register_widget("Recentposts_thumbnail");'));
    PHP:

    and add this to your style.css

    
    	.rpthumb {display: block; padding-bottom: 15px; margin-top: 15px; border-bottom: 1px dotted #d9d9d9;}
    	.rpthumb img {width: 50px; width: 50px; margin-right: 15px; float: left;}
    	.rpthumb-title {display: block; font: 12px Georgia, Geneva, "Times New Roman", times; margin-bottom: 6px;}
    	.rpthumb-date {display: block; font-size: 11px; color: #aaa9a9;}
    	.rpthumb:hover {text-decoration: none !important;}
    	.rpthumb:hover .rpthumb-title {text-decoration: underline;}
    	
    
    PHP:
    and it will end up providing a widget that will create output like I have at BlogSense Industry News
     
    adbox, Apr 11, 2012 IP
  5. cinigallery

    cinigallery Greenhorn

    Messages:
    63
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    16
    #5
    anyone know to add popular posts without using plugin?

    Please post it here
     
    cinigallery, Apr 11, 2012 IP
  6. blogideas

    blogideas Peon

    Messages:
    117
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I'm curious why you wouldn't want to use a plugin or widget? It makes the process much easier.
     
    blogideas, Apr 11, 2012 IP
  7. cinigallery

    cinigallery Greenhorn

    Messages:
    63
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    16
    #7
    my hosting told my blog using more CPU.they suggested me to remove plugin.so i want to use php codes instead of plugin.

    Do you have any idea to show post with thumbnail ?
     
    cinigallery, Apr 11, 2012 IP