Search This Blog

How To Create Wordpress Theme from Scratch #4

We come to the most interesting part of Wordpress theme system, the content of our blog itself. In Wordpress, content of blog is stored in posts table. This table is mapped in Wordpress object the_posts(). Open our content.php then change it to make it like code below:

<?php
/**
 * The default template for displaying content
 *
 * @package WordPress
 * @subpackage Dummy
 * @since Dummy 0.000001
 */
?>
        <div id="content"><!-- start content -->
            <?php if (have_posts()): // do we have any post?
                while(have_posts()): // if yes, print some of them
                    the_post();
            ?>
            <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <div class="entry"><?php the_content(); ?></div>
            </div><!-- end post entry looping -->   
            <?php endwhile; ?>
            <?php else:
// if no..., say that I do apologies... ?>
            <p>Woo hoo, nothin' here!</p>
            <?php endif; ?>
        </div><!-- end content -->

Save it, then try it with your browser.
Print multiple posts on our front page

Code above contain only several of Wordpress template tag. We discuss it here:
the_posts(): preparing the post object, get data from posts table.
the_ID(): print ID of post.
post_class(): print the CSS class for styling.
the_title(): print title of post.
the_permalink(): print permalink of post. Permalink is Wordpress way to structure the URL. Make it pretty and readable.
the_content(): print the content or body of the post.

Our theme now show the content.

How to create Wordpress theme from part #1
How to create Wordpress theme from part #2
How to create Wordpress theme from part #3
How to create Wordpress theme from part #4

share and comment


Related Posts :