Personal tools
User Handbook/Admin Panel/Content/News/User Defined Tags
From CMSMS
Table of Contents
This page in: English - Deutsch - Français - Svenska - Русский - Norsk - Polski - Nederlands - Español - Lietuvių
User Defined Tags for News module
Pagination
NOTE: Pagination is available by default in version 1.1 This information is for those still using the older versions.
This UDT allows you to add "Older/Newer News" type links at the bottom of pages containing News, as well as the page-number-links. Note that this does not work for 'news' type pages. You will need to set your page type to 'Content' and add the appropriate {news} or {cms_module} tags.
1. Create a User Defined Tag "newsindex" as follows:
global $gCms, $number;
$start = ($_REQUEST['start']) ? $_REQUEST['start'] : $params['start'];
$number = ($_REQUEST['number']) ? $_REQUEST['number'] : $params['number'];
$older = $params['older'] ? $params['older'] : 'Older Stories';
$newer = $params['newer'] ? $params['newer'] : 'Newer Stories';
/*Get URL for 1st page*/
$hm =& $gCms->GetHierarchyManager();
$firstpage = $gCms->variables['content_id'];
$curnode = &$hm->getNodeById($firstpage);
$curcontent =& $curnode->getContent();
/* Count the number of articles we have in total */
$db = &$gCms->db;
$tables=cms_db_prefix().'module_news';
$cond='';
if (isset($params['count_expired'])) {
switch ($params['count_expired']) {
case 'true':
$cmpr='<';
break;
case 'false':
$cmpr='>';
break;
default:
return 'Wrong argument in "count_expired"';
}
$cond='(end_time '.$cmpr.' NOW() OR end_time IS NULL )';
}
if (isset($params['category'])) {
$tables.=', '.cms_db_prefix().'module_news_categories';
if ($cond!='') $cond.=" AND ";
$cond.="(news_category_name LIKE '".$params['category']."') AND (".cms_db_prefix()."module_news_categories.news_category_id = ".cms_db_prefix()."module_news.news_category_id)";
}
if($cond!='') $cond='WHERE ('.$cond.')';
$query = 'SELECT COUNT(news_id) FROM '.$tables.' '.$cond;
$newscount = &$db->GetOne($query);
/* utility to make a URL */
function join_uri($middle) {
global $gCms, $number;
return 'index.php?page=' . $gCms->variables['page_name'] . '&start=' . $middle . '&number=' . $number;
}
/* Create the Next and Previous URLS */
$older_uri = join_uri($start + $number);
$newer_uri = (($_REQUEST['start'] - $params['number']) == $params['start'])
? $curcontent->GetURL()
: join_uri($start - $number);
/* Make the page links */
$newscrumbs='';
$page = 0;
for( $i=0; $i <= $newscount; $i += $number ) {
$page++;
if( $i != $start ) {
$newscrumbs .= ($i == $params['start'])
? '<a href="'.$curcontent->GetURL().'">'.$page.'</a>'
: '<a href="'.join_uri($i).'">'.$page.'</a>';
} else {
$newscrumbs .= $page;
}
if( $i <= $newscount && isset($params['delimiter'] ) ) {
$newscrumbs.=$params['delimiter'];
}
}
$smarty->assign('news_start', $start);
$smarty->assign('news_number', $number);
$smarty->assign('news_count',$newscount);
$smarty->assign('news_newer_link', ($start > 0)
? "<a href=\"$newer_uri\">$newer</a>"
: ''
);
$smarty->assign('news_older_link', ($start + $number < $newscount)
? "<a href=\"$older_uri\">$older</a>"
: ''
);
$smarty->assign('news_crumbs',$newscrumbs);
This tag sets six smarty-variables (variables you can access in your page).
2. Create a page for your news. It should have a Content Type of 'Content' rather than 'News'
3. Execute your User Defined Tag by adding the following to the page's Content:
{newsindex number='5' start='0' category='General' count_expired='true' delimiter='|' older='Older Stories' newer='Newer Stories'}
Parameters:
-
startThe story number to default to at the top of this page -
numberThe number of stories to show on each page -
categorySpecifies the category of the displayed news; if not specified, every category is included -
count_expiredShow expired news in the pagination (takes 'true' or 'false') -
delimiterSpecify the delimiter of the page-number-links, like ' | ' in1 | 2 | 3 -
older: The text to use for the link to the previous page -
newer: The text to use for the link to the next page
That will set the six smarty variables:
-
$news_start: The story number that starts the current page -
$news_number: The number of stories on the current page -
$news_newer_link: A link to the next page (if there is a next page, empty string otherwise) -
$news_older_link: A link to the previous page (if there is a previous page, empty string otherwise) -
$news_count: The total number of stories available to show -
$news_crumbs: A list of pages (linked) separated by the delimiter provided
4. Add (or change) the {cms_module} or just {news} tag to insert your news, using the two variables:
{cms_module module='news' number=$news_number start=$news_start category='General' showarchive='true'}
Note that this must come after the previous tag.
5. Finally, create the next/prev links and the page-number-links ({$newscrumbs})
{$news_newer_link} {$news_crumbs} {$news_older_link}
In summary, add the following to your content:
{newsindex number='5' start='0' category='General' count_expired='true' delimiter='|' older='Older Stories' newer='Newer Stories'}
{cms_module module='news' number=$news_number start=$news_start category='General' showarchive='true'}
{$news_newer_link} {$news_crumbs} {$news_older_link}
This shows an archive of the now archived news with the proper pagination.
This page in: English - Deutsch - Français - Svenska - Русский - Norsk - Polski - Nederlands - Español - Lietuvių
