Actually putting a HTML nugget with your sorted categories is currently the only way.
You could order the categories by their creation date by modifying (resp. creating a new) plugin, however.
For the 0.9 snapshot I just patched the categories plugin. You can patch that as well by modifying those files:
1. Edit include/plugins_internal.inc.php.
2. Find the class serendipity_categories_plugin extends serendipity_plugin { ... } part and wholly replace it with this:
Code: Select all
class serendipity_categories_plugin extends serendipity_plugin {
var $title = CATEGORIES;
function introspect(&$propbag) {
global $serendipity;
$propbag->add('name', CATEGORIES);
$propbag->add('description', CATEGORY_PLUGIN_DESC);
$propbag->add('stackable', true);
$propbag->add('author', 'Serendipity Team');
$propbag->add('version', '1.0');
$propbag->add('configuration', array('authorid', 'image', 'sort_order', 'sort_method'));
}
function introspect_config_item($name, &$propbag)
{
global $serendipity;
switch($name) {
case 'authorid':
$row_authors = serendipity_db_query("SELECT realname, authorid FROM {$serendipity['dbPrefix']}authors");
$authors = array('all' => ALL_AUTHORS);
if (is_array($row_authors)) {
foreach($row_authors as $row) {
$authors[$row['authorid']] = $row['realname'];
}
}
$propbag->add('type', 'select');
$propbag->add('name', CATEGORIES_TO_FETCH);
$propbag->add('description', CATEGORIES_TO_FETCH_DESC);
$propbag->add('select_values', $authors);
$propbag->add('default', 'all');
break;
case 'sort_order':
$select = array();
$select['category_name'] = CATEGORY;
$select['category_description'] = DESCRIPTION;
$select['none'] = NONE;
$propbag->add('type', 'select');
$propbag->add('name', SORT_ORDER);
$propbag->add('description', '');
$propbag->add('select_values', $select);
$propbag->add('default', 'category_name');
break;
case 'sort_method':
$select = array();
$select['ASC'] = SORT_ORDER_ASC;
$select['DESC'] = SORT_ORDER_DESC;
$propbag->add('type', 'select');
$propbag->add('name', SORT_ORDER);
$propbag->add('description', '');
$propbag->add('select_values', $select);
$propbag->add('default', 'ASC');
break;
case 'image':
$propbag->add('type', 'string');
$propbag->add('name', XML_IMAGE_TO_DISPLAY);
$propbag->add('description', XML_IMAGE_TO_DISPLAY_DESC);
$propbag->add('default', serendipity_getTemplateFile('img/xml.gif'));
break;
default:
return false;
}
return true;
}
function generate_content(&$title) {
global $serendipity;
$which_category = $this->get_config('authorid');
$sort = $this->get_config('sort_order');
if ($sort == 'none') {
$sort = '';
} else {
$sort .= ' ' . $this->get_config('sort_method');
}
$categories = serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category, '', $sort);
$title = $this->title;
$html = '';
$image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif'));
$image = (($image == "'none'" || $image == 'none') ? '' : $image);
if (is_array($categories) && count($categories)) {
$categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED);
foreach ( $categories as $cat ) {
$html .= '<div style="padding-bottom: 2px;">';
if ( !empty($image) ) {
$html .= '<a href="'. serendipity_rewriteURL(PATH_FEEDS .'/'. PATH_CATEGORIES .'/'. serendipity_makePermalink(PERM_FEEDS_CATEGORIES, array('id' => $cat['categoryid'], 'title' => $cat['category_name']))) .'"><img src="'. $image .'" alt="XML" style="border: 0px" /></a> ';
}
$html .= '<a href="'. serendipity_rewriteURL(PATH_CATEGORIES . '/' . serendipity_makePermalink(PERM_CATEGORIES, array('id' => $cat['categoryid'], 'title' => $cat['category_name'])), 'serendipityHTTPPath') .'" title="'. $cat['category_name'] .'" style="padding-left: '. $cat['depth']*6 .'px">'. $cat['category_name'] .'</a>';
$html .= '</div>' . "\n";
}
}
$html .= sprintf(
'<br /><a href="%s" title="%s">%s</a>',
$serendipity['serendipityHTTPPath'] . $serendipity['indexFile'],
ALL_CATEGORIES,
ALL_CATEGORIES
);
print $html;
}
}
3. Edit include/functions_entries.inc.php
4. Find the function serendipity_fetchCategories(....) code and wholly replace it with:
Code: Select all
function serendipity_fetchCategories($authorid = null, $name = '', $order = 'category_name DESC') {
global $serendipity;
if (!isset($authorid) || $authorid === null) {
$authorid = ((isset($serendipity['authorid']) && !empty($serendipity['GET']['adminModule'])) ? $serendipity['authorid'] : 1);
}
if ($serendipity['serendipityUserlevel'] == USERLEVEL_ADMIN) {
$authorid = 'all';
}
if ($authorid != 'all' && is_numeric($authorid)) {
$where = " WHERE ((c.authorid = $authorid OR c.authorid = 0) " . (!empty($serendipity['serendipityUserlevel']) ? " OR a.userlevel < {$serendipity['serendipityUserlevel']}" : '') . ')';
} else {
$where = '';
}
if (!empty($name)) {
if ($where == '') {
$where = ' WHERE ';
} else {
$where = ' AND ';
}
$where .= " c.category_name = '" . serendipity_db_escape_string($name) . "'";
}
$querystring = "SELECT
c.*,
a.username,
a.realname
FROM {$serendipity['dbPrefix']}category AS c
LEFT OUTER JOIN {$serendipity['dbPrefix']}authors AS a
ON c.authorid = a.authorid $where";
if (!empty($order)) {
$querystring .= "\n ORDER BY $order";
}
return serendipity_db_query($querystring);
}
5. Then you can go to your categories plugin configuration and change the sorting method.
If that is too complicated, stick with the HTML nugget. You can also download the 0.9 snapshot tomorrow, but that also means living on the bleeding edge. Your choice
Regards,
Garvin