Jump to content

Don't Show Full Post Title On Popular Posts Sidebar Widget?


celebbiz

Recommended Posts

Hey guys real quick question for the pro's I have a recent posts sidebar widget on our site and I can select say show the last 10 most popular posts. The problem I am running into is that my keyword densaty is getting out of wack as the title of the posts is showing 10 times. I would like to exclude some words from showing from the widget...

 

Example: I have say 10 posts: Bald Red Widgets, Harry Red Widgets, Smooth Red Widgets etc etc. I would like for the widget to not use the full title of the posts and not show the word "Red Widgets". I was told I should do this useing something like the str_replace function however I have no idea where to put it or the code itself, can someone help?

 

//TABBED POSTS
class oswc_tabbed_posts extends WP_Widget {
function oswc_tabbed_posts() {
 /* Widget settings. */
 $widget_ops = array( 'classname' => 'Extended: Post Tabs', 'description' => __( 'Displays posts, comments, and tags in a jQuery tabbed format','made') );
 /* Widget control settings. */
 $control_ops = array( 'width' => 200, 'height' => 350, 'id_base' => 'oswc_tabbed_posts' );
 /* Create the widget. */
 $this->WP_Widget( 'oswc_tabbed_posts', 'Extended: Post Tabs', $widget_ops, $control_ops );
}
function widget( $args, $instance ) {
 global $oswc_front, $oswc_misc, $oswcPostTypes;
 $oswc_skin = $oswc_misc['skin'];

 //check to see if we are on a review type page
 $reviewPage = false;
 $post_id = $GLOBALS['post']->ID;
 $postTypeName = oswc_get_review_meta($post_id);
 $postTypeId = get_post_type($post_id); //setup the posttypeid object, which is used below to determine which post type we're on
 //review listing page
 if(!empty($postTypeName) && ($oswcPostTypes->has_type($postTypeName) || $oswcPostTypes->has_type(strtolower($postTypeName)))){
  $reviewPage = true;
  $reviewType = $oswcPostTypes->get_type_by_name($postTypeName); //get the review type object
  $reviewSkin = $reviewType->skin; //get the review skin
  if($reviewSkin=="dark") $oswc_skin="dark";
  if($reviewSkin=="light") $oswc_skin="";
 }
 //review taxonomy page
 if(is_tax()) {
  $reviewPage = true;
  $reviewType = $oswcPostTypes->get_type_by_id($postTypeId);
  $reviewSkin = $reviewType->skin; //get the review skin
  if($reviewSkin=="dark") $oswc_skin="dark";
  if($reviewSkin=="light") $oswc_skin="";
 }
 //single review page
 if (is_single() && $oswcPostTypes->has_type($postTypeId, true)) {
  $reviewPage = true;
  $reviewType = $oswcPostTypes->get_type_by_id($postTypeId);
  $reviewSkin = $reviewType->skin; //get the review skin
  if($reviewSkin=="dark") $oswc_skin="dark";
  if($reviewSkin=="light") $oswc_skin="";
 }

 //get all template tags (need to be excluded below)
 $oswc_featured_tag = $oswc_front['featured_tag'];
 $oswc_spotlight_tags = $oswc_front['spotlight_tags'];
 $oswc_trending_tag = $oswc_front['trending_tags'];
 $oswc_latest_tag = $oswc_misc['latest_tag'];
 $oswc_dontmiss_tags = $oswc_front['dontmiss_tags'];

 extract( $args );
 /* User-selected settings. */
 $thumbsize = $instance['thumbsize'];
 $showpopular = $instance['showpopular'];
 $showrecent = $instance['showrecent'];
 $showcomments = $instance['showcomments'];
 $showtags = $instance['showtags'];
 $numpopular = $instance['numpopular'];
 $numrecent = $instance['numrecent'];
 $numcomments = $instance['numcomments'];
 $numtags = $instance['numtags'];
 $ordertags = $instance['ordertags'];
 /* HTML output */

 /* Before widget (defined by themes). */
 echo $before_widget;
 ?>

    <div id="tabbed-posts" class="complex-list<?php if($thumbsize=="footer-thumbnail") { ?> small<?php } ?>">
	    <ul class="tabnav">
   <?php if($showpopular) { ?><li><a class="first" href="#tabs-popular"><?php _e('Popular','made'); ?></a></li><?php } ?>
		    <?php if($showrecent) { ?><li><a href="#tabs-recent"><?php _e('Recent','made'); ?></a></li><?php } ?>
		    <?php if($showcomments) { ?><li><a href="#tabs-comments"><?php _e('Comments','made'); ?></a></li><?php } ?>
		    <?php if($showtags) { ?><li><a href="#tabs-tags"><?php _e('Tags','made'); ?></a></li><?php } ?>
	    </ul>
	    <br class="clearer" />
	    <div class="tabdiv-wrapper">

	  <?php if($showpopular) { ?>

			    <div id="tabs-popular" class="tabdiv">
				    <ul>
					    <?php // create popular query
					    $postcount=0;
   // get array of review types
   $arrTypes = array();
   foreach($oswcPostTypes->postTypes as $postType){
    if($postType->enabled) {
	  array_push($arrTypes, $postType->id);				  
    }
   }
   array_push($arrTypes, 'post');	  
   // setup the query	  
   $args=array('suppress_filters' => true, 'posts_per_page' => $numpopular, 'order' => 'DESC', 'orderby' => 'comment_count', 'post_type' => $arrTypes);
					    $pop_loop = new WP_Query($args);
					    if ($pop_loop->have_posts()) : while ($pop_loop->have_posts()) : $pop_loop->the_post(); $postcount++;
    $postType = get_post_type(); //get post type
    $reviewType = $oswcPostTypes->get_type_by_id($postType); //get review type object
    $isreview=false;
				   if($postType!='post' && $postType!='page') $isreview=true; //set review variable 
    $icon = $reviewType->icon;
    $icon_light = $reviewType->icon_light;
    if($oswc_skin=="dark") $icon=$icon_light;
    if(!isset($icon)){
	 $icon = get_template_directory_uri() . '/images/more-grey.png';
    }
    //show rating?
    $rating_hide = get_post_meta(get_the_ID(), "Hide Rating", $single = true);
    //check if this is a video post
    $isvideo=false;
    $video = get_post_meta(get_the_ID(), "Video", $single = true);
    if($video!="") $isvideo=true;
    ?>

    <li>

							    <div class="floatleft">

								 <a href="<?php the_permalink(); ?>" class="thumbnail darken<?php if($isvideo) { ?> video<?php } ?> small" title="<?php the_title(); ?>"><?php the_post_thumbnail($thumbsize, array( 'title'=> '' )); ?></a>	
							    </div>

							    <div class="floatleft">

								 <a class="post-title<?php if(!$isreview) { ?> wide<?php } ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>

								    <?php if($isreview) { ?>

									 <br class="clearer" />

									    <div class="icon">

										    <img alt="icon" src="<?php echo $icon; ?>" width="16" height="16" />

									    </div>
								    <?php } ?>

	  <?php if($isreview && $rating_hide!="true") { ?>
									    <div class="rating-wrapper small"><?php $oswcPostTypes->the_rating($reviewType); // show the rating ?></div>
								    <?php } ?>

							    </div>

							    <br class="clearer" />

    </li>

					    <?php endwhile;
					    endif; ?>
					    <?php wp_reset_query(); ?>
					    <li class="last"> </li> 
				    </ul>
			    </div>

		    <?php } ?>

		    <?php if($showrecent) { ?>

			    <div id="tabs-recent" class="tabdiv">
				    <ul>
				    <?php // create recent query
					    $postcount=0;
   $arrTypes = array();
   foreach($oswcPostTypes->postTypes as $postType){
    if($postType->enabled) {
	  array_push($arrTypes, $postType->id);				  
    }
   }
   array_push($arrTypes, 'post');	
   // setup the query	  
   $args=array('suppress_filters' => true, 'posts_per_page' => $numrecent, 'order' => 'DESC', 'orderby' => 'date', 'post_type' => $arrTypes);
					    $pop_loop = new WP_Query($args);
					    if ($pop_loop->have_posts()) : while ($pop_loop->have_posts()) : $pop_loop->the_post(); $postcount++;
    $postType = get_post_type(); //get post type
    $reviewType = $oswcPostTypes->get_type_by_id($postType); //get review type object
    $isreview=false;
				   if($postType!='post' && $postType!='page') $isreview=true; //set review variable 
    $icon = $reviewType->icon;
    $icon_light = $reviewType->icon_light;
    if($oswc_skin=="dark") $icon=$icon_light;
    if(!isset($icon)){
	 $icon = get_template_directory_uri() . '/images/more-grey.png';
    }
    //show rating?
    $rating_hide = get_post_meta(get_the_ID(), "Hide Rating", $single = true);
    //check if this is a video post
    $isvideo=false;
    $video = get_post_meta(get_the_ID(), "Video", $single = true);
    if($video!="") $isvideo=true;
    ?>

    <li>

							    <div class="floatleft">

								 <a href="<?php the_permalink(); ?>" class="thumbnail darken<?php if($isvideo) { ?> video<?php } ?> small" title="<?php the_title(); ?>"><?php the_post_thumbnail($thumbsize, array( 'title'=> '' )); ?></a>	
							    </div>

							    <div class="floatleft">

								 <a class="post-title<?php if(!$isreview) { ?> wide<?php } ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>					 

								    <?php if($isreview) { ?>

									 <br class="clearer" />

									    <div class="icon">

										    <img alt="icon" src="<?php echo $icon; ?>" width="16" height="16" />

									    </div>
								    <?php } ?>

	  <?php if($isreview && $rating_hide!="true") { ?>
									    <div class="rating-wrapper small"><?php $oswcPostTypes->the_rating($reviewType); // show the rating ?></div>
								    <?php } ?>

							    </div>

							    <br class="clearer" />

    </li>
					    <?php endwhile;
					    endif; ?>
					    <?php wp_reset_query(); ?>
					    <li class="last"> </li> 
				    </ul>
			    </div>

		    <?php } ?>

		    <?php if($showcomments) { ?>

			    <div id="tabs-comments" class="tabdiv">
				    <ul>
				    <?php //get recent comments
				    $args = array(
					    'status' => 'approve',
					    'number' => $numcomments
				    );
  $postcount=0;
				    $comments = get_comments($args);
				    foreach($comments as $comment) :
   $postcount++;	   
					    $commentcontent = strip_tags($comment->comment_content);  
					    if (strlen($commentcontent)>110) {
						    $commentcontent = substr($commentcontent, 0, 107) . "...";
					    }
					    $commentauthor = $comment->comment_author;
					    if (strlen($commentauthor)>50) {
						    $commentauthor = substr($commentauthor, 0, 47) . "...";  
					    }
					    $commentid = $comment->comment_ID;
					    $commenturl = get_comment_link($commentid); ?>
					    <li><a<?php if($postcount==1) { ?> class="first"<?php } ?> href="<?php echo $commenturl; ?>">"<?php echo $commentcontent; ?>"<span> - <?php echo $commentauthor; ?></span></a></li>
				    <?php endforeach; ?>
				    <li class="last"> </li> 
				    </ul>
			    </div>

		    <?php } ?>

		    <?php if($showtags) { ?>

			    <div id="tabs-tags" class="tabdiv">

				 <?php //setup and display tag cloud
  $featuredid = get_tag_id($oswc_featured_tag);
  if($featuredid=='') $featuredid=0;
  $spotlightid = get_tag_id($oswc_spotlight_tags);
  if($spotlightid=='') $spotlightid=0;
  $trendingid = get_tag_id($oswc_trending_tag);
  if($trendingid=='') $trendingid=0;
  $latestid = get_tag_id($oswc_latest_tag);
  if($latestid=='') $latestid=0;
  $dontmissid = get_tag_id($oswc_dontmiss_tags);
  if($dontmissid=='') $dontmissid=0;
  $excludes=$featuredid.','.$spotlightid.','.$trendingid.','.$latestid.','.$dontmissid;
  //echo "excludes=".$excludes;
  if($ordertags=='count') { $order="DESC"; }
  $tagargs = array('smallest' => 8, 'largest' => 22, 'orderby' => $ordertags, 'order' => $order, 'number' => $numtags, 'exclude' => array($excludes));
  //as of 5/2012 the exclude parameter does not work
  wp_tag_cloud($tagargs); ?>

			    </div>

		    <?php } ?>

	    </div>

    </div>

    <?php /* After widget (defined by themes). */
 echo $after_widget; ?>

   <?php
   }
function update( $new_instance, $old_instance ) {
 $instance = $old_instance;
 /* Strip tags (if needed) and update the widget settings. */
 $instance['thumbsize'] = strip_tags( $new_instance['thumbsize'] );
 $instance['showpopular'] = isset( $new_instance['showpopular'] );
 $instance['showrecent'] = isset( $new_instance['showrecent'] );
 $instance['showcomments'] = isset( $new_instance['showcomments'] );
 $instance['showtags'] = isset( $new_instance['showtags'] );
 $instance['numpopular'] = strip_tags( $new_instance['numpopular'] );
 $instance['numrecent'] = strip_tags( $new_instance['numrecent'] );
 $instance['numcomments'] = strip_tags( $new_instance['numcomments'] );
 $instance['numtags'] = strip_tags( $new_instance['numtags'] );
 $instance['ordertags'] = strip_tags( $new_instance['ordertags'] );
 return $instance;
}
function form( $instance ) {
 /* Set up some default widget settings. */
 $defaults = array( 'thumbsize' => 'widget-thumbnail', 'showpopular' => true, 'showrecent' => true, 'showcomments' => true, 'showtags' => true, 'numpopular' => 10, 'numrecent' => 10, 'numcomments' => 7, 'numtags' => 20, 'ordertags' => 'name' );
 $instance = wp_parse_args( (array) $instance, $defaults ); ?>

    <p>
	    <?php _e( 'Thumbnail Size:','made'); ?>    			
	    <input class="radio" type="radio" <?php if($instance['thumbsize']=='widget-thumbnail') { ?>checked <?php } ?>name="<?php echo $this->get_field_name( 'thumbsize' ); ?>" value="widget-thumbnail" />			   
	    <?php _e( 'Large','made'); ?>
	    <input class="radio" type="radio" <?php if($instance['thumbsize']!='widget-thumbnail') { ?>checked <?php } ?>name="<?php echo $this->get_field_name( 'thumbsize' ); ?>" value="footer-thumbnail" />
	    <?php _e( 'Small','made'); ?>			 
    </p>

    <p>
  <input class="checkbox" type="checkbox" <?php checked(isset( $instance['showpopular']) ? $instance['showpopular'] : 0  ); ?> id="<?php echo $this->get_field_id( 'showpopular' ); ?>" name="<?php echo $this->get_field_name( 'showpopular' ); ?>" />
  <?php _e( 'Display','made'); ?>
	    <input id="<?php echo $this->get_field_id( 'numpopular' ); ?>" name="<?php echo $this->get_field_name( 'numpopular' ); ?>" value="<?php echo $instance['numpopular']; ?>" style="width:30px" />
	    <?php _e( 'popular posts','made'); ?>
 </p>

    <p>
  <input class="checkbox" type="checkbox" <?php checked(isset( $instance['showrecent']) ? $instance['showrecent'] : 0  ); ?> id="<?php echo $this->get_field_id( 'showrecent' ); ?>" name="<?php echo $this->get_field_name( 'showrecent' ); ?>" />
  <?php _e( 'Display','made'); ?>
	    <input id="<?php echo $this->get_field_id( 'numrecent' ); ?>" name="<?php echo $this->get_field_name( 'numrecent' ); ?>" value="<?php echo $instance['numrecent']; ?>" style="width:30px" />
	    <?php _e( 'recent posts','made'); ?>
 </p>

    <p>
  <input class="checkbox" type="checkbox" <?php checked(isset( $instance['showcomments']) ? $instance['showcomments'] : 0  ); ?> id="<?php echo $this->get_field_id( 'showcomments' ); ?>" name="<?php echo $this->get_field_name( 'showcomments' ); ?>" />
  <?php _e( 'Display','made'); ?>
	    <input id="<?php echo $this->get_field_id( 'numcomments' ); ?>" name="<?php echo $this->get_field_name( 'numcomments' ); ?>" value="<?php echo $instance['numcomments']; ?>" style="width:30px" />
	    <?php _e( 'comments','made'); ?>
 </p>

    <p>
  <input class="checkbox" type="checkbox" <?php checked(isset( $instance['showtags']) ? $instance['showtags'] : 0  ); ?> id="<?php echo $this->get_field_id( 'showtags' ); ?>" name="<?php echo $this->get_field_name( 'showtags' ); ?>" />
  <?php _e( 'Display','made'); ?>
	    <input id="<?php echo $this->get_field_id( 'numtags' ); ?>" name="<?php echo $this->get_field_name( 'numtags' ); ?>" value="<?php echo $instance['numtags']; ?>" style="width:30px" />
	    <?php _e( 'tags','made'); ?>
 </p>

    <p>
  <input class="radio" type="radio" <?php if($instance['ordertags']=='name') { ?>checked <?php } ?>name="<?php echo $this->get_field_name( 'ordertags' ); ?>" value="name" />
  <?php _e( 'Order tags by name','made'); ?><br />
	    <input class="radio" type="radio" <?php if($instance['ordertags']=='count') { ?>checked <?php } ?>name="<?php echo $this->get_field_name( 'ordertags' ); ?>" value="count" />
  <?php _e( 'Order tags by post count','made'); ?>
 </p>

    <?php
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.