从自定义帖子类型中获取所有帖子

时间:2014-12-09 21:40:40

标签: php wordpress

我使用WP Types Plugin并且一切正常,现在我需要显示通过该插件创建的内容,这就是我正在做的事情:

$args = array(
    'posts_per_page'   => 15,
    'category_name'    => 'legislacion',
    'orderby'          => 'post_date',
    'order'            => 'DESC',
    'post_type'        => 'post',
    'post_status'      => 'publish',
    'suppress_filters' => true
);

$legislacion_posts = get_posts( $args );
?>

<ul>
    <?php foreach ( $legislacion_posts as $post ) : setup_postdata( $post ); ?> ?>
        <li>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </li>
    <?php endforeach;
    wp_reset_postdata(); ?>
</ul>

但是我没有收到该类别的帖子,为什么?

修改

这是archive-legislaciones.php档案的内容:

<?php

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * Pages Template
 *
 *
 * @file           archive-legislaciones.php
 * @package        Responsive
 * @author         Emil Uzelac
 * @copyright      2003 - 2013 ThemeID
 * @license        license.txt
 * @version        Release: 1.0
 * @filesource     wp-content/themes/responsive/page.php
 * @link           http://codex.wordpress.org/Theme_Development#Pages_.28page.php.29
 * @since          available since Release 1.0
 */
?>
<?php get_header(); ?>
<?php if ( is_page( 'legislaciones' ) ) { ?>
    <div id="content" class="grid col-620">
    <?php
    $args = array(
        'posts_per_page'   => 15,
        'category_name'    => 'legislacion',
        'orderby'          => 'post_date',
        'order'            => 'DESC',
        'post_type'        => 'post',
        'post_status'      => 'publish',
        'suppress_filters' => true
    );

    $legislacion_posts = get_posts( $args );
    ?>

    <ul>
        <?php foreach ( $legislacion_posts as $post ) : setup_postdata( $post ); ?>
            <li>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </li>
        <?php endforeach;
        wp_reset_postdata(); ?>
    </ul>
    </div>
    <?php get_sidebar(); ?>
<?php } ?>
<?php get_footer(); ?>

那里出了什么问题?

1 个答案:

答案 0 :(得分:0)

这一行,必须像那样

<?php foreach ( $legislacion_posts as $post ) : setup_postdata( $post ); ?>

您必须删除上一个?&gt;