Welcome, Guest. Please login or register.
Did you miss your activation email?
May 24, 2012, 07:57:05 AM

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.
155442 Posts in 21702 Topics by 7735 Members
Latest Member: lq0rrukl036lq
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: page_content feststellen.  (Read 694 times)
willie68

Offline Offline

Posts: 2


« on: October 10, 2008, 02:53:47 PM »

Hallo,
ich brauche eine Funktion mit der man feststellen kann, ob für einen Block Daten vorhanden sind. Z.Z. behelfe ich mich mit folgender Funktion (in frontend.functions. php):

Code:
if (!function_exists('has_page_content')) {
    function has_page_content($block = 1) {
        // Get outside objects
        global $TEXT,$MENU,$HEADING,$MESSAGE;
        global $globals;
        global $database;
        global $wb;
        $admin = & $wb;
        if ($wb->page_access_denied==true) {
            return false;
        }
        if ($wb->page_no_active_sections==true) {
            return false;
        }
        if(isset($globals) AND is_array($globals)) { foreach($globals AS $global_name) { global $$global_name; } }
        // Make sure block is numeric
        if(!is_numeric($block)) { $block = 1; }
        // Include page content
        if(!defined('PAGE_CONTENT') OR $block!=1) {
            $page_id=$wb->page_id;
            // First get all sections for this page
            $query_sections = $database->query("SELECT section_id,module,publ_start,publ_end FROM ".TABLE_PREFIX."sections WHERE page_id = '".$page_id."' AND block = '$block' ORDER BY position");
            // If none were found, check if default content is supposed to be shown
            if($query_sections->numRows() == 0) {
                if ($wb->default_block_content=='none') {
                    return false;
                }
                if (is_numeric($wb->default_block_content)) {
                    $page_id=$wb->default_block_content;
                } else {
                    $page_id=$wb->default_page_id;
                }                
                $query_sections = $database->query("SELECT section_id,module,publ_start,publ_end FROM ".TABLE_PREFIX."sections WHERE page_id = '".$page_id."' AND block = '$block' ORDER BY position");
                // Still no cotent found? Give it up, there's just nothing to show!
                if($query_sections->numRows() == 0) {
                    return false;
                } else {
                    return true;
                }
            } else {
                return true;
            }
        } else {
            return true;
        }
    }
}

Aufgerufen wird das folgender massen:
Code:
<?php if (has_page_content(4)) {
    echo 
"<div class=\"leftcol\">\n\r";
    
page_content(4);
    echo 
"</div>\n\r";
};
?>


Gibt's dazu was besseres?

und Tschoe
Willie
Logged
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #1 on: October 10, 2008, 02:56:08 PM »

Hallo und Willkommen Willi.

Es erschließt sich mir nicht ganz, was Du damit vorhast.
Magst Du mir den "tieferen Sinn" davon erläutern?

MfG,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2294



WWW
« Reply #2 on: October 10, 2008, 03:12:21 PM »

@Stefek: Sometimes you don't want to set the <div> for such a block.

Try this:

Code:
<?php 
// When multiple content blocks are used, they are shown here
ob_start(); 
page_content(4);
$content=ob_get_contents();  
ob_end_clean(); 
if (
$content<>"") { ?>

    <div id="leftcol">
           <?php echo $content?>
    </div>
<?php ?>

Ruud
Logged

Professional WebsiteBaker Solutions
willie68

Offline Offline

Posts: 2


« Reply #3 on: October 10, 2008, 10:26:41 PM »

Hallo und Willkommen Willi.

Es erschließt sich mir nicht ganz, was Du damit vorhast.
Magst Du mir den "tieferen Sinn" davon erläutern?

MfG,
Stefek
Ich möchte einen div nur dann erscheinen lassen, wenn's auch was zum anzeigen gibt.

@Stefek: Sometimes you don't want to set the <div> for such a block.

Try this:

Code:
<?php 
// When multiple content blocks are used, they are shown here
ob_start(); 
page_content(4);
$content=ob_get_contents();  
ob_end_clean(); 
if (
$content<>"") { ?>

    <div id="leftcol">
           <?php echo $content?>
    </div>
<?php ?>

Ruud
Thank you, working great, and i haven't to make 2 sql queries.

bye
Willie
Logged
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #4 on: October 10, 2008, 11:04:31 PM »

Jetzt verstehe ich.
Ich habe einfach nicht begriffen, was Du meinst, wegen der functions.php

Ja, der Vorschlag von Ruud ist sehr gut.
Ich habe grade ein Template ausgearbeitet, das 3 unterschiedliche Blöcke handhabt und zusätzlich dazu ein seitliches Menü einblendet, wenn es zu den oberen Menüpunkten vom Level 0 Childs (Unterseiten) gibt.
Ziemlich interessant diese Vorgehensweise und man kann ziemlich viel da raus holen.

Schönes WE,
Stefek

Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
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!