Forums

How to Return Latests Posts by Tag? (9 posts)

  1. iSimone
    Member
    Posted 3 years ago #

    I'm wondering how to get latest posts by tag? I do see the instructions, but I can't seem to get it right.

    The following would output the latest posts ordered by title:

    <?php
     $postslist = get_posts('numberposts=10&order=ASC&orderby=title');
     foreach ($postslist as $post) :
        setup_postdata($post);
     ?>
     <div>
     <?php the_date(); ?>
     <br />
     <?php the_title(); ?>
     <?php the_excerpt(); ?>
     </div>
     <?php endforeach; ?>

    But how can I display the latest posts by tag? Thanks for the help WordPress pros!

  2. iSimone
    Member
    Posted 3 years ago #

    *Bump*

  3. Hiranthi
    Member
    Posted 3 years ago #

    $orderby
    (string) (optional) Sort posts by one of various values (separated by space), including:

    * 'author' - Sort by the numeric author IDs.
    * 'category' - Sort by the numeric category IDs.
    * 'content' - Sort by content.
    * 'date' - Sort by creation date.
    * 'ID' - Sort by numeric post ID.
    * 'menu_order' - Sort by the menu order. Only useful with pages.
    * 'mime_type' - Sort by MIME type. Only useful with attachments.
    * 'modified' - Sort by last modified date.
    * 'name' - Sort by stub.
    * 'parent' - Sort by parent ID.
    * 'password' - Sort by password.
    * 'rand' - Randomly sort results.
    * 'status' - Sort by status.
    * 'title' - Sort by title.
    * 'type' - Sort by type

    Tags is not in the list, so you can't order by tags with this function.

  4. iSimone
    Member
    Posted 3 years ago #

    Nope what i was looking for is get posts by tag! not the order, thanks for the answer anyways.

  5. iSimone
    Member
    Posted 3 years ago #

    And another bump?

  6. Hiranthi
    Member
    Posted 3 years ago #

    ok.. now I just don't get it anymore.. are you trying to display the latest tags ONLY or something else completely?

  7. iSimone
    Member
    Posted 3 years ago #

    hehe, no I'm trying to display the latest posts by tag. Let us say I do a page about Angelina Jolie, I'd like to display the excerpts of of the last 10 posts that have the tag angelina?

  8. Hiranthi
    Member
    Posted 3 years ago #

    You should be able to add &tag=angelina and, according to the codex, that should do the trick =)

  9. iSimone
    Member
    Posted 3 years ago #

    Perfect illutic, I could get the output i wanted. I set it up on a page, now it shows the excerpt of the posts perfectly. But it gets the permalink, the image and the title of the page it's on. How can I get these of the actual posts I called?

    <div class="newspagetop">
    <?php
     $postslist = get_posts('numberposts=5&orderby=date&tag=heresthetag');
     foreach ($postslist as $post) :
        setup_postdata($post);
     ?>
    
     <?php $the_image = get_image(); ?>
    	<div class="newspage" <?php if($the_image != "") { ?> style="min-height:5.00em;" <?php } ?>>
    <?php if($the_image != "") {?>
    		<div class="newspage-img"><a href="<?php the_permalink() ?>"><?php echo $the_image; ?></a>
    		</div>
    			<div class="newspage-content"><?php }  else {?><div class="newspage-content" style="padding-left:0;"><?php }?>
    			<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Continue reading <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    				<div class="entry">
    				<?php the_excerpt() ?>
    				<p><span class="read_more"><a href="<?php the_permalink(); ?>">Read more...</a></span> <span class="feedback"><?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></span></p>
    				</div>
    			</div>
    	</div>
     <?php endforeach; ?>
    </div>

    Thanks for the input!

Topic Closed

This topic has been closed to new replies.

About this Topic