2016-07-13, 06:46:41
(2016-07-12, 01:20:59)Carlos Wrote: (Sorry for late response, a bit busy lately.)
Here's a modified version ofnm_list_recent_by_tag
, with posts sorted by title instead of recent date. You could add it to NM Addons, but I suggest you paste ir in your theme's functions.php file (create it if it doesn't exist).
Call it in your template or component with<?php nm_custom_list_alpha_by_tag('your-tag', 999); ?>
Code:function nm_custom_list_alpha_by_tag($tag='', $max=0) {
if (trim($tag) !== '') {
if ($max <= 0) {
global $NMRECENTPOSTS;
$max = $NMRECENTPOSTS;
}
$allposts = nm_get_posts();
$posts = array();
foreach ($allposts as $post)
if (in_array($tag, explode(',', $post->tags)))
$posts[] = $post;
unset($allposts);
function nm_comparePostTitles($a, $b) {
if (function_exists('mb_strtolower'))
return (mb_strtolower($a->title) < mb_strtolower($b->title)) ? -1 : 1;
else
return (strtolower($a->title) < strtolower($b->title)) ? -1 : 1;
}
usort($posts, 'nm_comparePostTitles');
$posts = array_slice($posts, 0, $max, true);
if (!empty($posts)) {
echo '<ul class="nm_recent">',PHP_EOL;
foreach ($posts as $post) {
$url = nm_get_url('post').$post->slug;
$title = stripslashes($post->title);
echo '<li><a href="'.$url.'">'.$title.'</a></li>',PHP_EOL;
}
echo '</ul>',PHP_EOL;
}
}
}
Cool, we have been without internet for a week, I will try this on localhost.
Thank you very much Carlos