Category: WordPress

Plugin developer, Core contributor and support volunteer. Yeah, I’m a WordPress fan!

  • Improving WordPress Search Further

    I wrote an article some time ago highlighting ways to implement search improvements to WordPress (and the default search DOES suck). Now, I’d like to update you on where I am, including some further changes that I made last night.

    Current Set-up

    My current set-up is that I’m displaying 3 posts per page. However, in the case of search results, I’m displaying 12 per page, as I display only an excerpt and restricted social sharing and other output. The idea, like the results from a search engine, is to find the post or page that you’re after and click on it for the full version.

    Recommended Plugins

    By default,WordPress only allows one “posts per page” value. To achieve this, you’ll need to read my original post which shows you how to override the search results to show more. I still use the Results Count plugin as well, which displays how many search results were returned.

    In addition, on all post and page types I use the WP Page Numbers plugin to allow users to easily scroll across multiple pages, rather than use the default WordPress “Next” and “Prev” buttons.

    Finally, Search Meter is an excellent plugin for finding out what your visitors are searching for.

    Modifying the Search Results

    Last night I had a brain-wave. After performing a search myself, I had one result. Except it was the usual excerpt and I had to click on it to view the full version. But, if there’s only one, why do this? Indeed, if there’s 3 or less, why not display the full posts, and only collapse to the excerpt version if there’s more than this?

    And that’s what I’ve changed – try it! Look for “wordpress“, for instance, and you’ll find pages of potential results, all displayed as limited excerpts. Look for “avforum” and one result will be returned and the entire post will be shown. Lovely.

    To do this I simply compare the results of $wp_query->found_posts with get_option('posts_per_page'). I do this outside of “the loop”.  The former will return the total number of posts being returned and the latter will return the number of posts per page that you’ve your WordPress to. In my case, this latter value is 3.

    So, if a search is performed and 1 results is returned out of 3, my theme can make the decision to output the full version of the post instead of the smaller version. I can also make the decision at this point whether to override the number per page to 12 or not (if I’m display the excertp versions).

    I hope this makes sense – please comment if you need any further clarity on this.

  • The WordPress Loop

    I often get asked about “the loop” in WordPress, as many of my plugins require knowledge of it for successful integration.

    “The loop” is simply some WordPress code that handles the fetching of post or pages. Each WordPress theme has a number of files that handle different types of output – for instance, index.php is used for displaying a number of posts, page.php displays pages and single.php shows a single post. Each of these contains the code for the loop.

    The first line is usually this…

    <?php while (have_posts()) : the_post(); ?>

    And the last line is usually…

    <?php endwhile; ?>

    Everything in between is the setting up and displaying of the post/page in question.

    So, let’s use Simple Social Bookmarks as an example. You will probably want to put the function call for this just before that last line of the loop – that will it will be the last thing displayed after each post or page. However, you may want other content to appear first, in which case you will choose a different location between the above 2 lines to put it.

    What I can’t tell you is exactly where you need to put the code – that’s entirely down to you and how you wish the output. Indeed, there’s no reason why, in the case of Simple Social Bookmarks, you have to put it in the loop – you could have one at the top of each page. Bear in mind, however, that if you put code outside of the loop then it may not be able to get certain information – in out example, you’d have to supply a URL, as normally this is supplied by the loop to indicate the current post/page.

    I hope this makes sense. If not, you can read more about it at WordPress.org.

  • Damn you WordPress – 3.0 launches!

    WordPress 3.0 has been launched. And it’s late. And I’m busy all of tomorrow. And the weekend.

    I’m not going to risk the install now – sods law says it will go hideously wrong.  I could try the install whilst I’m at work but their wireless network is so slow it’s nearly impossible to use.

    Damn you WordPress (shakes fist at sky).

    (More details tomorrow)

  • Adding a Heat Map to WordPress

    ClickHeat Screenshot

    Wanting to learn a bit more about the visitors to this site, I thought installing a heat map on the site would be a good start.

    I initially used PicNet Mouse Eye Tracking – this is free, but an advert for the service appears at the foot of your site. However, I soon came across the OpenSource ClickHeat. You can use this on any kind of site and is a PHP-based installation.

    After much gnashing of teeth, here’s how I got it installed…

    • Download the latest version of ClickHeat and unzip it
    • Install this into a folder on your server
    • Now, from the address bar of your browser, open up the folder. e.g. If you installed it to www.mysite.com/clickheat, you’d go to this directory in your address bar.
    • This will start the installer. I found errors straight away – make sure the config, log and cache folders are writeable.
    • Done. You simply need to add the code to start tracking – return to the ClickHeat folder to access your heat map and make settings changes.

    To test it’s working, simply append ?debugclickheat to the end of any of your sites URLs.

    I added the JavaScript (which is generated from the ClickHeat admin screen) directly to my footer.php file in the theme folder, wrapping it in a check to ensure that an admin isn’t signed in (so it doesn’t track my clicking!).

    One more problem I cam across – in the ClickHeat admin screens I kept getting the following error…

    Warning: ob_start() [ref.outcontrol]: output handler 'ob_gzhandler' cannot be used twice in /xxx/clickheat/index.php  on line 51

    Obviously, I’ve replaced the directory path with “xxx” for security reasons.

    After some searching around, I decided the best solution was to make a modification to the ClickHeat code itself. Open up the index.php file within the ClickHeat folder and attempt to find the line that starts with the following…

    if (@ini_get('zlib.output_compression')

    Before this line, add the following…

    ob_end_clean();

    And that’s worked for me.

    I’ll report back on how I get on with ClickHeat.

  • WordPress – Making Post/Page Content Expire

    WordPress – Making Post/Page Content Expire

    There are some excellent plugins available to allow you to make time sensitive posts and pages expire. However, these work for the entire post/page rather than just a section.

    Here’s the simple solution – a shortcode that you wrap around some content and allows you to specify a date on which it should expiry and simply not display anymore.

    (more…)