0

这让我整天发疯,不知道我做错了什么,但也许你的一只敏锐的眼睛会抓住它......

基本上,我有来自我想要存档的自定义帖子类型('eac_english')的帖子。使用 WP 模板层次结构指南,创建一个名为“archive-eac_english.php”的文档应该可以解决这个问题,但是当我将我的代码添加到这个文档时,它不会调用定义的帖子。相反,它只是返回一个空白页。

这是我的 funtion.php 代码:

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'eac_english',
        array(
            'labels' => array(
                'name' => __( 'English' ),
                'singular_name' => __( 'English' )
            ),
            'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
            'taxonomies' => array('category'),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'en'),
        )
    );

然后,在标记为 archive-eac_english.php 的文档中,我有以下内容:

<?php
    $the_query = new WP_Query( array( 
  'post_type' => 'eac_english',
  'orderby' => 'date',
  'category_name' => 'past-featured-artist', //name of category by slug
  'order' => 'DESC',
  'posts_per_page' => 12)); // how many posts to show
    $x = 0;

    while ( $the_query->have_posts() ) :
   $the_query->the_post(); ?>
            <div class="home_post_box">
                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('grid-image'); ?></a>
                <a href="<?php the_permalink(); ?>" class="home_post_text"><h3><?php the_title(); ?></h3></a>
            </div><!--//home_post_box-->  

    <?php $x++; ?>
    <?php endwhile; ?>

    <?php wp_reset_query(); ?>

我有一个“eac_english”帖子,其类别定义为“past-featuerd-artist”,但是当我访问该页面“url/category/past-featured-artist/”时,没有返回任何内容。

现在,如果我将“archive-eac_english.php”中的所有代码添加到“archive.php”中,它就没有问题,但显然这并没有让我选择只调用“eac_english”下组织的帖子。

这里的任何帮助将不胜感激!干杯,

4

1 回答 1

1

刚刚意识到我将存档页面称为“archive-eac_english”,然后将其更改为“category-past-featured-artist”,一切顺利。

于 2013-03-24T03:16:33.060 回答