[SOLVED] ListIt Module: How to set up 'Read more' function
[SOLVED] ListIt Module: How to set up 'Read more' function
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.
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.
Last edited by allan1412 on Fri Feb 25, 2011 8:48 am, edited 1 time in total.
Re: ListIt Module: How to set up 'Read more' function
afaik this is not possible but maybe someone has an idea. i am excited…
Re: ListIt Module: How to set up 'Read more' function
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...
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)...
Method Two Query The Database For The Record
Create a UDT called listit_get_record
Put this code in the UDT...
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.
The {$itemDetail} array being returned by this UDT always contains these keys:
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:
Next modify the ListIt template named "default" constructing your own custom template. An example would be:
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.
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)...
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...
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:
I added my rewrite rule like this:
Summary Index
For this just add some <a href=""> tags to a new summary template, maybe something like...
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;
}
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}
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);
}
}
Code: Select all
{listit_get_record db_prefix='cms_' listit_name='listit'}
Code: Select all
{$itemDetail.title|cms_escape}
{$itemDetail.category_name|cms_escape}
{$itemDetail.active|cms_escape}
Code: Select all
{$itemDetail.alias|cms_escape}
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}
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
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]
Code: Select all
RewriteRule ^([0-9]*)/([0-9]*)(.htm)$ index.php?mact=ListIt,cntnt01,default,0&cntnt01itemid=$1&cntnt01returnid=$2 [NC,L]
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]
Code: Select all
RewriteRule ^listit/([0-9]*)(.htm)$ index.php?mact=ListIt,cntnt01,default,0&cntnt01itemid=$1&cntnt01returnid=62 [NC,L]
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}
Last edited by Owens on Mon Mar 07, 2011 11:00 am, edited 2 times in total.
Re: ListIt Module: How to set up 'Read more' function
awesome! thank you owens!!
Re: ListIt Module: How to set up 'Read more' function
Your welcome.
Thank you for saying thanks!
Thank you for saying thanks!
Re: ListIt Module: How to set up 'Read more' function
Thanks Owens - just what I was looking for - and very detailed.
Re: ListIt Module: How to set up 'Read more' function
Your welcome allan1412.
ListIt needs some tweaks and it could be a very powerful plugin.
ListIt needs some tweaks and it could be a very powerful plugin.
Re: ListIt Module: How to set up 'Read more' function
owens, are you the developer of the plugin? you may want to check out the feature ideas and bug fixes in the forge?
Re: ListIt Module: How to set up 'Read more' function
No, I'm not the developer, and had nothing to do with the creation of ListIt. That would be Ben Malen (benmalen).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?