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 :)


1282 Votes

41 Comments

Feed
  1. Can you override the XML file?

    This would be a good idea until you lose the ability to update Joomla without losing the param override?

    Cheers
    Phill
  2. Yes, I have seen such cases before
    In fact, the Tcefhi for several sites in the net and found a forum ( منتديات )follows the same method in question, may be the clearest, including
    Special thanks to Mr. filer with all my heart
  3. @Phill

    I was just wondering the same thing the other day and I don't believe it is currently possible. There doesn't even seem to be a way to get this functionality with the use of a plugin.
  4. Since you are modifying the XML this is essentially a Hack.. I dont suppose a override is possible in this case. .But the idea is cool :)
    We are soon releasing a new extension ( 1st Jan 6 PM India Time at techjoomla.com ) that allows you to tag titles of articles with tags like New! Hot! etc.

    It only uses template overides no hacks. I suppose the overide could be modified a bit to make it look like a title icon rather than a tag.. If anyone in interested in this kind of functionality using a extension, let me know.. We can think of incorporating it in the next version..
  5. Thanks a lot for Good Article. I was not aware that joomla 1.5 has template overwriting functionality.

    Thanks
    Shweta
    jobberclub.com ><img src=" />
  6. Good tutorial. Any chance you can publish another to demonstrate styling for dates in article titles as done in the core team blogs?

    Thanks
  7. Is it possible to make these tags show not just pn their category page, but also on the Frontpage for all articles that have them? Cause thats what I really want...
  8. nice article... can you also explain a little more about overriding functionality in styling a few other core aspects such as date? Thanks
  9. Thanks, great post. Can you do a little more information on overriding though?
  10. Overriding functionality for other core aspects would be good too.
  11. Thanks for the code as I have long been looking this for Joomla sites. This should make Joomla sites/contents more SEO friendly.
  12. This idea is great, but I'd like to extend this to be used in individual articles rather than menu items. How would this be done? Really cool!
  13. But how can i access the template parameters in blog.php ?
    I am currently working on a new template and want to give the user the possibility to define global parameters in the template-parameters menu.
    But I cannot figure out, how to access there params inside a template-override (ie: [templatename]/html/com_content/article/default.php

    I've already tried:
    $templ = &JFactory::getTemplate();

    But no Template-Parameters are in this object :\
  14. I am still fairly green at all this sort of stuff.
    I tried this on a test site but cannot get the image to appear. The padding works and even if I change it to float on the right, but cannot get the image to show. Any help would be appreciated?
  15. I had the same problem as bananas: The padding works but the image does not show. I also tried using a .gif instead of a.png, but get the same result.

    Everything went exactly as prescribed, except in the last part of my default.php file I had this:

    article->title; ?>

    ... instead of the OPs:

    escape($this->article->title); ?>

    I tried it both ways with the same result.

    Also, my statements were wrapped in a
    "

    I'm using the JA Purity template with Joomla 1.5x.

    Any ideas?
  16. I have tried exactly waht you said but i still cant get the image to appear
  17. Thanks for a very informative article.
    I have been wondering if there is a way to override header java scripts inserted by a plugin from specific pages like for example the home page. I have clashing java scripts on my home page and would love to use this system to do so.
    Is it possible?
  18. For Bananas and Foxtrot: I solved the same problem changing the image url's from

    to


    Basically I remove the leading '\'.
    Salut!
  19. why you guys just add those icons as a css classes for h1 h2 h3 ?
  20. Thanks for sharing such a wonderful information.I have beens searching for a longtime.
    Thank you.
    ipod
  21. Hello, :-)
    How to use Template Overrides to change the layout of the Joomla contact form ? Which files to changes ?
    Thank you.
  22. great post sir..
    thanks for sharing. really helped a lot here.
    regards,

    --------------------------------------------------
    Ugg Boots | Uggs
  23. Thanks, great post. a little more explanation on how overriding would be great.

    well done so far. 8-)
  24. great post sir..
    thanks for sharing. really helped a lot here.
    regards,
    -------------------------------------------
    UGGS
  25. I don't know what i'm doing wrong but I just spent over an hour going through this tutorial but it's not working.
  26. It's a good starting point but with no further possibility (for my knowledge) to extend articles styling parameter to frontpage is quite enough usefullness.
    Anyway I learned something new, thanks ;-)
  27. Very nice article but it would be really nice if these parameters could be added to the front page too.
  28. thanks for sharing. really helped a lot here.
  29. thanks for sharing. really helped a lot here.
  30. Appreciate your help. Thank you kindly
  31. joomla is so good. thanks for the great information.
  32. why? confused
  33. good to know about this.
  34. thansk for sharing.:-D
  35. Hi all, anybody know where the best place is for free Joomla templates?
    Many Thanks
  36. That's great, thanks for all the info<img src=" />
  37. You can have the same result by using a System parameter / CSS page suffix into any Menu Voice you want to display icon.

    Simply start the CSS page suffix with a BLANK char (i.e. " poesie") then modify your template adding icons for componentheading (larger) and contentheading (smaller)

    div.componentheading.poesie { 
      background:transparent url(../images/blue/subclass/feather48.png) no-repeat scroll 0 0px;
      padding:12px 54px;
    }
    td.contentheading.poesie { 
      background:transparent url(../images/blue/subclass/feather.png) no-repeat scroll 0 0;
      padding-left:25px;
    }


    ;-)
  38. i have a oomla website. how can i put it on cd. am kinda novice. so gimme the basics.
  39. I don't know what i'm doing wrong but I just spent over an hour going through this tutorial but it's not working. 8-)
  40. Like others, I found this AMAZINGLY useful. And, Like others would love to see this fuctionality on the FrontPage Blog Layout.
  41. Very interesting, but if i'd like to use different size icons? for example, 24 or 32px icons? how can I modify the css?

Add Comment


    • >:o
    • :-[
    • :'(
    • :-(
    • :-D
    • :-*
    • :-)
    • :P
    • :\
    • 8-)
    • ;-)