Support » Fixing WordPress » Get recent post permalinks by category

  • Hi,

    So I’ve created a custom page template for my “Topics” Page.

    What I want to do is add in some PHP to the custom page template my Topics page uses, to retrieve permalinks for the 3 most recent posts from a chosen category.

    (From post category 1)
    –> Permalink for post 1
    –> Permalink for post 2
    –> Permalink for post 3

    Can anyone advise on doing this? I’ve seen many solutions but wasn’t able to get any working. I’d rather avoid using a plugin if possible.

    Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • <ul>
    	$category_posts = new WP_Query('cat=x&showposts=y');
    while ($category_posts ->have_posts()) : $category_posts->the_post();?>
     <a class="yourclass" href="<?php the_permalink(); ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?> </a></li>
     <?php endwhile; ?>

    Replace x with the category ID and y with the number of links you’d like to retrieve

    Is there any particular place I need to put this, as pasting it into my .php file doesn’t seem to work.

    Thanks 🙂

    Ok I’ve added this in, but it doesn’t seem to work when I change “cat=x” to cat=1 or cat=categoryname

    How can I select only topics from a certain category?

    Thanks for all the help so far! 🙂

    Add the code to the custom page template you created for your Topics page

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get recent post permalinks by category’ is closed to new replies.