Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #671344
    lkd
    Participant

    Hello,
    i would like to show how many post view and comment are there for every blog post.

    I would like this to be displayed in meta post on post itself displaying near date and post category
    i would also like it to be displayed on the little recent post list from ome page. example in attached pictures

    I know there is no integrated way to do this so i found a plugin that i think do the job well. WP-Post-views

    this plugin help says:

    1- Open wp-content/themes/<YOUR THEME NAME>/index.php. You may place it in archive.php, single.php, post.php or page.php also.
    2- Find: <?php while (have_posts()) : the_post(); ?>
    3- Add Anywhere Below It (The Place You Want The Views To Show): <?php if(function_exists(‘the_views’)) { the_views(); } ?>
    4- Or you can use the shortcode [views] or [views id=”1″] (where 1 is the post ID) in a post

    Can you help me find the exact place to paste the code given by plugin help in x theme files? so it would be displayed as i would like it to be?

    thanks a lot

    #671466
    Zeshan
    Member

    Hi Kholic,

    Thanks for writing in! As this is related to the integration of 3rd party plugin, regretfully, we cannot provide support for third party plugins or scripts as our support policy in the sidebar states due to the fact that there is simply no way to account for all of the potential variables at play when using another developer’s plugin or script. Because of this, any questions you have regarding setup, integration, or troubleshooting any piece of functionality that is not native to X will need to be directed to the original developer.

    Thank you for your understanding.

    #671574
    lkd
    Participant

    i am not asking you to modify anything

    I just want to know as you are the dev of X Thme, what is the specific place in X theme template (indexph and other xtheme template files) i should insert the code into to make it display post view count where i want (as shoiwn on the pictures)

    #671582
    lkd
    Participant

    Or by the way, as it is a blog classic feature ios there a way in X theme to display post views count and comment count in posts meta?

    #671770
    Zeshan
    Member

    Hi Kholic,

    The file responsible for the output of blog posts is _index.php and located under wp-content/themes/x/framework/views/global/ directory. You can copy it to the same directory level in your child theme to make customizations.

    As for the recent posts, you’ll need to modify the shortcode itself in order to apply the changes. As this is a custom development, it would be outside the scope of support we can offer. You may wish to consult a developer to assist you with this. X is quite extensible with child themes, so there are plenty of possibilities.

    By default, X only provides comment count functionality. In your first shared screenshot, where “Leave a comment” is written, it’ll be replaced with the amount of comments when the post has one or more comments.

    Thanks for understanding. Take care!

    #672773
    lkd
    Participant

    ok
    thanks

    #672845
    Paul R
    Moderator

    You’re welcome! 🙂

    #678716
    lkd
    Participant

    Back again,
    Please can you just indicate which files contained in :wp-content/themes/x-child/framework/views/global/
    which one have configuration code for showing the comment counts included by default in x theme?

    also which particular codes stanza do thath please?

    #678731
    Paul R
    Moderator

    Hi,

    The comments counts are included in renew entry Meta.

    You can add this in your child theme’s functions.php then modify it as you wish.
    By adding this code in your child theme, it will override xtheme default entry meta.

    
    function x_renew_entry_meta() {
    
        //
        // Author.
        //
    
        $author = sprintf( '<span>%s</span>',
          get_the_author()
        );
    
        //
        // Date.
        //
    
        $date = sprintf( '<span><time class="entry-date" datetime="%1$s">%2$s</time></span>',
          esc_attr( get_the_date( 'c' ) ),
          esc_html( get_the_date() )
        );
    
        //
        // Categories.
        //
    
        if ( get_post_type() == 'x-portfolio' ) {
          if ( has_term( '', 'portfolio-category', NULL ) ) {
            $categories        = get_the_terms( get_the_ID(), 'portfolio-category' );
            $separator         = ', ';
            $categories_output = '';
            foreach ( $categories as $category ) {
              $categories_output .= '<a href="'
                                  . get_term_link( $category->slug, 'portfolio-category' )
                                  . '" title="'
                                  . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                  . '"> '
                                  . $category->name
                                  . '</a>'
                                  . $separator;
            }
    
            $categories_list = sprintf( '<span>%s</span>',
              trim( $categories_output, $separator )
            );
          } else {
            $categories_list = '';
          }
        } else {
          $categories        = get_the_category();
          $separator         = ', ';
          $categories_output = '';
          foreach ( $categories as $category ) {
            $categories_output .= '<a href="'
                                . get_category_link( $category->term_id )
                                . '" title="'
                                . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                . '">'
                                . $category->name
                                . '</a>'
                                . $separator;
          }
    
          $categories_list = sprintf( '<span>%s</span>',
            trim( $categories_output, $separator )
          );
        }
    
        //
        // Comments link.
        //
    
        if ( comments_open() ) {
    
          $title  = apply_filters( 'x_entry_meta_comments_title', get_the_title() );
          $link   = apply_filters( 'x_entry_meta_comments_link', get_comments_link() );
          $number = apply_filters( 'x_entry_meta_comments_number', get_comments_number() );
    
          if ( $number == 0 ) {
            $text = __( 'Leave a Comment' , '__x__' );
          } else if ( $number == 1 ) {
            $text = $number . ' ' . __( 'Comment' , '__x__' );
          } else {
            $text = $number . ' ' . __( 'Comments' , '__x__' );
          }
    
          $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
            esc_url( $link ),
            esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
            $text
          );
    
        } else {
    
          $comments = '';
    
        }
    
        //
        // Output.
        //
    
        if ( x_does_not_need_entry_meta() ) {
          return;
        } else {
          printf( '<p class="p-meta">%1$s%2$s%3$s%4$s</p>',
            $author,
            $date,
            $categories_list,
            $comments
          );
        }
    
      }
    

    Hope that helps

    #678972
    lkd
    Participant

    As i am already using Renew, do I need to add this my child theme function.php??

    and as already using meta in which file is that code snippet already present?

    #679070
    Rupok
    Member

    Hi there,

    Thanks for updating. Please re-read the reply and follow the instruction. If you need to edit anything then modify the code and use on your Child Theme to overwrite the parent theme’s function.

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-671344 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>