A neat way to spice up your WordPress search page is to highlight search terms within your search results. I’ve seen some tutorials on the net on how to do this, but I haven’t found one that highlights both title and post content and is a drop-in modification for WordPress. Today I will bring you this drop-in hack for highlighting search terms on your WordPress blog. Installation 1. Copy and paste the following code into your theme’s functions.php file: function hls_set_query() { $query = attribute_escape(get_search_query()); if(strlen($query) > 0){ echo ‘ <script type=”text/javascript”> var hls_query = “‘.$query.'”; </script> ‘; } } function hls_init_jquery() { wp_enqueue_script(‘jquery’); } add_action(‘init’, ‘hls_init_jquery’); add_action(‘wp_print_scripts’, ‘hls_set_query’); If you are having issues with copy-paste from this blog, here is a link to the same code in a txt file: Code to insert into functions.php 2. Copy and paste the following code into your theme’s header.php file (just before […]
[Continue Reading...]Let me start off by saying that this post will not talk about how to get sponsors, how to determine prizes, or how to determine rules for a blog contest. This post will talk about how to tweak your WordPress blog to solve the biggest problem in running a blog contest to gain RSS subscribers. Problem The issue here is that there is no easy way to track if each contestant has actually subscribed to your RSS feed. Without the ability to confirm RSS subscription, anybody can just claim that they have subscribed to your feed and get a free entry into the contest. Solution A known solution to this problem is to include a special contest code into your RSS feed and not have this code visible on your website. That way each contestant will be forced to grab the code from your feed and submit the code via […]
[Continue Reading...]Reader John writes in: How does one use paging with an offset? Doing so breaks the navigation controls. The problem with using an offset in a query is that WordPress ignores any reference to paging. In other words, you can use an offset and paging, but not both together. This can be solved by tapping into the post_limits filter. Step 1: Add the ‘my_post_limit’ Function The my_post_limit function is what the post_limits filter will use to update the standard loop query. We’ll use the function to use paging and offsets together. This function should be placed in your theme’s functions.php file. function my_post_limit($limit) { global $paged, $myOffset; if (empty($paged)) { $paged = 1; } $postperpage = intval(get_option('posts_per_page')); $pgstrt = ((intval($paged) -1) * $postperpage) + $myOffset . ', '; $limit = 'LIMIT '.$pgstrt.$postperpage; return $limit; } //end function my_post_limit Step 2: Add the Filter Reference <?php add_filter('post_limits', 'my_post_limit'); ?> <div id="recent"> […]
[Continue Reading...]There are many plugins which are useful when it comes to displaying ads to your visitors but there are only a few of them which allow you to determine to whom and when you should. Who Sees Ads does help you to determine to whom and when you should display advertisements, though, there is a limitation with the plugin as it does not allow you to control the ads shown on single post level. In this post we will talk about the quick and easy way to hide advertisements for any particular post by making some minor changes to your theme. The Condition To Skip Advertisements For Single Posts Talking about conditions whatever you do there is always a condition under which you perform any action. We will use a similar logic and create conditions under which the advertisements should not be displayed for certain posts. The condition we will […]
[Continue Reading...]A reader writes in: I’m developing a new theme and I’m having trouble getting duplicate posts from showing when running two loops (one standard loop and one from a specific category). Even when I copied the specific code from directly from the codex, it was not working. The Codex article the reader mentioned was regarding the Loop. Although the example shows how to avoid a single duplicate post, it doesn’t show how to avoid duplicating multiple posts. Here’s how to show two individual loops without duplicating posts in either loop. Step 1: Add a ‘posts_where’ Function A WordPress filter is needed to accomplish this, and we’re going to be tapping into the ‘posts_where‘ filter. The reason being is we need to modify the query used for the loop and exclude some posts. Here’s the function we’ll be using called post_strip: function post_strip($where) { global $myPosts, $wpdb; $where .= " AND […]
[Continue Reading...]For the past few weeks I’ve been working on a WordPress plugin. One of my goals was to have fancy and relevant error messages. I contemplated writing my own error manager, and even began a very basic one. I experienced hurdle after hurdle, and finally I thought to myself, “Wouldn’t WordPress have its own error manager also?” So I did a quick source-code search and came across the WP_Error class. One of the hurdles I ran into in creating my own error manager was error localization. The WP_Error class makes localizing error messages extremely simple. Adding Error Messages To add an error message, the first thing you’ll want to do is instantiate your own instance of WP_Error. $myErrors = new WP_Error(); The next step is to add in your error messages. $myErrors->add('access_denied', __('You do not have permission to do that.',$myLocalizationName)); There are a few things to notice here. There is […]
[Continue Reading...]Obviously Powered by WordPress. © 2003-2013
9 Ways to Make Your WordPress Blog “Smart”
Many of you might be confused by the title and the term “smart”. To me a “smart” blog is a blog that behaves differently depending on its visitors’ behavior and characteristics. A simple example of this is a blog that displays a list of today’s most popular posts on the sidebar. The list changes based on visitors’ behavior so to this is definitely a smart blog feature. There are plenty of WordPress plugins out there that do this for you automatically (e.g. Top 10), but that is not the point. The point here is that having the ability to morph your blog per visitor activity can assist you in meeting your conversion goals (whatever they may be). A list of popular posts is quite a simple feature, so let me take you to another level by showing you more ways to make your blog smart. List of “Smart” Features to […]
[Continue Reading...]