Most Recent Posts

Here’s a new plugin for you all here to play with!
{lastposts} return the most recent posts on your blog!
It has one parameter, posts, which is an integer between 1 and 20 to return that number of posts.

{lastposts posts='20'}
{if $lastposts != ''}
<br /><b>Most Recent Posts</b><br />
{foreach from=$lastposts key=key item=title}
<nobr><a href="{$siteurl}/archives/p/{$key}/c/1/more/1" title='{$title}'>{$title|truncate:50:"..."}</a></nobr><br />

Smarty and WP, again

Last week I revived my interest in integrating WordPress and Smarty again. I tested the latest release and I’m very impressed by the wealth of options and configurability! I want to use it myself!
To that end I need to get Smarty in there. I wrote a script that fetches a list of functions from the files in wp-includes and outputs a list of Smarty instructions to mirror the current WordPress Template Tags. That’ll make it easy to mirror the tags as they develop.

Kae Verens is doing sterling work finding out what’s working or not!

I think I’m at the stage where Smarty templates are working reasonably ok, but if caching is enabled it falls down because updates to the site need to inform Smarty. That’s relatively easy to do of course!
Next on the list is multi-blog support and that’ll be tricky. It’ll probably be some combination of the Permalink structures already in WP, and prepending the site ID to the URL somewhere. I’m looking at template-functions-links.php – Maybe in the get_settings( 'home' ) bit I can add the wpblog variable. *ponder*
Later… I want to get support for multi-blogs into my hack too before I release anything. Here’s a related post about that. I should have something for people to try next week!

Major Caching Update

I finally got around to profiling this site and came up with some astounding conclusions – it takes almost a second to fetch each post on this blog!
Therefore I’ve started to catch blog posts seperately from the main index page. In simple testing I’ve already noticed a significant speed-up but if you notice anything strange please leave a comment here or email me at the usual address!

b2++ Updates

Regular visitors to this site will have noticed that this blog and others on the server take an inordinate amount of time to display sometimes. Basically, this machine is unfortunately under-powered but we’re working on making the best of use of the available hardware with some changes to MySQL and Apache and to b2++ too. Here’s what I did this morning:

  • Referers are checked and only if requests go to either “/”, “index.php” or “archive/” are they recorded.
  • Referers are now recorded using INSERT DELAYED.
  • I added keys on the post_date and post_category fields in *posts tables. The main SELECT is now a “range” instead of “all” request.

Here’s a short bash script you can use to update your db. Remember to change “username” and “password” to suit your own setup.

for i in `echo show tables | mysql -u username -ppassword b2|grep posts`; do echo "ALTER TABLE \`$i\` ADD INDEX ( \`post_category\` )"| mysql -u username -ppassword b2; echo "ALTER TABLE \`$i\` ADD INDEX ( \`post_date\` )"| mysql -u username -ppassword b2; done

Useful links: Mysql Optimization | Optimizing MySQL: Hardware and the Mysqld Variables (mentioned previously) | MySQL Optimisation and a few other pages.

Most Popular Posts

I’ve just added a new plugin to the site that lists the most popular posts on your blog.
The command is {popularposts} which creates an array, $pposts, containing the list of posts. Unfortunately it’ll only work if you use the newer $blogid/archives/p/1/ type url, not the old $blogid/archives/m/200407/#1
Thank you Nargler for the MySQL substring_index code. Helped a lot!

Here’s an example usage:

{if $pposts != ''}
  <b>Most Popular Posts</b><br />
  {foreach from=$pposts key=key item=hits}
    <nobr><a href="{$siteurl}/archives/p/{$hits.postID}/c/1/more/1" title='{$hits.title}'>{$hits.title|truncate:30:"..."}</a>: {$key}</nobr><br />

Referer Checking Now Ignoring Bots!

I’ve added code to the referer checking to check for a few common bots:

  • “”
  • “”
  • “”
  • “”
  • “Feedster, LLC.”
  • “”
  • “”
  • “”
  • “”
  • “”
  • “Ask Jeeves/Teoma”
  • “ia_archiver”
  • “”

There are others but these showed up in the access logs of the last few minutes!
Sorry guys, your referer lists will be a lot shorter now!

B2++ 0.8.1 out!

Although it’s a minor update, the latest release of b2++ should be installed by everyone running b2++. I have provided a very simple upgrade package as well with only the changed files so you’ve no excuse not to upgrade!
Check the download page for links!

  • Referer display of Google and Yahoo queries nicer.
  • Cosmetic changes to backend pages.
  • Added Photoblog plugin.

b2++ Post Titles in URLs

Here’s another minor b2++ update. I added the blog post titles to permalinks, The title isn’t used to find the actual post, it’s simply there for search engines to find and index.
It should help somewhat in your rankings if you select your post titles carefully!

b2++ Photoblog

What with the proliferation of photoblogs around the Internet I thought we should get in on the act!

  • Displays one image, with optional surrounding html code.
  • If no image is available selects a previous image at random.
  • Only certain images will be used. No surprises!

What to do:

  • Add this code to your blog template: {photoblog}
  • There are optional parameters too:
    start: Starting html code.
    msg: Title of the picture.
    randmsg: Title of a random photo
    end: Ending html code.
    class: css class inserted into the img tag.

    ie. {photoblog start="<div align='center'>" msg="<b>Pic of the Day</b>" end="</div>" class="pictureborder"}
    To always display a random photo just pass when='random' to the plugin.
  • Upload images to your blog with the filenames photoblog-YYYYMMDD.jpg

Paginated Posts in b2++

Minor b2++ update here but it’s a good one for those of you with lots of content. b2 always had a “Previous Page/Next Page” function but I never enabled it in b2++. This morning I fixed that so to activate it do the following:

  • Go into the Options page and change “Show XX days/posts” to “Show XX posts paged” where XX is some number.
  • Add the following code to your blog template: {$posts_nav_link}. I’ve put mine instead a blockquote tag but you can do what you like to style the links.

Next up is a Smarty function that takes as parameters a b2 function name and parameters to make it easy to call original b2 functions.