WordPress:在标题下方而不是上方放置一个函数

时间:2019-02-23 04:14:05

标签: javascript wordpress

我一直在使用一个脚本,该脚本将函数的内容放在帖子标题的上方。两个问题。首先,我希望此内容显示在帖子下方。另一个?此内容以某种方式插入到h1标签内部而不是其下方。因此,您在H1内有一个段落。不是世界上最伟大的程序员,那么我该如何纠正呢?

这是我在帖子模板中显示标题的地方:

<?php the_title( '<h1 class="tribe-events-single-event-title">', '</h1>' ); ?>

这是函数:

add_filter( 'the_title', 'dv_comment_rating_display_average_rating' );

函数dv_comment_rating_display_average_rating($ content){

global $post;

    if ( false === dv_comment_rating_get_average_ratings( $post->ID ) ) {
        return $content;
    }

    $stars   = '';
    $average = dv_comment_rating_get_average_ratings( $post->ID );

    for ( $i = 1; $i <= $average + 1; $i++ ) {

        $width = intval( $i - $average > 0 ? 20 - ( ( $i - $average ) * 20 ) : 20 );

        if ( 0 === $width ) {
            continue;
        }

        $stars .= '<span style="overflow:hidden; width:' . $width . 'px" class="dashicons dashicons-star-filled"></span>';

        if ( $i - $average > 0 ) {
            $stars .= '<span style="overflow:hidden; position:relative; left:-' . $width .'px;" class="dashicons dashicons-star-empty"></span>';
        }
    }

        $count_comments = get_comment_count();
        $comments  = $count_comments['approved'];

        $custom_content  = '<p class="average-rating">' . $stars . '<a href="#comments-title">' . $comments . ' reviews</a></p>';
        $custom_content .= $content;
        return $custom_content;
    }

0 个答案:

没有答案