Monday, March 4, 2013

[Wordpress] Wordpress theme tutorial for beginners (3) - Dynamic Blog Content

This article is continued with [Wordpress][Tutorial with image] Wordpress theme tutorial for beginners (2), After created the basic interface , let make some dynamic blog content!

After adding the code , your blog will be able to display the blog categories, Archives, and also the blog content let add the code to sidebar.php first:

Add code into sidebar.php


    <div id="sidebar">
    <!-- Side Bar Categories -->
    <h2 ><?php _e('Categories'); ?></h2>
    <ul >
    <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
    </ul>
    <!-- Side Bar Archives -->   
    <h2 ><?php _e('Archives'); ?></h2>
    <ul >
    <?php wp_get_archives('type=monthly'); ?>
    </ul>   
    </div>

Remarks :
Function wp_list_cats() is for call the Categories
wp_list_cats(‘arguments’);wp_list_cats('sort_column=name&optioncount=1&hierarchical=0');
Reference:http://codex.wordpress.org/Function_Reference/wp_list_cats Function wp_get_archives () is for call the Blog Archiveswp_get_archives( $args );wp_get_archives('type=monthly'); Reference:http://codex.wordpress.org/Function_Reference/wp_get_archives

Add code into index.php

asdsad
 <?php get_header(); ?>
    <div id="content">    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>    <h1><?php the_title(); ?></h1>    <h4>Posted on <?php the_time('F jS, Y') ?></h4>    <p><?php the_content(__('(more...)')); ?></p>    <hr> <?php endwhile; else: ?>    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>    </div><?php get_sidebar(); ?><?php get_footer(); ?>


The structure is about checking is there any posts first. 
If there is any post, print the title, post time and content.
Otherwise, display the text “Sorry, no posts matched your criteria”

Result :




Reference:

No comments :

Post a Comment