Dynamic Layout ( Different Layout for each Page ) - php

I'm trying to implement different layouts in Joomla. I'm using the Alias Name for setting
different layouts for each page. I read an E-book about Joomla and there's no another method to create different layouts and or set it in the Backend Panel.
I wanted to ask, is there be another method / way to set a different page from Backend Panel for each page ? I just want to make sure it's possible in Joomla 1.5.
My Previous Method
// Get Alias Page
function getCurrentAlias(){
$menu= &JSite::getMenu();
$active= $menu->getActive();
return $active->alias;
}
After getting the Alias page name, I used a conditional statement to get different content
for each page.
<-- Header Part -->
<-- Start Content Part -->
if( $pageName == "home" ){
{{Content Home}}
}elseif( preg_match("#^(news).*$#", $pageName) ){
{{Content News}}
}...etc
<-- End Content Part -->
<-- Footer Part -->

First, I wold recommend not using 1.5, it reaches end of life next month.
however, if you are going to use 1.5, you are making it a lot harder than you need to. If you want to have significant structural differences from one page to another, you can install a template for each different structure you would like to use, then assign each template to the appropriate menu item. You would have to create menu items, even if they are in a hidden menu that is not displayed on the site.
You can also control the structure of the page using CSS and collapsible module positions. Add this so you can set a page class suffix that adds an ID to the body tag of the page, making it easy to have page specific CSS:
<?php
$menu = &JSite::getMenu();
$active = $menu->getActive();
if (is_object( $active )) :
$params = new JParameter( $active->params );
$pageclass = $params->get( 'pageclass_sfx' );
endif;
?>
<body id="<?php echo $pageclass ? $pageclass : 'default'; ?>">
Then for each of the module positions on the page, you can make them collapsible so they do not show up on the page if they are not being used:
<?php if ($this->countModules('top')) : ?><div id="top"><jdoc:include type="modules" name="top" style="xhtml" /></div><?php endif; ?>
So basically, if you don't put any modules in the "top" position it never gets put on the page. Using these 2 items in combination you can control exactly how each page looks with a single template.

When we where using Joomla! 1.5 we used an extension called "Menu Dependent Items" to load particular CSS, JS etc
Through loading the right CSS etc we where able to completely relayout any given page.
Of course with the advent of template "Styles" in Joomla! 2.5+ we no longer need it as we can assign just the style variation to the menu item.

Related

Styling separate elements on a page in Wordpress

Using Wordpress I am designing a theme for a client's website.
I have set the landing/home page to a static page, and I'm using front-page.php as the default template for this.
My question is how can I style individual elements on the page when all of the page content is called in at once using <?php get_template_part( 'template-parts/content', get_post_format() ); ?>
Currently I multiple <div>'s in the WP page content editor like so:
However, I'm concerned that my client or something else, may delete this content by accident and completely spoil the design. How can I separate content and style it accordingly in my template?
My question is how can I style individual elements on the page?
There are always body classes you can use for different pages/posts.
How can I separate content and style it accordingly in my template?
There are few options depend on what you need:
Turn off "Visual" editor mode for each user account. It sort of helps.
Move the custom HTML into the template files. If that's OK.
Use custom fields, preferably with Advanced custom fields plugin.
For every page,if you need the alone class then function :body_class() : is sufficient.Syntax :- < body < ?php body_class(); ?> > and you can also implement the another function : post_class : for the loop class.Syntax :- < body < ?php post_class(); ?> >

In Wordpress, how can I change the destinations of my links dependent on what page user is on?

I have the problem that I am using a theme where the navigation is simply 'scrolling' to a given part (eg. #contact) when pressed. However, I have implemented some seperate subpages that exits this scrollable page and thus renders the navigation ineffective.
My question is, how can I change the destination of my links or maybe change the menu entirely when users are on these subpages?
I should clarify that all the pages that need 'the new' navigation use a different page template called full_width.php. But since it is using an include header function I can't just replace the navigation.
Thank you for your time!
Here is simple solution based on templates.
if ( is_page_template('full_width.php') ) {
//menu for full width page
} else {
// Returns false when 'full_width.php' is not being used.
wp_nav_menu( $args );//read for args in codex to make menu you want.
}

Joomla - Change template position based on the Article

I need to change some positions on the Joomla template based on the article loaded.
Ex: I need to use different set of positions for a home page and different set of positions for inner pages. There are some common positions as well (Menu, Header, Footer,etc...).
Okay this is a bit tricky, you can get the current page name (menu name) and then make if statements for each "page" you made in the template source, i'll give an example ... Let's say you have a contact page and you want to add a position to it if the user is on the contact page ...
<?php
$currentpage = JSite::getMenu()->getActive()->name ;
// in joomla 2.5
$currentpage = JSite::getMenu()->getActive()->title;
if($currentpage == "Contact"){
echo '<jdoc:include type="modules" name="Contact" />';
}
?>
And so you have to workout your whole template and anticipate for each page, this was a simple example and it's up to you to expand it ...

Accessing $_SESSION from outside of Joomla

I used Joomla 1.5 for a site that I developed for a gaming company. Part of the site consists of a character generater for the game that they developed. The issue is that users want to be able to print the character sheets off, without having the Joomla template surrounding it.
As for the specifics, I have the directphp extension installed, and the entire generator is written in PHP (with a little JavaScript to handle things that PHP can't). As the generator spans several dozen page calls, it made sense to store everything in $_SESSION. All of this works correctly. In an attempt to make the final sheet printer friendly, I tried redirecting the user to a page outside of Joomla (though on the same server, and even within the same folder) but I cannot access the $_SESSION data from this new page.
I have seen several posts (a few on this site) that point to loading the Joomla Framework and accessing it that way, which I have tried, but the data that I was looking for does not appear to be contained there. Has anyone come across this problem before, or know how to get to that data?
You are making this WAY harder than it needs to be. You don't have to write any additional code to accomplish what you are trying to do. In order to print our the component output without all of the Joomla template, you just append ?tmpl=component to your URLs and Joomla will display only to component output without any of the template. If you want to give it a custom stylesheet or anything special, you can also add in a template override by adding a file named component.php in your template folder.
In order to control the CSS per page, you can add Page Class Suffixes in the menu items. Then add this code to index.php so you can use them.
Somewhere in the head add this:
$menu = &JSite::getMenu();
$active = $menu->getActive();
$pageclass = "";
if (is_object( $active )) :
$params = new JParameter( $active->params );
$pageclass = trim($params->get( 'pageclass_sfx' ));
endif;
Replace your body tag with this:
<body id="<?php echo $pageclass ? $pageclass : 'default'; ?>">
Any page that you do not specific a Page Class Suffix for will use default as the body ID, any that you do will use what ever you specify.

Joomla : How can we assign a different layouts to different menu IDs?

I am running Joomla and seeking you help for the following issue.
Lets say I have 3 layouts in my template and the layout files are named as...
index.php
index2.php
index3.php
I have 5 menu links say....
Link 1
Link 2
Link 3
Link 4
Link 5
What I am looking for is......
For Link 1, Link 4 and Link 5, I want Joomla to load the regular index.php but for Link 2 I want Joomla to load index2.php and similarly for Link 3 I want it to load index3.php.
What I mean is... How can we assign a different layouts to different menu IDs?
I know there is an inbuilt option to choose a different Template based on menu ID but I do not want to duplicate the template files just for this one function. Everything in my templates is the same just the change is in the layout depending on the Menu ID.
Kindly Help.
Are you using a commercial template or something custom? You should be able to code your index.php so that the layout is determined by the modules loaded on the page. You then control what modules show up by the menu assignments in the module parameters. You can control the layout being displayed through CSS, Page Class Suffix, and the code on index.php.
Every module position in your template should be collapsible - meaning that if no modules are loaded to the position, it does not get added to the HTML. Use something like this:
<?php if ($this->countModules('left')) : ?>
<jdoc:include type="modules" name="left" style="xhtml" />
<?php endif; ?>
You can also use a combination of the Page Class Suffix that you can set on the System Parameters of a menu item and CSS to control the layout of the page. I add the Page Class Suffix to the BODY tag of my templates so I can control every page individually.
First, you need to figure out which menu item you are on:
<?php
$menu = &JSite::getMenu();
$active = $menu->getActive();
if (is_object( $active )) :
$params = new JParameter( $active->params );
$pageclass = $params->get( 'pageclass_sfx' );
endif;
?>
Then you need to add that to the BODY tag as an ID:
<body id="<?php echo $pageclass ? $pageclass : 'default'; ?>">
Now you can use module positions and CSS to control every page. You can achieve vastly different layouts without having to go back in and touch code.
I always use include_once or for security purpose require_once, from my point of view it is a better way of programming in the template process.
- What do you think ?
- Example I would do this way :
(isset($_GET['Itemid']))?$itemID=$_GET['Itemid']:"";
OU POUR LES PURISTES DE JOOMLA :
$itemID=JRequest::getInt('Itemid',0);
if($itemID == '57')
{
require_once ("index1.php");
}
if($itemID == '58')
{
require_once ("index2.php");
}
else
{
// template code of index.php
}
On the basis of your menu ID (ItemID) you can include a different index<x>.php in your main index.php, like so:
$itemID = $_GET['ItemID'];
if($itemID == '57')
{
include index1.php
}
if($itemID == '58')
{
include index2.php
}
else
{
// template code of index.php
}

Categories