I know pretty much no PHP other than what I've tinkered with on WordPress, but I'm trying to customize my theme to allow two authors to be listed on the front-end of posts.
I installed the Co-Authors Plus plugin (Here) And from the back end it's working well, both authors show up.
For it to show up on the front end, according to several support articles I need to adjust the theme functions to check if there are multiple authors, and if so display them.
I understand the basics and identified the theme file, but have no idea how to incorporate it because it seems that the theme isn't calling a function to display the authors, it's calling a variable in a much larger function (again, I don't know php, so if I'm wrong here, please let me know).
This is the bare bones code provided by Co-Authors Plus:
if ( function_exists( 'coauthors_posts_links' ) ) {
coauthors_posts_links();
} else {
the_author_posts_link();
}
But when I look in the functions file I don't see where that could go. I see this:
// mom_post_meta
function mom_posts_meta ($class = '', $display = null) {
$num_comments = get_comments_number(); // get_comments_number returns only a numeric value
if ( comments_open() ) {
if ( $num_comments == 0 ) {
$comments = __('No Comments', 'theme');
} elseif ( $num_comments > 1 ) {
$comments = $num_comments .' '. __(' Comments', 'theme');
} else {
$comments = __('1 Comment', 'theme');
}
$write_comments = '<a href="' . get_comments_link() .'">'. $comments.'</a>';
} else {
//$write_comments = __('Comments off', 'theme');
$write_comments = '';
}
$author_link = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
if (class_exists('userpro_api')) {
global $userpro;
$author_link = $userpro->permalink(get_the_author_meta( 'ID' ));
}
$categories = get_the_category();
$separator = ', ';
$cats = '';
if($categories){
foreach($categories as $category) {
$cats.= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s", 'theme' ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
}
}
$output = '<div class="mom-post-meta '.$class.'">';
$author = mom_option('post_meta-author') == 1 ? '<span class="author vcard">'.__('Posted by:', 'theme').' <span class="fn"><a href="'.$author_link.'">'.get_the_author().'</a></span></span>': '';
$date = mom_option('post_meta-date') == 1 ? '<span>'.__('On:', 'theme').' <time datetime="'.get_the_time('c').'" itemprop="datePublished" class="updated">'.get_mom_date_format().'</time></span>': '';
//$date = mom_option('post_meta-date') == 1 ? '<span>'.__('The last Update:', 'theme').' <time datetime="'.get_the_time('c').'" itemprop="datePublished" class="updated">'. get_post_modified_time(mom_option('date_format')).'</time></span>': '';
$cat = mom_option('post_meta-cat') == 1 ? '<span>'.__('In', 'theme').': '.trim($cats, $separator).'</span>': '';
$comments = mom_option('post_meta-comments') == 1 ? '<span>'.$write_comments.'</span>': '';
if ($display == 'date_comments') {
$output .= $date.$comments;
} else {
$output .= $author.$date.$cat.$comments;
}
if(function_exists('the_views')) {
$output .= '<span>'.__('Views:', 'theme').' '.the_views(false).'</span>';
}
$output .= get_mom_show_review_score();
$output .= '</div>';
echo $output;
}
I see that the $author line is what defines the output on the front end, but without an understanding of php I'm not sure how to include an if-else statement in there. I tried a few amateur edits, and just got errors. Any guidance of how to incorporate this while preserving the theme styling would be so very much appreciated.
I'm using Momizat's Goodnews theme.
Aucun commentaire:
Enregistrer un commentaire