[SOLVED] CMS_Selflink and CGBlog

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
Bilmartech
Forum Members
Forum Members
Posts: 50
Joined: Mon Feb 21, 2011 2:08 am

[SOLVED] CMS_Selflink and CGBlog

Post 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?
Last edited by Bilmartech on Fri Sep 02, 2011 5:58 am, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: CMS_Selflink and CGBlog

Post 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)
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Bilmartech
Forum Members
Forum Members
Posts: 50
Joined: Mon Feb 21, 2011 2:08 am

Re: CMS_Selflink and CGBlog

Post 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.
Bilmartech
Forum Members
Forum Members
Posts: 50
Joined: Mon Feb 21, 2011 2:08 am

Re: CMS_Selflink and CGBlog

Post 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!!!
Post Reply

Return to “Modules/Add-Ons”