Recent Topics

1 Jan 28, 2005 18:25    

Way back in the day there was Isaac's version http://forums.b2evolution.net/viewtopic.php?t=1422 It's wicked-smart but it's got a bug or two in it that never got cleaned up. Recently gacjezv came up with a really quick method at http://forums.b2evolution.net/viewtopic.php?p=14025#14025 that is probably tweakable but I don't know in what ways. Recently I decided I wanted to make up something better than Isaac's version, so I came up with a third method.

First add a chunk to your _main.php file:

<div class="bSideItem">
<h3>Recent Posts</h3>
<ul>
<?php require( dirname(__FILE__).'/_recentposts.php' ); // RECENT POSTS INCLUDED HERE ?>
</ul>
</div>

Set it up as need be for your skin.

Next drop this file in your skins/skinname folder as _recentposts.php:

<?php 
/* Another drab little snoogle from EdB - {@link http://wonderwinds.com}
 * 
 * b2evolution - {@link http://b2evolution.net/}
 * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
 * @copyright (c)2003-2004 by Francois PLANQUE - {@link http://fplanque.net/}
 *
 * @package evoskins
 * @subpackage your_skin_name
 */
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );

# You can customize the following as you wish:
# maximum number of recentpost entries to display:
$recpo_limit = 12;
# recentpost global delimiters:
$recpo_main_start = '';
$recpo_main_end = '';
# recentpost item delimiters:
$recpo_item_before = '<li>';
$recpo_item_after = "</li>\n";
# the following are true/false conditions
# show posts from all blogs?
$recpo_allblogs = true;
# show and link post author?
$recpo_author = false;
$recpo_author_link = true;
# show and link post category?
$recpo_category = false;
$recpo_category_link = true;
# show and link number of comments?
$recpo_comments = false;
$recpo_comments_link = true;
# this matters if author or category or comments is true
# recentcomment show number class:
$recpo_before_class = '<em>';
$recpo_class = 'dimmed';
$recpo_after_class = '</em>';

// --- you must be 21 to enter (ID required) --- //

$posts_shown = 0;
if( $recpo_allblogs ) {
	$sql = "SELECT ID, post_title, cat_ID, cat_name, cat_blog_ID FROM $tableposts JOIN $tablecategories ON ( post_category = cat_ID) WHERE post_status = 'published' ORDER BY post_issue_date DESC";
	} else {
	$sql = "SELECT ID, post_title, cat_ID, cat_name, cat_blog_ID FROM $tableposts JOIN $tablecategories ON ( post_category = cat_ID) WHERE post_status = 'published' AND cat_blog_ID = $blog ORDER BY post_issue_date DESC";
	}
$results = $DB->get_results($sql);
echo $recpo_main_start;
if ($results) {
	foreach ($results as $result) {
		$posts_shown = ($posts_shown+1);
		if( $posts_shown > $recpo_limit ) {
			break;
			}
		$post_title = stripslashes($result->post_title);
		$title = htmlspecialchars(stripslashes($result->post_title));
		$this_post = $result->ID;
		$NewItem = Item_get_by_ID( $this_post );
		$permalink = $NewItem->gen_permalink( '', '', false, '&' );
		if( $recpo_author || $recpo_category ) {
			$this_blog = $result->cat_blog_ID;
			$NewBlog = Blog_get_by_ID( $this_blog );
			}
		echo $recpo_item_before;
		echo '<a href="'.$permalink.'" title="link to '.$post_title.' post">'.$title.'</a>';
		$closing_bit = '';
		$count_comments = 0;
		if( $recpo_comments ) {
			$query = "SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $this_post";
			$count_comments = $DB->get_var($query);
			$comment_link = $permalink.'#comments';
			}
		if( $recpo_author || $recpo_category || ($count_comments > 0) ) {
			$closing_bit = ' <span class="'.$recpo_misc_class.'">(';
			}
		if( $recpo_author ) {
			$auth_id = $NewItem->Author->get('ID');
			$auth_name = $NewItem->Author->get('preferedname');
			if( $recpo_author_link ) {
				$auth_link = '<a href="'.$NewBlog->get( 'blogurl', 'raw' ).'?author='.$auth_id.'" title="Browse all posts by this author">'.$auth_name.'</a>';
				$closing_bit .= 'by '.$auth_link;
				} else {
				$closing_bit .= 'by '.$auth_name;
				}
			if( $recpo_category || $count_comments ) {
				$closing_bit .= ', ';
				}
			}
		if( $recpo_category ) {
			$cat_id = $result->cat_ID;
			$cat_name = $result->cat_name;
			if( $recpo_category_link ) {
				$cat_link = '<a href="'.$NewBlog->get( 'blogurl', 'raw' ).'?cat='.$cat_id.'" title="Browse all posts in this category">'.$cat_name.'</a>';
				$closing_bit .= 'in '.$cat_link;
				} else {
				$closing_bit .= 'in '.$cat_name;
				}
			if( $count_comments ) {
				$closing_bit .= ', ';
				}
			}
		if( $count_comments ) {
			if( $recpo_comments_link ) {
				$closing_bit .= '<a href="'.$comment_link.'" title="link to last comment on '.$post_title.' post">';
				$closing_bit .= $count_comments.' comments</a>';
				} else {
				$closing_bit .= $count_comments.' comments';
				}
			}
		if( $closing_bit ) {
			$closing_bit .= ')</span>';
			}
		echo $recpo_before_class.$closing_bit.$recpo_after_class;
		echo $recpo_item_after;
		}
	}
echo $recpo_main_end;

?>


As you can see by reading the stuff in the top half, you get to pick some stuff to display with the recent posts title. If you want some detail on how those little bits work [url=http://wonderwinds.com/hackblog.php/2005/01/28/recent_posts_hack_for_b2evo]read my blog post[/url] and be happy.

2 Jan 31, 2005 13:36

works great - thanks :D

3 Aug 30, 2006 22:31

This doesn't seem to work with 1.8.1 - I get a message about an unknown column "ID"

Is there a similar plugin or hack that works with the new b2evo? I found this sort of function was quite important.

4 Aug 30, 2006 22:52

I just clicked 'watch this topic for replies' which is how I tell myself I want to come back and do something here. I'm super-busy with a real-world event and overhauling a very dynamic web, but I do want to come back to this for 1.8.1. Maybe someone will beat me to it? If not I'll do what I can to kick it out again.


Form is loading...