Joomla! Hacks
A selection of Joomla! customisations created by hypertexture.net in the deployment of our projects...
:: Core Customisations
Scrolling Page Navigation
One aspect of the standard version of Joomla! that has always bothered us here at hypertexture.net is how the page navigation links are displayed when there are more than 10 pages to a particular item.
Normally on the 10th page of an item the displayed page navigation links are as follows, with the current page displayed with a black span tag in place of an anchor:
This format provides no indication to the user that there are more than 10 pages available other than that the 'Next >' and 'End >>' text are links, thereby reducing the usability of the standard Joomla! page navigation function.
In order to improve upon the format of Joomla!'s page navigation links, hypertexture has altered this function to display the current page in the centre of the line of links so that the user can easily jump back and forth through nearby pages:
The page navigation function is duplicated in both the frontend and administrator areas of Joomla!, as well as in the VirtueMart e-commerce component, each of which can be found as follows:
- Frontend : /includes/pageNavigation.php - function writePagesLinks( $link )
- Admninistrator : /administrator/includes/pageNavigation.php - function getPagesLinks()
- VirtueMart : /administrator/components/com_virtuemart/classes/pageNavigation.class.php - function getPagesLinks()
As the above functions are virtually identical, it is simply a case of opening each file in turn, searching for the relevant function and then finding the line defining the $start_loop variable:
$start_loop = (floor(($this_page-1)/$displayed_pages))*$displayed_pages+1;
Then insert the following code immediately after the definition of the $start_loop variable:
if ($this_page > 5 ) { $start_loop = $this_page - 4; }
if ($this_page > ($total_pages - 4) && $total_pages > 10) { $start_loop = $total_pages - 9; }
(The first line sets the start of the list of links to be 4 less than the current page, excluding the first five pages where the previously defined $start_loop variable is used, whilst the second line ensures that at the end of the list of links, ten items are displayed rather than just the current page and the four preceeding ones.)
Et Voilà! Scrolling Joomla! page navigation links...
:: Module Modifications
Social Bookmark Script
We really like Alexander Hadj Hassine's Social Bookmark Script here at hypertexture.net - it's a great little module with a near comprehensive list of bookmarking websites to choose from. However, one important website missing from the available options is Facebook, which we have added to the modified version of Alexander's module available for download below.
» Download hypertexture's modified Social Bookmark Script Module
(We have also replaced the PHP short tags ('<?') in Alexander's code with the standard PHP open tag of '<?php' to improve the functionality of the script.)
:: Template Tamperings
Return to Top Script for SEF URLs
The standard implementation of a return to top link in Joomla! using a PHP $_SESSION[] variable often fails once Search Engine Friendly URLs are implemented on a website, with pages returning to the site homepage rather taking the user to the top of the current page.
This problem can be overcome by including the following JavaScript in the head section of your template's index.php file and then referring to it using an anchor href of "javascript:returnToTop();".
<script type="text/javascript">
function returnToTop(){
var this_page = window.location.href;
if (this_page.indexOf('#') > -1){
var split_link = this_page.split('#');
window.location.href = split_link[0];
}
else {
window.location.href = this_page;
}
}
</script>
(This function basically takes the URL of the page currently being viewed and uses this to provide the return to top link, with the if loop removing any relative anchor that may be present in that URL.)
Component Specific Coding
A handy little technique for displaying component specific HTML, CSS, JavaScript or PHP in your templates is to set up a PHP if loop in your template's index.php file that only runs when the component in question is accessed. For example, an if loop for Joomla!'s Wrapper component would be coded as follows:
<?php if ($option == "com_wrapper"){ ?>
...insert HTML, <style/> or <script/> here...
<?php } ?>
To specify other components, simply replace the 'com_wrapper' in the above code with the name of the component you wish to select.
