Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Ricard Torres

    (@quicoto)

    Yes of course. You can either use the shortcode, check out the FAQ page or code it yourself.

    If it’s the latter, use the get_posts function. Use the orderby to sort the posts by the rating.

    https://codex.www.ads-software.com/Function_Reference/get_posts

    Example of arguments for the get_posts function:

    $args = array (
    	    	'post_type' 			 => $post_type,
    			'post_status'            => 'publish',
    			'cat'                    => $category,
    			'pagination'             => false,
    			'posts_per_page'         => $posts_per_page,
    			'cache_results'          => true,
    			'meta_key'	=> '_thumbs_rating_up', // or '_thumbs_rating_down'
    			'orderby'	=> 'meta_value_num'
    		);

    Best,

    Rick

    LeuName7

    (@leuname7)

    Would it be possible to expand your answer a little? I would like this feature too but I’m not sure how to implement it.

    Thank you!

    Plugin Author Ricard Torres

    (@quicoto)

    My code above will fetch posts ordered by the Thumbs Rating Up value (the + counts).

    If you take a look at the Codex link I’ve posted, you’ll see a simple use of get_posts. Like so:

    <ul>
    <?php
    
    $args = array( 'posts_per_page' => 5, 'offset'=> 1, 'category' => 1 );
    
    $myposts = get_posts( $args );
    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    	<li>
    		<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    	</li>
    <?php endforeach;
    wp_reset_postdata();?>
    
    </ul>

    In this example you would just need to modify the arguments to fit your needs (do you need a specific category? How many posts do you want to show? Don’t forget to add the order by!)

    Let me know if this helps.

    Rick

    Hello Ricard,

    Let me first thank you for your great plugin ??

    I’m using the thumbs rating system for an archive posts page.
    It is currently displayed by date and I’d like to reorder them by vote.
    As the votes are stored in the postmeta table I couldn’t manage to do a posts_orderby.
    Maybe you could give me a hint? ??

    PS : I’ve tried your shortcode but I’d like to keep the ‘post list’ style.

    Thank you!

    Caspa

    Plugin Author Ricard Torres

    (@quicoto)

    Hi Caspa,

    Thanks.

    I don’t understand why you can’t use the post meta data.

    Are you using get_posts ? If so pass the arguments to order by votes:

    meta_key'	=> '_thumbs_rating_up', // or '_thumbs_rating_down'
    'orderby'	=> 'meta_value_num'

    Feel free to paste some of your code (the part where you fetch and order the posts).

    Hello,

    I just solved my issue by adding this to function.php :

    add_filter( 'pre_get_posts' , 'my_change_order' );
    function my_change_order( $query ) {
    	if($query->is_archive)
    
    	    $query->set( 'meta_key', '_thumbs_rating_up' );
    		$query->set( 'orderby' , 'meta_value' );
    		$query->set( 'order' , 'desc' );
    
    	return $query;
    }

    But it doesn’t display the posts with no vote because they’re missing from the postmeta table as long as they don’t have any vote.
    Maybe you know how I could change that?

    Thanks!

    Caspa

    Plugin Author Ricard Torres

    (@quicoto)

    Right, you would need 2 things:

    1) A sort of a process to update all existing posts.

    2) A hook in your functions.php to set the post meta to 0 when you publish the post.

    I’m afraid I don’t have the time to code it for you. Take a look at the source code of the plugin, it has everything you need (how to get the post meta, how to update it, etc..)

    Good luck.

    I want to do this but none of the arguments are working for some reason. This is what i have in my entire page for loop-blog.php

    Maybe someone could point me in the right direction of where/what to add/edit – Thanks.

    <?php
    $blog_defaults = array(
    	'thumbnail'		=> '1',
    	'author'		=> '1',
    	'published'		=> '1',
    	'categories'	=> '1',
    	'comment_info'	=> '1',
    	'continue_btn'	=> '1',
    	'updated'		=> '0',
    	'tags'			=> '0',
    );
    
    $blog_elements = frontier_option('blog_elements', array());
    $blog_elements = wp_parse_args($blog_elements, $blog_defaults);
    ?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class('blog-view'); ?>>
    <?php do_action('frontier_before_blog_article'); ?>
    
    <header class="entry-header cf">
    	<?php do_action('frontier_before_blog_post_header'); ?>
    	<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    	<?php do_action('frontier_after_blog_post_header'); ?>
    </header>
    
    <div class="entry-byline cf">
    	<?php do_action('frontier_before_blog_post_byline'); ?>
    
    	<?php if ( $blog_elements['author'] == 1 ) : ?>
    		<div class="entry-author author vcard">
    			<?php $frontier_post_author_url = get_the_author_meta('user_url') != '' ? get_the_author_meta('user_url') : get_author_posts_url( get_the_author_meta('ID') ); ?>
    			<i class="genericon genericon-user"></i><a class="url fn" href="<?php echo esc_url( $frontier_post_author_url ); ?>"><?php the_author(); ?></a>
    		</div>
    	<?php endif; ?>
    
    	<?php if ( $blog_elements['published'] == 1 ) : ?>
    		<div class="entry-date">
    			<i class="genericon genericon-day"></i><a class="updated" href="<?php the_permalink(); ?>"><?php the_time(get_option('date_format')); ?></a>
    		</div>
    	<?php endif; ?>
    
    	<?php if ( get_post_type( $args ) == 'post' && $blog_elements['categories'] == 1 ) : ?>
    		<div class="entry-categories">
    			<i class="genericon genericon-category"></i><?php the_category(', '); ?>
    		</div>
    	<?php endif; ?>
    
    	<?php if ( $blog_elements['comment_info'] == 1 ) : ?>
    		<div class="entry-comment-info">
    			<i class="genericon genericon-comment"></i><a href="<?php the_permalink(); ?>#comment-area"><?php comments_number( __('Comments', 'frontier'), __('1 Comment', 'frontier'), __('% Comments', 'frontier') ); ?></a>
    		</div>
    	<?php endif; ?>
    
    	<?php edit_post_link( __('Edit', 'frontier'), '<i class="genericon genericon-edit"></i>' ); ?>
    
    	<?php do_action('frontier_after_blog_post_byline'); ?>
    </div>
    
    <div class="entry-content cf">
    	<?php do_action('frontier_before_blog_post_content'); ?>
    
    	<?php if ( frontier_option('blog_display', 'excerpt') == 'excerpt' ) : ?>
    
    		<?php if ( $blog_elements['thumbnail'] == 1 ) : ?>
    			<?php if ( apply_filters( 'frontier_has_post_thumbnail', has_post_thumbnail() ) ) : ?>
    				<div class="entry-thumbnail">
    					<a class="post-thumbnail" href="<?php the_permalink(); ?>">
    						<?php
    							if ( frontier_option('excerpt_thumbnail', '150') == '150' )
    								$frontier_excerpt_thumbnail = get_the_post_thumbnail( get_the_ID(), 'thumbnail' );
    							else
    								$frontier_excerpt_thumbnail = get_the_post_thumbnail( get_the_ID(), 'thumb-200x120' );
    
    							echo apply_filters( 'frontier_excerpt_thumbnail' , $frontier_excerpt_thumbnail );
    						?>
    					</a>
    				</div>
    			<?php endif; ?>
    		<?php endif; ?>
    
    <?=function_exists('thumbs_rating_getlink') ? thumbs_rating_getlink() : ''?>
    
    		<div class="entry-excerpt"><?php the_excerpt(); ?></div>
    
    	<?php else : ?>
    
    		<?php the_content(); ?>
    
    	<?php endif; ?>
    
    <?php
    $args = array (
    	    	'post_type' 			 => $post_type,
    			'post_status'            => 'publish',
    			'cat'                    => $category,
    			'pagination'             => false,
    			'posts_per_page'         => $posts_per_page,
    			'cache_results'          => true,
    			'meta_key'	=> '_thumbs_rating_up', // or '_thumbs_rating_down'
    			'orderby'	=> 'meta_value_num'
    		);
    ?>
    
    	<?php wp_link_pages( array(
    		'before'           => '<div class="page-nav">' . __('<span>Pages</span>', 'frontier'),
    		'after'            => '</div>',
    		'link_before'      => '<span>',
    		'link_after'       => '</span>',
    		'next_or_number'   => 'number',
    		'nextpagelink'     => __('Next page', 'frontier'),
    		'previouspagelink' => __('Previous page', 'frontier'),
    		'pagelink'         => '%',
    		'echo'             => 1 ) );
    	?>
    
    	<?php do_action('frontier_after_blog_post_content'); ?>
    </div>
    
    <footer class="entry-footer cf">
    	<?php do_action('frontier_before_blog_post_footer'); ?>
    
    	<?php if ( frontier_option('blog_display', 'excerpt') == 'excerpt' ) : ?>
    
    		<?php if ( $blog_elements['continue_btn'] == 1 ) : ?>
    			<a href="<?php the_permalink(); ?>" class="continue-reading">
    				<?php $frontier_continue_reading_text = ( get_post_type() == 'page' ) ? __('Read Page', 'frontier') : __('See Full Size', 'frontier'); ?>
    				<?php echo apply_filters( 'frontier_continue_reading_text', $frontier_continue_reading_text ); ?>
    			</a>
    		<?php endif; ?>
    
    	<?php endif; ?>
    
    	<?php if ( $blog_elements['updated'] == 1 ) : ?>
    		<div class="entry-updated updated">
    			<?php printf( __( 'Updated: %1$s &mdash; %2$s', 'frontier' ), get_the_modified_date(), get_the_modified_time() ); ?>
    		</div>
    	<?php endif; ?>
    
    	<?php if ( get_post_type() == 'post' && $blog_elements['tags'] == 1 ) : ?>
    		<div class="entry-tags"><?php the_tags(); ?></div>
    	<?php endif; ?>
    
    	<?php do_action('frontier_after_blog_post_footer'); ?>
    </footer>
    
    <?php do_action('frontier_after_blog_article'); ?>
    </article>
    Plugin Author Ricard Torres

    (@quicoto)

    Really hard to debug like this.

    My recommendation would be to create an empty (and clean) page template https://codex.www.ads-software.com/Page_Templates

    Then assign it to a Draft page and start playing with the code. Try the simplest example from https://codex.www.ads-software.com/Template_Tags/get_posts

    Once it’s working add the Thumbs Rating order. And then, once that’s working try to implement it in your other templates.

    Good luck!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Can the thumbs up / down change the order of the post on the page?’ is closed to new replies.