0

There are two ways of writing php snippets to place html on the home page and then html on all other pages... This is for Joomla 3.++

<?php
$menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'HTML for HOME PAGE HERE'; 
} else {
echo 'HTML for ALL OTHER PAGES HERE';
} ?>

This code allows for just focusing on the home page only:

<?php
$menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
    echo 'HTML FOR HOME PAGE HERE';
}
?>

What I would like to do, specifically like the second code snippet, is focus on specific pages on the site....

The reason being is A. I don't want to create a template for every other page type I am creating... And B. I don't want to have to place template elements of styling in my html module positions. I feel the custom HTML or blog / article posts should simply be for content insertion.

So is there a way to instead of calling on the $menu->getDefault()) <<<< make that getPage???

Christian Matthew
  • 4,014
  • 4
  • 33
  • 43

2 Answers2

0

Use JInput to get the page information from the request.

Elin
  • 6,507
  • 3
  • 25
  • 47
  • so what would that statement look like in its entirety? – Christian Matthew Jun 21 '14 at 17:26
  • Assuming you have $app, and depending on what you want to select based on something like `if ($app->input->getInteger($Itemid) == 105) { ...}` or `if ($app->input->getString($option) == 'com_weblinks') { ...}` – Elin Jun 21 '14 at 19:46
0

Found the answer. You can do a direct page edit and ifelse edits for multiple pages.

<?php
//This is the code for the page with menu ID 102
$menuID = JSite::getMenu()->getActive()->id ;
if ($menuID == '102')
{
echo '<strong>long</strong>';
}
?>

Here is the code for multiple pages.

<?php
//This is the code for the page with menu ID 6
$menuID = JSite::getMenu()->getActive()->id ;
if ($menuID == '6')
{
echo '';
}
elseif ($menuID == '2') //This is the HTML for page with menu ID 2
{
 echo '';
 }
 elseif ($menuID  == '4') //THis is the html for page with menu id 4
 {
 echo '';
 }
 else  //This is the HTML code for the rest of the pages
 {
echo '';
}
?>

Found the answer here.

Joomla if else for menu by ID or url

Community
  • 1
  • 1
Christian Matthew
  • 4,014
  • 4
  • 33
  • 43
  • is there any performance hits for this solution? As well, I am assuming that I can cut out the last else statement because I don't have the major html on its on and this is only needed where I want to put the html at for other pages. Is this the correct way to understand this? – Christian Matthew Jun 22 '14 at 17:05
  • Is there any disadvantages to doing it this way? like many php calls? – Christian Matthew Jul 09 '14 at 13:59