Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QUESTION Variable layout in one web
#1
Hi, I have a problem that I want you to help me with. I have a web (in development) the layout of which is not absolutely identical in all its pages. The pages are grouped in several groups (according to their topic) and each group has other color appearance and other navigation. Apart from that the layout of (almost) all pages is identical:

HEADER - contains the name of the web (and a link to the start page at the same time) which is common for all pages;
--------------
NAME OF THE RESPECTIVE GROUP - and a link to the start page of the respective group, it has background going with the respective group;
NAVIGATION BAR - contains only links to other pages of the same group and has background going with the respective group;
--------------
PROPER CONTENT of the individual page, it has background according to the respective group;
--------------
FOOTER - common for all pages.

The start page of the entire web differs in that it has only the common header and the proper content (of its specific appearance) and the common footer.
And now the question: how should I assemble every page with respect to these differences if I want to use the composite Innovation template (I want that the user can adjust only the proper content of a page through the wysiwyg editor)?
I have searched the forum and found two possible solutions but don't know what is appropriate for me:
1) to use the IM Extra Fields addon - but it looks quite complicated to me and I don't know whether it really does what I require;
2) to use more templates (themes) and to attach the respective template to the concrete page (thread Different layout / themes on each page).
Is one of these two solutions or maybe another solution the best for my demand?
Thank you.
Reply
#2
Using multiple templates is the most simple method to achieving this.

Other option would be to use components and I18N Custom Fields or IM Extra Fields plugin to create a kind of switch that allows switching between different layouts in a single template file. Something like:


PHP Code:
$slug get_page_slug(false);
// Change 12 to your category ID
$item imanager()->getItem(12'name='.$slug);

// Navigation switch
if($item->fields->layout1->value == 1) {
    
get_component('sidebar');
} elseif(
$item->fields->layout2->value == 1) {
    
get_component('navi2');
} elseif(
$item->fields->layout3->value == 1) {
    
get_component('navi1');
} else { 
?>
    <ul>
        <li><a href="#">Item 4</a></li>
        <li><a href="#">Item 5</a></li>
        <li><a href="#">Item 6</a></li>
    </ul>
<?php ?>
Reply
#3
(2017-02-04, 06:23:19)Bigin Wrote: Using multiple templates is the most simple method to achieving this.

And I need different header file for each template, do I?
Reply
#4
If your headers different, then yes
Reply
#5
So I have tried to implement it and it is really easy. But what I am at my wit's end with are navigations. I have tags <nav></nav> in the header of every group of pages where belongs the navigation specific for the respective group (I have no common "central" navigation, see above). But what I should insert between the tags in the template so that the respective navigation appear there? Any modification of the generic "<?php get_navigation(get_page_slug(FALSE)); ?>"? Should I create more navigation files? And how will I determine that links to respective pages should belong to the specific navigation only? Thanks.
P.S. An example what I want: One of my groups of pages calls "Contacts" and has only two pages: "General contacts" and "Contacts to individual employees". So I want that a navigation list containing links only to these two pages appear between <nav> tags in the template on which appearance of the two pages is based.
Reply
#6
Well, maybe I ask too complicatedly. What I need are in fact more navigations. Maybe some plugin makes what I need, I don't know.
But I have one more question: is it possible to insert a link manually? Something like a href="<?php get_site_url(); ?>" which makes a link to the start page but what makes a link to a specific page (according to its slug)?
Reply
#7
(2017-02-12, 20:13:16)lotova Wrote: Well, maybe I ask too complicatedly. What I need are in fact more navigations. Maybe some plugin makes what I need, I don't know.

You can make different menus with I18N, check the docs (on mvlcek's site). Or maybe check the Hierarchical menus plugin.

(2017-02-12, 20:13:16)lotova Wrote: But I have one more question: is it possible to insert a link manually? Something like a href="<?php get_site_url(); ?>" which makes a link to the start page but what makes a link to a specific page (according to its slug)?

You could use something like this:
PHP Code:
<?php $mySlug 'the-slug'?>

<a href="<?php echo find_url($mySlugreturnPageField($mySlug'parent')); ?>">... 

If you must use this in several places, it might be better to put the code in a function in your theme's functions.php and call it.
Reply
#8
I fear as I look at it that it will be a superhuman task for me.

Quote:it might be better to put the code in a function in your theme's functions.php and call it

So, if I use the Innovation theme, the relevant file is .../theme/Innovation/functions.php?
Reply
#9
Yes, that file.

Insert this in functions.php:

PHP Code:
function getPageURL($page) {
  echo 
find_url($pagereturnPageField($page'parent'));


then call it in your template like:
PHP Code:
<a href="<?php getPageURL('your-slug'); ?>"
Reply
#10
Sad 
Thanks. (Although the structure of the function is a mystery for me [Image: sad.gif] ).
Reply
#11
(2017-02-12, 21:54:17)Carlos Wrote: You can make different menus with I18N, check the docs (on mvlcek's site)

Well, I looked at it but it seems to me that everything that relates to I18N requires good knowledge of PHP and how GetSimple works and I have neither so I cannot use it. There is a page "Multiple independent menus" there but I don't understand it ("you can create (empty) dummy root pages" - ?). However, it is written there: "If all but one of the menus are rather static, you could also hardcode them into your template instead". I believe that that is the only way how I can achieve my goal without months of additional studying.
So I decided to manually create five independent menu files, each with links to the required pages and to use the function based on the page slug that you described above with each link and then to include the respective menu file in the corresponding template (because I assume that the end user will not create new pages, only modify existing ones). Like this:

Code:
<nav><?php include('menu1.php'); ?></nav>

But I have a question: where should I locate these menu files so that I can include them this way?
Reply
#12
You can just put your files in your theme's folder and they should be included by your template.

However I suggest you name them menu1.inc.php, etc., so that they get ignored by the template selector in the page editor (or else, some user could select them as page template).

PS If you're going to hardcode the links, perhaps you don't need that function I posted - you can directly paste them in your <a href="..."> tags.
Reply
#13
(2017-02-16, 01:46:22)Carlos Wrote: PS If you're going to hardcode the links, perhaps you don't need that function I posted - you can directly paste them in your <a href="..."> tags.

But I need it. If I had static web with invariable html files I could use directly the names of the html files. But I don't know names of pages (their URL) build in a CMS in advance. What else can I use than a structure like what follows?

Code:
<ul>
<li><a href="<?php getPageUrl('slug1'); ?>">Page1</a></li>
<li><a href="<?php getPageUrl('slug2'); ?>">Page2</a></li>
<li><a href="<?php getPageUrl('slug3'); ?>">Page3</a></li>
</ul>
Reply
#14
I need to ask one more question in connection with my variable layout.

One part of my web has this structure:

Code:
- Page 1 (Parent 1)
  - Page 2 (Parent 2)
    - Page 3
    - Page 4
  - Page 5 (Parent 2)
    - Page 6
    - Page 7

Pages 3, 4, 6, 7 are children of their parents of the second level and these two parents are children of the parent 1. I want that in pages 2-7 a menu is displayed that is common for all these pages but that this menu is not displayed in the page 1 although it has the same layout as its children (so: menu everywhere except of the page 1).
I found a section "Components Depending On The Parent Page" in the wiki but "get_component" is used there. But my menu is not a component created through the Theme editor (Edit components) but a file inserted via include (e.g. <nav><?php include('menu1.php'); ?></nav>) as mentioned in this thread above. How should I achieve the goal in that case? Thank you.
Reply
#15
use i18n menu with custom callout function
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#16
(2017-03-14, 23:38:12)shawn_a Wrote: use i18n menu with custom callout function

I will unfortunately cite myself from above that i18 is without knowledge of PHP impossible to use for me.
Could it be done in a simpler way?
What simple crosses my mind is this:
To include the concrete menu (e.g. 'menu3.php') in the respective partial template (inside the <nav> HTML element) and then to add a simple condition in the template like this (schematically):
Code:
if (page's slug == xx) {do not display the <nav> element}

(I want to skip navigation in one (parent) page in only one specific group of pages where I know the slug of the topmost (parent) page in advance, not generally in all parent pages in the entire web).
Could it be done this way?
Reply
#17
I cant see how you can create custom menus without knowledge of php
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply




Users browsing this thread: 1 Guest(s)