简体   繁体   中英

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

Excluding "uncategorized" i've got three categories: 'News', 'E1', 'E2' I also got two pages (E1, E2) with the same blog-template. The plan is, to show on each page all entries of 'News' and all of the fitting 'E*'-category. How would I do this? The Theme I'm using ist Attitude-Free from Theme-Horse.

<?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(); ?>

If you want to retrieve all posts of a category, you can use get_posts() wordpress function.

For example

<?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 ); ?>

Then you only have to loop into this array, and show them as you want.

If you want more information, this is the page .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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