Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
page-content-blocks depending on the page
#1
Question 
There is a page in the wiki with info about components depending on the page: http://get-simple.info/wiki/components-d...rent_pages.

Can this also be done with pages? So I use different pages as content blocks instead of components, depending on the page.

It seams an easier way to do something similar by using the Simple Input Tabs, or I18N Custom Fields plugin, but I thought if I could do without a plugin.
Reply
#2
Insert in theme's functions.php file:
PHP Code:
if (!function_exists('page_exists')) {
  function 
page_exists($slug) {
    if (
$slug) {
      global 
$pagesArray;
      if (isset(
$pagesArray[$slug]) || file_exists(GSDATAPAGESPATH.$slug.'.xml')) return true;
    }
    return 
false;
  }


Example usage, for subpages named block-whatever (and a another block-default):
PHP Code:
<?php
if (page_exists('block-'.get_page_slug(false))) {
  
getPageContent('block-'.get_page_slug(false));
} else {
  
getPageContent('block-default');
}
?>
Reply
#3
Thanks, that seems to work. It is a bit confusing though at first.
Reply
#4
I just tried to do the same as the example in the wiki but for pages instead of components.
Wrapping the example into another function might make this a bit more clear.
Reply




Users browsing this thread: 1 Guest(s)