【问题标题】:Display contents from custom post type in Wordpress在 Wordpress 中显示自定义帖子类型的内容
【发布时间】:2014-12-21 14:54:24
【问题描述】:

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

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

但是即使我将内容分配给该类别,也不会显示任何内容,我做错了什么?显示该内容的正确方法是什么?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

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

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

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

    如果您的立法是自定义分类法,那么您基本上是在调用带有 post_type legislaciones 的帖子和具有将在 url 中确定的值的分类法立法

    这一切都在 Codex 中有详细说明,关于 Template Hierarchy 的页面

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

    【讨论】:

      猜你喜欢
      • 2014-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多