WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I set and reversed the order of a list of post titles on my front page with:

global $post;
$args = array( 'category' => 6 );
$myposts = get_posts( $args );
$reverseposts = array_reverse( $myposts, true);
foreach( $reverseposts as $post ) : setup_postdata($post); ?>
<?php the_title(); ?>
<?php endforeach; ?>

Now I'm not being able to find the proper "a href" line to link those titles to its posts called in another temp file. I hardcoded:

<a href="<?php bloginfo('template_url'); ?>/category6"><?php the_title(); ?></a>

but I guess there's a proper way to get "category6" dynamically.

Any help would be most appreciated. Thx in advance.

share|improve this question

get_category_link is what you are looking for. And you could just use:

<?php echo get_category_link(6); ?>

and that will output the url to the category page.

<a href="<?php echo get_category_link(6); ?>"><?php the_title(); ?></a>
share|improve this answer
Thx, weston. I added it to my previous line: <a href="<?php bloginfo('template_url'); ?>/<?php echo get_category_link(6); ?>"><?php the_title(); ?></a> and it worked. Do u think i could add a page jump straight to where the post is on the page? – luprates Mar 16 '12 at 19:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.