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

WordPress Theme – wp_enqueue_script() and Conditional Tags

March 06th, 2009 | Author: Sunny

Conditional Tag:

Using Conditional Tags for testing whether a certain condition is met, and then returns either TRUE or FALSE.

For example,
is_home() will return TRUE if the main blog page is being displayed.

Some of the conditional tags may contain parameters for conditions.  More information can be found here: http://codex.wordpress.org/Conditional_Tags
Function: wp_enqueue_script():

wp_enqueue_script(handle, src, deps, ver) is a function for adding Javascripts to a WordPress generated page.  It accepts four parameters:

Usage: wp_enqueue_script(handle, src, deps, ver)
handle - (string) Name of the script. Lowercase string.
src - (string) (Optional) Path to the script from the root directory of WordPress. Default is false.
deps - (array) (Optional) Array of handles of any script that this script depends on; scripts that must be loaded before this script.  Default is false.
ver - (string) (Optional) String specifying the script version number, if it has one. Defaults is false.

Category: WordPress | Tags: , , | 1 Comment

WordPress Theme – bloginfo() and include tags

March 05th, 2009 | Author: Sunny

I am learning Flex and iPhone programming right now, but since I have installed WordPress, so I have decided to learn about how to write WordPress Theme first. (Yea.. I just want to learn everything…)

This is my very first WordPress Theme.  Very simple, and kinda modified from the default theme which comes with WordPress.  I actually have hard time to understand the API and function references from WordPress when I was drafting it at the beginning, but it is kinda straight forward.  It is not completely done, and I may just zip it here when it is completed in the future.

mysmallprogramtheme

I am not going to write much detail here, but going to put some references here for myself for future development.

bloginfo() , get_bloginfo():
http://codex.wordpress.org/Template_Tags/get_bloginfo

get_header(), get_footer(), get_sidebar(), comments_template():
http://codex.wordpress.org/Include_Tags

Category: WordPress | Tags: , , | 1 Comment