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

时间:2015-03-31 22:26:42

标签: php wordpress function themes

除了我在WordPress上修改过的内容之外,我几乎都不知道PHP,但是我试图自定义我的主题以允许两位作者列在帖子的前端。

我安装了Co-Authors Plus插件(Here) 两位作者从后端开始工作得很好。

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

我理解基本知识并确定主题文件,但不知道如何合并它,因为它似乎没有调用一个函数来显示作者,它调用了一个变量。更大的功能(再次,我不知道php,所以如果我在这里错了,请告诉我。)

这是Co-Authors Plus提供的简单代码:

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;
}

我看到$ author行是定义前端输出的,但是如果不了解php,我不知道如何在那里包含if-else语句。 我尝试了一些业余编辑,只是有错误。任何关于如何在保留主题造型的同时融入这一指导的指导都将非常受欢迎。

我正在使用Momizat的Goodnews主题。

0 个答案:

没有答案