WebsiteBaker Support (2.12.x) > Modules

Blog_menu mit aktivem Link (class)?

(1/3) > >>

Concilla:
Liebe WebsiteBaker,

ich habe ein blog_menu für eine Newsseite, das die jeweiligen Newsgruppen anzeigt. Leider kann der aktive Link per CSS nicht farbig gestaltet werden, da er keine zusätzliche Klasse enthält. Wenn der  jeweilig angeklickte Link z.B. class=“active“ erhalten würde,  bedürfte es sicherlich Änderungen im Modul (include.php)? Könntet Ihr mir hier bitte helfen? Oder ist das zu kompliziert?

Vielen Dank im Voraus.

dbs:
Hallo, sprichst du vom Modul "blog_menu" und vom Modul "News"?
Die wissen ja eigentlich nichts voneinander, holen sich nur bestimmte Daten aus der Datenbank.

Für die Module blog_menu und blog funktioniert es, wenn man in der include.php von blog_menu die while-Schleife in Zeile 96 so anpasst

--- Code: --- <?php
// diese zeilen nicht, ist nur für bunten code. 
// das li hat eine class="active" erhalten

                  while($history = $result->fetchRow()){
                    // $output .= "<li><a href=\"" .WB_URL.PAGES_DIREC TORY .$page_link .PAGE_EXTENSION ."?y=".$history['y']."&amp;m=".$history['m']."&amp;method=".$date_option."\">" .$history['mo']." ".$history['y']."</a> (".$history['total'].")</li>\n";
                    
                    // mark current blog menu link as active ------------
                    $curr_link = WB_URL.PAGES_DIRECTORY .$page_link .PAGE_EXTENSION ."?y=".$history['y']."&m=".$history['m']."&method=".$date_option;
                    $curr_addr = WB_URL.$_SERVER['REQUEST_URI'];
                    $active    = ($curr_addr == $curr_link) ? ' class="active"' : ''; 

                    $output .= "<li ".$active."><a href=\"" .WB_URL.PAGES_DIRECTORY .$page_link .PAGE_EXTENSION ."?y=".$history['y']."&amp;m=".$history['m']."&amp;method=".$date_option."\">" .$history['mo']." ".$history['y']."</a> (".$history['total'].")</li>\n";
                    // --------------------------------------------------
                }
--- End code ---

Concilla:
Danke für Deine Anwort. Ich habe jetzt eine ganze Weile herum probiert, aber ich bekomme immer ein:

There was an uncatched exception
syntax error, unexpected end of file
in line (107) of (/modules/blog_menu/include.php)

oder in einer anderen Zeile. Bei mir im Modul blog_menu sieht es in der include.php so aus, kompletter Code:


--- Code: ---<?php
// function to display a Blog Menu on every page via (invoke function from template or code page)

if (!function_exists('display_blog_menu')) {
function display_blog_menu($page_id,$date_option = 0,$group_header = '<h1>Categories</h1>' ,$history_header = '<h1>History</h1>',$display_option = 0) {

// register outside object
global $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'];
}

// convert all numeric inputs to integer variables
$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 != "") {
echo $group_header;
}
$output = "";
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;";
$detail_result = $database->query($query_detail);
$num = $detail_result->numRows();
$output .= "<li><a href=\"" .WB_URL.PAGES_DIRECTORY .$page_link .PAGE_EXTENSION ."?g=".$group['group_id']."\">" .$group['title'] ."</a></li>\n";
       }
}
$output = "<ul>".$output."</ul>";
        echo $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 GROUP BY y,m ORDER BY y DESC,m DESC;";
        $result = $database->query($query);
if($result->numRows() > 0){
if ($history_header != "") {
echo $history_header;
}
while($history = $result->fetchRow()){
                $output .= "<li><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'].")</li>\n";
             }
         }
$output = "<ul>".$output."</ul>";
        echo $output;
}

}
}
--- End code ---

Die Zeile 96 ist bei mir eigentlich nur ein "}" und die while-Schleife beginnt in der Zeile 88.

dbs:
Wahrscheinlich weil die Klammern schlecht gesetzt sind im Original.
Deine Datei müsste so aussehen:

--- Code: ---<?php
// function to display a Blog Menu on every page via (invoke function from template or code page)

if (!function_exists('display_blog_menu')) {
    function display_blog_menu($page_id,$date_option = 0,$group_header = '<h1>Categories</h1>' ,$history_header = '<h1>History</h1>',$display_option = 0) {
        
        // register outside object
        global $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'];
        }
        
        // convert all numeric inputs to integer variables
        $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 != "") {
                    echo $group_header;
                }
                $output = "";
                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;";
                    $detail_result = $database->query($query_detail);
                    $num = $detail_result->numRows();
                    $output .=    "<li><a href=\"" .WB_URL.PAGES_DIREC TORY .$page_link .PAGE_EXTENSION ."?g=".$group['group_id']."\">" .$group['title'] ."</a></li>\n";
                  }
            }
            $output = "<ul>".$output."</ul>";
            echo $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 GROUP BY y,m ORDER BY y DESC,m DESC;";
            $result = $database->query($query);
            if($result->numRows() > 0){
                if ($history_header != "") {
                    echo $history_header;
                }
                while($history = $result->fetchRow()){
                    // $output .= "<li><a href=\"" .WB_URL.PAGES_DIREC TORY .$page_link .PAGE_EXTENSION ."?y=".$history['y']."&amp;m=".$history['m']."&amp;method=".$date_option."\">" .$history['mo']." ".$history['y']."</a> (".$history['total'].")</li>\n";
                    
                    // mark current blog menu link as active ------------
                    $curr_link = WB_URL.PAGES_DIRECT ORY .$page_link .PAGE_EXTENSION ."?y=".$history['y']."&m=".$history['m']."&method=".$date_option;
                    $curr_addr = WB_URL.$_SERVER['REQUEST_URI'];
                    $active    = ($curr_addr == $curr_link) ? ' class="active"' : ''; 

                    $output .= "<li ".$active."><a href=\"" .WB_URL.PAGES_DIREC TORY .$page_link .PAGE_EXTENSION ."?y=".$history['y']."&amp;m=".$history['m']."&amp;method=".$date_option."\">" .$history['mo']." ".$history['y']."</a> (".$history['total'].")</li>\n";
                    // --------------------------------------------------
                }
            }
            $output = "<ul>".$output."</ul>";
            echo $output;
        }

    }
}
--- End code ---

edit: fehlende letzte Klammer hinzugefügt...

Concilla:
Nein, tut mir leid. Bei mir wird leider keine Klasse "active" hinzugefügt  :-( Ich habe den Code, so wie von Dir geschickt, komplett ausgetauscht. Es ist alles so, wie es vorher auch war (li ohne aktiver Klasse bei Klick auf eine Gruppe), nachdem ich aus DIREC TORY noch DIRECTORY gemacht habe, da dies Fehler angezeigt hat.

Navigation

[0] Message Index

[#] Next page

Go to full version