Wordpress link to last category post

Discussion in 'PHP' started by Sisk, Oct 21, 2009.

  1. #1
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    Code (markup):
    what i wanne do is to take the last post title from a category i pick
    thnx
     
    Sisk, Oct 21, 2009 IP
  2. WritEffects

    WritEffects Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You might want to read the function - get_posts() - @ http://codex.wordpress.org. I believe your question is related to this function. It might help you. Just search for it there. :)
     
    WritEffects, Oct 21, 2009 IP
  3. Sisk

    Sisk Member

    Messages:
    104
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #3
    i did searched but i did`nt find an answer . if you can help me let a post here with an ideea
     
    Sisk, Oct 21, 2009 IP
  4. WritEffects

    WritEffects Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The approach I told you about is gonna involve a bit of coding, so you are familiar with PHP and WP? If there is a plugin for what you are asking, all the better. Try searching for it at wordpress.org plugins page.

    Here is the link for function get_posts(). Read the page and you will see good explanations and some sample codes.

    Example, this line
    get_posts('category=1&numberposts=3&orderby=date');
    Code (markup):
    > category is set to 1, assuming you have that as a category ID
    > numberposts is set to 3, so it returns 3 posts of category 1. Since you just want the latest post of a category, you might want to set this as 1.
    > orderby is set to 'date', w/c should order the posts by date, DESC is the default. Although I think the natural order is always most recent post first

    And this, get_all_category_ids(), will help you too, in case you have a lot of categories or just don't know the category ID. There is a sample code on that page with explanation.

    Hope this helps.
     
    WritEffects, Oct 21, 2009 IP
  5. Sisk

    Sisk Member

    Messages:
    104
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #5
    thnx a lot . i will try this way
     
    Sisk, Oct 22, 2009 IP
  6. Sisk

    Sisk Member

    Messages:
    104
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #6
    <?php  query_posts('showposts=1&cat=6'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    <?php endwhile; ?>
    PHP:
    thnx for the advice
     
    Sisk, Oct 26, 2009 IP