Theme là phần không thể thiếu với Website wordpress, bằng một vài thao tác đơn giản bạn có thể tự viết một theme zin cho mình. Đăng nhập vào phần quản trị wordpress tạo một folder mới. Trong đó tạo những file sau :
comments-popup.php , comments.php , footer.php , functions.php , header.php , index.php , rtl.css , screenshot.png , sidebar.php , style.css
Nó sẽ có dạng thế này
Trong file comments.php copy và paste đoạn code sau vào
<?php
if ( post_password_required() ) : ?>
<?php _e('Enter your password to view comments.'); ?>
<?php return; endif; ?>
<?php comments_number(__('No Comments'), __('1 Comment'), __('% Comments')); ?>
<?php if ( comments_open() ) : ?>
<a href="#postcomment" title="<?php _e("Leave a comment"); ?>">»</a>
<?php endif; ?>
<?php if ( have_comments() ) : ?>
<?php foreach ($comments as $comment) : ?>
<?php echo get_avatar( $comment, 32 ); ?>
<?php comment_text() ?>
<cite><?php comment_type(_x('Comment', 'noun'), __('Trackback'), __('Pingback')); ?> <?php _e('by'); ?> <?php comment_author_link() ?> — <?php comment_date() ?> @ <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a></cite> <?php edit_comment_link(__("Edit This"), ' |'); ?>
<?php endforeach; ?>
<?php else : ?>
<?php _e('No comments yet.'); ?>
<?php endif; ?>
<?php if ( comments_open() ) : ?>
<?php _e('Leave a comment'); ?>
<?php if ( get_option('comment_registration') && !is_user_logged_in() ) : ?>
<?php printf(__('You must be <a href="%s">logged in</a> to post a comment.'), wp_login_url( get_permalink() ) );?>
<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<?php if ( is_user_logged_in() ) : ?>
<?php printf(__('Logged in as %s.'), '<a href="'.get_option('siteurl').'/wp-admin/profile.php">'.$user_identity.'</a>'); ?> <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="<?php _e('Log out of this account') ?>"><?php _e('Log out »'); ?></a>
<?php else : ?>
<input type="text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1" />
<?php _e('Name'); ?> <?php if ($req) _e('(required)'); ?>
<input type="text" name="email" id="email" value="<?php echo esc_attr($comment_author_email); ?>" size="22" tabindex="2" />
<?php _e('Mail (will not be published)');?> <?php if ($req) _e('(required)'); ?>
<input type="text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3" />
<?php _e('Website'); ?>
<?php endif; ?>
<textarea name="comment" id="comment" cols="58" rows="10" tabindex="4"></textarea>
<input name="submit" type="submit" id="submit" tabindex="5" value="<?php esc_attr_e('Submit Comment'); ?>" />
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; ?>
<?php else : ?>
<?php _e('Sorry, the comment form is closed at this time.'); ?>
<?php endif; ?>
Trong WordPress, tệp footer.php nằm trong thư mục chủ đề của bạn. Tệp footer.php chứa mã chịu trách nhiệm hiển thị phần chân trang của trang web của bạn, bao gồm điều hướng chân trang, thông tin bản quyền và bất kỳ nội dung bổ sung nào bạn đã thêm vào khu vực chân trang. Trong file footer.php copy và paste đoạn code sau vào
<?php
?>
</div>
<?php get_sidebar(); ?>
<?php echo sprintf(__("Powered by <a href='http://wordpress.org/' title='%s'><strong>WordPress</strong></a>"), __("Powered by WordPress, state-of-the-art semantic personal publishing platform.")); ?>
</div>
<?php wp_footer(); ?>
</body>
</html>
Functions.php là tập tin đóng vai trò quan trọng trong WordPress. Nó là một file gồm nhiều chức năng giúp cho website hoạt động hiệu quả. Trong file functions.php copy và paste đoạn code sau vào
<?php
add_theme_support( 'automatic-feed-links' );
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '',
'after_title' => '',
));
?>
Tại file header.php chúng ta sẽ khai báo các thẻ HTML cần thiết mà trong một tài liệu HTML chuẩn đều có như <html>, <head>, <body>,….và nhất là phần thẻ <head> là phần quan trọng nhất. Trong file header.php copy và paste đoạn code sau vào
<?php
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<title><?php wp_title('«', true, 'right'); ?> <?php bloginfo('name'); ?></title>
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php wp_get_archives(array('type' => 'monthly', 'format' => 'link')); ?>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div id="rap">
<h1 id="header">
<a href="<?php bloginfo('url'); ?>/"><?php bloginfo('name'); ?></a>
<span id="tagline"><?php bloginfo('description'); ?></span>
</h1>
<div id="content">
<!-- end header -->
Tiếp tục phần này, chúng ta sẽ viết code cho file index.php. Đây là file mà nó sẽ làm trang chủ mặc định cho WordPress và thường là ở phần này chúng ta sẽ viết code hiển thị danh sách các post mới nhất trên website. Trong file index.php copy và paste đoạn code sau vào
<?php
get_header();
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_date('','<h2>','</h2>'); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> — <?php the_tags(__('Tags: '), ', ', ' — '); ?> <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
<div class="storycontent">
<?php the_content(__('(more...)')); ?>
</div>
<div class="feedback">
<?php wp_link_pages(); ?>
<?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?>
</div>
</div>
<?php comments_template(); // Get wp-comments.php template ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php posts_nav_link(' — ', __('« Newer Posts'), __('Older Posts »')); ?>
<?php get_footer(); ?>
Sidebar là thanh bên cạnh sườn của trang wordpress chúng ta tạo, ở sidebar có các widget mà chúng ta thêm vào để hiển thị các nội dung của thanh sidebar. Trong file sidebar.php copy và paste đoạn code sau vào
<?php
?>
<div id="menu">
<ul>
<?php
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php wp_list_pages('title_li=' . __('Pages:')); ?>
<?php wp_list_bookmarks('title_after=&title_before='); ?>
<?php wp_list_categories('title_li=' . __('Categories:')); ?>
<li id="search">
<label for="s"><?php _e('Search:'); ?></label>
<form id="searchform" method="get" action="<?php bloginfo('url'); ?>">
<div>
<input type="text" name="s" id="s" size="15" /><br />
<input type="submit" value="<?php esc_attr_e('Search'); ?>" />
</div>
</form>
</li>
<li id="archives"><?php _e('Archives:'); ?>
<ul>
<?php wp_get_archives(array('type' => 'monthly')); ?>
</ul>
</li>
<li id="meta"><?php _e('Meta:'); ?>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</li>
<?php endif; ?>
</ul>
</div>
<!-- end sidebar -->
File Style.css là file mà chúng ta sẽ thêm các code css làm đẹp cho website giống như chúng ta Sơn nhà vậy. Trong file style.css ta lần lượt viết các code css cho web.
Còn file screenshot.png là file ảnh bạn có thể tải ảnh lên và đặt tên file là screenshot.png. Nó là ảnh đại diện cho theme wordpress của chúng ta.
ok như vậy đã xong
Giờ ra trình soạn thảo của wordpress để đăng bài. Sau khi đăng bài xong trở ra trang chủ Website tận hưởng thành quả. Bạn có thể dùng mẫu này để làm trang mặc định cho trang web của mình.
Ý kiến của bạn
Bạn phải đăng nhập để gửi bình luận.