Previous and next article in news details page

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
osxfil
Forum Members
Forum Members
Posts: 186
Joined: Wed Apr 01, 2009 6:03 pm

Re: Previous and next article in news details page

Post by osxfil »

folco3 wrote: This is cool can it be modified into CGBlog?
sure, here is modified prev_next UDT for CGBlog:

Code: Select all

if (!function_exists('MyGetModuleInstance'))
{
        function &MyGetModuleInstance($module)
        {
                global $gCms;

                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;
        }
}

global $gCms;
$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"));
and code for detail template:

Code: Select all

{prev_next pageid=$page_id currid=$entry->id currdate=$entry->postdate}
<p>
{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}
<p>
beherenow_uk
Forum Members
Forum Members
Posts: 103
Joined: Fri Nov 28, 2008 11:26 am

Re: Previous and next article in news details page

Post by beherenow_uk »

Hi all,

I know this was asked a couple of times previously, but i didn't see an obvious answer... Is it possible to amends the code above for CGBlog to allow the Prev/Next to stick to the current category?

This code is awesome, if I can just work it out it for the current category, it would be even better!

Thanks.
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: Previous and next article in news details page

Post by Gregor »

I think the SQL-code would look like something like this (just the select statement):

Code: Select all

// get all CGBlog articles sorted by ascending date (NEXT)
$query_next = "SELECT cgblog_id, cgblog_title 
FROM ".cms_db_prefix()."module_cgblog 
WHERE cgblog_date > ?
AND status = 'published'
AND (end_time >= CURRENT_DATE OR end_time IS NULL) 
AND cgblog_id 
IN (SELECT blog_id FROM ".cms_db_prefix()."module_cgblog_blog_categories) 
ORDER BY cgblog_date 
ASC LIMIT 1";

// get all CGBlog articles sorted by ascending date (PREV)
$query_prev = "SELECT cgblog_id, cgblog_title 
FROM ".cms_db_prefix()."module_cgblog 
WHERE cgblog_date < ?
AND status = 'published'
AND (end_time >= CURRENT_DATE OR end_time IS NULL) 
AND cgblog_id 
IN (SELECT blog_id FROM ".cms_db_prefix()."module_cgblog_blog_categories) 
ORDER BY cgblog_date 
ASC LIMIT 1";
However, a quick test learned that this is not working very. Had not had the time to look into it. Some help would be very helpfull.

Gregor
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: Previous and next article in news details page

Post by Gregor »

While using the sql-editor in phpmyadmin, I came to the following code that works in selecting the accoriding blog-items that are releated to a certain blog_id, in the code @blog_id

Code: Select all

select cgblog_title, cgblog_data
from cms_module_cgblog
where cgblog_id in ((select blog_id
from cms_module_cgblog_blog_categories
where category_id in
(select category_id 
from cms_module_cgblog_blog_categories
where blog_id = '272' )));
Problem, it is pretty slow and require some improvement....

Gregor
RHF
Forum Members
Forum Members
Posts: 20
Joined: Sun Jan 23, 2011 1:55 am

Re: Previous and next article in news details page

Post by RHF »

osxfil wrote:
folco3 wrote: This is cool can it be modified into CGBlog?
sure, here is modified prev_next UDT for CGBlog:
...
Hi osxfil.
I have been using your prev_nest UDT for CGBlog and really like it.
However, after upgrading to 1.10, it is broken on my site.
From the upgrade notes, it appears the problem may be due to using the $gCms->modules array.
Do you have an updated version compatible with 1.10.x?
Thanks
Bob
chrismarie

Re: Previous and next article in news details page

Post by chrismarie »

This thread has the updated UDT and another solution provided my Manuel: http://forum.cmsmadesimple.org/viewtopi ... =4&t=58551
Post Reply

Return to “Tips and Tricks”