Php WordPress模板中的编辑功能-可以只编辑一个变量吗?

Php WordPress模板中的编辑功能-可以只编辑一个变量吗?,php,wordpress,function,themes,Php,Wordpress,Function,Themes,除了在WordPress上修改过的内容外,我对PHP几乎一无所知,但我正在尝试自定义我的主题,以允许两位作者出现在文章的前端 我安装了合著者Plus插件() 从后端来看,两位作者都表现得很好 为了让它显示在前端,根据几个例子,我需要调整主题函数,以检查是否有多个作者,如果有,则显示他们 我了解基本知识并确定了主题文件,但不知道如何合并它,因为主题似乎不是调用函数来显示作者,而是调用一个更大的函数中的变量(同样,我不懂php,因此如果我在这里出错,请让我知道) 这是合著者提供的基本代码,外加: i

除了在WordPress上修改过的内容外,我对PHP几乎一无所知,但我正在尝试自定义我的主题,以允许两位作者出现在文章的前端

我安装了合著者Plus插件() 从后端来看,两位作者都表现得很好

为了让它显示在前端,根据几个例子,我需要调整主题函数,以检查是否有多个作者,如果有,则显示他们

我了解基本知识并确定了主题文件,但不知道如何合并它,因为主题似乎不是调用函数来显示作者,而是调用一个更大的函数中的变量(同样,我不懂php,因此如果我在这里出错,请让我知道)

这是合著者提供的基本代码,外加:

if ( function_exists( 'coauthors_posts_links' ) ) {
coauthors_posts_links();
} else {
the_author_posts_link();
}
但是,当我查看函数文件时,我看不到它的用途。我看到:

// 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;
}
//mom\u post\u meta
函数mom\u posts\u meta($class='',$display=null){
$num_comments=get_comments_number();//get_comments_number只返回一个数值
如果(注释打开()){
如果($num_comments==0){
$comments=u;('No comments','theme');
}elseif($num_comments>1){
$comments=$num_comments.''._('comments','theme');
}否则{
$comments=_uu('1 Comment','theme');
}
$write_comments='';
}否则{
//$write_comments=uuu('comments off','theme');
$write_comments='';
}
$author\u link=esc\u url(获取作者帖子url(获取作者元数据('ID'));
如果(类_存在('userpro_api')){
全球$userpro;
$author\u link=$userpro->permalink(获取作者元('ID'));
}
$categories=get_the_categories();
$separator=',';
$cats='';
如果($类别){
foreach($categories作为$category){
$cats.=''.$separator;
}
}
$output='';
$author=mom_选项('post_meta-author')==1?“”。';
$date=mom_选项('post_meta-date')==1?'.'.''.'On:','theme').'.获取'u mom_-date_格式()':'';
//$date=mom\u选项('post\u meta-date')==1?'.''.'最后更新:','theme')。'.获取\u post\u修改的\u时间(mom\u选项('date\u格式')。':'';
$cat=mom_选项('post_meta-cat')==1?''。'''In','theme'):''。trim($cats,$separator)。''';
$comments=mom_选项('post_meta-comments')==1?'.$write_comments'.':'';
如果($display=='date\u comments'){
$output.=$date.$comments;
}否则{
$output.=$author.$date.$cat.$comments;
}
如果(函数_存在(‘_视图’)){
$output.=''.''.'视图:','主题'。'.'视图(假)。'';
}
$output.=get_mom_show_review_score();
$output.='';
echo$输出;
}
我看到$author行定义了前端的输出,但是如果不了解php,我不知道如何在其中包含if-else语句。 我尝试了几次业余编辑,但都出错了。任何关于如何在保留主题风格的同时融入这一点的指导都将不胜感激


我使用的是Momizat的Goodnews主题。

第一段代码不在functions.php文件中,而是在一个模板文件中,您希望在其中显示共同作者的列表。但是模板文件只调用函数文件。函数文件包含实际定义作者名称和链接外观的内容。例如,下面是single post文件主要部分的代码:您的评论上的最后一个
if
语句没有多大意义,因为它在任何情况下都调用
mom\u single\u post\u content()
。但是,尝试在您的单个邮政文件中插入第一个代码,在<<代码>之前或之后,如果语句(您不应该编辑主题的文件,最后考虑使用A)