Staticpages block

Creating a block listing newly edited staticpages on your site

Here is a simple customisable function that creates a phpblock listing all your staticpages when modified.

Firstly, copy the following code and add it to your lib-custom.php at the bottom of the file.


/*
* phpblock_Staticpages: creates html listing all newly edited staticpages
*                       for inclusion in a block
*
* The function itself is very short and simple, but is set up so you can
* customise it easily.
*
* From Heather Engineering (http://www.heatherengineering.com/)
*/


function phpblock_Staticpages() {
    global $_CONF,$_TABLES;

// ------------------- CUSTOMISE THESE VARIABLES TO SUIT ------------------- //

    $lag = 60*60*24*7;             // seconds since edit to display as new
    $nothingnew = "No new pages";  // text to display when no pages to display
    $max_len = 15;                 // maximum length of string to display
    $max_pages = 10;               // maximum number of pages to show

                                   // start tag for date/new text
    $span_s = '<span style="float:right;color:red;font-size:x-small;">';
    $disp = "date";                // if "date" will show date, otherwise will
                                   // return contents of $disp (text/<img> tag
                                   // etc.)
    $span_e = '</span>';           // end tag for date/new text

                                   // format link to show in block
    if ($_CONF['url_rewrite'] == true) {
        $l = '<a href="'.$_CONF['site_url'].'/staticpages/index.php/%s"> %s </a>';
    } else {
        $l = '<a href="'.$_CONF['site_url'].'/staticpages/index.php?page=%s"> %s </a>';
    }

// ---------- YOU SHOULDN'T NEED TO CUSTOMISE ANYTHING BELOW HERE ---------- //

    $retval = '';
    $diff   = time()-$lag;
    $sql = "SELECT sp_id, sp_date, sp_title
            FROM
            ORDER BY sp_date DESC"
;
    $q = DB_Query($sql);
    $nrows = DB_numRows( $q );
    if( $nrows == 0 ) {
        $retval = $nothingnew;
    } else {
        for( $i = 0; $i < $max_pages; $i++ )
        {
            $A = DB_fetchArray( $q );
            if (strtotime($A['sp_date']) > $diff) {
                if (strlen($A['sp_title']) > $max_len) {
                    $A['sp_title'] = substr($A['sp_title'],0,$max_len).'...';
                }
                $retval .= sprintf($l, $A['sp_id'], $A['sp_title']);
                if ($disp=="date") {
                    $d = explode(" ",$A['sp_date']);
                } else {
                    $d = $disp;
                }
                $retval .= $span_s.$d[0].$span_e;
            $retval .= '<br>';
            }
        }
    }
    return $retval;
}

Then, edit the to section of the block to suit - how long to show pages for, what text to show, etc. Each line is well marked, so you should have no trouble working it out.

Next, you need to create the block. From the block manager on your administration control panel, create a new block. Set the title to "Staticpages" or something like that, the name to anything unique you like, and set the topic and position options as you like. Make it a PHP block, and set the name of the function to "phpblock_Staticpages". Finally set access permissions at the bottom of the page and save.

You can also download the code from the downloads section.

|