新建主題,新建index.php和style.css:
在index.php加入以下循環輸出post的代碼:
~~~
<?php
if(have_posts()) :
while (have_posts()) : the_post(); ?>
<h2>文章的標題</h2>
<?php endwhile;
else :
echo '<p>No content found</p>';
endif;
?>
~~~
網站有6遍文章,動態輸出:

動態輸出具體標題和內容:
~~~
<?php
if(have_posts()) :
while (have_posts()) : the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
<?php endwhile;
else :
echo '<p>No content found</p>';
endif;
echo paginate_links();
?>
~~~

使用WP_Query函數輸出文章分類:
~~~
<!-- home-columns -->
<div class="home-colums clearfix">
<!-- one-half -->
<div class="one-half">
<?php // opinion posts loop begins here
$opinionPosts = new WP_Query('cat=10&posts_per_page=2');
if ($opinionPosts->have_posts()) :
while ($opinionPosts->have_posts()) : $opinionPosts->the_post();?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endwhile;
else :
// fallback no content message here
endif;
wp_reset_postdata(); ?>
</div><!-- /one-half -->
<!-- one-half -->
<div class="one-half last">
<?php // opinion posts loop begins here
$newPosts = new WP_Query('cat=8&posts_per_page=2');
if ($newPosts->have_posts()) :
while ($newPosts->have_posts()) : $newPosts->the_post();?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endwhile;
else :
// fallback no content message here
endif;
wp_reset_postdata(); ?>
</div><!-- /one-half -->
</div><!-- /home-columns -->
~~~

帶有特色圖輸出特定類別的文章:
~~~
<section class="class">
<ul class="class">
<li>
<a href="#" target="_blank">
<img src="<?php bloginfo('template_directory'); ?>/picture/picture.jpg" alt="123" />
<p>類別<br /><strong>123</strong><br /></p></a>
</li>
<?php
$cats = new WP_Query('cat=18&posts_per_page=');
if ($cats->have_posts()) :
while ($cats->have_posts()) : $cats->the_post();?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('cases&posts-image'); ?>
<p>類別<br /><strong><?php the_title(); ?></strong><br /></p></a>
</li>
<?php endwhile;
else :
// fallback no content message here
endif;
wp_reset_postdata(); ?>
</ul>
</section>
~~~
【1】全部循環
~~~
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!--需要循環的模塊-->
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
~~~
【2】調用某個分類,顯示多少遍的循環
~~~
<?php if (have_posts()) : ?>
<?php query_posts('cat=3' . $mcatID. '&caller_get_posts=1&showposts=6'); ?>
<?php while (have_posts()) : the_post(); ?>
<!--需要循環的模塊-->
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
~~~
【3】特定頁面/文章
~~~
<?php query_posts('page_id=2');//修改頁面ID ?>
<?php while (have_posts()) : the_post(); ?>
<?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 300,"……"); //修改顯示字數 ?>
<?php endwhile;wp_reset_query();?>
~~~
調用某個分類下的文章
~~~
<?php $rand_posts =
get_posts('category=ID&numberposts=5&orderby=date');foreach($rand_posts as $post) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach;?>
~~~
- WordPress平臺的網站開發
- 電商主題開發
- WooCommerce主題開發優化部分
- 首頁開發
- WooCommerce
- 判斷用戶是否登錄
- WordPress Menu
- WooCommerce PayPal Checkout Gateway
- 頁面和文章
- 調用產品和文章
- 判斷屬于哪個頁面
- 相關文章
- 消除文章分享按鈕集底部的文字
- wordpress主題模板和主題開發
- wordpress主題準備
- wordpress主題文件結構
- 豪源主題
- WooCommerce SEO
- 插件開發
- wordpress二次開發
- theme基本顯示
- menu調用
- 分拆為header.php和footer.php
- 頁面、文章樣式選擇顯示
- 面包屑導航 Breadcrumb
- 特色圖
- 閱讀次數統計
- 分頁功能
- Advanced Custom Fields
- Custom Post Type UI
- post type
- 小工具
- 小工具調用
- shortcode
- 文章循環輸出
- 標題和文章限制字數輸出顯示
- WordPress主題theme1開發
- wordpress搭建多站點
- wordpress常用函數
- wordpress循環代碼
- Woocommerce
- Woocommerce支持
- WordPress插件開發
- wordpress會員插件
- WordPress插件使用
- WordPress插件集
- WordPress的核心
- Wordpress原理
- Wordpress要點
- WordPress網站搬家
- WPML
- 服務器
- Cloud 9
- test
- 網站