我有一个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>
我想我应该编辑
<?php ct_mission_news_post_byline( $author, $date ); ?>
行,但是我不知道如何。我尝试了一些方法,但没有任何效果。
我希望能够在帖子标题下和发布日期旁边显示作者的姓名。预先感谢所有愿意帮助我的人。祝你有美好的一天!
我有一个WordPress博客,有些文章是由多位作者撰写的,因此,我希望在帖子上显示它们。通过安装共同作者已经实现了部分目标...
此: