Skip to main content
added 5229 characters in body
Source Link

Here's the link to code for the Recent/Popular posts widget

<?php

/**

  • MyThemeShop Tabs Widget */ function mts_popular_tabs( $posts = 3 ) { $popular = new WP_Query('showposts='. $posts .'&orderby=comment_count&order=desc'); $popular_post_num = 1; while ($popular->have_posts()) : $popular->the_post(); ?>
  • ID), 'thumbnail'); ?> '>" alt="" width='50' height='50' class="wp-post-image" /> '>/images/smallthumb.png" alt="" width='50' height='50' class="wp-post-image" /> " href="">

    ">
  • have_posts()): $the_query->the_post();?>
  • ID), 'thumbnail'); ?> '>" alt="" width='50' height='50' class="wp-post-image" /> '>/images/smallthumb.png" alt="" width='50' height='50' class="wp-post-image" /> " href="">

    ">
  • 'widget_tab', 'description' => __('Display the popular Posts and Latest Posts in tabbed format'));$control_ops = array('width' => 400, 'height' => 350);$this->WP_Widget('tab', __('MyThemeShop: Tab Widget'), $widget_ops, $control_ops);}function widget( $args, $instance){extract($args);$popular_post_num = $instance['popular_post_num'];$recent_post_num = $instance['recent_post_num'];?>
    <div id="tabber">
            
        <ul class="tabs">
            <li><a href="#popular-posts"><?php _e('Popular Posts', 'mythemeshop'); ?></a></li>
            <li class="tab-recent-posts"><a href="#recent-posts"><?php _e('Recent Posts', 'mythemeshop'); ?></a></li>
        </ul> <!--end .tabs-->
            
        <div class="clear"></div>
        
        <div class="inside">
        
            <div id="popular-posts">
                <ul>
                    <?php rewind_posts(); ?>
                    <?php mts_popular_tabs($popular_post_num); ?>
                </ul>           
            </div> <!--end #popular-posts-->
               
            <div id="recent-posts"> 
                <ul>
                    <?php mts_latest_tabs($recent_post_num); ?>                      
                </ul>   
            </div> <!--end #recent-posts-->
            
            <div class="clear"></div>
            
        </div> <!--end .inside -->
        
        <div class="clear"></div>
        
    </div><!--end #tabber -->
    
        <?php
    }
    
    function update( $new_instance, $old_instance ) {
        $instance = $old_instance;
        $instance['popular_post_num'] = $new_instance['popular_post_num'];
        $instance['recent_post_num'] =  $new_instance['recent_post_num'];
        return $instance;
    }
    
    function form( $instance ) { 
        $instance = wp_parse_args( (array) $instance, array( 'popular_post_num' => '5', 'recent_post_num' => '5') );
        $popular_post_num = $instance['popular_post_num'];
        $recent_post_num = format_to_edit($instance['recent_post_num']);
    ?>
        <p><label for="<?php echo $this->get_field_id('popular_post_num'); ?>"><?php _e('Number of popular posts to show::'); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id('popular_post_num'); ?>" name="<?php echo $this->get_field_name('popular_post_num'); ?>" type="text" value="<?php echo $popular_post_num; ?>" /></p>
        
        <p><label for="<?php echo $this->get_field_id('recent_post_num'); ?>"><?php _e('Number of latest posts to show:'); ?></label>
        <input class="widefat" type="text" id="<?php echo $this->get_field_id('recent_post_num'); ?>" name="<?php echo $this->get_field_name('recent_post_num'); ?>" value="<?php echo $recent_post_num; ?>" /></p>
    
    <?php }
    

    }

    register_widget('mts_Widget_Tabs');

    ? http://pastebin.com/YbMhKAMV

    Blockquote

    Here's the code for the Recent/Popular posts widget

    <?php
    

    /**

    • MyThemeShop Tabs Widget */ function mts_popular_tabs( $posts = 3 ) { $popular = new WP_Query('showposts='. $posts .'&orderby=comment_count&order=desc'); $popular_post_num = 1; while ($popular->have_posts()) : $popular->the_post(); ?>
  • ID), 'thumbnail'); ?> '>" alt="" width='50' height='50' class="wp-post-image" /> '>/images/smallthumb.png" alt="" width='50' height='50' class="wp-post-image" /> " href="">

    ">
  • have_posts()): $the_query->the_post();?>
  • ID), 'thumbnail'); ?> '>" alt="" width='50' height='50' class="wp-post-image" /> '>/images/smallthumb.png" alt="" width='50' height='50' class="wp-post-image" /> " href="">

    ">
  • 'widget_tab', 'description' => __('Display the popular Posts and Latest Posts in tabbed format'));$control_ops = array('width' => 400, 'height' => 350);$this->WP_Widget('tab', __('MyThemeShop: Tab Widget'), $widget_ops, $control_ops);}function widget( $args, $instance){extract($args);$popular_post_num = $instance['popular_post_num'];$recent_post_num = $instance['recent_post_num'];?>
    <div id="tabber">
            
        <ul class="tabs">
            <li><a href="#popular-posts"><?php _e('Popular Posts', 'mythemeshop'); ?></a></li>
            <li class="tab-recent-posts"><a href="#recent-posts"><?php _e('Recent Posts', 'mythemeshop'); ?></a></li>
        </ul> <!--end .tabs-->
            
        <div class="clear"></div>
        
        <div class="inside">
        
            <div id="popular-posts">
                <ul>
                    <?php rewind_posts(); ?>
                    <?php mts_popular_tabs($popular_post_num); ?>
                </ul>           
            </div> <!--end #popular-posts-->
               
            <div id="recent-posts"> 
                <ul>
                    <?php mts_latest_tabs($recent_post_num); ?>                      
                </ul>   
            </div> <!--end #recent-posts-->
            
            <div class="clear"></div>
            
        </div> <!--end .inside -->
        
        <div class="clear"></div>
        
    </div><!--end #tabber -->
    
        <?php
    }
    
    function update( $new_instance, $old_instance ) {
        $instance = $old_instance;
        $instance['popular_post_num'] = $new_instance['popular_post_num'];
        $instance['recent_post_num'] =  $new_instance['recent_post_num'];
        return $instance;
    }
    
    function form( $instance ) { 
        $instance = wp_parse_args( (array) $instance, array( 'popular_post_num' => '5', 'recent_post_num' => '5') );
        $popular_post_num = $instance['popular_post_num'];
        $recent_post_num = format_to_edit($instance['recent_post_num']);
    ?>
        <p><label for="<?php echo $this->get_field_id('popular_post_num'); ?>"><?php _e('Number of popular posts to show::'); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id('popular_post_num'); ?>" name="<?php echo $this->get_field_name('popular_post_num'); ?>" type="text" value="<?php echo $popular_post_num; ?>" /></p>
        
        <p><label for="<?php echo $this->get_field_id('recent_post_num'); ?>"><?php _e('Number of latest posts to show:'); ?></label>
        <input class="widefat" type="text" id="<?php echo $this->get_field_id('recent_post_num'); ?>" name="<?php echo $this->get_field_name('recent_post_num'); ?>" value="<?php echo $recent_post_num; ?>" /></p>
    
    <?php }
    

    }

    register_widget('mts_Widget_Tabs');

    ?

    Blockquote

    Here's the link to code for the Recent/Popular posts widget http://pastebin.com/YbMhKAMV

    added 5229 characters in body
    Source Link

    Here's the code for the Recent/Popular posts widget

    <?php
    

    /**

    • MyThemeShop Tabs Widget */ function mts_popular_tabs( $posts = 3 ) { $popular = new WP_Query('showposts='. $posts .'&orderby=comment_count&order=desc'); $popular_post_num = 1; while ($popular->have_posts()) : $popular->the_post(); ?>
  • ID), 'thumbnail'); ?> '>" alt="" width='50' height='50' class="wp-post-image" /> '>/images/smallthumb.png" alt="" width='50' height='50' class="wp-post-image" /> " href="">

    ">
  • have_posts()): $the_query->the_post();?>
  • ID), 'thumbnail'); ?> '>" alt="" width='50' height='50' class="wp-post-image" /> '>/images/smallthumb.png" alt="" width='50' height='50' class="wp-post-image" /> " href="">

    ">
  • 'widget_tab', 'description' => __('Display the popular Posts and Latest Posts in tabbed format'));$control_ops = array('width' => 400, 'height' => 350);$this->WP_Widget('tab', __('MyThemeShop: Tab Widget'), $widget_ops, $control_ops);}function widget( $args, $instance){extract($args);$popular_post_num = $instance['popular_post_num'];$recent_post_num = $instance['recent_post_num'];?>
    <div id="tabber">
            
        <ul class="tabs">
            <li><a href="#popular-posts"><?php _e('Popular Posts', 'mythemeshop'); ?></a></li>
            <li class="tab-recent-posts"><a href="#recent-posts"><?php _e('Recent Posts', 'mythemeshop'); ?></a></li>
        </ul> <!--end .tabs-->
            
        <div class="clear"></div>
        
        <div class="inside">
        
            <div id="popular-posts">
                <ul>
                    <?php rewind_posts(); ?>
                    <?php mts_popular_tabs($popular_post_num); ?>
                </ul>           
            </div> <!--end #popular-posts-->
               
            <div id="recent-posts"> 
                <ul>
                    <?php mts_latest_tabs($recent_post_num); ?>                      
                </ul>   
            </div> <!--end #recent-posts-->
            
            <div class="clear"></div>
            
        </div> <!--end .inside -->
        
        <div class="clear"></div>
        
    </div><!--end #tabber -->
    
        <?php
    }
    
    function update( $new_instance, $old_instance ) {
        $instance = $old_instance;
        $instance['popular_post_num'] = $new_instance['popular_post_num'];
        $instance['recent_post_num'] =  $new_instance['recent_post_num'];
        return $instance;
    }
    
    function form( $instance ) { 
        $instance = wp_parse_args( (array) $instance, array( 'popular_post_num' => '5', 'recent_post_num' => '5') );
        $popular_post_num = $instance['popular_post_num'];
        $recent_post_num = format_to_edit($instance['recent_post_num']);
    ?>
        <p><label for="<?php echo $this->get_field_id('popular_post_num'); ?>"><?php _e('Number of popular posts to show::'); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id('popular_post_num'); ?>" name="<?php echo $this->get_field_name('popular_post_num'); ?>" type="text" value="<?php echo $popular_post_num; ?>" /></p>
        
        <p><label for="<?php echo $this->get_field_id('recent_post_num'); ?>"><?php _e('Number of latest posts to show:'); ?></label>
        <input class="widefat" type="text" id="<?php echo $this->get_field_id('recent_post_num'); ?>" name="<?php echo $this->get_field_name('recent_post_num'); ?>" value="<?php echo $recent_post_num; ?>" /></p>
    
    <?php }
    

    }

    register_widget('mts_Widget_Tabs');

    ?

    Blockquote

    Here's the code for the Recent/Popular posts widget

    <?php
    

    /**

    • MyThemeShop Tabs Widget */ function mts_popular_tabs( $posts = 3 ) { $popular = new WP_Query('showposts='. $posts .'&orderby=comment_count&order=desc'); $popular_post_num = 1; while ($popular->have_posts()) : $popular->the_post(); ?>
  • ID), 'thumbnail'); ?> '>" alt="" width='50' height='50' class="wp-post-image" /> '>/images/smallthumb.png" alt="" width='50' height='50' class="wp-post-image" /> " href="">

    ">
  • have_posts()): $the_query->the_post();?>
  • ID), 'thumbnail'); ?> '>" alt="" width='50' height='50' class="wp-post-image" /> '>/images/smallthumb.png" alt="" width='50' height='50' class="wp-post-image" /> " href="">

    ">
  • 'widget_tab', 'description' => __('Display the popular Posts and Latest Posts in tabbed format'));$control_ops = array('width' => 400, 'height' => 350);$this->WP_Widget('tab', __('MyThemeShop: Tab Widget'), $widget_ops, $control_ops);}function widget( $args, $instance){extract($args);$popular_post_num = $instance['popular_post_num'];$recent_post_num = $instance['recent_post_num'];?>
    <div id="tabber">
            
        <ul class="tabs">
            <li><a href="#popular-posts"><?php _e('Popular Posts', 'mythemeshop'); ?></a></li>
            <li class="tab-recent-posts"><a href="#recent-posts"><?php _e('Recent Posts', 'mythemeshop'); ?></a></li>
        </ul> <!--end .tabs-->
            
        <div class="clear"></div>
        
        <div class="inside">
        
            <div id="popular-posts">
                <ul>
                    <?php rewind_posts(); ?>
                    <?php mts_popular_tabs($popular_post_num); ?>
                </ul>           
            </div> <!--end #popular-posts-->
               
            <div id="recent-posts"> 
                <ul>
                    <?php mts_latest_tabs($recent_post_num); ?>                      
                </ul>   
            </div> <!--end #recent-posts-->
            
            <div class="clear"></div>
            
        </div> <!--end .inside -->
        
        <div class="clear"></div>
        
    </div><!--end #tabber -->
    
        <?php
    }
    
    function update( $new_instance, $old_instance ) {
        $instance = $old_instance;
        $instance['popular_post_num'] = $new_instance['popular_post_num'];
        $instance['recent_post_num'] =  $new_instance['recent_post_num'];
        return $instance;
    }
    
    function form( $instance ) { 
        $instance = wp_parse_args( (array) $instance, array( 'popular_post_num' => '5', 'recent_post_num' => '5') );
        $popular_post_num = $instance['popular_post_num'];
        $recent_post_num = format_to_edit($instance['recent_post_num']);
    ?>
        <p><label for="<?php echo $this->get_field_id('popular_post_num'); ?>"><?php _e('Number of popular posts to show::'); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id('popular_post_num'); ?>" name="<?php echo $this->get_field_name('popular_post_num'); ?>" type="text" value="<?php echo $popular_post_num; ?>" /></p>
        
        <p><label for="<?php echo $this->get_field_id('recent_post_num'); ?>"><?php _e('Number of latest posts to show:'); ?></label>
        <input class="widefat" type="text" id="<?php echo $this->get_field_id('recent_post_num'); ?>" name="<?php echo $this->get_field_name('recent_post_num'); ?>" value="<?php echo $recent_post_num; ?>" /></p>
    
    <?php }
    

    }

    register_widget('mts_Widget_Tabs');

    ?

    Blockquote

    Source Link

    Getting Duplicate Posts on Home Page with Widget Added Between Posts

    I'm trying to add a widget area in between posts on the home page. I got them to show right where I want them, after the first post. The problem is that the first two posts are duplicated. The same post that shows above the new widget area is also shown after the widget area. If I take out the call for widget code and just place regular ad code then the posts don't duplicate. This only happens when I call for the widget. I'm not sure how else I could fix this.

    Here's what my code looks like in index.php

    <?php $postnum = 1; $showads = 1; $counter = 1; ?>
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        
            <article class="article">
            <div class="post-single post_box">
                <header>
                <div class="headline_area">
                <h2 class="entry-title"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
            <?php if($options['mts_headline_meta'] == '1') { ?>
                <div class="headline_meta">
                <p class="theauthor"><?php _e('By ', 'mythemeshop'); the_author_posts_link(); ?></p>
                <p class="themeta"><span class="thetime"><?php the_time('F j, Y'); ?></span><span class="thecategories"><?php the_category(' ') ?></span><span class="thecomments"><a href="<?php comments_link(); ?>" rel="nofollow"><?php comments_number('No comments','1 Comment','% Comments'); ?></a></span></p>
                </div>
            <?php } ?>
                </div><!--.headline_area-->
                </header>
                <?php if($options['mts_thumbnails'] == '1') { ?>
                <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="nofollow"><?php if ( has_post_thumbnail() ) { echo '<div class="featured-thumbnail">'; the_post_thumbnail('thumbnail', array('title' => '')); echo '</div>'; } ?></a>
                <?php } ?>
                <div class="format_text entry-content">
                    <?php the_excerpt(); ?>
                    <p><a href="<?php the_permalink() ?>" class="readmore" rel="nofollow">Read More...</a></p>
                </div>
            </div><!--.post-single-->
            </article>
            
            <?php if ($postnum == $showads) { ?>
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Hot-Widget") ) : ?><?php endif; ?>
    <?php } $postnum++; ?>
    
        <?php endwhile; else: ?>
    

    If I add a normal ad code in between the two lines below, then the posts aren't duplicated but whenever I call for the widget then the posts are duplicated.

    <?php if ($postnum == $showads) { ?>
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Hot-Widget") ) : ?>         <?php endif; ?>
    <?php } $postnum++; ?>
    

    Here's what my page looks like now http://carrenomedia.com/rp