2

i want to do the next thing:

i'm developing a Joomla website that has a background with some images displaying.

what i want is to display different images depending on the website section displayed, for example:

HOME: ../images/img1.jpg ../images/img2.jpg

ABOUT US: ../images/img3.jpg ../images/img4.jpg

i thought of using some kind of override on the "edit menu item" layout on the back-end to add some new fields where i choose the pictures i want that section to display, and then output those files as HTML on the template.

is there a way to do this?

or maybe there's an easier way.

Techie
  • 44,706
  • 42
  • 157
  • 243

4 Answers4

2

This isn't something you should need to write code for with Joomla as there are a variety of ways to do this using either template style variations (in 2.5+) or various extensions.

We have used the "Menu Dependent Items" extension over the years when we need a simple solution and it works across 1.5->2.5.

Craig
  • 9,335
  • 2
  • 34
  • 38
  • im using joomla 2.5, this seems perfect but i get this error Strict Standards: Non-static method JSite::getMenu() should not be called statically, assuming $this from incompatible context in D:\xampp\htdocs\{sitename}\modules\mod_menu_dep_items\mod_menu_dep_items_class.php on line 75 Strict Standards: Non-static method JApplication::getMenu() should not be called statically, assuming $this from incompatible context in D:\xampp\htdocs\{sitename}\includes\application.php on line 523 – Axel Lijdens Nov 12 '12 at 03:35
  • Strict Standards: Non-static method JApplication::getMenu() should not be called statically, assuming $this from incompatible context in D:\xampp\htdocs\{sitename}\includes\application.php on line 523 Strict Standards: Only variables should be assigned by reference in D:\xampp\htdocs\{sitename}\modules\mod_menu_dep_items\mod_menu_dep_items_class.php on line 75 – Axel Lijdens Nov 12 '12 at 03:37
  • also, i'd like to set more than just one image – Axel Lijdens Nov 12 '12 at 03:46
  • The strict standards **warning** means you have your error level set at "Development" in Joomla! or in your `php.ini` — generally not a problem unless you're running in a very strict environment as it's just a warning. – Craig Nov 12 '12 at 04:30
  • This is the most efficient way to do it. As for the error you're getting, you can disable ESTRICT error reporting. See link for more info: http://stackoverflow.com/questions/1248952/php-5-disable-strict-standards-error – Lodder Nov 12 '12 at 05:37
  • i'm gonna try modify the module to set all images in a folder, thanks! – Axel Lijdens Nov 13 '12 at 01:46
0

If I understand your question

<?php
$menu = &JSite::getMenu();
$menuItem = $menu->getActive();

print_r($menuItem);
?>

Depending on the menu you are in you can output the CSS. Let me know if you have any issues.

Techie
  • 44,706
  • 42
  • 157
  • 243
  • nope, because i need to make an uotput as an tag, and i need a way to add to the "edit/new menu item" on the backend a way to select thepictures that will be shown on that section, like you choose wich modules will be displyed, or the metadata otions – Axel Lijdens Nov 12 '12 at 01:49
  • depending on the menu you get you can echo the img tag. But what you are asking for is to develop a component which does your task. – Techie Nov 12 '12 at 01:54
  • not a component, i just need to add an extra field on the menu displayed when creating a menu item. the idea is just output the "src" of certain images based on the current section of the website – Axel Lijdens Nov 12 '12 at 02:12
  • just got what you want. then you will have extend the core files. let me look into that – Techie Nov 12 '12 at 02:14
0

I agree with using template styles.

Copy your template and add a new parameter for background image to template.xml. Then add the code to insert the image to index.php for the template.

Then make a style for each image that you want to use.

Assign the appropriate style to the appropriate menu items.

Elin
  • 6,507
  • 3
  • 25
  • 47
0

This may helpful to u....

First you must create a field in administrator/components/com_menus/models/forms/item.xml

example

<field name="your_fieldname" type="media"
                label="fieldname"
                description="Give your field description" />

Add this line in administrator/components/com_menus/views/item/tmpl/edit.php

<li><?php echo $this->form->getLabel('your_fieldname'); ?>
<?php echo $this->form->getInput('your_fieldname'); ?></li>

Add one more field in yourtableprefix_menu,field name must be your fieldname.

Added

in file includes/menu.php,function load()

add your fieldname in the following line

$query->select('m.id, m.menutype, m.title, m.alias, m.path AS route, m.link, m.type, m.level, m.language,m.our_image');

i am added m.our_image,like this you can add your fieldname

In index.php file

$menu = &JSite::getMenu();
$menuItem = $menu->getActive();
print_r($menuItem); 
echo $menuItem->your_fieldname; //for get the particular value
rynhe
  • 2,509
  • 1
  • 21
  • 27
  • 1
    I really would not edit core files in this way. Among other things they will be overwritten potentially when you update. If you really want to add a field you should use a plugin to do it. – Elin Nov 12 '12 at 06:47