Sunday, 31 January 2016 07:36

Using PHP include to navigate up a folder

On occassion I've needed to include a file that was outside the current the directory. To do so use the following:

<?php
include(dirname(__FILE__)."/../../blocks/mod_events.php");
?>

The include(dirname(_FILE_) returns the current path.

Published in Blog

The following is a conditional to do something if the post is contained within wither of these three categories:

<?php if (in_category( array( gallery,this,another ) )) {
echo 'BINGO!!';
} ?>
Published in Blog

Before you proceed, please note that the code below will remove featured images from all posts on your WordPress site by simply just pasting. Also note that this code will not delete any of your uploaded images, they will still be available in Media Library and you can reuse them anytime.

All you need to do is copy and paste this code in your theme’s functions.php file.

global $wpdb;
$wpdb->query( "
    DELETE FROM $wpdb->postmeta 
    WHERE meta_key = '_thumbnail_id'
" );

As soon as you save your functions.php file this script will run a database query and remove featured images from all posts.

Important: Please remove this code immediately after saving your functions.php file. You will not be able to set featured images in WordPress as this code will keep removing featured images from posts.

 

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
Monday, 12 October 2015 01:19

Adding a favicon to the Joomla T3 framework

One of the annoying bugs of the T3 framework is that it over writes the favicon everytime the framework is updates. To fix this, upload the favicon outside of your template directory. In decided to upload it directly into th root template folder.

Firstly, I put the variable $path at the top of the head. This is only neccassary if you want to dynamically insert the URL - But it's handy to do so, and I suggest you do, otherwise you would have to type the full absolute path.

<?php
$app = JFactory::getApplication();
$path = JURI::base(true).'/templates/'.$app->getTemplate().'/';
?>

 

Put the following into the head block, but make sure it comes after the call to load the T3 head:

<link rel="shortcut icon" href="<?php echo $path; ?>../favicon.ico" />

 

My head block looks something like this:

<?php
// T3 BASE HEAD
$this->addHead();
?>

<link rel="shortcut icon" href="<?php echo $path; ?>../favicon.ico" />
Published in Blog
Friday, 09 October 2015 23:30

Get the active template path

Stick this in the head:

<?php
$app = JFactory::getApplication();
$path = JURI::base(true).'/templates/'.$app->getTemplate().'/';
?>

and call it using the $path variable:

<?php echo $path; ?>
Published in Blog
Sunday, 28 June 2015 04:55

Displaying specific custom fields

There are many times I need to display a spcific custom field inside a post. An example of this is where I have set up custom fields for various social networking URL's, and need to style those URL's into icons or badges. The following shows how I have done this with four custom fields.

Published in Blog
Tuesday, 23 June 2015 23:33

Module position anywhere

The following snippet will create a module position. Place this inside any file, including view files. Replace the text my-new-position with the name of your new module position.

Published in Blog
Page 3 of 3