Droplet -> Blogmenu

sky writer

Maybe this will help others.

I did a code compare between the "Blog Menu" news/view.php and the News V3.5 view.php.  There was just a short bit of code to add over, to fix my issue...

find:

// Check if we should only list posts from a certain group
if(isset($_GET['g']) AND is_numeric($_GET['g']))
    {
$query_extra = " AND group_id = '".$_GET['g']."'";
} else {
$query_extra = '';
}

// Get settings


Change to:


// Check if we should only list posts from a certain group
if(isset($_GET['g']) AND is_numeric($_GET['g']))
    {
$query_extra = " AND group_id = '".$_GET['g']."'";
} elseif(isset($_GET['m']) AND is_numeric($_GET['m']) AND isset($_GET['y']) AND is_numeric($_GET['y']) AND isset($_GET['method']) AND is_numeric($_GET['method'])){
$startdate = mktime(0,0,0,$_GET['m'],1,$_GET['y']);
$enddate = mktime(0,0,0,$_GET['m']+1,1,$_GET['y']);
switch($_GET['method']){
case 0:
$date_option = "posted_when";
break;
case 1:
$date_option = "published_when";
break;
}
$query_extra = " AND ".$date_option." >= '$startdate' AND ".$date_option." < '$enddate'";
} else {
$query_extra = '';
}

// Get settings

sky writer

I had the full Blog Menu working fine through 2.7-2.8.
But now that I have upgraded to 2.8.1, with the News V3.5, the Archive (by date) section doesn't function.  It displays the list, and shows the number of posts within each, but when I click on any of the dates, it just shows the full list of news posts.

I assumed this was because the News V3.5 replaced the ammended blog menu news/view.php file.

So... I tried this droplet.  It does the exact same thing.  Anyone have this working on 2.8.1 with the news V3.5?  Any thoughts on why I might be encountering this issue?

ochsadad

Under WB 2.7 I created a Droplet copying and pasting the code in the block shown above but I get an error message "This Droplet has invalid PHP code"

crnogorac081

Web developer

tiesy


pcwacht

Code taken from the snippet BlogMenu
Minor improvements
1 - If categorie doesn't have items, don't show categorie
2 - Only posts are calculated wich are shown (publishdate!)


// Set default values
if ( !isset($page_id) )        {$page_id=4;}
if ( !isset($date_option) )    {$date_option=1;}
if ( !isset($group_header) )    {$group_header='<h1>Categorie:</h1>';}
if ( !isset($history_header) )    {$history_header='<h1>Archive:</h1>';}
if ( !isset($display_option) )    {$display_option=0;}

// Set globals
global $wb, $database;
//get link to the page
$query = "SELECT link FROM " .TABLE_PREFIX ."pages WHERE page_id=$page_id;";
$result = $database->query($query);
if($result->numRows() > 0){
   $link = $result->fetchRow();
   $page_link = $link['link'];
}
$output='';    
$t = time();
$page_id = (int) $page_id;
if($display_option==0 or $display_option==2){ //show categories
   // query to obtain categories for the selected page
   $query = "SELECT * FROM " .TABLE_PREFIX ."mod_news_groups WHERE page_id=$page_id AND active=true;";
   // make database query and obtain active groups and amount of posts per group
   $result = $database->query($query);
   if($result->numRows() > 0){
       if ($group_header != "") {
           $output .= $group_header;
       }
       while($group = $result->fetchRow()){
           $id = $group['group_id'];
           $query_detail = "SELECT * FROM " .TABLE_PREFIX ."mod_news_posts               WHERE page_id=$page_id AND active=true AND group_id=$id".
             " AND (published_when = '0' OR published_when <= $t)".
             " AND (published_until = 0 OR published_until >= $t) ;";
            $detail_result = $database->query($query_detail);
           $num = $detail_result->numRows();
           if ($num>=1) {
             $output .=    "<a href=\"" .WB_URL.PAGES_DIRECTORY .$page_link .PAGE_EXTENSION ."?g=".$group['group_id']."\">" .$group['title'] ."</a> (".$num.")<br />\n";
           }
             }
   }
   $output1 = $output;
}
if($display_option==0 or $display_option==1){ //show history
   //determine sorting method
   switch($date_option){
       case 0:
                   $date = "posted_when";
           break;
       case 1:
           $date = "published_when";
                       break;
   }
   $output = "";
   //query to obtain history per month for the selected page
          $query = "SELECT MONTHNAME(FROM_UNIXTIME(".$date.")) as mo,MONTH(FROM_UNIXTIME(".$date.")) as m,FROM_UNIXTIME(".$date.",'%Y') as y,COUNT(*) as total FROM " .TABLE_PREFIX ."mod_news_posts WHERE page_id=$page_id AND active=true ".
       " AND (published_when = '0' OR published_when <= $t)".
       " AND (published_until = 0 OR published_until >= $t)".
       " GROUP BY y,m ORDER BY y DESC,m DESC;";
   $result = $database->query($query);
   if($result->numRows() > 0){
       if ($history_header != "") {
           $output .= $history_header;
       }
       while($history = $result->fetchRow()){
                   $output .= "<a href=\"" .WB_URL.PAGES_DIRECTORY .$page_link .PAGE_EXTENSION ."?y=".$history['y']."&m=".$history['m']."&method=".$date_option."\">" .$history['mo']." ".$history['y']."</a> (".$history['total'].")<br />\n";
             }
   }
   $output2 = $output;
}
return $output1."<br / ><br />".$output2;


As allways,
Have fun.

John
[url="http://www.ictwacht.nl"]http://www.ictwacht.nl[/url] = Dutch ICT info
[url="http://www.pcwacht.nl"]http://www.pcwacht.nl[/url] = My first
both still work in progress, since years.....