在Wordpress中显示自定义帖子类型的内容

时间:2014-12-21 14:54:25

标签: php wordpress

我正在使用Types插件来创建Wordpress自定义帖子类型(CPT),现在我需要显示该内容。我创建了一个名为category-legislaciones.php的页面,其中legislaciones是CPT本身的类别,使用Types plugin创建。这是我在该页面上的代码:

<?php
    $args = array( 'post_type' => 'legislaciones', 'posts_per_page' => 15 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
?>
<h1 class="post-title"><?php the_title(); ?></h1>

<?php $options = get_option( 'responsive_theme_options' ); ?>
<?php if ( $options['breadcrumb'] == 0 ): ?>
    <?php echo responsive_breadcrumb_lists(); ?>
<?php endif; ?>

<div id="post-<?php the_ID(); ?>">
    <div class="post-entry">
        <?php the_content( __( 'Read more &#8250;', 'responsive' ) ); ?>
        <?php wp_link_pages( array(
            'before' => '<div class="pagination">' . __( 'Pages:', 'responsive' ),
            'after'  => '</div>'
        )); ?>
    </div>
    <?php if ( comments_open() ) : ?>
        <div class="post-data">
            <?php the_tags( __( 'Tagged with:', 'responsive' ) . ' ', ', ', '<br />' ); ?>
                <?php the_category( __( 'Posted in %s', 'responsive' ) . ', ' ); ?>
        </div><!-- end of .post-data -->
    <?php endif; ?>

        <div class="post-edit"><?php edit_post_link( __( 'Edit', 'responsive' ) ); ?></div>
    </div><!-- end of #post-<?php the_ID(); ?> -->

    <?php comments_template( '', true ); ?>
        <?php if ( $wp_query->max_num_pages > 1 ) : ?>
            <?php if ( function_exists( 'wp_paginate' ) ) {
                wp_paginate();
            } ?>
        <?php endif; ?>

    <?php get_search_form(); ?>
    <?php endwhile; ?>

但是,即使我将内容分配到该类别,我做错了什么也没有显示?显示该内容的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

看起来你在混音 自定义帖子类型(post_type =&gt;&#39; post_type&#39; =&gt;&#39; legislaciones&#39;) 和自定义分类,

或者你真的同时拥有自定义帖子类型和自定义分类法吗?

如果您的立法者是自定义帖子类型,则您文件的正确名称将为archive-legislaciones.php,并且您不需要特定查询

如果您的立法者是自定义分类法,那么您在这里基本上要求使用post_type legislaciones和Taxonomy legislaciones的帖子,其值将在URL中确定

这在食典委详细介绍,关于Template Hierarchy

的页面

它不属于你的问题,但你的代码会在页面上重复15次面包屑和评论表,这真的是你想要的吗?