0

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

<?php
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.

1 Answer 1

1

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>
1
  • 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
    Commented Mar 16, 2012 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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