建站學院(LieHuo.Net)訊 在以前的文章中我們介紹了的,這篇教程介紹一下主題index.php代碼,它是生成的是網站首頁顯示的內容,還是以默認模板default為例。下面是index.php的完整代碼:
以下為引用的內容:
<div id="content" class="narrowcolumn"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div <?php post_class(); ?> id="post-<?php the_ID(); ?>"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h2> <small><?php the_time(__('F jS, Y', 'kubrick')) ?> <!-- by <?php the_author() ?> --></small> <div class="entry"> <?php the_content(__('Read the rest of this entry »', 'kubrick')); ?> </div> <p class="postmetadata"><?php the_tags(__('Tags:', 'kubrick') . ' ', ', ', '<br />'); ?> <?php printf(__('Posted in %s', 'kubrick'), get_the_category_list(', ')); ?> | <?php edit_post_link(__('Edit', 'kubrick'), '', ' | '); ?> <?php comments_popup_link(__('No Comments »', 'kubrick'), __('1 Comment »', 'kubrick'), __('% Comments »', 'kubrick'), '', __('Comments Closed', 'kubrick') ); ?></p> </div> <?php endwhile; ?> <div class="navigation"> <div class="alignleft"><?php next_posts_link(__('« Older Entries', 'kubrick')) ?></div> <div class="alignright"><?php previous_posts_link(__('Newer Entries »', 'kubrick')) ?></div> </div> <?php else : ?> <h2 class="center"><?php _e('Not Found', 'kubrick'); ?></h2> <p class="center"><?php _e('Sorry, but you are looking for something that isn’t here.', 'kubrick'); ?></p> <?php include (TEMPLATEPATH . "/searchform.php"); ?> <?php endif; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?> <?php get_header(); ?> |
先說下三個函數get_header(); get_sidebar(); get_footer();分別輸出各自的模板代碼如header.php、sidebar.php、footer.php;相應的模板代碼生成后加入相應位置。
第5行的if (have_posts()) : 為判斷是否含有日志;
第7行的 while (have_posts()) : 為當有日志時,進行循環操作;the_post(); 為對單個循環中的一篇日志進行操作。
第9行:post_class();輸出個性化的日志class——官方參考例如置頂文章回輸出不同的class,可以加入參數自定義生成的類名如:post_class(’myclass’);;the_ID();生成日志id數字號。
第10行:the_permalink()為每篇日志對應內容頁的鏈接,the_title();為日志標題;
第11行:the_time(__(’F jS, Y’, ‘kubrick’)為日志發布時間;
第14行:the_content(__(’Read the rest of this entry »’, ‘kubrick’));為日志內容;
第17行:the_tags(__(’Tags:’, ‘kubrick’) . ‘ ‘, ‘, ‘, ‘<br />’); 為日志所在標簽;printf(__(’Posted in %s’, ‘kubrick’), get_the_category_list(’, ‘));為日志所在分類;
第20行: endwhile; 結束循環;
第23行: next_posts_link(__(’« Older Entries’, ‘kubrick’))上一篇日志鏈接;
第24行: previous_posts_link(__(’Newer Entries »’, ‘kubrick’)) ?>下一篇日志鏈接;
第27行: else : 為沒有日志時候的情況,
第29行:php _e(’Not Found’, ‘kubrick’);為沒有發現日志
第30行:php _e(’Sorry, but you are looking for something that isn’t here.’, ‘kubrick’);為相關提示;
第31行:include (TEMPLATEPATH . “/searchform.php”);插入搜索表單模板;
第33行:endif;結束判斷。
下一篇 怎樣讓Css的層垂直居中于瀏覽器