Step 1

Enter your contact information.

Step 2

Enter your project information.

Step 3

Choose the PHP programmers you want to hire.

Compare Free PHP Quotes





Country



How-to show popular posts on your WordPress blog?

*Attention PHP Programmers* - Add A Free Listing! Get more clients.

Win a new Compaq Presario Notebook!

Yesterday I replaced my list of current PHP articles on this blog with a list of popular articles. I’m sure it’s possible in WordPress to get those list if you count the number of comments, but actually I was looking for solution based on real traffic.

Since I’m using WordPress.com Stats, I would like to use the rankings generated by this service or plugin. Searching Google, I found some widget called “WordPress.com Stats: Top Posts Widget” which works out of the box (if like to use a widget). In my case I have a custom sidebar with different custom sections using custom code. The following example explains how-to use that code on your website.

First your need to install the WordPress.com Stats plugin

Yes, the WordPress Stats plugin is required, because the list is based on that data. It’s possible that you need to wait a couple of days before you can continue with the code below (the system need to store some data first).

The tutorial code

Locate the place where you like to add the list; that can be inside the sidebar, the footer or maybe on your blog’s homepage. Add this code snippet:

<?php 
echo '
<h2>Most Popular Articles</h2>
<ul>';
$max = 5;
$top_posts = stats_get_csv('postviews', "days=7&limit=10");
foreach($top_posts as $post) {
	$post_obj = get_post($post['post_id']);
	if (isset($post_obj) && $post_obj->post_type == 'post' && $cnt < $max) {
		echo '
<li><a href="'.$post['post_permalink'].'">'.$post['post_title'].'</a> ('.$post['views'].')</li>';
		$cnt++;
	}
}
echo '
</ul>';
?>

Wordpress Themes">WidgetReady

This snippet is very easy to explain, first let us look on the first two rows:

$max = 5;
$top_posts = stats_get_csv('postviews', "days=7&limit=10");

We created a variable that holds the number of entries we like to show. In Inside the function we’re able to enter values for the time period and a limit for the number of posts. This number is higher than the number we defined before. Running that function will create an array named $top_posts with this kind of key/value pairs:


[0] => Array (
[post_id] => 3933
[post_title] => Sending e-mails via SMTP with PHPmailer and Gmail
[post_permalink] => http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/
[views] => 819
)
[1] => Array (
[post_id] => 5249
[post_title] => Parse html with PHP preg_match_all()
[post_permalink] => http://www.web-development-blog.com/archives/parse-html-with-preg_match_all/
[views] => 555
)
[2] => Array (
[post_id] => 3249
...
)

Actually this array has all the information we need for our list, it’s possible that this array contains other pages too. We need to get the post type for each post and use that value as a filter inside the “foreach” loop. The “if” is also the control source to show only the maximum number of posts as defined before. Our limit (10) inside the function is higher than the “real” limit, this way we have “enough” possible elements to work with.

What are the advantages?

It depends on the traffic you get. If one post is getting most of your site’s traffic, is the chance bigger that more people will share your article with others. This activity might have the result of more traffic to the same post and of course other posts. There is also a great advantage for your on-site SEO, because these popular posts are listed on your homepage (and maybe site-wide), they get much more “link juice” than without these links. This authority is good for all pages linked from your popular pages. Similar Posts:


Source http://www.web-development-blog.com/?p=1524
Tue, 16 Nov 2010 14:27:26 GMT
Tags: code, PHP Scripts, popular, seo, sidebar, snippet, stats, Wordpress Development,

*Attention PHP Programmers* - Add A Free Listing! Get more clients.


code


Titanium Mobile Android Development: Soundboard App

In this series of tutorials we use Appcelerator’s Titanium Mobile platform to create Android applications. This tutorial walks you through developing and packaging a soundboard application. Full source and packaged application is available on Help NASA Code Its Way Through Space

The National Aeronautics and Space Administration has launched a new website to help build a community around the agency's open source projects.

PHP Scripts


Why should you cache your PHP website?

Most web servers are able to handle “normal” traffic and there are plenty of websites which doesn’t have so much traffic. So maybe you ask yourself: Why should you cache your PHP powered website? The apache web server is able to serve ma

WordPress categories, optimization tips and custom pages

It’s not a SEO secret, inner links to / from strong category pages will help your site to rank higher in Google. Sad enough that WordPress doesn’t provide a lot of functionality for these important sections on your blog site. This is the infor

popular


Members:
Rocky River
Lytell Designs Profile
Lytell Designs

Creating unique design solutions that are both affordable and inspiring. Specializing in design, layout & production of printed materials, logos & illustrations.

Rocky River, Ohio US
Mesa
Hamilton Arts Profile
Hamilton Arts

Let Hamilton Arts assist you with your web design needs. We can assure you that our design will not only impress but also work within your budget.

Mesa, Arizona US
Dunmore
Computer Wonders Profile
Computer Wonders

Get a website for $400.00. Please see our Facebook page for more details. http://www.facebook.com/Computer.Wonders

Dunmore, Pennsylvania US
San Antonio
Integrity Web Design Profile
Integrity Web Design

Integrity Web Design builds website, will get clients listed on search engines, directories, design brochures, business cards, bookmarks, catalogs, booklets, calendars, door hangers, & club flyers.

San Antonio, Texas US
Gilbert
Freddythunder Profile
Freddythunder

Gilbert, Arizona US
Design Leads


PHP Programmers Valid HTML 4.0 Transitional Valid CSS!

Internet Explorer 9 Arrives With More Speed, Better Web Standards Support

Microsoft has released Internet Explorer 9, the first major update for Microsoft’s browser in



WebKit Isn’t Breaking the Web. You Are

The prevalence of "works best in WebKit" sites is threatening to make the web look like it did in th



DuckDuckGo Search Engine Crowdsources Plugins

Google competitor DuckDuckGo has launched DuckDuckHack, a developer platform that allows anyone to a



Firefox to Keep Version Numbers After All

Calling it all a misunderstanding, Mozilla says that, for now, Firefox will continue using version n



Samuel L. Ipsum: Pulp Fiction Placeholder Text

Really you should be designing for the content, a practice that pretty much precludes the use of pla



Article Tags
PHP Programmers Articles
Browsers| Web Standards| CSS| firefox| HTML5| Web Basics| Programming| Web Services| Mobile| JavaScript| Web Development| Visual Design| Multimedia| chrome| Google| responsive design| This Week in Web| CSS 3| Opera| Web Apps|
Friends:
Live Help Chat Software
Web Design Quote
Web Design