首页 文章

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

提问于
浏览
2

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

<?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' ) . ' ', ', ', '
' ); ?> <?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 回答

  • 1

    看起来你正在混合自定义帖子类型(post_type =>'post_type'=>'legislaciones')和自定义分类法,

    或者你真的有自定义帖子类型和自定义分类与相同的slug?

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

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

    这一切都在Codex中详细介绍,关于Template Hierarchy的页面

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

相关问题