Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Include components inside page
#4
DonR Wrote:This is what I'm using to manage and reuse components to be displayed outside the "page" wysiwyg editor. Sometimes some difference in the header, sidebar or other static area of the page is useful.

The i18n component is installed. For the sidebar it could be coded like this:

Code:
<?php
        $page = (string) return_page_slug();
        // echo $page;  //uncomment to see the string for the active page
        if ($page == "index")  
            get_i18n_component('sidebar-custom-1');
        elseif ($page == "contact")
            get_i18n_component('sidebar-custom-1');
        elseif ($page == "testimonials")
            get_i18n_component('sidebar-custom-2');
        else
            get_i18n_component((string) return_page_slug()); // returns a component matching the name of the page
    ?>

I'm new to GetSimple, so please let me know if this flexibility is already handled elsewhere. I didn't find much about making custom code for individual pages and pieced this code from the excellent documentation for the i18n and other plugins. Thank you.

This is exactly the easiest way to have custom sidebars.
You could of cause also test e.g. for the parent of a page like
Code:
if (return_parent() == "products") get_i18n_component('sidebar-products');
to have all products with parent page "products" have the same sidebar ;-)

There is another possibility, if you have only a few custom sidebar components, but lots of pages and want to assign components to pages. You can use the I18N Custom Fields plugin and configure it to have a dropdown field (named e.g. 'sidebar-component') with all possible component names. Then this dropdown field will be shown on every page edit view and you can choose a component to display in the sidebar.
In the template you would just include
Code:
get_i18n_component(get_custom_field('sidebar-component', 'name-of-default-component'));
which will display the selected component or the component name-of-default-component if nothing is selected on the page.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply


Messages In This Thread
Include components inside page - by amaurib - 2011-09-12, 08:04:08
Include components inside page - by mvlcek - 2011-09-12, 15:57:16
Include components inside page - by DonR - 2011-09-13, 05:17:16
Include components inside page - by mvlcek - 2011-09-13, 06:05:13



Users browsing this thread: 2 Guest(s)