This is a compilation of http://forums.b2evolution.net/viewtopic.php?t=10004 and is reposted here for convenience. Thanks to [url=http://forums.b2evolution.net/profile.php?mode=viewprofile&u=4712]xangelusx[/url] for making the hack and [url=http://forums.b2evolution.net/profile.php?mode=viewprofile&u=6738]Boblebad[/url] for making custom sort work with 1.9.2.
First, the alphabetical bloglist sorter. This file works in 1.9.1 and 1.9.2 and might work in the 1.8.* generation, but there's no promise of that. Rename your current skins/yourskin/_bloglist.php file to something like skins/yourskin/_bloglist_ORIGINAL.php just in case this doesn't work for you, then save this as skins/yourskin/_bloglist.php:
<?php
/**
* This is the template that displays the links to the available blogs
*
* This file is not meant to be called directly.
* It is meant to be called by an include in the _main.php template.
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2006 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package evoskins
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
if( ! $display_blog_list )
{ // We do *not* want the blog list to be displayed
return;
}
# this is what will start and end your blog links
if(!isset($blog_list_start)) $blog_list_start = '<ul>';
if(!isset($blog_list_end)) $blog_list_end = '</ul>';
# This is what will separate items in the list
if(!isset($blog_list_separator)) $blog_list_separator = '';
# this is what will separate your blog links
if(!isset($blog_item_start)) $blog_item_start = '<li>';
if(!isset($blog_item_end)) $blog_item_end = '</li>';
# This is the class of for the selected blog link:
if(!isset($blog_selected_link_class)) $blog_selected_link_class = '';
# This is the class of for the other blog links:
if(!isset($blog_other_link_class)) $blog_other_link_class = '';
# This is additionnal markup before and after the selected blog name
if(!isset($blog_selected_name_before)) $blog_selected_name_before = '[';
if(!isset($blog_selected_name_after)) $blog_selected_name_after = ']';
# This is additionnal markup before and after the other blog names
if(!isset($blog_other_name_before)) $blog_other_name_before = '';
if(!isset($blog_other_name_after)) $blog_other_name_after = '';
# This is the blogparam that will be displayed as the name:
if(!isset($blog_name_param)) $blog_name_param = 'shortname';
# This is the blogparam that will be displayed as the link title:
if(!isset($blog_title_param)) $blog_title_param = 'name';
/**
* Custom Sorting Hack :: START
* Create an array to collect all of the blogs in. We can then easily
* sort/order and join them below.
*/
$blog_links = array();
for( $curr_blog_ID = blog_list_start();
$curr_blog_ID != false;
$curr_blog_ID = blog_list_next() )
{
if( !blog_list_iteminfo( 'in_bloglist', false ) ) { // don't show
continue;
}
$blog_link = $blog_item_start;
if( $curr_blog_ID == $blog ) { // This is the blog being displayed on this page:
$blog_link .= '<a href="';
$blog_link .= blog_list_iteminfo('blogurl', false);
$blog_link .= '" class="'.$blog_selected_link_class.'" title="';
$blog_link .= format_to_output( blog_list_iteminfo($blog_title_param, false), 'htmlattr' );
$blog_link .= '"><span>';
$blog_link .= $blog_selected_name_before;
$blog_link .= format_to_output( blog_list_iteminfo($blog_name_param, false ), 'htmlbody' );
$blog_link .= $blog_selected_name_after;
$blog_link .= '</span></a>';
} else { // This is another blog:
$blog_link .= '<a href="';
$blog_link .= blog_list_iteminfo('blogurl', false);
$blog_link .= '" class="'.$blog_other_link_class.'" title="';
$blog_link .= format_to_output( blog_list_iteminfo($blog_title_param, false), 'htmlattr' );
$blog_link .= '"><span>';
$blog_link .= $blog_other_name_before;
$blog_link .= format_to_output( blog_list_iteminfo($blog_name_param, false), 'htmlbody' );
$blog_link .= $blog_other_name_after;
$blog_link .= '</span></a>';
} // End of testing which blog is being displayed
$blog_link .= $blog_item_end;
/**
* Custom Sorting Hack
* Use $blog_name_param as a named key for sorting later on.
*/
$blog_links[blog_list_iteminfo($blog_name_param, false )] = $blog_link;
}
/**
* Custom Sorting Hack
* Order the blogs alphabetically based on the array keys (using $blog_name_param)
*/
ksort($blog_links);
/**
* Custom Sorting Hack :: END
*/
// Output:
echo $blog_list_start;
echo implode( $blog_list_separator, $blog_links );
echo $blog_list_end;
/*
nolog */
?>
Next, the customizable bloglist sorter. This first version works with version 1.9.1, and the next will work with version 1.9.2. In both cases you will need to edit the file to organize your blogs the way you wish. In both cases it has a mechanism that will include any blogs you haven't added to the custom sort list.
Again rename your existing skins/yourskin/_bloglist.php as something like skins/yourskin/_bloglist_ORIGINAL.php just in case this doesn't work for you. Now save the following as skins/yourskin/_bloglist.php:
<?php
/**
* This is the template that displays the links to the available blogs
*
* This file is not meant to be called directly.
* It is meant to be called by an include in the _main.php template.
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package evoskins
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
if( ! $display_blog_list )
{ // We do *not* want the blog list to be displayed
return;
}
# this is what will start and end your blog links
if(!isset($blog_list_start)) $blog_list_start = '<ul>';
if(!isset($blog_list_end)) $blog_list_end = '</ul>';
# This is what will separate items in the list
if(!isset($blog_list_separator)) $blog_list_separator = '';
# this is what will separate your blog links
if(!isset($blog_item_start)) $blog_item_start = '<li>';
if(!isset($blog_item_end)) $blog_item_end = '</li>';
# This is the class of for the selected blog link:
if(!isset($blog_selected_link_class)) $blog_selected_link_class = '';
# This is the class of for the other blog links:
if(!isset($blog_other_link_class)) $blog_other_link_class = '';
# This is additionnal markup before and after the selected blog name
if(!isset($blog_selected_name_before)) $blog_selected_name_before = '<strong>';
if(!isset($blog_selected_name_after)) $blog_selected_name_after = '</strong>';
# This is additionnal markup before and after the other blog names
if(!isset($blog_other_name_before)) $blog_other_name_before = '';
if(!isset($blog_other_name_after)) $blog_other_name_after = '';
# This is the blogparam that will be displayed as the name:
if(!isset($blog_name_param)) $blog_name_param = 'shortname';
# This is the blogparam that will be displayed as the link title:
if(!isset($blog_title_param)) $blog_title_param = 'name';
/**
* Custom Sorting Hack :: START
* Create an array to collect all of the blogs in. We can then easily
* sort/order and join them below.
*/
$blog_links = array();
for( $curr_blog_ID = blog_list_start();
$curr_blog_ID != false;
$curr_blog_ID = blog_list_next() )
{
if( !blog_list_iteminfo( 'in_bloglist', false ) )
{ // don't show
continue;
}
$blog_link = $blog_item_start;
if( $curr_blog_ID == $blog )
{ // This is the blog being displayed on this page:
$blog_link .= '<a href="';
$blog_link .= blog_list_iteminfo('blogurl', false);
$blog_link .= '" class="'.$blog_selected_link_class.'" title="';
$blog_link .= format_to_output( blog_list_iteminfo($blog_title_param, false), 'htmlattr' );
$blog_link .= '"><span>';
$blog_link .= $blog_selected_name_before;
$blog_link .= format_to_output( blog_list_iteminfo($blog_name_param, false ), 'htmlbody' );
$blog_link .= $blog_selected_name_after;
$blog_link .= '</span></a>';
}
else
{ // This is another blog:
$blog_link .= '<a href="';
$blog_link .= blog_list_iteminfo('blogurl', false);
$blog_link .= '" class="'.$blog_other_link_class.'" title="';
$blog_link .= format_to_output( blog_list_iteminfo($blog_title_param, false), 'htmlattr' );
$blog_link .= '"><span>';
$blog_link .= $blog_other_name_before;
$blog_link .= format_to_output( blog_list_iteminfo($blog_name_param, false), 'htmlbody' );
$blog_link .= $blog_other_name_after;
$blog_link .= '</span></a>';
} // End of testing which blog is being displayed
$blog_link .= $blog_item_end;
/**
* Custom Sorting Hack
* Use blog_ID as a numeric key for custom sorting later on.
* We could also use $blog_name_param in place of 'blog_ID' but the ID is a
* safer value as the name of a blog is more likely to change over time.
*/
$blog_links[blog_list_iteminfo('blog_ID', false )] = $blog_link;
}
/**
* Custom Sorting Hack
* Create new array to work with
*/
$sorted_blog_links = array();
/**
* Custom Sorting Hack
* Use the format below to sort your blogs in a custom order using the Blog_ID
*/
if (isset($blog_links['1'])) { $sorted_blog_links[] = $blog_links['1']; unset($blog_links['1']); }
if (isset($blog_links['4'])) { $sorted_blog_links[] = $blog_links['4']; unset($blog_links['4']); }
if (isset($blog_links['2'])) { $sorted_blog_links[] = $blog_links['2']; unset($blog_links['2']); }
if (isset($blog_links['3'])) { $sorted_blog_links[] = $blog_links['3']; unset($blog_links['3']); }
if (isset($blog_links['6'])) { $sorted_blog_links[] = $blog_links['6']; unset($blog_links['6']); }
if (isset($blog_links['5'])) { $sorted_blog_links[] = $blog_links['5']; unset($blog_links['5']); }
/**
* Custom Sorting Hack
* If there are any blogs remaining in $blog_links then add them to the end off the sorted blog list
* This prevents new blogs from going missing if they haven't been added to the above list yet.
*/
if (sizeof($blog_links)) {
$sorted_blog_links = $sorted_blog_links + $blog_links;
}
/**
* Custom Sorting Hack
* Assign sorted blog list to $blog_links and clean up old list
*/
$blog_list = $sorted_blog_links;
unset($sorted_blog_links);
/**
* Custom Sorting Hack :: END
*/
// Output:
echo $blog_list_start;
echo implode( $blog_list_separator, $blog_links );
echo $blog_list_end;
/*
nolog */
?>
Use this if you're running version 1.9.2:
<?php
/**
* This is the template that displays the links to the available blogs
*
* This file is not meant to be called directly.
* It is meant to be called by an include in the _main.php template.
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2006 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package evoskins
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
if( ! $display_blog_list )
{ // We do *not* want the blog list to be displayed
return;
}
# this is what will start and end your blog links
if(!isset($blog_list_start)) $blog_list_start = '<ul>';
if(!isset($blog_list_end)) $blog_list_end = '</ul>';
# This is what will separate items in the list
if(!isset($blog_list_separator)) $blog_list_separator = '';
# this is what will separate your blog links
if(!isset($blog_item_start)) $blog_item_start = '<li>';
if(!isset($blog_item_end)) $blog_item_end = '</li>';
# This is the class of for the selected blog link:
if(!isset($blog_selected_link_class)) $blog_selected_link_class = '';
# This is the class of for the other blog links:
if(!isset($blog_other_link_class)) $blog_other_link_class = '';
# This is additionnal markup before and after the selected blog name
if(!isset($blog_selected_name_before)) $blog_selected_name_before = '[';
if(!isset($blog_selected_name_after)) $blog_selected_name_after = ']';
# This is additionnal markup before and after the other blog names
if(!isset($blog_other_name_before)) $blog_other_name_before = '';
if(!isset($blog_other_name_after)) $blog_other_name_after = '';
# This is the blogparam that will be displayed as the name:
if(!isset($blog_name_param)) $blog_name_param = 'shortname';
# This is the blogparam that will be displayed as the link title:
if(!isset($blog_title_param)) $blog_title_param = 'name';
$blog_links = array(); // we collect all links first, to easily implode them
for( $curr_blog_ID = blog_list_start();
$curr_blog_ID != false;
$curr_blog_ID = blog_list_next() )
{
if( !blog_list_iteminfo( 'in_bloglist', false ) ) { // don't show
continue;
}
$blog_link = $blog_item_start;
if( $curr_blog_ID == $blog ) { // This is the blog being displayed on this page:
$blog_link .= '<a href="';
$blog_link .= blog_list_iteminfo('blogurl', false);
$blog_link .= '" class="'.$blog_selected_link_class.'" title="';
$blog_link .= format_to_output( blog_list_iteminfo($blog_title_param, false), 'htmlattr' );
$blog_link .= '">';
$blog_link .= $blog_selected_name_before;
$blog_link .= format_to_output( blog_list_iteminfo($blog_name_param, false ), 'htmlbody' );
$blog_link .= $blog_selected_name_after;
$blog_link .= '</a>';
} else { // This is another blog:
$blog_link .= '<a href="';
$blog_link .= blog_list_iteminfo('blogurl', false);
$blog_link .= '" class="'.$blog_other_link_class.'" title="';
$blog_link .= format_to_output( blog_list_iteminfo($blog_title_param, false), 'htmlattr' );
$blog_link .= '">';
$blog_link .= $blog_other_name_before;
$blog_link .= format_to_output( blog_list_iteminfo($blog_name_param, false), 'htmlbody' );
$blog_link .= $blog_other_name_after;
$blog_link .= '</a>';
} // End of testing which blog is being displayed
$blog_link .= $blog_item_end;
//use blog_ID as a numeric key for custom sorting later on.
// We could also use $blog_name_param in place of 'blog_ID' but the ID is a
// safer value as the name of a blog is more likely to change over time.
$blog_links[blog_list_iteminfo('ID', false )] = $blog_link;
}
//Custom blog sorting
// Create new array to work with
$sorted_blog_links = array();
// Add a few blogs in custom order based on the key used above (use isset to prevent errors in case a
// blog is not available. We also want to unset/remove the sorted blog from the original array.
if (isset($blog_links['1'])) { $sorted_blog_links[] = $blog_links['1']; unset($blog_links['1']); }
if (isset($blog_links['5'])) { $sorted_blog_links[] = $blog_links['5']; unset($blog_links['5']); }
if (isset($blog_links['6'])) { $sorted_blog_links[] = $blog_links['6']; unset($blog_links['6']); }
if (isset($blog_links['7'])) { $sorted_blog_links[] = $blog_links['7']; unset($blog_links['7']); }
if (isset($blog_links['4'])) { $sorted_blog_links[] = $blog_links['4']; unset($blog_links['4']); }
if (isset($blog_links['2'])) { $sorted_blog_links[] = $blog_links['2']; unset($blog_links['2']); }
if (isset($blog_links['3'])) { $sorted_blog_links[] = $blog_links['3']; unset($blog_links['3']); }
// If there are any blogs remaining in $blog_links then add them to the end off the sorted blog list
// This prevents new blogs from going missing if they haven't been added to the above list yet.
if (sizeof($blog_links)) {
$sorted_blog_links = $sorted_blog_links + $blog_links;
//clean up old blog_links
unset($blog_links);
}
// Output:
echo $blog_list_start;
echo implode( $blog_list_separator, $sorted_blog_links );
echo $blog_list_end;
/*
nolog */
?>
In both cases above, you'll want to know how to customize the order of your blogs, so find something that looks like this and customize it:
if (isset($blog_links['1'])) { $sorted_blog_links[] = $blog_links['1']; unset($blog_links['1']); }
if (isset($blog_links['4'])) { $sorted_blog_links[] = $blog_links['4']; unset($blog_links['4']); }
if (isset($blog_links['2'])) { $sorted_blog_links[] = $blog_links['2']; unset($blog_links['2']); }
if (isset($blog_links['3'])) { $sorted_blog_links[] = $blog_links['3']; unset($blog_links['3']); }
if (isset($blog_links['6'])) { $sorted_blog_links[] = $blog_links['6']; unset($blog_links['6']); }
if (isset($blog_links['5'])) { $sorted_blog_links[] = $blog_links['5']; unset($blog_links['5']); }
And there you go! Alphabetized or Custom-Sorted bloglists, done in the skin.
That you so much... the sorting works great. However, (bet you saw that coming, eh?) I have one small problem. I have two rows in the blog list and it appears to calculate the line break before the sorting takes place. Therefore, I have a blog title (the link) broken between the first line and the second line. Is there anyway that sorting can be done before the position for the line break is determined?
Thanks again!
BTW, I used the custom sorting with 1.9.2.