Try get_query_vars('cat')
example (not tested):
<?php
$current_category = get_query_var('cat');
$random_posts = get_posts('posts_per_page=3&orderby=rand&cat='.$current_category);
if ($random_posts) {
$html = '<ul>';
foreach ( $random_posts as $random_post ) {
$html .= '<li><a href="'.get_permalink( $random_post->ID ).'" title="'.esc_attr(strip_tags($random_post->post_title)).'" >'. $random_post->post_title.'</a></li>';
}
$html .= '<ul>';
echo $html;
}
?>
thank you… i tried this…
<?php
$current = get_query_var('cat');
$myposts = get_posts('numberposts=10&orderby=name&cat=4&order=RAND');
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?> v <?php the_field('version'); ?></a></li>
<?php endforeach; ?>
but it is not working…
this worked…
<?php
$current = get_query_var('cat');
$args = array( 'numberposts' => 10, 'orderby' => 'rand', 'order' => 'RAND', 'category' => $current );
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>