Recent Topics

[SKIN HACK] alphabetize / custom sort blogs

Started by on Feb 19, 2007 – Contents updated: Feb 19, 2007

Feb 19, 2007 21:17    

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.

Feb 21, 2007 20:16

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.

Feb 21, 2007 20:42

... or perhaps I should just avoid using short names with spaces? I'd rather not have to resort to that, it looks much better with the spaces. But, I can see how there may not be specified line break if it just relies on HTML.

Feb 21, 2007 20:45

I'm pretty sure that's not an issue with this hack. In your style sheet you'll want to add

white-space: nowrap;


to where you have a defined for your bloglist. Usually it'll be in for example a.BlogButton and a.BlogButtonCurr. It says that white space in an a isn't allowed to wrap. Groovy eh?

Feb 21, 2007 21:08

Excellent... thank you.

Apr 24, 2007 11:03

Hello, I have just installed, and am still playing with, b2evo v 1.9.3.

Should/ could these same "customizable bloglist sorter" instructions apply to my version? I did give them a go but it didnt work so Im either doing something wrong or 1.9.3 needs something different :).

Thank you.

EDIT: Another question, probably in the wrong category but??...copying and pasting the "trackback URL" into my browser address bar is coming up with this error message on an otherwise blank page:

<?xml version="1.0" encoding="iso-8859-1" ?>
- <response>
<error>1</error>
<message>No url to your permanent entry given.</message>
</response>

Is this normal? I could well be misunderstanding how a trackback URL is supposed to work??

Any help greatly appreciated!
Kia ora from NZ

Apr 26, 2007 23:59

AFAIK this will work in v1.9.3, especially since I have it working on one of my 1.9.3 installations.

Trackbacks are completely off-topic in this particular thread, but so what. The trackback URL is not designed to be something you put in your address bar. That's why it shows up as text instead of a link. Search the forums for 'trackback' with me as the author and you'll find long-winded explanations of how they work.

Jun 03, 2007 23:16

@EdB

Thanks heaps for this. Works really well. B) Thanks for the tip on "white-space: nowrap;" as well. It had been really annoying me! :p

Jun 16, 2007 12:04

EdB wrote:

AFAIK this will work in v1.9.3, especially since I have it working on one of my 1.9.3 installations.

What does it mean: "Will work?"
Is it working in 1.9.3 or not? I have installed it but i doesn´t take effect :(

Jun 16, 2007 13:18

When I say "I have it working on one of my 1.9.3 installations" I mean it works on a 1.9.3 installation. Also 1.10.1 and 1.10.2 versions.

Sep 08, 2007 17:19

I'm using 1.9.3 and the alphabetic sort didn't work for me out of the box. There were some minor differences that shouldn't have been too bad but basically the effects of my css were not correctly affecting the list. Which is very odd because the html output looked just fine.

In the end I modified the _bloglist.php in /skins itself ala thus:


//ORIG!!!!!!!	$blog_links[] = $blog_link;
	$blog_links[blog_list_iteminfo($blog_name_param, false )] = $blog_link;  //sorting hack!!!!!!!!
}

//sorting hack!!!!!!!!
ksort($blog_links);
//sorting hack end !!!!!!!!

I appreciate this is a bit naughty but it worked and the various other things I tried didn't. Maybe this knowledge will help someone out.

Cheerio for now,

Alan

Jan 28, 2008 15:38

does this hack still apply for versions 2.x? Or is there now a UI for establishing blog sort order?

ty

kazar

Jan 28, 2008 17:43

var msg = "";
var ¥åßßåpresence = ¥åßßåIsLoggedIn;

for (var x = 1; ¥åßßåpresence; x++)
{
msg = "ty so much No. " + x + "\n";
}

alert(msg);

Jan 28, 2008 18:11

var x=0; while( kazarIsLoggedIn() ){ alert( 'You\'re welcome No.'+(++x) ); }

;)

¥

Aug 23, 2008 03:45

Could someone please assist with a way to custom order the blog names list with the new 2.4.2.

Thanks in advance

Bj

Nov 12, 2008 17:03

Apparently in 2.4.6 the _bloglist.php file is not used. I even renamed it and still have the same bloglist. So, any other way to get an alphabetical list based on short-name?

Jul 20, 2010 20:13

I run a multilingual blog on several domains (marbella-villla.com) and would like to sort but also display the little flags in these tabs of the header blog_list like they are used in coll_list
%locale_flag( #blog_locale# )%

Is there a chance including that in my template?
I amusing a modified "Nautica_2l"

Any help very much apretiated.


Form is loading...

b2evolution CMS – This forum is powered by b2evolution CMS, a complete engine for your website.