• vbdeco

    (@vbdeco)


    Hi,

    I’m using Nisarg theme for my blog. I want to add a post rating by using “wp-postratings” plugin.

    This is what developper say to install it :

    Find: <?php while (have_posts()) : the_post(); ?>
    Add Anywhere Below It (The Place You Want The Ratings To Show): <?php if(function_exists(‘the_ratings’)) { the_ratings(); } ?>

    Could you tell me in wich file could i add this code to have post ratings after my post ?

    Regards.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Subrata Sarkar

    (@subrataemfluence)

    That’s up to you. Say you want to display the rating stars just below the title of your post. If so you can do this:

    <?php
      while(have_posts()): the_post();
      echo the_title();
      echo '<hr />';
      if(function_exists(‘the_ratings’)) { the_ratings(); }
    ?>
    Thread Starter vbdeco

    (@vbdeco)

    Hi,
    No i want to display rathing just before the comments.

    Subrata Sarkar

    (@subrataemfluence)

    I presume your comment section comes beneath the actual post_content. If so you might reposition your rating starts under post_content so that the snippet looks like:

    <?php
      while(have_posts()): the_post();
      echo the_title();
      echo '<hr />';
      echo the_content();
      echo '<hr />';
      if(function_exists(‘the_ratings’)) { the_ratings(); }
      echo '<hr />';
      // Your Comment section starts here
    ?>
    Thread Starter vbdeco

    (@vbdeco)

    But in which PHP file ?

    • This reply was modified 8 years ago by vbdeco.
    Thread Starter vbdeco

    (@vbdeco)

    Don’t you know ?

    Subrata Sarkar

    (@subrataemfluence)

    It is the page where your blog posts are being listed or the page where you are showing a blog’s detail information. It is hard to know what file structure you are using, if you have a child theme etc.

    Usually detail page comes from single.php.

    To know what php file is working behind a page there is a nice plugin available.
    https://www.ads-software.com/plugins/what-the-file/.

    Please go ahead and install it. You will know yourself where you to put the code for rating plugin ??

    Thread Starter vbdeco

    (@vbdeco)

    Thank you.

    So there are :
    template-parts/content.php
    and single.php.

    Problems : when i add code in these files, “rating stars” are out row :

    capture

    I need stars after “escapades”. It is not first time i used this pluggin, but it’s the first time i can’t use it with Niasarg theme.

    • This reply was modified 8 years ago by vbdeco.
    Thread Starter vbdeco

    (@vbdeco)

    Code for single.php :

    <?php
    /**
     * The template for displaying all single posts.
     *
     * @package Nisarg
     */
    
    get_header(); ?>
    
    	<div class="container">
            <div class="row">
    			<div id="primary" class="col-md-9 content-area">
    				<main id="main" role="main">
    
    				<?php while ( have_posts() ) : the_post(); ?>
    
    					<?php get_template_part( 'template-parts/content',get_post_format()); ?>
    				</main><!-- #main -->
    <div class="post-navigation">				
    					<?php nisarg_post_navigation(); ?>
    				</div>
    
    				<div class="post-comments">
    					<?php
    						// If comments are open or we have at least one comment, load up the comment template.
    						if ( comments_open() || get_comments_number() ) :
    							comments_template();
    						endif;
    
    						if(!comments_open())
    							_e('Comments are closed.','nisarg');
    
    					?>
    				</div>			
    
    				<?php endwhile; // End of the loop. ?>
    
    				
    			</div><!-- #primary -->
    
    			<?php get_sidebar('sidebar-1'); ?>
    		</div> <!--.row-->            
        </div><!--.container-->
        <?php get_footer(); ?>
    

    Code for template-parts/content.php

    <?php
    /**
     * Template part for displaying posts.
     *
     * @package Nisarg
     */
    
    ?>
    
    <article id="post-<?php the_ID(); ?>"  <?php post_class('post-content'); ?>>
    
    	<?php
    	if ( is_sticky() && is_home() && ! is_paged() ) {
    		printf( '<span class="sticky-post">%s</span>', __( 'Featured', 'nisarg' ) );
    	} ?>
    
    	<?php nisarg_featured_image_disaplay(); ?>
    	
    	<header class="entry-header">	
    	
    		<span class="screen-reader-text"><?php the_title();?></span>
    
    		<?php if ( is_single() ) : ?>
    			<h1 class="entry-title"><?php the_title(); ?></h1>
    		<?php else : ?>
    			<h2 class="entry-title">
    				<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
    			</h2>
    		<?php endif; // is_single() ?>
    
    		<?php if ( 'post' == get_post_type() ) : ?>
    		<div class="entry-meta">
    			<h5 class="entry-date"><?php nisarg_posted_on(); ?></h5>
    		</div><!-- .entry-meta -->
    		<?php endif; ?>
    	</header><!-- .entry-header -->
    	
    			<div class="entry-content">
    				<?php					
    					the_content('...<p class="read-more"><a class="btn btn-default" href="'. esc_url(get_permalink( get_the_ID() )) . '">' . __(' Read More', 'nisarg') . '<span class="screen-reader-text"> '. __(' Read More', 'nisarg').'</span></a></p>');
    				?>
    <?php
    					wp_link_pages( array(
    						'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'nisarg' ),
    						'after'  => '</div>',
    					) );
    				?>
    			</div><!-- .entry-content -->
    
    	<footer class="entry-footer">
    		<?php nisarg_entry_footer(); ?>
    	</footer><!-- .entry-footer -->
    </article><!-- #post-## -->
    
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Add Post ratings’ is closed to new replies.