如何在WordPress中显示近期评论
方法一、修改index.php 直接在当前主题模板的首页index.php中修改调出代码,比如上面的代码中是让20和22分类不显示出来。
方法二、functions.php修改:这个方法是比较好的,建议使用。
//在首页中排除某些分类function exclude_category_home( $query ) {if ( $query->is_home ) {$query->set( 'cat', '-20, -22' ); //你要排除的分类ID}return $query;}add_filter( 'pre_get_posts', 'exclude_category_home' );这个方法直接不会有任何页面空缺问题,而且在最新内容中也不会出现。
直接在当前主题的functions.php添加上面的脚本,修改对应的分类排除。
...
wordpress怎么在页面上添加相关的文章?
方法一:标签相关首先获取文章的所有标签,接着获取这些标签下的 n 篇文章,那么这 n 篇文章就是与该文章相关的文章了。
现在可以见到的WordPress相关文章插件都是使用的这个方法。
下面是实现的代码:global $post;$post_tags = wp_get_post_tags($post->ID);if ($post_tags) {foreach ($post_tags as $tag) {// 获取标签列表$tag_list[] .= $tag->term_id;}// 随机获取标签列表中的一个标签$post_tag = $tag_list[ mt_rand(0, count($tag_list) - 1) ];// 该方法使用 query_posts() 函数来调用相关文章,以下是参数列表$args = array('tag__in' =>array($post_tag),'category__not_in' =>array(NULL), // 不包括的分类ID'post__not_in' =>array($post->ID),'showposts' =>6, // 显示相关文章数量'caller_get_posts' =>1);query_posts($args);if (have_posts()) {while (have_posts()) {the_post(); update_post_caches($posts); ?>* }}else {echo '* 暂无相关文章';}wp_reset_query();}else {echo '* 暂无相关文章';}?>方法二:分类相关本方法是通过获取该文章的分类id,然后获取该分类下的文章,来达到获取相关文章的目的。
global $post;$cats = wp_get_post_categories($post->ID);if ($cats) {$args = array('category__in' =>array( $cats[0] ),'post__not_in' =>array( $post->ID ),'showposts' =>6,'caller_get_posts' =>1);query_posts($args);if (have_posts()) {while (have_posts()) {the_post(); update_post_caches($posts); ?>* }} else {echo '* 暂无相关文章';}wp_reset_query(); }else {echo '* 暂无相关文章';}?>
如何让WordPress一个页面显示全部分类的文章
方法一、修改index.phpwhile ( have_posts() ) : the_post(); ?>直接在当前主题模板的首页index.php中修改调出代码,比如上面的代码中是让20和22分类不显示出来。
方法二、functions.php修改:这个方法是比较好的,建议使用。
//在首页中排除某些分类function exclude_category_home( $query ) {if ( $query->is_home ) {$query->set( 'cat', '-20, -22' ); //你要排除的分类ID}return $query;}add_filter( 'pre_get_posts', 'exclude_category_home' );这个方法直接不会有任何页面空缺问题,而且在最新内容中也不会出现。
直接在当前主题的functions.php添加上面的脚本,修改对应的分类排除。
wordpress获取指定形式的文章
先确定查询 参数:$args = array('post_type'=>'post','post_status' =>'publish','order' =>'DESC','tax_query' =>array(array('taxonomy' =>'post_format','field' =>'slug','terms' =>array( 'post-format-aside' ))));再去查询:$asides = get_posts( $args );if ( count($asides) ) {foreach ( $asides as $aside ) {// 在这里循环输出}}其它文章格式的查询参照上述示例代码。
当然了,你也可以其它查询函数,但是参数却类似上面列出的。
不了解再问。
祝愉快!
如何让wordpress显示所有分类下所有文章列
=>/a>,即不置顶);$query = new WP_Query( $args );if ($query-> ?>?>?php the_title();have_posts()) : while ($query->have_posts()) : $query->the_post()?php the_permalink() ?>"><; ;?php endwhile;在循环中你可以使用WordPress的调用函数都是可以的,根据需要修改即可;ignore_sticky_posts'...
wordpress首页如何调用最新文章
$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(); ?>以上是热门文章的调用代码,放在侧边栏试试就知道了
转载请注明出处51数据库 » wordpress have_posts