海豚的WordPress Theme教程 part4

  这回讲index.php,从这篇开始我不帖相关的css内容了,因为详细解释css内容就变成css教程了,而事实上我自己都没怎么搞清楚css,一般都是边改边学。需要相关css的可以直接去下载KD02模版,自己慢慢研究。

index.php
[php]<?php get_header(); ?>

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post(); ?>

">" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?>
<?php the_author() ?> @ <?php the_time() ?> <?php the_time('F jS, Y') ?>

<?php the_content('

[more...]'); ?>

<?php the_category(', ') ?> | <?php edit_post_link('Edit','','|'); ?> <?php comments_popup_link('Comments (0)', 'Comments (1)', 'Comments (%)'); ?>

-->

<?php endwhile; ?>

<?php posts_nav_link('','','« Previous Entries') ?>
<?php posts_nav_link('','Next Entries »','') ?>

<?php else : ?>

Not found.
<?php _e("Sorry, but you are looking for something that isn't here."); ?>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>

<?php endif; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>[/php]

  • line1, line43, line45: 负责把header.php, sidebar.php, footer.php的内容引入,这样这几部分就作为一个整体展现在访问者面前了。
  • line5-line26: 其中内容就是每篇post在首页的显示内容。一般来说分成三个部分:标题,包括文章題目,作者名字,写作时间;正文内容;留言提示,比如有多少留言,文章所属分类。至于具体位置随个人爱好,如果你不懂php也没什么关系,随便找一个模版然后依样画葫芦copy & paste就可以了。
  • line28-line31: 导航栏。就是下一页/上一页这个东西。
  • line35-line37: 这个是当一篇文章都没有的时候显示的报措信息。

  基本上index.php主要内容就是一个循环语句,不断显示每篇文章直到你后台设定的那个显示文章数为止。
  这篇内容比较少,明天会把有关sidebar.php和footer.php的part5跟上。到part5其实整个模版就接近完成了,其他的几个文件基本上都是从这几个文件中演变出去,不会太费事。
  海豚的这个简单教程很快会结束,然后把Kamus要求修改的Blix模版完成,四月底想做一个新的模版。新模版可能会比较中规中矩,不过将会融入WidgetsWordPress Theme Toolkit或许还有AJAX效果的留言以方便后期修改。

Comments

写得太好了。。。关注。。希望你做完新模板再写一个教程,尤其是那些新的效果。嘿嘿

Hi, dolphin,

Your site looks cool, good tutorial on wp theme as well.

One little question : Is the page layout going to be deformed by enlarging the font size of the Chinese Character, say, to 16px?

I think it won't be deformed, but you'd better to control within 12px-22px.

Hi Dolphin, let's make friends and share views on BLOG :)
My BLOG is here: http://www.calvin.sh.cn. Welcome!

感谢!~

Pretty nice site, wants to see much more on it!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.

More information about formatting options

Syndicate content