Joomla - Change template position based on the Article - php

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 ...

Related

Dynamic title depending on page (DRUPAL 7)

Before I made the switch to Drupal (previously just static HTML), I had a div title in my header that changed depending on what page the user was on using the following code:
ABOUT PAGE
<?php
$title = "ABOUT US</span>";
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/includes/header.php";
include_once($path); ?>
The reason this worked, however, was because I was using static HTML... which means I had every page set to use its own Index.PHP, located at (for the About page, for example) public_HTML/about/index.php. Therefore, I could edit each page individually to my liking by editing its respective Index file...
Now, with Drupal.. instead of having so many Index.PHP files like I did before (which was messy IMO...), I want to have every page use the same page.tpl.php (with the exception of the front page, which uses page--front.tpl.php).
Can I somehow modify the above PHP code to display a different title using IF statements depending on what page the user is on?
For example... (I have no idea how to PHP code so this is just to give you experts an idea of what I would want..)
Ifpage=about, $title=About Us;
Ifpage=contact, $title=Contact Us;
Could this code all be in the same page.tpl.php?
Thank you so much!
Drupal 7 has a title field for each content type. Why don't you use that?
It shows by default and you can change it for every node.
It is this code in your template file.
<?php print render($title_prefix); ?>
<?php if ($title): ?>
<h1 class="title" id="page-title">
<?php print $title; ?>
</h1>
<?php endif; ?>
<?php print render($title_suffix); ?>
$title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
$title: The page title, for use in the actual HTML content.
$title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template.
See https://api.drupal.org/api/drupal/modules!system!page.tpl.php/7 for all the variables available in your page.tpl template file.
If you want to style one part different from the other you could use an extra field for it.
Or if you need to do something with the value (I wouldn't suggest this!!!).
switch ($title) {
case "About Us":
// Do something with the title
break;
case "Contact Us":
// Do something with the title
break;
case 2:
// Do something with the title
break;
}
Here's a simple approach:
Add a new field for the content type
Call it title2
Render the two fields
Use css to inline align them and add styling
Here was my solution since I am unable to position a Drupal-based title block right next to a non-Drupal based logo DIV..
I created a div called .headertitle and positioned/styled it how I want.
My header.php is an PHP include file which is called by each page and the headertitle has a PHP condition..
<?php if(empty($headertitle)) $headertitle = "ASK REAL QUESTIONS, <br><span class='white'>GET FREE ANSWERS.</span>";
echo $headertitle; ?>
That way, if no text is declared for the .headertitle, it takes the default form of "ASK REAL QUESTIONS, GET FREE ANSWERS."
...Now, I had to figure out a way to actually declare text for the .headertitle depending on what page I was on...
I did this by using a custom template for each page (node) by using this file.. "page--node--nodeid.tpl.php".
So, for my ABOUT US page, I created a tpl.php file called "Page--node--7.tpl.php".. for this page, the 7 is the nodeid which is easy to find.
Then, I added the following PHP code to declare text for the .headertitle specifically on the ABOUT US page which looks like this...
<?php $headertitle = "ABOUT<span class='white'>.US</span>"; include('includes/header.php'); ?>
DONE AND DONE.
I'll do that for each page. :)

Contao: Frontend - Get theme section of another page - not the current page

I would need to reach a custom section by page id (or PageModel Object), but I don't find a way to get the FrontendTemplate. I would like to use it in a dropdown navigation to echo a custom section of the hovered (parent) page.
If somebody will search for, the answer is:
<?php
$articles = \ArticleModel::findPublishedByPidAndColumn($id, $column_name);
echo static::getArticle($articles[0]); // for ex. the first article
?>

Dynamic Layout ( Different Layout for each Page )

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.

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
}

wordpress plugin admin menu

I am trying to create a wordpress plugin admin menu. The problem that I am running into is with the menus. I am trying to add a page in the admin without actually adding the menu link. So for example I want to have a menu called test then I want to have some extra pages but I don't want physical links to them because they are only going to be used when there is an id to pass to them. is this possible and if so please someone explain because i can't seem to figure it out.
Yes. In your callback function for the admin page, just write out different sections and use conditional checks to display the right content. Then, under the page's title, add a <ul> with the class subsubsub containing the links to take the user to the right place. Something like this:
function my_awesome_admin_page(){
echo '<h2>My Title</h2>';
echo '<ul class="subsubsub"> <li>Foo</li> <li>Bar</li> </ul>';
if($_GET['foo'] != 'bar'){
//You're on the first page
} else {
//You're on the second page
}
}
I forget what the class is to signify the current subpage, but you can take a look on the 'Add Plugin' admin page. I think it's selected.

Categories