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

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


A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.