其實主要涉及的就是分類,文章,摘要,博客自定義信息調用等方法
1,首先調用導航,需要使用分類內容
2,首頁調用文章內容,一般包括標題,摘要,作者,時間等內容
3,到具體欄目頁面,調用指定欄目下的內容(分為指定調用和自動調用)
4,文章頁面的展示
5,圖片內容調用(一般來說是調用文章中的第一個圖片)
1 調用分類 2 3 <?php 4 $categories = get_categories(); 5 foreach($categories as $category): 6 ?> 7 8 <li><a href="?cat=<?php echo $category->cat_ID; ?>" class="selected filter-data"> 9 <?php echo $category->name; ?></a></li> 10 11 <?php endforeach; ?>
首頁和欄目頁摘要調用 <?php the_excerpt();?> 文章頁摘要(其實主要是在single.php可以使用) <?php global $more ; $more = false; ?> <?php the_content('(more)');?> <?php $more = true; ?>
調用具體欄目的文章摘要 <?php $posts = get_posts( "category=6&numberposts=1" ); ?> <?php if( $posts ) : ?> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><h2><?php the_title(); ?></h2> </a> <p class="ttime"><?php the_time('Y年M月d日g:i a'); ?></p> <p><?php the_content(); ?></p> <?php endforeach; ?> <?php endif; ?>
調用分類文章【自動判斷欄目】 <?php if( $posts ) : ?> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><h2><?php the_title(); ?></h2> </a> <p class="ttime"><?php the_time('r'); ?></p> <p><?php the_content(); ?></p> <?php endforeach; ?> <?php endif; ?>
調用文章中第一個圖片,此代碼應該寫在function.php中 function 那個echo_first_image($width="85",$height="100") { global $post, $posts; ob_start(); ob_end_clean(); //通過正則表達式匹配文章內容中的圖片標簽 $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); //第一張圖片的html代碼,下面加了那個縮放的js哦。。如果你不打算縮放,請刪除 $first_img = '<img src="'. $matches[1][0] .'" width="'.$width.'" height="'.$width.'" alt="'.$post->post_title .'" onload="javascript:DrawImage(this,'.$width.','.$height.')" />'; if(empty($matches[1][0])){ //如果文章中沒有圖片,就調用下面的的默認代碼,自己改圖片url,也有縮放js $first_img = '<img src="'. get_bloginfo('template_url') .'/images/defalt.jpg" alt="'.$post->post_title .'" width="'.$width.'" height="'.$height.'" class="img-sidebar"/>'; } //輸出代碼 echo '<a href="'.get_permalink().'" title="'.$post->post_title.'" >'. $first_img .'</a>'; } 頁面中調用應該這樣寫 <?php echo_first_image('85','100');?>
數據庫中各個表的簡介
wp_options wp的總體信息表
用戶相關
wp_user
wp_usermeta
分類相關
wp_term 菜單分類表
wp_term_relationship 分類關系表
wp_term_taxonomy 分類表的分類表
wp_links 友情鏈接表
wp_links的分類表和菜單欄目的分類表是一樣的都是wp_term_taxonomy
分類的依據是taxonomy列的名稱,值是link_category是友情鏈接的分類名
值是category是菜單分類名。還有一個count列,記錄了相關分類下的文章和子鏈接
文章相關表
wp_postmeta
wp_posts
評論相關
wp_comments
wp_commentsmeta
