Fork me on GitHub

Last x articles in sections block  Bottom

Go to page 1 - 2 [+1]:

  • I can't seem to find a block that displays the last x articles in Sections.
    Where to look?
  • 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>&middot;</big></strong>&nbsp;';
                   
        $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...
  • This works great!

    I also want to display the total amount of articles in sections in this block. How do I do that?
  • 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...
  • Could you tell me exactly how? I am no PHP-expert wink
  • 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...
  • This code makes the block disappear. ;)
  • 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...
  • 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...
  • Great! That worked :) What do I have to do to get the total below the list?
  • what?
  • Really, I need help with this. I tried moving one line but that didn't work?
    C'mon? :?:
  • 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...
  • Magicx also wrote a similar block.
    You can download it at http://www.portalzine.de

Go to page 1 - 2 [+1]:

This list is based on users active over the last 60 minutes.