Popular Posts for Your WordPress Blog

Adding a list of popular posts to your website is a great way to increase user engagement on your site. It shows your readers what people are reading and interacting with the most – which in turn should encourage people to browse around your website more.

There are lots of posts across the blogosphere describing how to do this. Some look at the number of comments, and others track the page views, but they are all quite complex and cumbersome.

I even developed a system for looking at the most popular posts based upon comment count, with a date limit to keep things recent, and it worked (you can still see it in action on the homepage carousel), but wasn’t perfect.

Then today I had a brain(fart)wave.

I have used the WordPress stats plugin for a while and it displays a nice little list of the most popular posts on the WordPress Dashboard… and I got to thinking – “why don’t I use that list myself?”

My first stop was the plugin code – and 5 minutes later I had found a very simple couple of lines of code that would grab the most popular posts using the stats api.

5 minutes after that I had written the following code, and added it to the #footer of this very site (it’s in the right hand column labelled “Currently Hot”).

<?php
	if (function_exists('stats_get_csv')) {
		$top_posts = stats_get_csv ('postviews', 'days=7&limit=8');

		if (count($top_posts) > 0) {
			echo '<ol>';
			foreach ($top_posts as $p) {
?>
				<li><a href="<?php echo $p['post_permalink']; ?>"><?php echo $p['post_title']; ?></a></li>
<?php
			}
			echo '</ol>';
		}

	}
?>

This code works really well, the stats are accurate, and it even has built in database caching. What’s not to like?

Note: The WordPress stats plugin, fully enabled, is a requirement for this to work.

Oh – and if you want the 1 line version check below. Personally I prefer the slightly longer version above.

<?php foreach ($top_posts = stats_get_csv ('postviews', 'days=7&limit=8') as $p) { ?><a href="<?php echo $p['post_permalink']; ?>"><?php echo $p['post_title']; ?></a><?php } ?>

WordPress Search Tips and Security Flaws

WordPress Search Tips

Tags: search, security, WordPress

If you want to customize WordPress’s search functionality you’ll have to scour the internet for bits of WordPress code in a post apocalyptic wasteland of seemingly irrelevant information. Not anymore! I’ve put these chunks of code and tips below to help you customize your users’ search experience without banging your head against the wall to get things working. In some situations you may have strangle your WordPress search for security/survival reasons, but don’t worry, we’ll cover that too.

Custom search functions

I create complex WordPress builds for small and large companies. While many web designers and developers tell you to ditch WordPress’s search capabilities for an off site engine like Google’s. Others suggest using bloated plugins that play with your WordPress code. I personally suggest using WordPress’s search with some simple tips. Here I’ll show you how to alter your WordPress theme to make it much more powerful.

Exclude custom post types

With the introduction of custom post types to WordPress 3.0 you might need to exclude your new items from the built in search engine. There are some extremely complicated methods we could use to do this, but the simplest method is to use the exclude_from_search property when you create the custom post type. For more information check out the WordPress codex on creating custom post types.

This is a quick, simple, and problem free WordPress tip that will make your life much easier. Although this is the simplest way to exclude custom post types, I’ve listed an alternative method below.

// Here we create our custom post type for a feeds add_action('init', 'my_custom_init'); // This is where we set our variables function my_custom_init() { $labels = array( 'name' => _x('Feeds', 'post type general name'), 'singular_name' => _x('Feed', 'post type singular name'), 'add_new' => _x('Add Feed', 'Feed Item'), 'add_new_item' => __('Add New Feed'), 'edit_item' => __('Edit Feed'), 'edit' => _x('Edit', 'feed'), 'new_item' => __('New Feed'), 'view_item' => __('View Feed Information'), 'search_items' => __('Search Feeds'), 'not_found' => __('No feeds were found with that criteria'), 'not_found_in_trash' => __('No feed found in Trash'), 'view' => __('View Feed') ); // Additional arguments (where we place our search exclusion) $args = array( 'labels' => $labels, // This is where we set whether the new post type gets included in a search or not // Defaults to false, but you'll want to set it to true to exclude the item 'exclude_from_search' => true, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'hierarchical' => true, 'menu_position' => null, 'supports' => array('title', 'editor', 'author', 'custom-fields', 'revisions', 'page-attributes') ); register_post_type('feeds',$args); } 

Search a specific post type

WordPress gives you the ability to target specific post types. Place this at the bottom of your functions.php file and you’re good to go! This is a slightly modified version of the ingenious category search exclude script that has been floating around web design blogs for a while. I’d love to give credit for this, but so many designers are claiming it that I don’t know who the original author is.

function SearchFilter($query) { if ($query->is_search) { // Insert the specific post type you want to search $query->set('post_type', 'feeds'); } return $query; } // This filter will jump into the loop and arrange our results before they're returned add_filter('pre_get_posts','SearchFilter'); 

We can modify this a bit to search two custom post types or more such as podcasts along with our feeds category. This is done by inserting our items into an array so WordPress can swallow the data without choking on our awesome request.

function SearchFilter($query) { if ($query->is_search) { // Insert the specific post types you want to search $query->set('post_type', array('feeds', 'podcasts')); } return $query; } add_filter('pre_get_posts','SearchFilter'); 

Search posts only

On the occasion I need to shut off all of my pages search posts only. Since WordPress can take any post_type query information we throw at it, why not just tell it to search posts only?

function SearchFilter($query) { if ($query->is_search) { $query->set('post_type', 'post'); } return $query; } add_filter('pre_get_posts','SearchFilter'); 

Search specific categories only

You can search specific categories using the same logic for the custom post type search used above. Just plug in your categories and WordPress will take care of everything you need. To get your category IDs, you’ll need to go to “Your Post’s Name” -> Categories (or chosen taxonomy name) and look for the id in the link such as http://www.ashbluewebdesign.com/wp-admin/categories.php?action=edit&cat_ID=125. If you need a more detailed explanation check out this simple post on WordPress IDs. Once again just shove this into the bottom of your functions.php file.

function SearchFilter($query) { if ($query->is_search) { // Insert the specific categories you want to search $query->set('cat', '8,9,12'); } return $query; } add_filter('pre_get_posts','SearchFilter'); 

Search pages only

Sometimes what you really need is to serach pages only. This can be easily done by setting your post type to page.

function SearchFilter($query) { if ($query->is_search) { $query->set('post_type','page'); } return $query; } add_filter('pre_get_posts','SearchFilter'); 

Putting it all together

Taking what we’ve done with these functions, you can shove them into an array and force out some really unique search results. For instance, why not search only pages and feeds, while excluding posts?

function SearchFilter($query) { if ($query->is_search) { $query->set('post_type', array('page', 'feeds')); } return $query; } add_filter('pre_get_posts','SearchFilter'); 

Shutting off WordPress’s search

A really good tip I can give you is to completely shut off the search when you don’t need it. I’ve personally used the search on websites against their will by simply plugging in http://www.yoursite.com/?s=yoursearchtermshere. Feed the user a 404 error page with no results. Do so by telling your functions.php file to direct all searches to it. This code originally comes from WPEngineer. Check out the article for a more thorough explanation.

function fb_filter_query( $query, $error = true ) { if ( is_search() ) { $query->is_search = false; $query->query_vars[s] = false; $query->query[s] = false; // to error if ( $error == true ) $query->is_404 = true; } } add_action( 'parse_query', 'fb_filter_query' ); add_filter( 'get_search_form', create_function( '$a', "return null;" ) ); 

Security Flaw – Private Page Excerpt Tip

If you set a page in WordPress to password protected you’ll notice that it won’t display an excerpt for people searching. Problem is that private pages still display an excerpt, leaving sensitive data open to potential hackers. The best thing you can do here is set the pages to password protected if the information is extremely important. The alternative would be to delete the excerpt in your WordPress search loop. Making it so no excerpt whatsoever appears when somebody searches. Either method is not necessarily ideal. Currently I’m searching for a method to strip private pages from the search, but I’m having trouble finding out how to do so. Please let me know if you have any leads that don’t involve a plugin.

Supply chain management



YouTube Video WordPress plugin and Tools Collection

Integrate YouTube In Your Site or WordPress

  • YouTube badge maker – will show your viewers images of your 6 most recently uploaded videos.
  • YouTube WordPress Plugin – Display YouTube videos on your WordPress blog according to Tags.
  • YouTube Video Gallery WordPress Plugin – displays a gallery of videos from youtube.com.
  • WordPress Related Videos Plugin – Uses tags to look for related videos on YouTube, displays the three most recent related videos on your WordPress blog post and updates videos automatically.
  • WordPress Favourite YouTube Videos – WordPress plugin / widget to display, in a very configurable manner, your latest favorite videos from Youtube.
  • Viper�s Video Quicktags – WP plugin that easily generates codes for copy / pasting to embed videos from sites like YouTube and Google Video or for self-hosted videos into your posts.
  • WP-FLV – WordPress plugin simplfies the process of inserting flash video files (FLV) inside a WordPress post or page.
  • TubePress – a highly configurable WordPress plugin that displays YouTube videos in an embedded gallery in posts and/or pages.

Save and Download YouTube Videos

  • Delutube – Lets you view deleted Youtube videos.
  • Video Downloader – a firefox extension that allows you to download youtube videos to your computer from YouTube and most video sites.
  • YouTubeX – allows you to save and download YouTube videos easily using only your IE or firefox browser.
  • TubeSock – grabs YouTube videos from the web and copies them to your video iPod, Mac, or PlayStation Portable.
  • VideoDL – is a quick AJAX application that allows you to download online video into your computer. It supports top 3 video sites – YouTube, Google Video, and Break.com.
  • Download YouTube via bookmarklets – A collection of Greasemonkey scripts and bookmarklets to do the job.
  • Youtube-dl – is a small command-line program to download videos from YouTube.com. It requires the Python interpreter, version 2.4 or later.
  • KeepVid – Download videos direct from most video sites like YouTube.
  • YouTube Downloader – enter url and download YouTube videos.
  • Youtube Grabber – is a free tool that downloads FLV files from youtube.
  • GooTube FLV Retriever – enter the video page URL, download the youtube video.
  • Capture Youtube and Google videos - save them as AVI files encoded in the MPEG4 format, using only one command.
  • YouRipper – a freeware software which enables you to download videos from the YouTube and Google Video
  • Save YouTube Videos – paste the youtube video url and download the video.

Top Youtube Third party tools

  • Splicd – lets you isolate an interesting clip from a YouTube video and provides you with a link to share it with your family, friends, and colleagues.
  • YouTube Userscripts – a collection of scripts to perform several tasks with YouTube.
  • Youtube Video Slideshow – insert a username or a video tag below and it starts a slideshow.
  • fTube – a YouTube player that downloads the list of 25 most recent videos featured on the YouTube front page. The user can select a video from the list and hit the play button to play it in-Flash.
  • TubeCH – YouTube flash player.
  • iTube – grab Youtube videos, then convert and import them into iTunes. Requires .Net framework and works exclusively on Windows.
  • TvTube – For Mac users. Allows you to browse YouTube, Google Video and Yahoo Videos, for movie clips that people upload, choose your favorite clips and add them to your shared library.
  • YouTube API Extraction Tool – PHP script that taps into the YouTube API to deliver videos by tag, by username or what’s a current favorite.
  • YouTube Widget – brings all of YouTubes videos to your Mac Dashboard.
  • Search The Tube – A quick way to find videos for your website, blog or profile.
  • YoutubeCrazyVideos – A Youtube videos desktop player. Freeware.
  • IndexTube – categorized and browsable index of the publicly available Youtube videos.
  • YouTube Podcaster – makes Podcast feed from your submitted keyword or url. The feed is made up from embedded youtube video IDs and all videos are converted to the MP4 file format.
  • MemoriesOnWeb – freeware photo slideshow software for YouTube.
  • Overstream – lets you add subtitles to online videos.

Top / Best YouTube Videos Services

  • PureVideo – collects top 10 videos from around the web
  • The World Internet TV charts – tracks the most popular video clips from four leading Internet TV sites.
  • Top YouTube Videos – a daily updated selection of the most popular videos from YouTube.
  • Vidspedia – is a collection of the best Google and YouTube videos, submitted and rated by users.
  • Youtube top-rated – a coverpop with the 1,001 top rated videos from YouTube updated every week.
  • Best of YouTube – a blog selecting the best Youtube videos.
  • Viral Video Chart – tracks the world’s most blogged about videos including GooTube and MySpace.

Installing CakePHP on Ubuntu

CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. Using commonly known design patterns like MVC and ORM within the convention over configuration paradigm, CakePHP reduces development costs and helps developers write less code.

Installation is actually quite an easy task. But I couldn’t find good information at the beginning. So here I am writing for you. I am using Ubuntu 9.10. This will work for any *nix systems.


Step 1:

In order to work with cakephp you need to have Apache server , MySql Database and PHP. To get them

sudo apt-get install apache2 mysql-server php5


Step 2:

Download the Latest version or the stable version of Cakephp. You can get it from here download
I am using 1.2 version of cakephp


Step 3:

Copy and Extract the compressed file to the webroot(/var/www) and rename to cakephp or some project_name. Open http://localhost/cakephp in your browser. You will see something like this.

cakephp installation step3cakephp installation step3


Step 4:

Enable write permission for app/temp
sudo chmod -R 777 cakephp/app/tmp


Step 5:

Enable mod_rewrite. More about mod_rewrite here.

sudo a2enmod rewrite


Step 6:

Edit the file /etc/apache2/sites-enabled/000-default and change AllowOverride None to AllowOverride All. You can use any text editor. I am using vi editor.

sudo vi /etc/apache2/sites-enabled/000-default

<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>


Step 7:

Changing the value of security.salt in app/config/core.php. At line 151 or near to it you can see something like this
Configure::write(‘Security.salt’, ‘DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi’);

Just change the value of it.I have come up with this value
Configure::write(‘Security.salt’, ‘UubWwvniR2G0FgaC9miDYhG93b0qyJfIxfs2guVo’);


Step 8:

Database Configuration. The database configuration file is located at cakephp/app/config/database.php.default
change the file name to database.php
sudo mv database.php.default database.php

Then edit the following

sudo vi cakephp/app/config/database.php

class DATABASE_CONFIG {

var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'sudeep',
'database' => 'cakephp',
'prefix' => '',
);

You can connect to any database you want. Make sure that username and password of your database are correct.


Step 9:

Restart Apache server to see changes
sudo /etc/init.d/apache2 restart


Step 10:

Open http://localhost/cakephp/ in your browser.If all goes well you should be able to cakephp page in colors, something like this.

cakephp installation step10cakephp installation step10

Expert user Vs Novice user

Expert users (meaning with extended experience in the application) expects advance features and capabilities. They will want more customization options. Since they have a stable mental model of the application structure they feel free to explore the application and try new things. They will not be too worried about making mistakes since they feel secure that they will know how to bypass them.

Novice users, on the other hand, are new to the system and will need a simple and basic interface. Since they are new in the system they will expect more secure ways of doing things in the system (for example they will choose the templates or wizards to do their first steps in the system). Novice users’ interface should provide simple ways to achieve important frequently performed tasks. When designing to novice users we should remember what the main use cases and don’t shadow them with unnecessary features.

Follow

Get every new post delivered to your Inbox.

Join 62 other followers