繁体   English   中英

仅在我的页面上显示特定类别的博客条目(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 ); ?>

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

如果您需要更多信息,请访问此页面

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM