WordPress.org

Ready to get started?Download WordPress

Forums

WP-PostViews
Number of views in entry_meta (1 post)

  1. shoganrea
    Member
    Posted 1 year ago #

    Hello,

    I'd like to include the number of views in the entry_meta of my TwentyTwelve child theme but I don't know much about HTML. I added this code in the function.php of my child theme:

    if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
    /**
    * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
    *
    * Create your own twentytwelve_entry_meta() to override in a child theme.
    *
    * @since Twenty Twelve 1.0
    */
    function twentytwelve_entry_meta() {
    // Translators: used between list items, there is a space after the comma.
    $categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );

    // Translators: used between list items, there is a space after the comma.
    $tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );

    $date = sprintf( '<time class="entry-date" datetime="%3$s">%4$s</time>',
    esc_url( get_permalink() ),
    esc_attr( get_the_time() ),
    esc_attr( get_the_date( 'c' ) ),
    esc_html( get_the_date() )
    );

    $author = sprintf( '<span class="author vcard"></span>',
    esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
    get_the_author()
    );

    // Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
    if ( $tag_list ) {
    $utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>. It was read x times.', 'twentytwelve' );
    } elseif ( $categories_list ) {
    $utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>. It was read x times.', 'twentytwelve' );
    } else {
    $utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>. It was read x times.', 'twentytwelve' );
    }

    printf(
    $utility_text,
    $categories_list,
    $tag_list,
    $date,
    $author
    );
    }
    endif;

    I want to show the number of views as "It was read x times", but don't know how to include the number of views there. Is this possible and can somebody give me a hint how to do it?

    Thanks in advance. :)

    http://wordpress.org/extend/plugins/wp-postviews/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic