โชว์บทความทั้งหมด จากหมวดหมู่
<?php
//for each category, show all posts
$cat_args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'showposts' => -1,
'category__in' => array($category->term_id),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
foreach($posts as $post) {
setup_postdata($post); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
} // foreach($posts
} // if ($posts
} // foreach($categories
?>จะโชว์เรียงลงมา
Category Name 1
post title 1
post title 2
post title 3
Category Name 2
Post title 1
etc. etc.
โชว์หน้าละ 10 หัวข้อ
ใช้
query_posts( 'posts_per_page=10' );
http://codex.wordpress.org/Function_Reference/query_posts
ตัวอย่าง
<div class="WebboardList"><br />
<div class="clear"></div>
<?php query_posts( 'posts_per_page=100' );?>
<?php if (have_posts()) : ?>
<ul><?php while (have_posts()) : the_post(); ?>
<li>
<div class="LeftTitle">
<h2>
<img src="<?php bloginfo('template_url'); ?>/images/icon_01.jpg" align="absmiddle"> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
</h2>
</div>
<div class="LeftDate"><?php echo get_the_date(); ?></div>
<div class="clear"></div>
</li>
<?php endwhile; wp_reset_query();?>
</ul>
<div class="clear"></div>
<?php endif?>
</div>
<div class="clear"></div>โชว์ 2โพส
<?php
$terms = get_terms( 'category', array(
'hide_empty' => false,
'order_by' => 'name',
'order' => 'ASC',
'number' => 2,
'taxonomy' => 'category'
) );
//print_r($terms);
foreach($terms as $termss)
{
//echo "<br/>";
//echo $termss->term_id;
//echo "<br/>";
?>
<h1> <?php echo $termss->name; ?></h1>
<?php
//echo "<br/>";
//echo $termss->slug;
$query = query_posts("category_name='$termss->name'&showposts=5");
//print_r($query);
foreach($query as $querys)
{
//$querys->ID;
?>
<h3><?php echo $querys->post_title; ?></h3>
<p><?php echo $querys->post_content; ?></p>
<?php //echo "<br/>";
}
}
?>