- b2evolution CMS Support Forums
- Archives
- Obsolete Forum Threads
- [Skin-Hack] WordyPost
1 edb Dec 16, 2004 17:41
WordyPost links posts that have the most words. Why? Because I can. In your skins/skinname/_main.php add
<?php require( dirname(__FILE__).'/_wordypost.php' ); // POSTS BY WORDCOUNT INCLUDED HERE ?>
Wrap it in a div if your skin does it that way.
In your skins/skinname folder add _wordypost.php and customize it as you see fit.
<?php
/* This lists posts according to word count.
*
* You are not supposed to call this file directly. You are supposed to call
* it "wordypost", and access it with a require() in your skin's _main.php.
*
* This is the second most useless file ever created.
* This piece of junk was written by EdB @ http://wonderwinds.com
*
* The most useless file ever created was the zip file for wordpress :)
*
* (I always put this part in because it looks mighty fancy)
* 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 wordypost entries to display:
if(!isset($wordypost_limit)) $wordypost_limit = 6;
# find wordyposts in all blogs (true) or only this blog (false)?
if(!isset($wordypost_all_blogs)) $wordypost_all_blogs = true;
# show wordyposts word count? true/false
if(!isset($wordypost_word_count)) $wordypost_word_count = true;
# show wordyposts post author? true/false
if(!isset($wordypost_author)) $wordypost_author = true;
# wordypost global delimiters:
if(!isset($wordypost_main_start)) $wordypost_main_start = '<h3 class="center">WordyPost Rules!</h3><ul>';
if(!isset($wordypost_main_end)) $wordypost_main_end = '</ul>';
# wordypost item delimiters:
if(!isset($wordypost_item_before)) $wordypost_item_before = '<li>';
if(!isset($wordypost_item_after)) $wordypost_item_after = "</li>\n";
// --- bust in half here if you want to do the multiskin thing --- //
if( $wordypost_all_blogs ) {
$sql = "SELECT ID, post_title, post_wordcount, post_author FROM $tableposts WHERE post_status = 'published' ORDER BY post_wordcount DESC LIMIT $wordypost_limit";
$results = $DB->get_results($sql);
} else {
$sql = "SELECT ID, post_title, post_wordcount, post_author FROM $tableposts grk JOIN $tablecategories qug ON ( grk.post_category = qug.cat_ID ) WHERE qug.cat_blog_id = $blog AND grk.post_status = 'published' ORDER BY post_wordcount DESC LIMIT $wordypost_limit";
$results = $DB->get_results($sql);
}
echo $wordypost_main_start;
if ($results) {
foreach ($results as $result) {
$lid = $result->ID;
$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 $wordypost_item_before;
echo '<a href="'.$permalink.'" title="link to '.$post_title.' post">'.$title.'</a>';
if( $wordypost_word_count || $wordypost_author ) {
$closing_bit = ' <span class="dimmed">(';
if( $wordypost_word_count ) {
$closing_bit = $closing_bit.$count.' words';
}
if( $wordypost_word_count && $wordypost_author ) {
$closing_bit = $closing_bit.' ';
}
if( $wordypost_author ) {
$author = $result->post_author;
$query = "SELECT user_nickname FROM $tableusers WHERE ID = $author";
$author_nickname = $DB->get_var($query);
$closing_bit = $closing_bit.'by '.$author_nickname;
}
$closing_bit = $closing_bit.')</span>';
echo $closing_bit;
}
echo $wordypost_item_after;
}
} else {
echo $wordypost_item_before;
echo 'Nothing to display...';
echo $wordypost_item_after;
}
echo $wordypost_main_end;
?>
Breaking it in half is easy - just follow the method of almost every sidebar content generator, or go to [url=http://wonderwinds.com/weblog.php/2004/12/15/wordypost_a_cute_little_b2evolution_thin]my blog post[/url] and check out the steps towards the bottom. Credits to whoo and mattbta for working up the 'related to' thing that has been inadvertently vaporized. Believe it or not this was that. Sort of.
3 edb Dec 17, 2004 00:31
I have a modified and untested version of the related to thing. I wanted to make it be one file for all blogs or this blog, so I did, but I never implemented or tested it. All I did was mix the two versions together and use another param to decide how to make the query. If you don't have a working copy I'll post the one I have.
Coolness. I'll try and post that function post-vaporization. Using that framework, you demonstrate you can run almost any sort of query against the db to get anything we want. After you dream up what you want to spit out, you've just got to iron out the SQL statements.
I'm going to have to give this one a whirl when I get home from work, but looking at the code, it looks good to me! Kudos, EdB!