I can't seem to find a block that displays the last x articles in Sections.
Where to look?
Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- Guite responded to »Can the Updated Version Check be Turned Off (Z 1.3)« 05:53 PM
- frw responded to »Bug in the SMTP mail transfer protocol - Port 25 - Zikula 1.2.9« 22. May
- mdee responded to »Short URL questions« 22. May
- mesteele101 responded to »Problem in Database Connection« 21. May
- Herr.Vorragend responded to »Clip Documentation and Doubt« 19. May
- mazdev responded to »zikula 1.3.3. and IE9« 19. May
- mesteele101 responded to »How to install Zikula for MSSQL ??? - Part II« 19. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
Last x articles in sections block
-
- Rank: Senior
- Registered: Sep 22, 2003
- Last visit: Oct 21, 2009
- Posts: 2774
Hi - try copying the code below into a file called "sections.php" and put in in your PN's includes/blocks directory. Sections do not store the dates they are published so the sort is done by the artid (newest articles have highest ids)...
Code
<?php
$blocks_modules['sections'] = array(
'func_display' => 'blocks_sections_display',
'func_add' => 'blocks_sections_add',
'func_update' => 'blocks_sections_update',
'func_edit' => 'blocks_sections_edit',
'text_type' => 'sections',
'text_type_long' => 'Latest Section Articles',
'allow_multiple' => true,
'form_content' => false,
'form_refresh' => false,
'show_preview' => true
);
// Security
pnSecAddSchema('Sectionsblock::', 'Block title::');
function blocks_sections_display($row) {
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
if (!pnSecAuthAction(0, 'Sectionsblock::', "$row[title]::", ACCESS_READ)) {
return;
}
$sect_col = &$pntable['seccont_column'];
$url = explode('|', $row['url']);
if (!$url[1]) {
$url[1] = 10;
}
if (!$url[2]) {
$url[2] = 50;
}
$query = "SELECT $sect_col[artid], $sect_col[title] FROM $pntable[seccont] ORDER BY $sect_col[artid] DESC LIMIT $url[1]";
$result = $dbconn->Execute($query);
while (list($artid,$title) =$result->fields) {
$result->MoveNext();
$title = strip_tags($title);
if(strlen($title) > $url[2]) { // Limit title length to avoid wrap
$title = substr($title,0,$url[2]);
$title .= '...';
}
if ($url[0])
$content .= '<strong><big>·</big></strong> ';
$content .= '<a href="modules.php?op=modload&name=Sections&file=index&req=viewarticle&artid='.$artid.'&page=1" class="pn-normal">'.$title.'</a>';
$content .= '<br>';
if (!$url[0])
$content .= '<br>';
}
if ($url[3])
$content .= '<div align="center" class="pn-sub"><a href="modules.php?op=modload&name=Sections&file=index" class="pn-sub">Sections Index</a></div>';
$row['content'] = $content;
themesideblock($row);
}
function blocks_sections_add($row) {
$row['url'] = 'true|10|50|true';
return $row;
}
function blocks_sections_update($vars) {
$vars['url'] = $vars[sections_showbullet].'|'.$vars[sections_total].'|'.$vars[sections_chars].'|'.$vars[sections_showmore];
return $vars;
}
function blocks_sections_edit($row) {
if (!empty($row['url'])) {
$url = explode('|', $row['url']);
$sections_showbullet = $url[0];
$sections_total = $url[1];
$sections_chars = $url[2];
$sections_showmore = $url[3];
} else {
$sections_showbullet = 'true';
$sections_total = 10;
$sections_chars = 50;
$sections_showmore = 'true';
}
if ($sections_showbullet == 'true')
$check_secshowbullet = 'CHECKED="CHECKED"';
if ($sections_showmore == 'true')
$check_secshowmore = 'CHECKED="CHECKED"';
$output .= '<tr><td valign="top">Show Bullet:</td><td><input type="checkbox" name="sections_showbullet" value="true" '.$check_secshowbullet.'></td></tr>';
$output .= '<tr><td valign="top">Number of Articles:</td><td><input type="text" name="sections_total" size="4" maxlength="3" value="'.$sections_total.'"></td></tr>';
$output .= '<tr><td valign="top">Characters in Titles:</td><td><input type="text" name="sections_chars" size="4" maxlength="3" value="'.$sections_chars.'"></td></tr>';
$output .= '<tr><td valign="top">Show Link to Sections</td><td><input type="checkbox" name="sections_showmore" value="true" '.$check_secshowmore.'></td></tr>';
return $output;
}
?>
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info... -
- Rank: Senior
- Registered: Sep 22, 2003
- Last visit: Oct 21, 2009
- Posts: 2774
I think you'd have to do a separate COUNT(*) query on the same table to fetch the total # of sections...
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info... -
- Rank: Senior
- Registered: Sep 22, 2003
- Last visit: Oct 21, 2009
- Posts: 2774
Try pasting this code just above the first $query:
Code
$query = "SELECT COUNT(*) as total FROM $pntable[seccont]";
$result = $dbconn->Execute($query);
$row = $result->GetRowAssoc(false);
$content .= '<span class="pn-sub">There are <b>'.$row[total].'</b> articles in the Sections.</span><br><br>';
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info... -
- Rank: Senior
- Registered: Sep 22, 2003
- Last visit: Oct 21, 2009
- Posts: 2774
I don't think so... I tested myself. Make sure you pasted it in right and paste it here:
Code
if (!$url[2]) {
$url[2] = 50;
}
// NEW CODE HERE
$query = "SELECT COUNT(*) as total FROM $pntable[seccont]";
$result = $dbconn->Execute($query);
$row = $result->GetRowAssoc(false);
$content .= '<span class="pn-sub">There are <b>'.$row[total].'</b> articles in the Sections.</span><br><br>';
// NEW CODE HERE
$query = "SELECT $sect_col[artid], $sect_col[title] FROM $pntable[seccont] ORDER BY $sect_col[artid] DESC LIMIT $url[1]";
$result = $dbconn->Execute($query);
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info... -
- Rank: Senior
- Registered: Sep 22, 2003
- Last visit: Oct 21, 2009
- Posts: 2774
Hi striky,
My bad... The code add-on to count the section stories *was* making the block dissappear for certain themes (but not all of them - weird!). I'm not sure why exactly, here's the new code:
Code
$query = "SELECT COUNT(*) FROM $pntable[seccont]";
$result = $dbconn->Execute($query);
while (list($total) =$result->fields) {
$result->MoveNext();
$content = '<span class="pn-sub">There are <b>'.$total.'</b> articles in the Sections.</span><br><br>';
}
Enjoy!
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info... -
- Rank: Senior
- Registered: Sep 22, 2003
- Last visit: Oct 21, 2009
- Posts: 2774
C'mon striky... FIOFY... ;)
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info... -
- Rank: Senior
- Registered: Sep 22, 2003
- Last visit: Oct 21, 2009
- Posts: 2774
How about c'mon, please?
Paste the block of code five posts up just before these lines where the block output is being done:
Code
$row['content'] = $content;
themesideblock($row);
Alter the code block above slightly so that the
's are in front of the text instead of after it... Enjoy! (if u get errors, just start with the original code)
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info... -
**unknown user**
- Rank: Softmore
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 178
Magicx also wrote a similar block.
You can download it at http://www.portalzine.de
- Moderated by:
- Support
