3 Useful WordPress Tips
With the new release of WordPress I thought it would be timely to show some examples of useful WordPress snippets to help you in your quest to build brilliant blogs/cms websites. Though these examples are relatively simple they’re all equally essential to help you in building a great site. Below are the examples which you can go and use immediately in your very own site.
Template Files
Sometimes you will want to customise your theme quite heavily and add additional blocks of content into certain pages on your site for example: Home or About Us. To make things easy for yourself you can create a Template name which can be selected within the admin panel of the page under Attributes > Template. To do this you would create your own file named whateveryoulike.php and put the following php before the code you wish to use as the template.
<?php
/**
* Template Name: My Template
*
*
* The "Template Name:" bit above allows this to be selectable
* from a dropdown menu in the page admin.
*
*/
?>
Now, select the template in the page admin area and you will see your page using the template you have created.
Linking To Images
When creating your own theme the easiest way to display images in your theme that haven’t been set within the CSS is to use this useful code snippet.
<img src="<?php echo bloginfo( 'template_directory' ) . ( '/images/myimage.gif' ); ?>" alt="My Image" />
This will search your themes images folder and pull out the image directly.
Including Files
You may be familiar with php includes but within WordPress it is better to call the include in a certain way.
<?php include( TEMPLATEPATH . '/header2.php' ); ?>
This little snippet has help me greatly and I think you may equally find it useful when developing more complex themes.
Related posts: