CMS Made Simple Forums
https://forum.cmsmadesimple.org/

Previous and next article in news details page
https://forum.cmsmadesimple.org/viewtopic.php?f=4&t=33554
Page 2 of 2

Author:  osxfil [ Tue Nov 02, 2010 7:07 am ]
Post subject:  Re: Previous and next article in news details page

folco3 \folco3:
This is cool can it be modified into CGBlog?

sure, here is modified prev_next UDT for CGBlog:
\$1:
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:
\$1:
{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>

Author:  beherenow_uk [ Mon Nov 07, 2011 11:00 pm ]
Post subject:  Re: Previous and next article in news details page

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.

Author:  Gregor [ Mon Dec 05, 2011 1:11 pm ]
Post subject:  Re: Previous and next article in news details page

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

\$1:
// 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

Author:  Gregor [ Sun Dec 11, 2011 7:27 pm ]
Post subject:  Re: Previous and next article in news details page

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
\$1:
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

Author:  RHF [ Mon Dec 12, 2011 5:35 pm ]
Post subject:  Re: Previous and next article in news details page

osxfil \osxfil:
folco3 \folco3:
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

Author:  chrismarie [ Thu May 24, 2012 11:11 am ]
Post subject:  Re: Previous and next article in news details page

This thread has the updated UDT and another solution provided my Manuel: viewtopic.php?f=4&t=58551

Page 2 of 2 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/