Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
This plugin creates a box with a number of links to other posts on the same blog. The look and feel is configurable via CSS. By default it displays 4 random posts, but that can be changed via code. I created this plugin to expose readers to more content and also to create more internal linking.

This is what it looks like when rendered on my blog (using some additional CSS styling):
moreposts_plugin.png


This is the minimal CSS styling that can be used. The plugin renders an outer DIV with each of the links rendered within its own DIV. This CSS can be added to the existing theme CSS, the plugin does not define where the CSS is to be added.
 Theme CSS style additions
.moreonblog_outer {padding-bottom:6px;}
.moreonblog_inner {padding:6px;padding-bottom:0;}




Below is the code for the plugin. It's written to display only on single posts, meaning it will not display anything when looking at the blog's main page where a list of blog entries is shown. The plugin is registered as a widget with the name 'moreonblog'.
 fp-plugins/moreonblog/plugin.moreonblog.php
<?php
/*
Plugin Name: MoreOnBlog
Plugin URI: http://www.igorkromin.net/
Type: Block
Description: Displays links to the other random posts on the blog.
Author: Igor Kromin
Version: 1.0
Author URI: http://www.igorkromin.net/
*/
function plugin_moreonblog_widget() {
global $fpdb, $fp_config;
$q =& $fpdb->getQuery();
if (($q && $q->single) || isset($fp_params['entry'])) {
$content = zzzzzx();
}
$widget = array();
$widget['subject'] = 'Other posts on '.$fp_config['general']['title'];
$widget['content'] = $content;
return $widget;
}
function zzzzzx() {
$q = new FPDB_Query(array('start'=>0, 'count'=>-1, 'fullparse'=>true), null);
$entry = array();
while($q->hasMore()) {
list($id, $e) = $q->getEntry();
$subj = $e["subject"];
$loc = get_permalink($id);
array_push($entry, array($subj, $loc));
}
$idx = (range(0, sizeof($entry)-1));
shuffle($idx);
$content = '<div class="moreonblog_outer">';
for($i = 0; $i < 4; $i++) {
$v = $idx[$i];
$content = $content .'<div class="moreonblog_inner"><a href="'.$entry[$v][1].'">'.$entry[$v][0].'</a></div>';
}
$content = $content . '</div>';
return $content;
}
register_widget('moreonblog', 'MoreOnBlog', 'plugin_moreonblog_widget');
?>


This code needs to be placed in the fp-plugins/moreonblog directory (which needs to be created first). The plugin then needs to be enabled via the admin Plugins page.

Note: there is a known issue with this plugin not working if there are less than 4 posts on a blog. I know this is a limitation and the fix is easy, but I'll leave that to the reader to figure out.

-i

Skip down to comments...
Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
 
comments powered by Disqus
Other posts you may like...