With get_posts(), how can I put a category as a variable

I’m a noob at this so please bear with me.

I have the following code to return post title as links within categoryID 6, which is working fine:

Read More
<?php global $post; $cat_posts = get_posts('numberposts=10&category=6');
  foreach($cat_posts as $post) : ?>
    <?php $postTitle = get_the_title(); if($title != $postTitle) :?>
    <li><a href="<?php the_permalink(); ?>">&rsaquo;&rsaquo; <?php the_title(); ?></a></li>
    <?php endif ;?>
<?php endforeach; ?>

However, the category ID is a variable, e.g. $catID, can I use this in the above code?

Thanks in advance!

Related posts

Leave a Reply

1 comment