phphtmljoomlajoomla3.3

How can I use PHP to place specific HTML on Certain Pages of my Template?


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


Solution

  • 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