仅在我的页面(WordPress)上显示特定类别的博客条目


only show blog-entries of specific categories on my page (wordpress)

不包括"未分类",我有三个类别:"新闻","E1","E2"我还得到了两个具有相同博客模板的页面(E1,E2)。计划是,在每个页面上显示"新闻"的所有条目和所有合适的"E*"类别。我该怎么做?我使用的主题是 从主题马中无态度。

<?php
/**
 * Template Name: Blog Full Content Display
 *
 * Displays the Blog with Full Content Display.
 *
 * @package Theme Horse
 * @subpackage Attitude
 * @since Attitude 1.0
 */
?>
<?php get_header(); ?>

<?php $args = array(
         'posts_per_page'   => 5,
         'offset'           => 0,
         'category'         => 'E1',
         'orderby'          => 'post_date',
         'order'            => 'DESC',
         'include'          => '',
         'exclude'          => '',
         'meta_key'         => '',
         'meta_value'       => '',
         'post_type'        => 'post',
         'post_mime_type'   => '',
         'post_parent'      => '',
         'post_status'      => 'publish',
         'suppress_filters' => true ); 
 $posts_array = get_posts( $args ); ?>

<?php
/** 
 * attitude_before_main_container hook
     */
    do_action( 'attitude_before_main_container' );
?>
<?php
/**
 * Überschrift
 *
 * bla
 */
?>
<h3>Content:</h3>
<div id="container">
<?php
    /** 
     * attitude_main_container hook
     *
     * HOOKED_FUNCTION_NAME PRIORITY
     *
     * attitude_content 10
         */
        do_action( 'attitude_main_container' );
    ?>
</div><!-- #container -->
<?php
    /** 
     * attitude_after_main_container hook
     */
    do_action( 'attitude_after_main_container' );
?>
<?php get_footer(); ?>

如果要检索某个类别的所有帖子,可以使用get_posts()wordpress函数。

例如

<?php $args = array(
         'posts_per_page'   => 5,
         'offset'           => 0,
         'category'         => 'E1',
         'orderby'          => 'post_date',
         'order'            => 'DESC',
         'include'          => '',
         'exclude'          => '',
         'meta_key'         => '',
         'meta_value'       => '',
         'post_type'        => 'post',
         'post_mime_type'   => '',
         'post_parent'      => '',
         'post_status'      => 'publish',
         'suppress_filters' => true ); 
 $posts_array = get_posts( $args ); ?>

然后,您只需循环到此数组中,并根据需要显示它们。

如果您想了解更多信息,请点击此处查看页面。