Page 1 of 1

[SOLVED] ListIt Module: How to set up 'Read more' function

Posted: Tue Feb 01, 2011 9:02 am
by allan1412
The 'ListIt' module is a great way to display certain types of content.
Can anyone help with this?
I need to use ListIt with a 'Summary / Detail' function similar to CGBlog ie display the summary content with a 'Read more' link to display the summary and full content in a separate page.

Re: ListIt Module: How to set up 'Read more' function

Posted: Tue Feb 01, 2011 1:35 pm
by nicmare
afaik this is not possible but maybe someone has an idea. i am excited…

Re: ListIt Module: How to set up 'Read more' function

Posted: Fri Feb 18, 2011 12:57 am
by Owens
Here is a detail summary view using UDTs. It will show a single detail record and a summary from ListIt, without making any modifications to the source code. I've never used the CGblog (I use NEWS on Studio-Owens.com as a Blog) so I have no idea if this would be similar. The ListIt Module is based upon the EAV datamodel so it isn't going to be suited for large amounts of records.

I am presenting two methods here. Method one just filters the existing data. Method two queries the DB to find the single record data. Both use the same concept to build URLs and create summary pages.

Method One Filter The Existing Data

Create a UDT called listit_details_check
Put this code in the UDT...

Code: Select all

if ($params['thisid'] == (int)$_GET['cntnt01itemid']) {
  echo True;
} else {
  echo False;
}
Next modify the ListIt template named "default"
Add a {capture} and {if} inside the {foreach}. This is what the stock "default" template will look like when modified (new code is on lines 2,3, and 19)...

Code: Select all

{foreach from=$items item=item}
{capture assign="idCheck"}{listit_details_check thisid=$item.item_id}{/capture}
{if $idCheck == True}
<div class="item">
<h2 class="item-title">{$item.title|cms_escape}</h2>
<div class="item-category">Category: {$item.category_name|cms_escape}</div>
{if !empty($item.fielddefs)}
    <div class="item-properties">
    {foreach from=$item.fielddefs item=fielddef}
        {if $fielddef.type == 'upload_file' || $fielddef.type == 'select_file'}
            {$fielddef.name|cms_escape}: <a href="{$fielddef.dir|cms_escape}/{$fielddef.value|cms_escape}">{$fielddef.value|cms_escape}</a><br />
        {else}
            {$fielddef.name|cms_escape}: {$fielddef.value|cms_escape}<br />
        {/if}
    {/foreach}
    </div>
{/if}
</div><!-- item -->
{/if}
{/foreach}
Method Two Query The Database For The Record

Create a UDT called listit_get_record
Put this code in the UDT...

Code: Select all

$db_prefix = $params['db_prefix'];
$listit_name = $params['listit_name'];
$itemid = (int)$_GET['cntnt01itemid'];
if (is_int($itemid)) {
  $gCms = cmsms(); //global $gCms;
  $smarty = &$gCms->GetSmarty();
  $db =& $gCms->GetDB();
  $r = $db->Execute("SELECT category_id, title, active FROM ".$db_prefix."module_".$listit_name."_item AS i
    WHERE i.item_id=".$db->qstr($itemid)." LIMIT 1");
  if ($r) {
    $data= array();
    $row = $r->FetchRow();
    $data['title'] = $row['title'];
    $data['active'] = $row['active'];
    $r1 = $db->Execute("SELECT category_name FROM ".$db_prefix."module_".$listit_name."_category AS c
          WHERE c.category_id=".$db->qstr($row['category_id'])." LIMIT 1");
    if ($r1) {
      $rowC = $r1->FetchRow();
      $data['category_name'] = $rowC['category_name'];
    }
    $r2 = $db->Execute("SELECT fielddef_id, value FROM ".$db_prefix."module_".$listit_name."_fieldval AS fv
      WHERE fv.item_id=".$db->qstr($itemid));
    if ($r2) {
      while($r2 && $rowFv = $r2->FetchRow()) {
        $r3 = $db->Execute("SELECT alias FROM ".$db_prefix."module_".$listit_name."_fielddef AS fd
          WHERE fd.fielddef_id=".$db->qstr($rowFv['fielddef_id'])." LIMIT 1");
        if ($r3) {
          $rowFd = $r3->FetchRow();
          $data[$rowFd['alias']] = $rowFv['value'];
        }
      }
    }
    $smarty->assign('itemDetail', $data);
  }
}
The UDT is used like this; inserting your own database table prefix and change the listit_name if you cloned this as a new module.

Code: Select all

{listit_get_record db_prefix='cms_' listit_name='listit'} 
The {$itemDetail} array being returned by this UDT always contains these keys:

Code: Select all

{$itemDetail.title|cms_escape}
{$itemDetail.category_name|cms_escape}
{$itemDetail.active|cms_escape}
The {$itemDetail} array will also contain the alias and value of your custom defined Field Definitions. It can be used like the following; replace alias with the alias you defined:

Code: Select all

{$itemDetail.alias|cms_escape}
Next modify the ListIt template named "default" constructing your own custom template. An example would be:

Code: Select all

{listit_get_record db_prefix='cms_' listit_name='listit'}
{if $itemDetail.active == 1}
<div class="item" style="margin-top:50px;">
  <h2 class="item-title">{$itemDetail.title|cms_escape}</h2>
  <div class="item-category">Category: {$itemDetail.category_name|cms_escape}</div>
  <div class="item-properties">
    Something: {$itemDetail.alias|cms_escape}<br/>
    Something Link: <a href="{$itemDetail.alias|cms_escape}">Something</a><br />
  </div>
</div><!-- item -->
{/if}
URL construction for the Details Page
Then construct a URL to call your new the ListIt Module detail page:
&cntnt01itemid=1 : is the ListIt item_id that is to be displayed
&cntnt01returnid=58 : is the page template to use for displaying your single record.

Code: Select all

http://www.yoursite.com/index.php?mact=ListIt,cntnt01,default,0&cntnt01itemid=1&cntnt01returnid=58
Pretty URLs
If using Mod Rewrite you could clean up the URL by doing the method found in the CMSMS handbook on this page under "For News module":
http://wiki.cmsmadesimple.org/index.php ... stallation

Basically create a subfolder called /listit and add an .htaccess file to it with the following code (change the .htm if you are using a different extension or no extension at all)...

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteBase / 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]*)(.htm)$ index.php?mact=ListIt,cntnt01,default,0&cntnt01itemid=$1&cntnt01returnid=62 [NC,L]
If you didn't want to hard code the page to use as the template you could use a rewrite rule with something like this...

Code: Select all

RewriteRule ^([0-9]*)/([0-9]*)(.htm)$ index.php?mact=ListIt,cntnt01,default,0&cntnt01itemid=$1&cntnt01returnid=$2 [NC,L]
the first INT passed would be used for the ListIt item_id and the second one passed would be used for the page content_id.

What I actually did here was to just add one line to the existing .htaccess file in my ROOT directory. I don't like having a bunch of extra folders on my server. Right before this line:

Code: Select all

RewriteRule ^(.+)(.htm)$ index.php?page=$1 [QSA]
I added my rewrite rule like this:

Code: Select all

RewriteRule ^listit/([0-9]*)(.htm)$ index.php?mact=ListIt,cntnt01,default,0&cntnt01itemid=$1&cntnt01returnid=62 [NC,L]
Summary Index
For this just add some <a href=""> tags to a new summary template, maybe something like...

Code: Select all

{foreach from=$items item=item}
<div class="item">
<a href="weeklyspecials/{$item.item_id}.htm">{$item.title|cms_escape}</a>
</div><!-- item -->
{/foreach}

Re: ListIt Module: How to set up 'Read more' function

Posted: Fri Feb 18, 2011 8:13 am
by nicmare
awesome! thank you owens!!

Re: ListIt Module: How to set up 'Read more' function

Posted: Fri Feb 18, 2011 12:46 pm
by Owens
Your welcome. O0

Thank you for saying thanks!

Re: ListIt Module: How to set up 'Read more' function

Posted: Mon Feb 21, 2011 7:45 am
by allan1412
Thanks Owens - just what I was looking for - and very detailed.

Re: ListIt Module: How to set up 'Read more' function

Posted: Mon Feb 21, 2011 12:40 pm
by Owens
Your welcome allan1412.

ListIt needs some tweaks and it could be a very powerful plugin.

Re: ListIt Module: How to set up 'Read more' function

Posted: Mon Feb 21, 2011 12:43 pm
by nicmare
owens, are you the developer of the plugin? you may want to check out the feature ideas and bug fixes in the forge? O0

Re: ListIt Module: How to set up 'Read more' function

Posted: Mon Feb 21, 2011 1:48 pm
by Owens
nicmare wrote:owens, are you the developer of the plugin? you may want to check out the feature ideas and bug fixes in the forge? O0
No, I'm not the developer, and had nothing to do with the creation of ListIt. That would be Ben Malen (benmalen).