Recent Topics

1 Dec 27, 2004 16:03    

List all posts in the category of the post currently displayed. Only works on single-post pages. In _main.php add this to the posts loop:

if( $disp == 'single' ) {
$post_id_is = $Item->get('ID');
$main_cat_is = $Item->get('main_cat_ID');
}


Next add this to the sidebar:

<?php if( $disp == 'single' ) { ?>
<div class="bSideItem">
<h3>In this category</h3>
<ul>
<?php require( dirname(__FILE__).'/_inthiscategory.php' ); // POSTS IN THIS CATEGORY INCLUDED HERE ?>
</div>
<?php } ?>


Finally add this as _inthiscategory.php to your skins/skinname folder:

    <?php
    /* This lists posts in a specific category.  It is supposed to be a sidebar
     * item for single-post pages because it lists other posts according to the
     * current post's category.  Pretty snazzy eh?
     *
     * Another outstanding hack by EdB @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.' );

    if( $disp != 'single' ) {
    return true;
    }
     
    # You can customize the following as you wish:
    # maximum number of inthiscat entries to display:
    $inthiscat_limit = 24;
    # show inthiscat word count? true/false
    $inthiscat_word_count = false;
    # show inthiscat post author? true/false
    $inthiscat_author = false;
    # inthiscat global delimiters:
    $inthiscat_main_start = '';
    $inthiscat_main_end = '';
    # inthiscat item delimiters:
    $inthiscat_item_before = '<li>';
    $inthiscat_item_after = "</li>\n";
    # inthiscat item currently displayed additional markup:
    $inthiscat_item_current_before = '<em>';
    $inthiscat_item_current_after = '</em>';
     
    // --- the crux of the biscuit is the apostrophe --- //
     
    $sql = "SELECT ID, post_title, post_wordcount FROM $tableposts JOIN $tablepostcats ON ( post_category = postcat_cat_ID ) WHERE ID = postcat_post_ID AND post_status = 'published' AND postcat_cat_ID = $main_cat_is ORDER BY ID DESC LIMIT $inthiscat_limit";
    $results = $DB->get_results($sql);
     
    echo $inthiscat_main_start;
    if ($results) {
    foreach ($results as $result) {
    $lid = $result->ID;
    $word_count = $result->post_wordcount;
    $post_title = stripslashes($result->post_title);
    $title = htmlspecialchars(stripslashes($result->post_title));
    $NewItem = Item_get_by_ID( $lid );
    $permalink = $NewItem->gen_permalink( '', '', false, '&' );
    echo $inthiscat_item_before;
    if( $lid == $post_id_is ) {
    echo $inthiscat_item_current_before.$title.$inthiscat_item_current_after;
    } else {
    echo '<a href="'.$permalink.'" title="link to '.$post_title.' post">'.$title.'</a>';
    }
    if( $inthiscat_word_count || $inthiscat_author ) {
    $closing_bit = ' <span class="dimmed">(';
    if( $inthiscat_word_count ) {
    $closing_bit = $closing_bit.$word_count.' words';
    }
    if( $inthiscat_word_count && $inthiscat_author ) {
    $closing_bit = $closing_bit.' ';
    }
    if( $inthiscat_author ) {
    $auth_pref_name = $NewItem->Author->get('preferedname');
    $closing_bit = $closing_bit.'by '.$auth_pref_name;
    }
    $closing_bit = $closing_bit.')</span>';
    echo $closing_bit;
    }
    echo $inthiscat_item_after;
    }
    } else {
    echo $inthiscat_item_before;
    echo 'How can this be?  There\'s nothing to display!';
    echo $inthiscat_item_after;
    }
    echo $inthiscat_main_end;
     
    ?>


A little bit more info is available at http://wonderwinds.com/weblog.php/2004/12/25/list_posts

2 Jan 05, 2005 22:29

I just discovered that the version of this I am currently using will hit the 30 second php limit when you preview a post. I do not know if the version here does the same thing, but if it does there is a very easy fix for it. The bit that goes in your _main.php needs another if statement. Like so:

<?php if( $disp == 'single' ) {
if( ! $preview ) { ?>
<div class="bSideItem">
<h3>In this category</h3>
<ul>
<?php require( dirname(__FILE__).'/_inthiscategory.php' ); // POSTS IN THIS CATEGORY INCLUDED HERE ?>
</ul>
</div>
<?php }
} ?>

In plain english: if you're on a single post and you're not on a preview then do it up, otherwise bag it.


Form is loading...