如何在wordpress中显示该类别的所有帖子?
4 个回答
- 投票数
-
- 2011-05-18
<?php $args = array( 'category' => 7, 'post_type' => 'post' ); $postslist = get_posts( $args ); foreach ($postslist as $post) : setup_postdata($post); ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> <?php endforeach; ?>
只需更改类别ID(数字7) 并更改插件中的post_type
要了解有关post_type的更多信息,请参见链接 http://codex.wordpress.org/Custom_Post_Types
<?php $args = array( 'category' => 7, 'post_type' => 'post' ); $postslist = get_posts( $args ); foreach ($postslist as $post) : setup_postdata($post); ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> <?php endforeach; ?>
just change the category id (number 7) and change the post_type that was in the plugin
to learn more about post_type, see link http://codex.wordpress.org/Custom_Post_Types
-
- 2011-05-17
使用wordpress相当容易.您必须了解,帖子通常显示在"循环"内,这是一个重复出现的小代码.您必须使用一个.
<?php $catPost = get_posts(get_cat_ID("NameOfTheCategory")); //change this foreach ($catPost as $post) : setup_postdata($post); ?> <div> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p><?php the_content(); ?></p> </div> <?php endforeach;?>
您应该将输出更改为适合您的需求
It is quite easy to do it with wordpress. You have to understand that post are normally display within a "loop", a small code that repeat itself. You have to use one to do that.
<?php $catPost = get_posts(get_cat_ID("NameOfTheCategory")); //change this foreach ($catPost as $post) : setup_postdata($post); ?> <div> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p><?php the_content(); ?></p> </div> <?php endforeach;?>
You should change the output to what fit your needs
-
- 2018-09-21
您可以使用此代码访问特定类别的所有帖子.在您的category.php页面中,使用代码小精灵
$current_category = get_queried_object(); ////getting current category $args = array( 'post_type' => 'our-services',// your post type, 'orderby' => 'post_date', 'order' => 'DESC', 'cat' => $current_category->cat_ID // current category ID ); $the_query = new WP_Query($args); if($the_query->have_posts()): while($the_query->have_posts()): $the_query->the_post(); echo "<h2>".the_title()."</h2>"; echo "<p>".the_content()."</p>"; endwhile; endif;
You can use this code for accessing all post of specific category. In your category.php page use the spinet of code
$current_category = get_queried_object(); ////getting current category $args = array( 'post_type' => 'our-services',// your post type, 'orderby' => 'post_date', 'order' => 'DESC', 'cat' => $current_category->cat_ID // current category ID ); $the_query = new WP_Query($args); if($the_query->have_posts()): while($the_query->have_posts()): $the_query->the_post(); echo "<h2>".the_title()."</h2>"; echo "<p>".the_content()."</p>"; endwhile; endif;
-
- 2016-01-26
这是从别人编写的代码改编而成的,我从很久以前就受益匪浅,因为它知道它的来源(如果最初编写它的人正在阅读本文,再次感谢).它可以满足您的要求:
<?php $catPost = get_posts('cat=888&posts_per_page=-1000'); foreach ($catPost as $post) : setup_postdata($post); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_post_thumbnail('name of your thumbnail'); ?> </a> <h4> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_title(); ?> </a> </h4> <hr/ style="clear:both;"> <?php endforeach;?>
This is adapted from code someone else wrote, and which I benefitted from too long ago to know where it came from (if the person who originally wrote it is reading this, thanks again). It works for your request:
<?php $catPost = get_posts('cat=888&posts_per_page=-1000'); foreach ($catPost as $post) : setup_postdata($post); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_post_thumbnail('name of your thumbnail'); ?> </a> <h4> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_title(); ?> </a> </h4> <hr/ style="clear:both;"> <?php endforeach;?>
我已经使用"自定义帖子类型"插件创建了一个类别,现在仅显示该类别的5个最新帖子.
我想要显示该类别的所有帖子.
例如,假设我有电影类别-我想要该类别中的所有电影.
我应该在哪里使用什么代码?
我对wordpress不太了解,因此,我希望逐步进行此过程.