Thursday, 27 April 2017 05:44

Get entry type. Is it a post or a page?

Here's a handy little snippet that determines if an entry is a post or page within a loop. I found this usefull for determining the entry type within search results, where I wanted to style the results differently depending on what type of result it was.

$pagetype = get_post_type( $post_id );

echo $pagetype;

if ($pagetype == "post") {
// do something

Published in Blog
Tuesday, 21 February 2017 11:46

Custom post types in a loop

The following creates a loop of custom post types. This example creates a testimomnials block. 

<?php $loop = new WP_Query( array( 'post_type' => 'testimonial',
'posts_per_page' => 4 )
); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

$clientname = (types_render_field( "client-name", array( 'raw' => true) ));
$quote = (types_render_field( "quote", array( 'raw' => true) ));

<p><?php echo $quote; ?>&nbsp;<span><?php echo $clientname; ?></span></p>

<?php endwhile; wp_reset_query(); ?>

Check this article for more information

Published in Blog

Put the following in the themes functions.php file:

function is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;

Test it using the following conditional within your theme:

<?php if (is_blog()) { echo 'You are on a blog page'; } else { echo 'no blog'; } ?>
Published in Blog
Wednesday, 11 January 2017 01:09

Modifying the comments form

Take a look in the themes comments.php file and you will see a line where the comments area is called in using:

<?php comment_form(); ?>

In some cases I found it was contained within a conditional like this:

if ( comments_open() ) comment_form();

You can replace it with the following code, injecting in any modifications to the fields as you need:

if ( comments_open() ) { ?>

<?php $comment_args = array( 'title_reply'=>'Leave a reply',

'fields' => apply_filters( 'comment_form_default_fields', array(

'author' =>
'<div class="row">
<div class="large-4 columns comment-form-author">' .
'<input id="author"
name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
'" size="30"' . $aria_req . ' placeholder="Name*" />

'email' =>
'<div class="large-4 columns comment-form-email">' .
'<input id="email" name="email" type="text"
value="' . esc_attr( $commenter['comment_author_email'] ) .
'" size="30"' . $aria_req . ' placeholder="Email*" />

'url' =>
class="large-4 columns comment-form-url">' .
'<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
'" size="30"
placeholder="Website" />
</div>', )

'comment_field' => '<div>' .

'<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" placeholder="Comment*"
></textarea>' .


'comment_notes_after' => '',


comment_form($comment_args); ?>

<?php } ?>
Published in Blog
Wednesday, 11 January 2017 00:17

Changing the default "read more" link

This function tells WordPress to remove the default more which looks like this: […], and replace it with a link.

Open your functions.php file, and paste the following code inside the php tags:

// Changing excerpt more
function new_excerpt_more($more) {
global $post;
return '… <a href="'. get_permalink($post->ID) . '">' . 'Read More &raquo;' . '</a>';
add_filter('excerpt_more', 'new_excerpt_more');


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
Tuesday, 22 November 2016 11:03

Adding widget areas using functions.php

The following code inserted into your child themes functions.php file will create two new widget areas called banner and dropmenu:

* Register our sidebars and widgetized areas.
function arphabet_widgets_init() {

register_sidebar( array(
'name' => 'banner',
'id' => 'banner',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );

register_sidebar( array(
'name' => 'dropmenu',
'id' => 'dropmenu',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );


add_action( 'widgets_init', 'arphabet_widgets_init' );


Create a hook in your theme by using the following: 

<?php dynamic_sidebar( 'dropmenu' ); ?>
Published in Blog
Saturday, 17 September 2016 02:28

Echo the page name

Here is a quick and wasy way to display the page heading inside a wordpress template:

<h1 class="pageheading"><?php global $post;
echo $post->post_title; ?></h1>

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:


$menuitemid = JRequest::getInt('Itemid');
$db =& JFactory::getDBO();
$query = "SELECT note FROM #__modules WHERE id = '".$module->id."' ";
$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
Page 1 of 2