• hey guys been trying this for awhile now, finally got my review section of my site running and want to create a widget that lists 8 random reviews in my sidebar.

    I’ve tried a few tutorials on making a widget but i cant get it to work with my query for the reviews.

    heres the code for the review list

    <div class="review-list">
    
    <h2 class="review-titleblock">Reviews</h2>
    
    <div class="score">
    
    <?php $args = array(
    	'post_type' => 'reviews',
    	'orderby'   => 'rand',
    	'meta_key'  => 'mymetabox_Score',
    	'posts_per_page' => 8,
    
    );
    $query = new WP_Query( $args ); ?>
    
    <?php if ( $query->have_posts() ) : ?>
    <?php while ( $query->have_posts() ) : $query->the_post(); ?>
    
    <div id="review-item"><div class="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    			<a href="<?php echo the_permalink(); ?>">
                                    <h4 class="review-list-title"><?php the_title(); ?></h4>
    
    			</a>
          <div class="review-scorebg"><?php gamergreed_score(); ?></div>
    </div>
    
    		<?php endwhile; ?>
    
    <?php wp_reset_postdata(); ?>
    <?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
    
    </div>
    
    </div>
    </div>

    can anyone help me add this into a widget i can add into my sidebar?

    thanks in advance!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘creating a widget’ is closed to new replies.