Welcome, Guest. Please login or register.
Did you miss your activation email?
February 12, 2012, 08:04:04 PM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
149679 Posts in 21101 Topics by 7538 Members
Latest Member: ionline
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Droplet -> Blogmenu  (Read 1359 times)
pcwacht
AddOn Development
*
Offline Offline

Posts: 2814



WWW
« on: December 07, 2009, 08:16:13 PM »

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!)

Code:
// 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
Logged

http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....
tiesy

Offline Offline

Posts: 123


WWW
« Reply #1 on: December 10, 2009, 06:32:57 PM »

Hi,
works great. Thanks!
Logged
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1680



« Reply #2 on: December 10, 2009, 08:07:35 PM »

wow great staff
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
ochsadad

Offline Offline

Posts: 1


« Reply #3 on: January 29, 2010, 03:30:33 PM »

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"
Logged
sky writer

Offline Offline

Posts: 252



« Reply #4 on: February 18, 2010, 05:32:33 AM »

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?
Logged
sky writer

Offline Offline

Posts: 252



« Reply #5 on: February 19, 2010, 10:37:18 PM »

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:
Code:
// 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:

Code:
// 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
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!