WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.8 is now available!


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Droplet -> Blogmenu
  • Print
Pages: [1]   Go Down

Author Topic: Droplet -> Blogmenu  (Read 8761 times)

Offline pcwacht

  • Posts: 2923
  • Gender: Male
    • Dutch ICT info
Droplet -> Blogmenu
« 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: [Select]
// 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.....

Offline tiesy

  • Posts: 125
    • Wir in Wallenhorst
Re: Droplet -> Blogmenu
« Reply #1 on: December 10, 2009, 06:32:57 PM »
Hi,
works great. Thanks!
Logged

Offline crnogorac081

  • Posts: 2163
  • Gender: Male
Re: Droplet -> Blogmenu
« Reply #2 on: December 10, 2009, 08:07:35 PM »
wow great staff
Logged
Web developer

ochsadad

  • Guest
Re: Droplet -> Blogmenu
« 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

Offline sky writer

  • Posts: 926
Re: Droplet -> Blogmenu
« 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

Offline sky writer

  • Posts: 926
Re: Droplet -> Blogmenu
« 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: [Select]
// 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: [Select]
// 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

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Droplet -> Blogmenu
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2