【问题标题】:How to display multiple authors on a WordPress post如何在 WordPress 帖子上显示多个作者
【发布时间】:2020-02-05 05:50:05
【问题描述】:

我有一个 WordPress 博客,其中一些文章是由多个作者撰写的,因此我想在帖子上显示它们。通过安装Co-Authors Plus plugin 已经实现了部分目标。此插件仅允许您为帖子分配多个作者,但它不会自动在已发布的帖子中显示两位作者。为此,我不得不调整我的主题 Mission News 的 post-author.php 文件,并帮助自己使用 this guide。我成功编辑了文件(如下面的代码所示),现在两个名字 Rachele 和 Collaboratore 都显示在this post 的末尾。

原始的 post-author.php 文件

<?php if ( get_theme_mod( 'author_box_posts' ) == 'no' ) return; ?>
<div class="post-author">
    <?php if ( get_theme_mod( 'author_avatar_posts' ) != 'no' ) : ?>
    <div class="avatar-container">
        <?php echo get_avatar( get_the_author_meta( 'ID' ), 78, '', get_the_author() ); ?>
    </div>
    <?php endif; ?>
    <div>
        <div class="author"><?php the_author(); ?></div>
        <p><?php the_author_meta('description'); ?></p>
    </div>
</div>

编辑后的 ​​post-author.php 文件

<?php if ( get_theme_mod( 'author_box_posts' ) == 'no' ) return; ?>
<div class="post-author">
    <?php if ( get_theme_mod( 'author_avatar_posts' ) != 'no' ) : 
    if ( function_exists( 'coauthors_posts_links' ) ) {
    coauthors_posts_links();
} else {
    the_author_posts_link();
}?>
    <div class="avatar-container">
        <?php echo get_avatar( get_the_author_meta( 'ID' ), 78, '', get_the_author() ); ?>
    </div>
    <?php endif; ?>
    <div>
        <p><?php the_author_meta('description'); ?></p>
    </div>
</div>

我想这里真正的问题是我对 php 的了解几乎不存在,因为我未能正确编辑 content.php 文件,我认为该文件是我需要编辑的文件,以便在文本中添加两个作者姓名在标题下方和发布日期旁边。

content.php 文件包含以下几行:

<?php
$author = get_theme_mod( 'post_author_posts' );
$date   = get_theme_mod( 'post_date_posts' );
?>
<div <?php post_class(); ?>>
    <?php do_action( 'ct_mission_news_post_before' ); ?>
    <article>
        <?php ct_mission_news_featured_image(); ?>
        <div class='post-header'>
            <h1 class='post-title'><?php the_title(); ?></h1>
            <?php ct_mission_news_post_byline( $author, $date ); ?>
        </div>
        <div class="post-content">
        <?php ct_mission_news_output_last_updated_date(); ?>
            <?php the_content(); ?>
            <?php wp_link_pages( array(
                'before' => '<p class="singular-pagination">' . esc_html__( 'Pages:', 'mission-news' ),
                'after'  => '</p>',
            ) ); ?>
            <?php do_action( 'ct_mission_news_post_after' ); ?>
        </div>
        <div class="post-meta">
            <?php get_template_part( 'content/post-categories' ); ?>
            <?php get_template_part( 'content/post-tags' ); ?>
            <?php get_sidebar( 'after-post' ); ?>
            <?php get_template_part( 'content/post-author' ); ?>
        </div>
        <?php get_template_part( 'content/more-from-category' ); ?>
    </article>
    <?php comments_template(); ?>
</div>

我想我应该编辑&lt;?php ct_mission_news_post_byline( $author, $date ); ?&gt; 行,但我不知道怎么做。我尝试了一些方法,但都没有成功。

我希望能够在帖子标题下方和发布日期旁边显示作者的姓名。 提前感谢所有愿意帮助我的人。 祝你有美好的一天!

【问题讨论】:

    标签: php html wordpress post author


    【解决方案1】:

    这个:

    (function_exists ('coauthors_posts_links')) {coauthors_posts_links ();} 
    

    另一个:

    {the_author_posts_link (); } 
    

    【讨论】:

    • 亲爱的martoria,感谢您的回答。我尝试添加代码,但由于我对 php 缺乏经验,它破坏了网站。你能告诉我我应该把代码放在 php 文件中的哪个位置吗?那太好了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-10
    • 2021-04-11
    • 1970-01-01
    相关资源
    最近更新 更多