在自定义邮件类型存档页面上显示日期和作者信息

时间:2017-06-26 作者:Andi Wilko

我创建了一个名为“文章”的自定义帖子类型,其功能与一般帖子类型相同;我使用相同的模板来显示这两个存档。

使用内置帖子的博客页面显示发布日期和发布时间,

Seen here

自定义帖子类型页面会忽略此信息

Seen here

我在这一点上迷路了,不知道我需要做什么,这是额外的,因为它使用相同的代码来显示两个页面。

这是post类型函数:

function post_type_articles() {

$labels = array(
    \'name\'                  => _x( \'Articles\', \'Post Type General Name\', \'text_domain\' ),
    \'singular_name\'         => _x( \'Article\', \'Post Type Singular Name\', \'text_domain\' ),
    \'menu_name\'             => __( \'Articles\', \'text_domain\' ),
    \'name_admin_bar\'        => __( \'Article\', \'text_domain\' ),
    \'archives\'              => __( \'Article Archives\', \'text_domain\' ),
    \'attributes\'            => __( \'Article Attributes\', \'text_domain\' ),
    \'parent_item_colon\'     => __( \'Parent Article\', \'text_domain\' ),
    \'all_items\'             => __( \'All Articles\', \'text_domain\' ),
    \'add_new_item\'          => __( \'Add New Article\', \'text_domain\' ),
    \'add_new\'               => __( \'Add New Article\', \'text_domain\' ),
    \'new_item\'              => __( \'New Article\', \'text_domain\' ),
    \'edit_item\'             => __( \'Edit Article\', \'text_domain\' ),
    \'update_item\'           => __( \'Update Article\', \'text_domain\' ),
    \'view_item\'             => __( \'View Article\', \'text_domain\' ),
    \'view_items\'            => __( \'View Article\', \'text_domain\' ),
    \'search_items\'          => __( \'Search Articles\', \'text_domain\' ),
    \'not_found\'             => __( \'Not found\', \'text_domain\' ),
    \'not_found_in_trash\'    => __( \'Not found in Trash\', \'text_domain\' ),
    \'featured_image\'        => __( \'Featured Image\', \'text_domain\' ),
    \'set_featured_image\'    => __( \'Set featured image\', \'text_domain\' ),
    \'remove_featured_image\' => __( \'Remove featured image\', \'text_domain\' ),
    \'use_featured_image\'    => __( \'Use as featured image\', \'text_domain\' ),
    \'insert_into_item\'      => __( \'Insert into article\', \'text_domain\' ),
    \'uploaded_to_this_item\' => __( \'Uploaded to this article\', \'text_domain\' ),
    \'items_list\'            => __( \'Articles list\', \'text_domain\' ),
    \'items_list_navigation\' => __( \'Articles list navigation\', \'text_domain\' ),
    \'filter_items_list\'     => __( \'Filter articles list\', \'text_domain\' ),
);
$args = array(
    \'label\'                 => __( \'Article\', \'text_domain\' ),
    \'description\'           => __( \'Article Description\', \'text_domain\' ),
    \'labels\'                => $labels,
    \'supports\'              => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'comments\', \'trackbacks\', \'revisions\', \'custom-fields\', \'page-attributes\', \'post-formats\', ),
    \'taxonomies\'            => array( \'category\', \'post_tag\' ),
    \'hierarchical\'          => false,
    \'public\'                => true,
    \'rewrite\'            => array( \'slug\' => \'articles\' ),
    \'show_ui\'               => true,
    \'show_in_menu\'          => true,
    \'menu_position\'         => 5,
    \'menu_icon\'             => \'dashicons-format-aside\',
    \'show_in_admin_bar\'     => true,
    \'show_in_nav_menus\'     => true,
    \'can_export\'            => true,
    \'has_archive\'           => \'articles\',
    \'exclude_from_search\'   => false,
    \'publicly_queryable\'    => true,
    \'capability_type\'       => \'post\',
);
register_post_type( \'articles\', $args );
}添加\\u操作(\'init\',\'post\\u type\\u articles\',0);

这是回路

<header class="entry-header">
    <?php
    if ( is_singular() ) :
        the_title( \'<h1 class="entry-title">\', \'</h1>\' );
    else :
        the_title( \'<h2 class="entry-title archive-header"><a href="\' . esc_url( get_permalink() ) . \'" rel="bookmark">\', \'</a></h2>\' );
    endif;

    if ( \'post\' === get_post_type() ) : ?>
    <div class="entry-meta">
        <?php factorypress_posted_on(); ?>
    </div><!-- .entry-meta -->
    <?php
    endif; ?>
</header><!-- .entry-header -->

<div class="entry-content">
<div class="row">
<div class="col-sm-3">
    <?php the_post_thumbnail(\'large\', array(\'class\' => \'img-responsive\')); ?>
</div><!-- /.col-sm-2 -->
<div class="col-sm-9">
    <?php
        the_content( \'more\', sprintf(
            wp_kses(
                /* translators: %s: Name of current post. Only visible to screen readers */
                __( \'Continue reading<span class="screen-reader-text"> "%s"</span>\', \'factorypress\' ),
                array(
                    \'span\' => array(
                        \'class\' => array(),
                    ),
                )
            ),
            get_the_title()
        ) );

        wp_link_pages( array(
            \'before\' => \'<div class="page-links">\' . esc_html__( \'Pages:\', \'factorypress\' ),
            \'after\'  => \'</div>\',
        ) );
    ?>
</div><!-- /.col-sm-10 -->

    </div><!-- /.row -->
</div><!-- .entry-content -->

<footer class="entry-footer">
    <?php factorypress_entry_footer(); ?>
</footer><!-- .entry-footer -->

如果你能帮我回答这个问题,请提前感谢!

3 个回复
最合适的回答,由SO网友:erichmond 整理而成

如果您使用的是自定义存档模板,我认为应该添加条件is\\u post\\u type\\u archive()

if ( \'post\' === get_post_type() || is_post_type_archive( array( \'articles\' ) ) );

SO网友:David

在《二十一个主题》中,我们可以在inc/template标签中找到。php:

// Early exit if not a post.
if ( \'post\' !== get_post_type() ) {
    return;
}
我们可以覆盖该文件,将代码块更改为:

// Early exit if not a post or article.
if ( \'post\' !== get_post_type() && \'articles\' !== get_post_type() ) {
    return;
}

SO网友:Den Isahac

代码中的这一特定行阻止执行factorypress_posted_on 方法,该方法显示post元数据。

if ( \'post\' === get_post_type() ) : ?>
仅当post类型为post 不是您的自定义帖子类型articles. 我认为您应该将这一行代码替换为以下代码:

if ( \'post\' === get_post_type() || \'articles\' === get_post_type()) : ?>

结束

相关推荐

显示Archives.php中的所有自定义帖子类型

我该怎么做?archive.php 只有以下内容:wp_get_archives(\'type=monthly\'); 以及wp_get_archives() 没有显示所有帖子类型的参数。我也认为archive-[post_type].php 不是我要找的,因为我希望所有帖子类型都显示在一个归档页面中。谢谢W