Here's a very handy snippet to create a PHP conditional if statement based on a specific K2 item ID:


<?php
$itemid = JRequest::getInt('Itemid');

if( $itemid == 123 ) {
echo 'do something';
} else {
echo 'these are not the droids you are looking for';
}
?>


<?php
$itemid = JRequest::getInt('Itemid');

if( $itemid == 123 ) {
echo 'do something';
} else {
echo 'these are not the droids you are looking for';
}
?>

The code above can be altered using the following hooks from the page URL:


$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
$layout = JRequest::getCmd('layout');
$page = JRequest::getCmd('page');
$task = JRequest::getCmd('task');
$id = JRequest::getInt('id');

Published in Blog

Here's a weird bug that I have identified from time to time. In the template options of T3, the layout field is displaying the full path to each laout option, rather than display each layout name.

Published in Blog
Thursday, 05 January 2017 07:00

Joomla com_content layout overrides

In the following example I will be doing an override to the Category blog layout. If you want to do overrides to the article layouts use the same method but make modifications as required.

The layout changes that I'm going to make are changes to the article feature image and article heading

  1. Move the files from components/com_content/views/category/tmpl into templates/<your_template>/html/com_content/category
  2. rename the name of each file with a unique identifying name. For instance, my new layout is called etsy, so I have renamed the file blog_item.php to etsy_item.php
  3. In the Joomla backend, navigate to the category and assign your new alternative layout. Once this is done, the category should now be successfully using the new layout.

    changing layouts
  4. Let's make some changes to the article heading. Joomla uses a series of building blocks for each part of the layout. You can find them in the layouts directory. For instance, the file generating the article heading can be found in layouts/joomla/content/blog_style_default_item_title.php - Copy this file into your own templates html directory templates/<your_template>/html/layouts
  5. Open up the file generating the article layout from your html directory. Mine can be found in templates/<your_template>/html/com_content/category/etsy_item
  6. Find the line that generates the heading:

    <?php echo JLayoutHelper::render('joomla.content.blog_style_default_item_title', $this->item); ?>

    Notice how the path name (after the word render) is typed using a series of dots rather than slashes to indicate each directory that the file can be found in.
  7. Modify this line to call up your new layout override. In my case the line becomes the following:

    <?php echo JLayoutHelper::render('blog_style_default_item_title_etsy', $this->item); ?>


    Notice that I have removed the path (after the word render) so that it no longer looks for this file within Joomlas core files. Now it will go straight to my new layout stored in the templates html/layouts directory
  8. Make any modifications to the new layout file as needed. Remember my one is found in templates/<your_template>/html/layouts/blog_style_default_item_title_etsy.php
Published in Blog
Thursday, 25 August 2016 09:29

Using the modules "Note" parameter

The Note field of a Joomla module is intended to display some comment for admin use in the back end, but it's such a handy parameter that it would be a real shame to just waste it on the back end.

One handy use I have for the note field is to use it to display some information on the front end, essentially turning it into a custom field. I quite commonly use it to create a button, using the note field to store the URL link, although it can for virtually any purpose.

The following is an example of how it can be incorporated into the module template file:

<?php

$menuitemid = JRequest::getInt('Itemid');
$db =& JFactory::getDBO();
$query = "SELECT note FROM #__modules WHERE id = '".$module->id."' ";
$db->setQuery($query);
$note = $db->loadResult();

echo $note;
?>

 

Published in Blog
Tuesday, 26 July 2016 05:56

Displaying a module title

Occasionaly it's neccessary to display a module title in a different position within your module overide. I've found that I most commonly need to do this with joomla's built in Custom HTML module. The solution is rather easy:

<?php if ($module->showtitle) {
echo '<h3>' .$module->title .'</h3>';
} ?>
Published in Blog
Monday, 18 April 2016 04:14

Pagination override breaks the site

I've just recently had to work through an issue where I needed to do an override to the pagination.php file. Any attempts to make changes and place it directly into the templates HTMl directory would break the website. Of course, information on why this was happening was pretty much non-existant at the Joomla forums. 

The fix became apparent when I inspected (and tested) the pagination.php override that can be found in one of Joomla's pre-packaged templates protostar. Copying that override and placing it in my own templates HTML directory worked.

For ease of use I have included a gist of the working modified pagination.php file here.

Published in Blog
Sunday, 10 April 2016 10:50

Module positions anywhere

Using this code, you can place a module position inside any php file in joomla:

<?php
$myblurb_modules = &JModuleHelper::getModules( 'my-new-position' );
foreach ($myblurb_modules as $myblurb) {
$_options = array( 'style' => 'xhtml' );
echo JModuleHelper::renderModule( $myblurb, $_options );
}
?>
Published in Blog
Tuesday, 12 January 2016 05:24

Installing Joomla on a Wamp local server

I've just created a quick video walk through of how to install Joomla on a local wamp environment. Mamp is one of those must have tools that all website developers use. It allows the developer to build and modify a database driven dynamic website on your local computer without uploading it to the internet. This allows for very quick development. Whilst for the inexperienced it might seem very complicated, rest assured that with enough practice you will become very quick at doing this.

Published in Blog
Monday, 19 October 2015 12:15

Text limit in Joomla

For com_content use the following:

<?php $truncated_text = JHtml::_('string.truncate', $this->item->introtext, 20); ?>
<?php echo $this->item->event->beforeDisplayContent; ?> <?php echo $truncated_text; ?>

For K2 use the following:

<?php echo JHtml::_('string.truncate', $this->item->introtext, 200); ?>
Published in Blog
Page 1 of 2