缺少自定义发布类型元数据

时间:2017-02-02 作者:user2141419

我已经用CPTUI创建了一个自定义帖子类型,并试图使帖子元数据与首页上的显示相同。但是,post元数据没有出现,好像丢失了一样。

试验场地为http://50.87.248.66/~tulalipl/具有自定义类型的页面为http://50.87.248.66/~tulalipl/natosha-gobin/

调用数据的php是。。。

  <?php
    $post = array( \'post_type\' => \'ngobin\', \'posts_per_page\' => \'5\'  );
    $loop = new WP_Query( $post );   
  ?>

     <?php while ( $loop->have_posts() ) : $loop->the_post();?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>

    <header class="entry-header">
        <?php
            if ( is_single() ) {
                the_title( \'<h3 class="entry-title">\', \'</h3>\' );
            } else {
                the_title( \'<h3 class="entry-title"><a href="\' . esc_url( get_permalink() ) . \'" rel="bookmark">\', \'</a></h3>\' );
            }
    if ( \'post\' === get_post_type() ): ?>
            <div class="post-details">
                <i class="fa fa-user"></i><?php the_author(); ?>
                <i class="fa fa-clock-o"></i> <time><?php the_time(\'m/j/y g:i A\'); ?></time>
                <i class="fa fa-folder"></i> <?php the_category(\', \' ) ?>
                <i class="fa fa-tags"></i> <?php the_tags(); ?>
                <div class="post-comments-badge"><a href="<?php comments_link(); ?>"><i class="fa fa-comments"></i><?php comments_number( 0, 1, \'%\' ); ?></a>
                </div> <!-- post-comments-badge-->
                  <?php edit_post_link( \'Edit\', \'<i class="fa fa-pencil"></i>\', \'\' ); ?>
                </div>



    <?php
        endif; ?>
    </header><!-- .entry-header -->
    <?php if ( has_post_thumbnail () ) {  // check for feature image ?>
        <div class="post-image">
              <?php the_post_thumbnail ();?>
        </div> <!-- ================ End Post Image ================= -->
        <?php } ?>
    <div class="post-excerpt">
        <?php if (is_single()) { 
        the_content(); 
        } else {
            the_excerpt();
        } ?>
    </div><!-- ================  End Post Excerpt  ================= -->

    <footer class="entry-footer">
        <?php the_language_of_puget_sound_entry_footer(); ?>
    </footer><!-- .entry-footer -->
</article><!-- #post-## -->


    <?php endwhile;  // end of the loop ?>

1 个回复
最合适的回答,由SO网友:Dave Romsey 整理而成

模板代码正在检查帖子类型是否为post, 并且仅显示post元信息,如果是true:

if ( \'post\' === get_post_type() ): ?>
自自定义帖子类型ngobin 正在查看,返回上述检查false 因此不会显示元数据。解决方法很简单;将post类型检查更改为ngobin:

if ( \'ngobin\' === get_post_type() ): ?>
        <div class="post-details">
            <i class="fa fa-user"></i><?php the_author(); ?>
            <i class="fa fa-clock-o"></i> <time><?php the_time(\'m/j/y g:i A\'); ?></time>
            <i class="fa fa-folder"></i> <?php the_category(\', \' ) ?>
            <i class="fa fa-tags"></i> <?php the_tags(); ?>
            <div class="post-comments-badge"><a href="<?php comments_link(); ?>"><i class="fa fa-comments"></i><?php comments_number( 0, 1, \'%\' ); ?></a>
            </div> <!-- post-comments-badge-->
              <?php edit_post_link( \'Edit\', \'<i class="fa fa-pencil"></i>\', \'\' ); ?>
            </div>
        </div>
<?php endif; ?>

相关推荐