The MU forums have moved to WordPress.org

How to generate permanent link to a post? (8 posts)

  1. unrealwonder
    Member
    Posted 13 years ago #

    I am trying to get generate the most recently added posts. I got the list of the posts using API wp_get_recent_posts.

    However this API does not give all the recent modified posts.

    I tried to get the permanent link using the_permalink() how ever its repeating the link of the first post :( .. i dont know what to do .

  2. dsader
    Member
    Posted 13 years ago #

    New Loop or no Loop, that is the question.

    No Loop:
    To get more posts, increase the $num in wp_get_recent_posts($num); the $num if missing is 10.
    However, this function gets every post, drafts and all.

    the_permalink() will only work inside "The Loop".
    get_permalink( $post_ID ) can be used outside the The Loop; and you have the $post_ID in the wp_get_recent_posts array.

    Poor Example usage to list 100 permalinks:

    <?php
    $num = (100);
    $my_recent_posts = wp_get_recent_posts($num);
    echo '<ul>';
    foreach($my_recent_posts as $my_recent_post) {
    echo '<li>';
    echo get_permalink( $my_recent_post['ID'] ); //bare bones to illustrate
    echo '</li>';
    }
    echo '</ul>';
    ?>

    I wouldn't generate a list this way, because drafts are included.

    New Loop:
    Instead I would construct a second Loop using a "new WP_Query".
    http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_1

    Better Example

    <?php
    $number = '100';
    	$r = new WP_Query(array('showposts' => $number, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
    	if ($r->have_posts()) :
    ?>
    	<ul>
    		<?php  while ($r->have_posts()) : $r->the_post(); ?>
    			<li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
    			<?php endwhile; ?>
    	</ul>
    <?php
    		wp_reset_query();
    	endif;
    ?>
  3. dsader
    Member
    Posted 13 years ago #

    Now, if recently updated/modifed is what you are after, the sql in wp_get_recent_posts orders by post_date so you may never get recent modified only recent added posts.

    You need a new function that'll order by post_modified_gmt instead.

    Found an example plugin with a template function and widget:
    http://wordpress.org/extend/plugins/recently-updated-posts/

  4. unrealwonder
    Member
    Posted 13 years ago #

    Thank you :D! You rock, that was a great help.

  5. unrealwonder
    Member
    Posted 13 years ago #

    I think i didn't describe the problem properly. I am using wordpress mu, and i would like to get say 20 recent updated posts. :( dosen't work still..

  6. unrealwonder
    Member
    Posted 13 years ago #

    I have solved this issue, i am able to display the most recent posts now check it out at http://www.bitcolors.com

  7. NetBlog
    Member
    Posted 13 years ago #

    the function
    get_permalink( $my_recent_post['ID'] )
    is doesn't work ...
    witch id of table's post ?

  8. dsader
    Member
    Posted 13 years ago #

    The "Poor Example" usage of get_permalink above in my post does work.

    http://mu.wordpress.org/forums/topic.php?id=11573#post-69567

About this Topic

  • Started 13 years ago by unrealwonder
  • Latest reply from dsader