Web Blog | Blog, Design, Create, cssOrigins.com

WordPress unleashed

For those of you out there that are wordpress developers this probably isn’t new or exciting information. But this is to those of you who just started or have very little php or otherwise programming experience.

Note that this article takes at the bare minimal a basic programming understanding (ie what a variable is, and that code is logical)

The if () { }

if statements are great if your looking to target specific content with your dynamic values, for instance call a sidebar only on the home page.

<?php if (is_front_page()) {
get_sidebar();
} ?>

or if you would like to target multiple pages, its very similar

<?php if (is_page(’2,3,6,home’)) {
// do stuff here on those specific pages,
}

Outside the loop

Calling your own posts or categories

<?php
$my_query = new WP_Query(‘category_name=yourcategory&showposts=4′);
echo ‘<ul>’;
while ($my_query->have_posts()) : $my_query->the_post();
echo ‘<li> stuff goes here </li>’;

endwhile;
echo ‘</ul>’;
?>

Custom Fields

call your custom field right before you need it
$key=”yourcustomfield”;
then simply call echo the key like so
echo get_post_meta($post->ID, $key, true);

a custom key can contain pictures, html, code.

HTML in php code

<?php echo ‘ <div>all this is html</div> ‘; ?>  make sure you end your echo quotes and use your semicolen to indicate the end of a statement. while everything else inside will be printed to the screen

Utilizing just these things can utterly unleash wordpress you will no longer be constrained to what you can put on your sidebar or you can hand craft your home page to pull posts from different sources. The possibilities are endless.

Some examples are as follow

  1. dynamically add or remove the sidebar from a page or post
  2. create custom banner images for each unique page
  3. call post titles in your sidebar that relate to the one the user is currently looking at

All this and more while keeping your site still around 90% editable in the designers eye and easily manageable in the clients eye.

I would like to mention that since the best and easiest way for editing material in custom places is by calling the categories they are associated with. This in turn can leave you with many categories some of which the client should add and edit and others maybe not so much. But my point is that it’s important to document those things and provide them to the client at the completion of your contract. It’s a good practice and it covers your bases, and outlines what can and cannot be changed within their site if you “sold” them that ability in the first place.

Tags: , , , , , , ,

2 Responses to “WordPress unleashed”

  1. John says:

    <?php if (is_page(’2,3,6,home’)) {
    // do stuff here on those specific pages,
    }

    you need this to be an array do you not?
    <?php if (is_page(array(’2,3,6,home’))) {