User Tools

Site Tools


de:components-depending-on-the_page

This is an old revision of the document!


Komponentes in Abhängigkeit von einer Seite

Komponente auf genau einer Seite anzeigen

Soll eine Komponente auf genau einer Seite angezeigt werden, kann diese einfach im Template (z.B. im Stadard-Template template.phpgesteuert werden:

<?php if (return_page_slug()=='PAGE') get_component('COMPNAME'); ?>

Hinweis: Unbedingt PAGE mit dem konkreten SLUG-Namen und COMPNAME mit dem konkreten Komponentennamen ersetzen.

Komponente in Abhängigkeit einer übergeordneten Seite

Um eine Komponente in Abhängigkeit einer übergeordnete Seite (Parent) zu landen reicht folgender Eintrag im Template aus.

<?php if (get_parent(0)=='PAGE') get_component('COMPNAME'); ?>

Hinweis: Unbedingt PAGE mit dem konkreten SLUG-Namen und COMPNAME mit dem konkreten Komponentennamen ersetzen.

Bestimmte Komponenten NICHT laden

Um auf bestimmten Seiten die ein oder andere Komponente NICHT zu laden, ist “==” mit “!=” im oberen Code zu ersetzen.

A System for Different Components on Different Pages

The Components might contain a header image, sidebar content, tagline text, anything. If you only want one page to be different it might be simplest to just make a duplicate page template, but if you want them different on each of several pages here is how.

The following text needs to be in a functions.php file in your theme folder:

<?php
if (!function_exists('component_exists')) {
    function component_exists($id) {
        global $components;
        if (!$components) {
             if (file_exists(GSDATAOTHERPATH.'components.xml')) {
                $data = getXML(GSDATAOTHERPATH.'components.xml');
                $components = $data->item;
            } else {
                $components = array();
            }
        }
        $exists = FALSE;
        if (count($components) > 0) {
            foreach ($components as $component) {
                if ($id == $component->slug) {
                    $exists = TRUE;
                    break;
                }
            }
        }
        return $exists;
    }
}
?>

Createa component which will be the default component and name it default. Create components for specific pages and name them to include the page slug of the page into which they should inserted, so name them e.g content-about and content-contact. Then trigger the component in your page template as described:

<?php  if (component_exists('content-'.get_page_slug(false)))
	  {get_component('content-'.get_page_slug(false));}
     else {get_component('default');}	?>

Links

Back to the GetSimple Wiki Contents Page

How to Have Different sidebars

de/components-depending-on-the_page.1399158118.txt.gz · Last modified: 2014/05/03 23:01 by Lars