Page 1 of 1
[SOLVED] CMS_Selflink and CGBlog
Posted: Tue Aug 30, 2011 8:33 pm
by Bilmartech
I have self link working for previous and next. I tried to load it only on the detail template from CGBlog but it is calling the pages from the menu and not from the articles in the blog? Is there a way to have this find only the previous and next articles in the blog?
Re: CMS_Selflink and CGBlog
Posted: Tue Aug 30, 2011 8:59 pm
by calguy1000
I've answered this same question numerous times for the various modules... but anyways.
The answer is NO. you can't.
Consider this simple example:
You have a page that calls {News sortby=$smarty.get.user_selected_sort_order sortorder=desc category=$smarty.get.user_selected_category}
(substitute your module name of choice)
This this displays a list of the matching items, with links to detail views as it should. You can click on one of those links and view a detail view, that link is sharable via twitter, facebook, bookmarks, and easily searchable by google.
You could just as easily be calling News, or CGBlog, or Products four different ways on the same page.
However, How can the system know (while still maintaining pretty urls, and sharable links) what is the logical next and previous item to display. given the sort order, the category, and other criterium (status, expiry dates, etc)
Re: CMS_Selflink and CGBlog
Posted: Tue Aug 30, 2011 9:41 pm
by Bilmartech
Thanks for responding.
The call doesn't necessarily have to know which article is "next or previous" based on any sort or category.
Since all CG Blog post are different based on the articleid why can't it be something like:
If Current ArticleID = X
Then
Previous = X-1
And
Next = X+1
I'm not sure how to write that and maybe selflink isn't the way to go here, but this seems logical to me and regardless of what category is called or date, ect the articleID will always be unique to each post.
Re: CMS_Selflink and CGBlog
Posted: Fri Sep 02, 2011 5:57 am
by Bilmartech
And here's the solution:
Create a UDT titled prev_next:
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);
And here is the code to insert into the details template in the blog module for the images to display:
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>
Just replace with your own images and it Works like a charm!!!