Adding a date hack to popular posts
-
We want to be able to adjust the popular posts on the homepage so that it only shows the most popular posts within one week and not those from a few months ago.
The theme is Technical Speech.
Site is here.The code we have at the moment is thus.
function popularPosts($options='') { $ns_options = array( "count" => "3", "comments" => "1", "before" => "<div class=\"postblock\">", "after" => "</div>", "show" => true, "place" => "content_col" ); $options = explode("&",$options); foreach ($options as $option) { $parts = explode("=",$option); $options[$parts[0]] = $parts[1]; } if ($options['count']) {$ns_options['count'] = $options['count'];} if ($options['comments']) {$ns_options['comments'] = $options['comments'];} if ($options['before']) {$ns_options['before'] = $options['before'];} if ($options['after']) {$ns_options['after'] = $options['after'];} if ($options['show']) {$ns_options['show'] = $options['show'];} if ($options['place']) {$ns_options['place'] = $options['place'];} global $wpdb; $posts = $wpdb->get_results("SELECT comment_count, ID, post_title, post_excerpt, post_content FROM $wpdb->posts WHERE post_type='post' AND post_status = 'publish' AND comment_count >= ".$ns_options['comments']." ORDER BY comment_count DESC LIMIT 0 , ".$ns_options['count']); foreach ($posts as $post) { setup_postdata($post); add_theme_support( 'post-thumbnails' ); $id = $post->ID; $title = $post->post_title; $count = $post->comment_count; $excerpt = $post->post_excerpt; $content = $post->post_content; if (!$excerpt){ $s = 1; if (strlen($content) > 325){ for ($i = 325 ; $i <= 350 ; $i++){ $temp_str = substr(strip_tags($content),$i,1); if ( $temp_str == " "){ $excerpt = substr(strip_tags($content),0,$i) . " [...]"; break; } } }else{ $excerpt = strip_tags($content) . " [...]"; } } if ($ns_options['place'] == 'content_col') { $popular .= $ns_options['before'].'<div class="postblockwrap"><h6><a href="' . get_permalink($id) . '" title="' . $title . '">' . $title . '</a></h6><p>'.$excerpt.'</p><a href="'.get_permalink($id).'" class="readmorelink">Read More</a></div>'.$ns_options['after']; }elseif ($ns_options['place'] == 'content_row'){ $popular .= '<div class="search_post"><div class="search_postdata"><a href="' . get_permalink($id) . '" title="' . $title . '">' . $title . '</a></div><p>'.$excerpt.'</p><div class="morelink" style="margin-bottom:5px;"><a href="'.get_permalink($id).'">Read More</a></div></div>'; }elseif ($ns_options['place'] == 'sidebar'){ $popular .='<li><a href="'.get_permalink($id).'" title="'.$title.'">'.$title.'</a></li>'; } } if ($ns_options['show']==1) {echo $popular;} else {return $popular;} }As always, any help will be much appreciated – thanks.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Adding a date hack to popular posts’ is closed to new replies.