WordPress Theme – A Very Nice Tutorial

March 11th, 2009 | Author: Sunny

I actually found a very nice tutorial site for designing the WordPress Theme. I will say compare to this site, my blog for designing the WordPress Theme is a mess… haha..

ok, anyway, here you go: http://www.webdesignerwall.com/tutorials/building-custom-wordpress-theme/

It has many tricks too. Good for anyone wants to do some graphic and web design (same as me :) )


WordPress Theme – Sidebar

March 10th, 2009 | Author: Sunny

In WordPress, there are widgets such as calender that may appear on your theme based on your appearance setting. Usually they will appear on sidebar when you add the widgets in the theme. If there is no widget adding to the sidebar, a function dynamic_sidebar() will return a FALSE value. This function is useful if you are designing a theme template because you may want to create something if there is no widget on the sidebar. For example, you may want to include your own widget to the sidebar if user has not included any widget in the theme appearance setting.

Further, if you want to add widget at the appearance setting, you will need to register the sidebar to WordPress in the file function.php. The function register_sidebar() will tell the plugin that your theme will need exactly one sidebar and your admin inteface should have Sidebar Widgets in the Presentation menu. register_sidebar() also allows you to decorate the widget by adding a parameter to it. For example,

<?php
if (function_exists(’register_sidebar’) )
register_sidebar(array(’before_widget’=>’ ‘,
‘after_widget’ => ‘ ‘,
‘before_title’ => ‘<div class=”title”>’,
‘after_title’=>’</div>’));
?>

before_widget and after_widget means that something that you want to decorate the widget.. you may think it can be a warper and you will warp your widgets. In this example, we put nothing, so there is no decoration for this widget warper. Then before_title and after_title, will decorate the wiget title with <div lass=”title”> and </div>. The output will look like this:

<div lass=”title”> Widgets Title </div>

What if you want to include more than one sidebar? Then instead of using register_sidebar(), you will use register_sidebars(n) where n is the number of sidebars. (starting with 1)

For more information, you may check out this page to see how to widgetizing themes with sidebar.
http://codex.wordpress.org/Widgetizing_Themes


WordPress Theme – WordPress Loop

March 08th, 2009 | Author: Sunny

WordPress Loop is the Loop that is used by WordPress to display each of your blog posts.  Using the Loop, WordPress processes each of the posts to be displayed on the current page and formats them within the Loop tags.

Basic WordPress Loop structure will look like this:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!– something you want to repeat within the Loop tag –>
<?php endwhile; else: ?>
<p><?php _e(’Sorry, no posts matched your criteria.’); ?></p>
<?php endif; ?>

Let me explain what is going on. First, you need to know that there is a global object called $wp_query, and when WordPress generates your blog pages, it will build and execute a DB query that results in an array of posts, and which will store in the $wp_query object and also return back to the blog header where it is stuffed into the global $post array.

The have_posts() actually calls $wp_query->have_posts() which checks a loop counter to see if there are any pots left in the post array and return a boolean value TRUE if there is post or FALSE when we have exhausted the loop. And the_post() calls $wp_query->the post() which advance the loop counter and sets up the global $post variable as well as all of the global post data. On the other hand, It takes the current item in the collection of the posts and makes it available for use inside the iteration of the Loop.

Once you understand how the WordPress loop works, then you can use this loop for displaying your blog posts. So, here are some functions that you probably will put inside the WordPress loop:

the_title() – Display the current post’s title

the_time(format) – Display the date with format

the_author() – Display the author name

the_permalink() – a Permanent Link that point to the current post

the_content() – Display the content of the post

There are more technique you can use and display inside the loop. Here I just post some common functions that you will usually use, but there are more function you can do such as comment for the post. You can find more information here:

http://codex.wordpress.org/The_Loop
http://codex.wordpress.org/The_Loop_in_Action

Category: WordPress | Tags: , , | 1 Comment