The Joomla! Community Portal ™

  • Print
  • Email

September 2008

2008-09 Joomla! Community Magazine

Joomla! Community Magazine - Learning

Add Styling Parameters for Joomla! 1.5 Articles Titles

So, what do the pro's do to get cool effects?

Written by Casey Lee

In this article, I'm going to show you a simple way to add a new parameter to a Menu Type that will allow you to add a custom icon to your Joomla! Article Titles. This is much like how the "Page Class Suffix" and "Module Class Suffix" are used for individual item styling. The reason I chose this method instead of just using the Page Class Suffix parameter is because it tends to modify too much of the output. In this simple tutorial, I just want to add one parameter to one element on the page - the Article Title.

 

Preview

 

Create sample data for illustration purposes

Let's create sample data to use as we work through this tutorial. Create a Section called "Articles."

Then, create these three Categories. For these Categories, we will improve usability by adding a relevant icon to each Category Article.

  • FAQ: A category listing of some basic frequently asked questions;
  • Media: A category listing of some basic downloadable media, such as movies;
  • Books: A category listing of some various book titles and reviews.

 

Go ahead and create about four dummy text Articles in each Category. I recommend using the Mass Content extension for this.

Add a Parameter to the Menu Type XML

Now, go to your root Joomla! directory and navigate to components/com_content/views/category/tmpl folder.

Open blog.xml and add the parameter below just after the <advanced> tag. Do the same for the default.xml file.

 <param name="icon_suffix" type="text" default="" label="Article Icon Class" 
description="Adds a class suffix for individual category article title styling"/>

Important note: For illustration purposes, only, "description" begins on a new line in the example above. When you copy the parameter, remove the line break and make certain the entire parameter is on one line.

Create Template Overrides

With Joomla! 1.5, Template Overrides allows us to format output the way we want it, rather than having to use the default layout provided by Core. Template Overrides are very easy to use. Basically, we copy the layout files from the core components into an "html" folder within our template folder. Then, we make changes. When Joomla! finds the layout files in our template/html folder, it uses those files as "overrides" to the Core Layout files.

To do so, go into your /templates/yourtemplatename directory. Create a new directory named "html". Beneath html, create another new directory named "com_content". If there already is an html or com_content directory, that's okay.

Inside the com_content directory, create two folders; one named "article" and another named "category".

Ex: /templates/rhuk_milkyway/html/com_content/category and /templates/rhuk_milkyway/html/com_content/article

Now, copy (not move) the Core components/com_content/views/category/tmpl/blog_item.php file to /templates/yourtemplatename/html/com_content/category Note: if this file already exists, it is best not to overwrite it. You can still continue this tutorial using the file available.

Again, copy (not move) the components/com_content/views/article/tmpl/default.php to /templates/yourtemplatename/html/com_content/article As before, simply use the existing file if one is already there. You can still continue this tutorial.

 

Add styling for the Title Icons to the Layout file

Open the /templates/yourtemplatename/html/com_content/category/blog_item.php file for editing.

You will see the code below with the exception of the highlighted code which is what we will now add and then save this file.

<td class="contentheading<?php echo $this->item->params->get( 'pageclass_sfx' ); ?>" width="100%">
 <?php if ($this->item->params->get('link_titles') && $this->item->readmore_link != '') : ?>
 <a href="/<?php echo $this->item->readmore_link; ?>" 
	class="contentpagetitle<?php echo $this->item->params->get( 'pageclass_sfx' ); ?>">
	<span class="<?php echo $this->params->get( 'icon_suffix' ); ?>"></span>
	<?php echo $this->escape($this->item->title); ?>
 </a>
 <?php else : ?>
	<span class="<?php echo $this->params->get( 'icon_suffix' ); ?>"></span>
	<?php echo $this->escape($this->item->title); ?>
 <?php endif; ?>
 </td>

Now open the newly copied /templates/yourtemplatename/html/com_content/article/default.php file.

You will see the code below with the exception of the highlighted code which is what we will now add and then save this file.

<td class="contentheading<?php echo $this->params->get( 'pageclass_sfx' ); ?>" width="100%">
		<?php if ($this->params->get('link_titles') && $this->article->readmore_link != '') : ?>
		<a href="/<?php echo $this->article->readmore_link; ?>" 
		class="contentpagetitle<?php echo $this->params->get( 'pageclass_sfx' ); ?>">
	<span class="<?php echo $this->params->get( 'icon_suffix' ); ?>"></span>
	<?php echo $this->escape($this->article->title); ?></a>
		<?php else : ?>
	<span class="<?php echo $this->params->get( 'icon_suffix' ); ?>"></span>
	<?php echo $this->escape($this->article->title); ?>
		<?php endif; ?>
</td>

Add in the CSS and Images

Ok, Joomla is pretty much ready for us, so we'll move into the designer's portion of this little tutorial now.

The first thing we'll need to do is to get our icons for the aforementioned categories (FAQ, Media, Books). I like to use the silk icon set because they're already a good size (16px), 32-bit transparent PNG, and of course free.

I've chosen the three below. Feel free to just grab these for now and drop them into your /templates/yourtemplatename/images directory.

  • FAQ
  • FAQ
  • FAQ

 

Then, let's open your template's primary stylesheet (usually template.css) /templates/yourtemplatename/css/template.css and add the following CSS at the bottom:

span.faq {
 background: url(../images/info.png) no-repeat 0px 5px;
 width: 18px;
 height: 20px;
 display: block;
 float: left;
 }
 span.media {
 background: url(../images/photo.png) no-repeat 0px 5px;
 width: 18px;
 height: 20px;
 display: block;
 float: left;
 }
 span.book {
 background: url(../images/book_open.png) no-repeat 0px 5px;
 width: 18px;
 height: 20px;
 display: block;
 float: left;
 }

 

Defining the Style in your Menu Item

Looking at the code above, we can see each class name (i.e., faq, media, book). These are the parameters you will now be able use to input into your Menu Manager

To use these values, login to your Joomla! Administration and create a new Menu Item using the Category Blog Layout Menu Item. (Navigate to Menus -> Main Menu -> and create an Article->Category layout menu item).

In the parameters to the right, you will see an "Advanced" tab where you'll notice a new parameter named "Article Icon Class". You can enter one of these three values: faq, media, or book. After saving your new Menu Item, view the Category Blog from the Frontend of your Joomla! Web site and select the new Menu Item. Once you have "drilled down" to the Article, you will see the new Title Icon.

If you want to change these up or add more, all you need to do is add the CSS class in the last step above. Hope you find a way to use this approach. Have fun with Joomla!



 

Editor Comment

When I invited Casey to share some templating secrets in the magazine, he asked if it would be okay to write a tutorial on how you can add parameters to the XML for Menu Types for use in Template Overrides. I highly encouraged him to do so since many professionals use this approach to get creative solutions. Here's a few tips for upgrades if you decide to do so, yourself.

Before you upgrade:

  1. Copy the changed XML files to your workstation and record the original location of each file.
  2. Perform a normal upgrade (i.e., backup, FTP watching logs closely, overwrite your site with FTP'ed files, etc.)
  3. Look at the original location of each XML file to see if your files are still in place. If a new XML file is there, re-apply your parameters to the changed file.
  4. As always, verify your Web site continues to work, as expected, following an upgrade.

If you decide you want to return to the core file, that's easy enough. Pull it back off of the release distribution. Also, sometimes, people change language files for preferences in word choice. The same approach to upgrading applies there, too.

 

Thanks Casey, great piece!
Amy :)


28 Comments

Feed
  1. Woo,that's really cool,and you have taught me a new way to cool joomla.Thanks, Casey Lee !
  2. As you've hacked a core file dont you run the risk of osing your modifications when you upgrade joomla? Is there another way to achieve this "very cool styling" without hacking the core code. I thought the whole point of template overrides was to avoid hacking core files?
  3. @Steve - Yes, you're right, however we've modified 2 files that are highly unlikely to ever be updated. Hopefully in J!1.6 we'll see the capability to override the xml menu files.
  4. Very cool. Could you give a hint how to make article titles, and maybe default font for article look different in different categories? Even in the frontpage?
  5. Great tutorial, thank you. Like many others I am also a bit worried when I start messing around with core Joomla files but sometimes the result justifies the means. Is there anyway to see some of your work as many of us learn through example and inspiration.
  6. Hi, is it possible to alter the content title according to author instead of article/category?
  7. Nice article, but why not use normal English spelling instead of the apostrophe style (th' instead of the etc). It makes the article less readable.
  8. Way cool. Fantastic Casey!!! Nick
  9. Nice tutorial. As Steve said hacking the core files is not the best approach for styling the websites. I would like to see a tutorial for doing the same but without touching the core files.
  10. Nice, but it is not good idea touching the core files...
  11. Nice tutorial. I've tried it and it's working. But, the same effect could be done either by giving "Page Class Suffix" new parameter + a bit tweaking on css file, while make new menu. How about to make this attribute applied permanently to each article? Even when they are published at the Frontpage?
  12. Hi, this is perfect tutorial, but it is only for category articles, and I want icon_suffix for each article with different image and that are in same category and section, what I must edit ? Thanks.
  13. Cool way to go about this feature but I too find myself worried like Steve K about Joomla upgrades causing issues with component level overrides. That is why when I develop templates to behave in the way described I instead make esentially dynamic style sheets covering component and other Joomla styles and then link those to the Template Parameter System. This approach offers the same level of customizability but is less like to need overhauls between Joomla versions as CSS styles seem to change very little, if at all, between versions of Joomla.
  14. how can I put the image in the home page?? thank
  15. Great tutorial. Thanks
  16. Hi Casey, nice and very simple like you say. But it's too much work for a little result.
  17. Nice article. It was very helpful for me.
  18. this is why i love "joomla community web site" more than "Joomla document web site" . J! doc web site is like "Joomla Encyclopaedia" but "Joomla Community web site" is also like an encyclopaedia but "Joomla Community web site" has great articles with more example like your article. Thanks Casey
  19. very cool this feature, i will integrate it in my [url=http://www.druckerie-dusch.de]T-Shirt[/url] website.
  20. Cool! I hope we can override xml menu files in future versions.
  21. Cool! I hope we can override xml menu files in future versions.
  22. Very nice effects. From Joomla 1.5 and it's MVC is very simple to make this kind of things thank you
  23. Excellent idea and cheers for the tutorial cos it'll allow users to immediately know what type of info they're about to read.
  24. Thanks Casey I have been hesitant to mess arround with any core files but your bog has given me a good place to start understanding the Joomla core.
  25. As you've hacked a core file dont you run the risk of osing your
  26. [b]hello[/b] i will install Joomla in my site after new version i hope add some plugin help for indexing in google like automatic sitemap will add new topic or replay does use ping like WordPress. i'm waiting
  27. This is perfect tutorial But that's only for article which that well be in the category and I want to tray that on my websites' http://www.brg8.com/ and I well see if I can do it on my other one, obviously I'll do it if it was working for me , http://sa30di.com is the other one.
  28. This is perfect tutorial But that's only for article which that well be in the category and I want to tray that on my websites'