CGBlog - Next/Previous Links? [SOLVED]
Posted: Wed Aug 10, 2011 12:58 pm
Using the latest versions of CMSMS and CGBlog, is it possible to display links to previous and next posts, similar to the cms_selflink tag?
Thanks.
Thanks.
Content management as it is meant to be
https://forum.cmsmadesimple.org/
Code: Select all
{prev_next pageid=$page_id currid=$entry->id currdate=$entry->postdate}
{if $cgblog_next_url}<a href="{$cgblog_next_url}"><< {$cgblog_next_text}</a> | {/if}
{if $cgblog_prev_url}<a href="{$cgblog_prev_url}">{$cgblog_prev_text} >></a>{/if}
Maybe I'm missing something but all I get are errors using this code: string(138) "Smarty error: syntax error: unrecognized tag 'prev_next' (Smarty_Compiler.class.php, line 590)"osxfil wrote:Hi guys, it's very simple:Code: Select all
{prev_next pageid=$page_id currid=$entry->id currdate=$entry->postdate} {if $cgblog_next_url}<a href="{$cgblog_next_url}"><< {$cgblog_next_text}</a> | {/if} {if $cgblog_prev_url}<a href="{$cgblog_prev_url}">{$cgblog_prev_text} >></a>{/if}
Code: Select all
if (!function_exists('MyGetModuleInstance'))
{
function &MyGetModuleInstance($module)
{
$gCms = cmsms();
if (isset($gCms->modules[$module]) &&
$gCms->modules[$module]['installed'] == true &&
$gCms->modules[$module]['active'] == true)
{
return $gCms->modules[$module]['object'];
}
// Fix only variable references should be returned by reference
$tmp = FALSE;
return $tmp;
}
}
$gCms = cmsms();
$db = &$gCms->db;
$cgblog = MyGetModuleInstance('CGBlog');
$pageid = ($_REQUEST['pageid']) ? $_REQUEST['pageid'] : $params['pageid'];
$currdate = $params['currdate'];
if(!$currdate) return;
// get all news articles sorted by ascending date
$query_next = "SELECT cgblog_id,cgblog_title FROM ".cms_db_prefix()."module_cgblog WHERE cgblog_date > ? AND status = 'published' ORDER BY cgblog_date ASC LIMIT 1";
$query_prev = "SELECT cgblog_id,cgblog_title FROM ".cms_db_prefix()."module_cgblog WHERE cgblog_date < ? AND status = 'published' ORDER BY cgblog_date DESC LIMIT 1";
$result_next = &$db->GetRow($query_next,array($currdate));
$result_prev = &$db->GetRow($query_prev,array($currdate));
if($result_next['cgblog_id']) {
$aliased_title = munge_string_to_url($result_next['cgblog_title']);
$prettyurl = 'aktuality/' . $result_next["cgblog_id"] .'/'.$pageid."/$aliased_title";
$next_uri = $cgblog->CreateLink('cntnt01', 'detail', $pageid, '', array('articleid' => $result_next["cgblog_id"]) ,'', true, false, '', true, $prettyurl);
}else{
$next_uri = "";
}
if($result_prev['cgblog_id']) {
$aliased_title = munge_string_to_url($result_prev['cgblog_title']);
$prettyurl = 'aktuality/' . $result_prev["cgblog_id"] .'/'.$pageid."/$aliased_title";
$prev_uri = $cgblog->CreateLink('cntnt02', 'detail', $pageid, '', array('articleid' => $result_prev["cgblog_id"]) ,'', true, false, '', true, $prettyurl);
}else{
$prev_uri = "";
}
$smarty->assign('cgblog_next_url', $next_uri);
$smarty->assign('cgblog_next_text', $cgblog->lang("next"));
$smarty->assign('cgblog_prev_url', $prev_uri);
$smarty->assign('cgblog_prev_text', $cgblog->lang("prev"));
As i wrote – you need add into language file in CGBlog terms for previous and next strings. If you use english language, then open in some editor this file from your web: modules/CGBlog/lang/en_US.php and insert these two lines:Bilmartech wrote:Still not sure what is wrong.. Now this is what shows on the page:
<< --Add Me - module:CGBlog string:next-- | --Add Me - module:CGBlog string:prev-- >>
Links show, but they do not work? I also think you have some items hard coded in the UDT like: 'aktuality/' I'll play around with it and see if i can tweak your UDT to get it to work.
Have you gotten yours to work with images yet?
Code: Select all
$lang['next'] = "Next";
$lang['prev'] = "Previous";
Code: Select all
$prettyurl = 'aktuality/' . $result_next["cgblog_id"] .'/'.$pageid."/$aliased_title";
Code: Select all
$prettyurl = 'aktuality/' . $result_prev["cgblog_id"] .'/'.$pageid."/$aliased_title";
Code: Select all
if($result_next['cgblog_id']) {
$blogtitle = ($result_next['cgblog_title']);
Code: Select all
$smarty->assign('cgblog_next_text', $blogtitle;
Code: Select all
$blogtitle = $result_prev['cgblog_title'];
Code: Select all
$smarty->assign('cgblog_prev_text', $blogtitle);
Code: Select all
if (!function_exists('MyGetModuleInstance'))
{
function &MyGetModuleInstance($module)
{
$gCms = cmsms();
if (isset($gCms->modules[$module]) &&
$gCms->modules[$module]['installed'] == true &&
$gCms->modules[$module]['active'] == true)
{
return $gCms->modules[$module]['object'];
}
// Fix only variable references should be returned by reference
$tmp = FALSE;
return $tmp;
}
}
$gCms = cmsms();
$db = &$gCms->db;
$cgblog = MyGetModuleInstance('CGBlog');
$pageid = ($_REQUEST['pageid']) ? $_REQUEST['pageid'] : $params['pageid'];
$currdate = $params['currdate'];
if(!$currdate) return;
// get all news articles sorted by ascending date
$query_next = "SELECT cgblog_id,cgblog_title FROM ".cms_db_prefix()."module_cgblog WHERE cgblog_date > ? AND status = 'published' ORDER BY cgblog_date ASC LIMIT 1";
$query_prev = "SELECT cgblog_id,cgblog_title FROM ".cms_db_prefix()."module_cgblog WHERE cgblog_date < ? AND status = 'published' ORDER BY cgblog_date DESC LIMIT 1";
$result_next = &$db->GetRow($query_next,array($currdate));
$result_prev = &$db->GetRow($query_prev,array($currdate));
if($result_next['cgblog_id']) {
$blogtitlenext = $result_next['cgblog_title'];
$aliased_title = munge_string_to_url($result_next['cgblog_title']);
$prettyurl = 'blog/' . $result_next["cgblog_id"] ."/$aliased_title";
$next_uri = $cgblog->CreateLink('cntnt01', 'detail', $pageid, '', array('articleid' => $result_next["cgblog_id"]) ,'', true, false, '', true, $prettyurl);
}else{
$next_uri = "";
}
if($result_prev['cgblog_id']) {
$blogtitle = $result_prev['cgblog_title'];
$aliased_title = munge_string_to_url($result_prev['cgblog_title']);
$prettyurl = 'blog/' . $result_prev["cgblog_id"] ."/$aliased_title";
$prev_uri = $cgblog->CreateLink('cntnt02', 'detail', $pageid, '', array('articleid' => $result_prev["cgblog_id"]) ,'', true, false, '', true, $prettyurl);
}else{
$prev_uri = "";
}
$smarty->assign('cgblog_next_url', $next_uri);
$smarty->assign('cgblog_next_text', $blogtitlenext);
$smarty->assign('cgblog_prev_url', $prev_uri);
$smarty->assign('cgblog_prev_text', $blogtitle);
Code: Select all
<p style="text-align: center;"> </p>
{prev_next pageid=$page_id currid=$entry->id currdate=$entry->postdate}
<table style="width: 99%;" border="0" align="center">
<tbody>
<tr>
<td style="width: 25%;">{if $cgblog_prev_url}<a href="{$cgblog_prev_url}"><img src="uploads/images/back.png" alt="{$cgblog_prev_text}" title="{$cgblog_prev_text}" width="128" height="128" /></a>{/if}</td>
<td style="width: 25%;" align="right">{if $cgblog_next_url}<a href="{$cgblog_next_url}"><img src="uploads/images/next.png" alt="{$cgblog_next_text}" title="{$cgblog_next_text}" width="128" height="128" /></a>{/if}</td>
</tr>
</tbody>
</table>
<p style="text-align: center;"> </p>
Code: Select all
Fatal error: Call to a member function GetRow() on a non-object in /home/username/public_html/domainname/subdirec/lib/classes/class.usertagoperations.inc.php(260) : eval()'d code on line 33
Code: Select all
$gCms
Code: Select all
What We Broke (Technical Stuff):
1: Removing $gCms→smarty, use cmsms()→GetSmarty() instead.
In older versions of CMSMS the $gCms object contained a reference to the global smarty object. The global smarty object is now a singleton to ensure that it cannot be instantiated more than once.
2: Removed the $gCms→config, use cmsms()→GetConfig() instead.
Similar to the Smarty object, the config object is also a singleton. Therefore that method of accessing the config object has been removed.
3: Removed the $gCms→modules array. use cms_utils::get_module() instead.
The public modules array, a throwback to the days of php4 has been removed, and replaced with a complete api (see the ModuleOperations class). A simple method to obtain a module object reference has been (since CMSMS 1.9) the cms_utils::get_module() method. This may effect your UDT’s the most.
4: Revised the content objects
In CMSMS 1.10, as the first step in revising our object interface for the sake of efficiency we have revised the Content object to ensure that all member variables are private and that accessors exist for each data member. The most prominent of these is the ‘mModifiedDate’ member of the content object, which was public but had no accessor method.
5: The CmsObject class is now final and a singleton.
In CMSMS 1.10, the CmsObject class (aka the $gCms variable) is now a final, non-extendable class.
6: Removed deprecated callbacks from the module api.
The last of the long deprecated callbacks were removed from the module class as they have been replaced by events for a long time.
7: Private, Protected, and final methods in the module API.
Our first step in the cleanup of the module API was to clean up the interfaces for this class. We have declared most methods to be public or protected. Some methods are also final and cannot be overridden. We have also deprecated the Redirect methods of the module API.
8: Replaced, but deprecated some members of the module class.
The smarty, db, and config members of the module class (which were references to the global versions of those objects) have been removed, and replaced with access methods. Though this should not break compatibility the following is now deprecated:
$this→smarty – when $smarty is not provided to you in scope, you should use cmsms()→GetSmarty()
$this→db – when $db not provided to you in scope, you should use cmsms()→GetDb();
$this→config – you should use cmsms()→GetConfig();
$this→cms – When not provided in scope, you should use $gCms = cmsms();
Sorry I didn't upgrade to 1.10 specifically because of a lot of the items that haven't been updated yet, so unfortunately I have no idea of if or even how to make it work....carasmo wrote:Help! If you can, pretty please, this doesn't work with Version 1.10 of CMSMS
Code: Select all
// nuked all the stuff above here.
$gCms = cmsms();
$db = cmsms()->GetDb(); // changed this line.
$cgblog = cms_utils::get_module('CGBlog'); // changed this line.
$pageid = ($_REQUEST['pageid']) ? $_REQUEST['pageid'] : $params['pageid'];
$currdate = $params['currdate'];
if(!$currdate) return;
// get all news articles sorted by ascending date
$query_next = "SELECT cgblog_id,cgblog_title FROM ".cms_db_prefix()."module_cgblog WHERE cgblog_date > ? AND status = 'published' ORDER BY cgblog_date ASC LIMIT 1";
$query_prev = "SELECT cgblog_id,cgblog_title FROM ".cms_db_prefix()."module_cgblog WHERE cgblog_date < ? AND status = 'published' ORDER BY cgblog_date DESC LIMIT 1";
$result_next = &$db->GetRow($query_next,array($currdate));
$result_prev = &$db->GetRow($query_prev,array($currdate));
if($result_next['cgblog_id']) {
$aliased_title = munge_string_to_url($result_next['cgblog_title']);
$prettyurl = 'aktuality/' . $result_next["cgblog_id"] .'/'.$pageid."/$aliased_title";
$next_uri = $cgblog->CreateLink('cntnt01', 'detail', $pageid, '', array('articleid' => $result_next["cgblog_id"]) ,'', true, false, '', true, $prettyurl);
}else{
$next_uri = "";
}
if($result_prev['cgblog_id']) {
$aliased_title = munge_string_to_url($result_prev['cgblog_title']);
$prettyurl = 'aktuality/' . $result_prev["cgblog_id"] .'/'.$pageid."/$aliased_title";
$prev_uri = $cgblog->CreateLink('cntnt02', 'detail', $pageid, '', array('articleid' => $result_prev["cgblog_id"]) ,'', true, false, '', true, $prettyurl);
}else{
$prev_uri = "";
}
$smarty->assign('cgblog_next_url', $next_uri);
$smarty->assign('cgblog_next_text', $cgblog->lang("next"));
$smarty->assign('cgblog_prev_url', $prev_uri);
$smarty->assign('cgblog_prev_text', $cgblog->lang("prev"));