Friday, July 19, 2013

Render modukes inside componet - Joomla

<?php
 $modules =& JModuleHelper::getModules('contact');
 foreach ($modules as $module)
 {
echo JModuleHelper::renderModule($module);
 }
 ?>

Where 'contact' is the name of the position

Wednesday, July 17, 2013

Find out all file names used in current page - Wordpress

Just paste this code to know what are the files used to display this page.

$included_files = get_included_files();
$stylesheet_dir = str_replace( '\\', '/', get_stylesheet_directory() );
$template_dir   = str_replace( '\\', '/', get_template_directory() );

foreach ( $included_files as $key => $path ) {

    $path   = str_replace( '\\', '/', $path );

    if ( false === strpos( $path, $stylesheet_dir ) && false === strpos( $path, $template_dir ) )
        unset( $included_files[$key] );
}

print_r('<pre>'); print_r( $included_files ); print_r('</pre>');

Display all posts of a category in Wordpress

In most cases query_posts() function will limit the number of posts from category based the reading input in settings.

To overcome this, pass the parameters to query_posts() as below

 query_posts( array('category_name' => 'some-category-name', 'posts_per_page' => '-1' )); 

In this 'posts_per_page' parameter should be set as -1.

Find which template is currently used - Wordpress

Place this bit of code in functions.php. So that any files inside theme can access this.

add_filter( 'template_include', 'var_template_include', 1000 );
function var_template_include( $t ){
    $GLOBALS['current_theme_template'] = basename($t);
    return $t;
}

function get_current_template( $echo = false ) {
    if( !isset( $GLOBALS['current_theme_template'] ) )
        return false;
    if( $echo )
        echo $GLOBALS['current_theme_template'];
    else
        return $GLOBALS['current_theme_template'];
}

To find the file name, simply echo this function in any of theme files.

get_current_template()