CGBlog - Next/Previous Links? [SOLVED]

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Ziggywigged
Power Poster
Power Poster
Posts: 424
Joined: Sat Feb 02, 2008 12:42 am
Location: USA

CGBlog - Next/Previous Links? [SOLVED]

Post by Ziggywigged »

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.
Last edited by Ziggywigged on Fri Sep 02, 2011 1:26 pm, edited 1 time in total.
Bilmartech
Forum Members
Forum Members
Posts: 50
Joined: Mon Feb 21, 2011 2:08 am

Re: CGBlog - Next/Previous Links?

Post by Bilmartech »

I am experimenting with the same thing.. Anyone have ideas or solutions?

Even if it's an idea.. post it and it may spark someone else to figure out the solution.

Thanks in advance.
osxfil
Forum Members
Forum Members
Posts: 186
Joined: Wed Apr 01, 2009 6:03 pm

Re: CGBlog - Next/Previous Links?

Post by osxfil »

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

Re: CGBlog - Next/Previous Links?

Post by Bilmartech »

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}
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
Forum Members
Forum Members
Posts: 186
Joined: Wed Apr 01, 2009 6:03 pm

Re: CGBlog - Next/Previous Links?

Post by osxfil »

i'm sorry :) UDT prev_next was missing:

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"));
On end you need add to your CGBlog language XML prev and next text strings.
Bilmartech
Forum Members
Forum Members
Posts: 50
Joined: Mon Feb 21, 2011 2:08 am

Re: CGBlog - Next/Previous Links?

Post by Bilmartech »

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?
osxfil
Forum Members
Forum Members
Posts: 186
Joined: Wed Apr 01, 2009 6:03 pm

Re: CGBlog - Next/Previous Links?

Post by osxfil »

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?
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:

Code: Select all

$lang['next'] = "Next";
$lang['prev'] = "Previous";
In UDT you need change in this two lines term 'aktuality/' to your pretty URL prefix, which you use for CGBlog module (you can find this setting in you CGBlog module administration under tab Settings, filed "Prefix to use on all URLS from the blog module:":

Code: Select all

$prettyurl = 'aktuality/' . $result_next["cgblog_id"] .'/'.$pageid."/$aliased_title";
and

Code: Select all

$prettyurl = 'aktuality/' . $result_prev["cgblog_id"] .'/'.$pageid."/$aliased_title";
Example of this solution you can find here: http://www.packaging-cz.cz/cz/aktuality/
Bilmartech
Forum Members
Forum Members
Posts: 50
Joined: Mon Feb 21, 2011 2:08 am

Re: CGBlog - Next/Previous Links?

Post by Bilmartech »

Ok... I got the links working just fine now.. what I need help with please is to get the Alt tags on the images to display the correct title of the corresponding blog.

I have assigned a var in the template: {assign var='blogtitle' value=$entry->title|escape}

But I can't figure out how to get the UDT to read that?

Instead of inserting language into the lang file.. is there a way to contain it in the UDT so that it does something like this:

Code: Select all

if($result_next['cgblog_id']) {
$blogtitle = ($result_next['cgblog_title']);
and then some how get it to read like this:

Code: Select all

$smarty->assign('cgblog_next_text', $blogtitle;
I am sure the way i wrote it is not correct.. i was simply trying to show you what i was trying to do...
Bilmartech
Forum Members
Forum Members
Posts: 50
Joined: Mon Feb 21, 2011 2:08 am

Re: CGBlog - Next/Previous Links?

Post by Bilmartech »

Got IT!

I added this into your UDT:

Code: Select all

$blogtitle = $result_prev['cgblog_title'];
then I changed the language line to this:

Code: Select all

$smarty->assign('cgblog_prev_text', $blogtitle);
did the same for the
"next" pieces of the code

On the image I added a ALT tag and a title tag with the {$cgblog_next_text} in it and now the image displays the blog title!

Thanks so much for your help!!
Bilmartech
Forum Members
Forum Members
Posts: 50
Joined: Mon Feb 21, 2011 2:08 am

Re: CGBlog - Next/Previous Links?

Post by Bilmartech »

Here is my finished 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 I did 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>
Works like a charm!!!
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: CGBlog - Next/Previous Links? [SOLVED]

Post by carasmo »

Help! If you can, pretty please, this doesn't work with Version 1.10 of CMSMS

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
According to the upgrade notes on the home page of CMSMS, the above doesn't work any longer. Since I'm no programmer, I don't know what to do.

This is what CalGuy wrote:
Note arrows and various elements on his notes are gone, look at the source: http://www.cmsmadesimple.org/2011/10/An ... Simple%29

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

Re: CGBlog - Next/Previous Links? [SOLVED]

Post by Bilmartech »

carasmo wrote:Help! If you can, pretty please, this doesn't work with Version 1.10 of 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
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: CGBlog - Next/Previous Links? [SOLVED]

Post by carasmo »

Good plan! I did a complete backup and made a sub directory linked up the database, made sure that 1.9.43 or whatever the last latest one worked smoothly, then did the upgrade, YIKES! Cataloger, Advanced Content, so many issues, no feedcontent except title (summarize tag is not supported but truncate is). I did get this UDT updated by the CalGuy himself and it works! But so many other things don't, so I'm going back to the old install:

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"));
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: CGBlog - Next/Previous Links? [SOLVED]

Post by calguy1000 »

I'll prolly release Cataloger this week. SjG is just too busy, so I volunteered to do it.

I Don't recommend using AdvancedContent anyways...

CGSimpleSmarty was released today.
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.
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: CGBlog - Next/Previous Links? [SOLVED]

Post by carasmo »

Thank you CalGuy/Robert. I switched all the stuff to regular content blocks and with a 1 or 0 and it works faster than AdvancedContent. I did did that thing, drop menus, checkboxes, etc.,
Post Reply

Return to “Modules/Add-Ons”