标准的category
[php]
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

<?php endwhile;?>
<?php endif; wp_reset_query(); ?>
[/php]
 
[php]
<!-- The Loop -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile; else: ?>
<p><?php _e('该会员还没投稿过文章哦'); ?></p>
<?php endif; ?>

<!-- End Loop -->
[/php]

最热门文章+分类内
[php]
<div class="tops">热点 </div>
<ul>
<?php $posts = query_posts($query_string . '&orderby=date&showposts=4&cat=1'); ?>
<?php while(have_posts()) : the_post(); ?>
<li class="clear">
<h3>
<a target="_blank" title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h3>
<p><?php _e(wp_trim_words( $post->post_content, 25,'......' ));?></p>
<span>
<a href="<?php the_permalink(); ?>">[详细]</a>
</span>
</li>
<?php endwhile; ?>
</ul>
[/php]
 

调用热门文章
[php]
<ul>
<?php
$post_num = 10; // 设置调用条数
$args = array(
‘post_password’ => ”,
‘post_status’ => ‘publish’, // 只选公开的文章.
‘post__not_in’ => array($post->ID),//排除当前文章
‘caller_get_posts’ => 1, // 排除置頂文章.
‘orderby’ => ‘comment_count’, // 依評論數排序.
‘posts_per_page’ => $post_num
);
$query_posts = new WP_Query();
$query_posts->query($args);
while( $query_posts->have_posts() ) { $query_posts->the_post(); ?>
<li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>
<?php wp_reset_query();?>
</ul>
[/php]
 

调用最新文章
[php]
<ul>
<?php $post_query = new WP_Query('showposts=4');
while ($post_query->have_posts()) : $post_query->the_post();
$do_not_duplicate = $post->ID; ?>

<li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>

<?php endwhile;?>
</ul>
[/php]
 

调用热门文章( 常用)
[php]
<h2>热门文章</h2>
<ul id="popular-posts">
<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 6");
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
<li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>">
<?php echo $title ?></a> {<?php echo $commentcount ?> 个评论}</li>
<?php } } ?>
</ul>
[/php]
 

列表调用(文章列表)
[php]
<div class="indent-left">
<ul class="list-1">
<?php if (have_posts()) : ?>
<?php query_posts('&orderby=rand&cat='.$category_id.'' . $mcatID. '&caller_get_posts=1&showposts=6'); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile;?>
<?php endif; wp_reset_query(); ?>
</ul>
</div>
[/php]
 

不同分类调用不同模板方法

第一种:假如“wordpress”这个分类的ID=1, 那么就新建一个模板category-1.php,系统会自动调用这个ID的,重点是记住这个文件命名格式category-*.php,这里的*代表着category的ID。

第二种:
[php]
<?php
if ( is_category(15) ) {
include(TEMPLATEPATH . '/category-pic.php');
}

else if ( is_category(16) ) {
include(TEMPLATEPATH .'/category-pic.php');
}

else {
include(TEMPLATEPATH . '/category-list.php');
}
?>
[/php]
 

另一种不会引起冲突的
[php]
<?php query_posts('showposts=3&cat=2');while(have_posts()):the_post();?>
<li>
<a href="<?php the_permalink();?>" target="_blank">
<?php if ( has_post_thumbnail() ) { ?> <?php the_post_thumbnail('js2'); ?> <?php } else {?>
<img src=<?php bloginfo('template_directory'); ?>/img/jsimg/1.jpg />
<?php } ?>
</a>
</li>
<?php endwhile;wp_reset_query();?>
[/php]
 

显示属于哪个分类名称,输出分类名
[php]
<?php $category = get_the_category(); echo $category[0]->cat_name; ?>
[/php]
 

第二种方法: 多个category中有效
[php]
<?php $thiscat = get_category($cat); echo $thiscat ->name;?>
[/php]
 

调用某个分类里最新文章
[php]
<ul class="col-lg-3 col-sm-9 col-xs-9">
<?php
query_posts('showposts=5&cat=4');
while(have_posts()) : the_post();
?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
[/php]
 

另一方案
[php]
<ul>
<?php query_posts('showposts=5&cat=1'); while(have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" target="_blank"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
[/php]
 

调用随机文章同类目下
[php]
<ul>
<?php
$cat = get_the_category();
foreach($cat as $key=>$category){
$catid = $category->term_id;
}
$args = array('orderby' => 'rand','showposts' => 8,'cat' => $catid );
$query_posts = new WP_Query();
$query_posts->query($args);
while ($query_posts->have_posts()) : $query_posts->the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile;?>
</ul>
[/php]
 

调用文章分类
[php]
<h2>Categories</h2>
<ul>
<?php wp_list_cats('sort_column=name'); ?>
</ul>
[/php]
 

wordpress如何调用分类目录new
[php]
<?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
[/php]
 

包含或排除某分类:

意思就是把分类ID为3,5,9,16的分类按名称顺序来排序:
[php]
<?php wp_list_categories('orderby=name&include=3,5,9,16'); ?>
[/php]
 

复制代码按名称排列,并显示每个分类的日志总数,并不显示ID为10的分类:
[php]
<?php wp_list_categories('orderby=name&show_count=1&exclude=10'); ?>
[/php]
 

显示或隐藏列表标题:

过滤ID为4和7的分类,并且列表标题设置为“哈哈”:
[php]
<?php wp_list_categories('exclude=4,7&title_li=哈哈'); ?>
[/php]
 

复制代码列表中只显示ID为5、9、23的分类,并把列表标题改为oetry(下面的格式是为了把“要显示的数据”和“标签参数区分开来”)
[php]
<?php wp_list_categories('include=5,9,23&title_li=<h2>' . __('Poetry') . '</h2>' ); ?>
[/php]
 

这个参数的意思是:按ID排序,关闭分类说明(就是鼠标移动到连接上就不显示你在后台填的分类说明了,只显示“察看XX分类下的所有文章”),并且只显示ID为8的分类下的子分类,如果没有,则参数无效,会按默认来显示。
[php]
<?php wp_list_categories('orderby=id&show_count=1&use_desc_for_title=0&child_of=8'); ?>
[/php]
 

外观是分类后面显示个(RSS),作用就不用我说了吧?
[php]
<?php wp_list_categories('orderby=name&show_count=1&feed=RSS'); ?>
[/php]
 

这个比较酷,相信大家都喜欢:分类名称后面显示一个自己制定的小图标,作用是RSS。
[php]
<?php wp_list_categories('orderby=name&show_count=1&feed_image=/images/rss.gif'); ?>
[/php]
 

花式列表:改变当前正在浏览的分类名字的样式。’style=list’的作用是给输出的html代码中加一个class=”current- cat”, 然后你在CSS里添一个.current-cat {color:red;}那么我浏览分类AAA时,列表中的“AAA”3个字就是红色的,浏览BBB,“BBB”就是红色的。
[php]
<?php wp_list_categories('style=list' ); ?>
[/php]
 

获取文章摘要
[php]
<?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 288,"……"); ?> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>
[/php]
 

调用代码
[php]
<?php
$content = get_the_content();
$trimmed_content = wp_trim_words( $content, 40, '<a href="'. get_permalink() .'"> ...阅读更多</a>' );
echo $trimmed_content;
?>
[/php]
 

简介
[php]
<p><?php _e(wp_trim_words( $post->post_content, 25,'......' ));?></p>
[/php]
 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。