Oct
15
2011Get Permalink, Title and Excerpt for Any Post Anywhere Outside the Loop in WordPress

To get a permalink and Post Title outside of the standard WordPress post loop, you have to use the get_permalink() function. This function takes a post ID as argument, and returns the permalink:
<h2><a href="<?php echo get_permalink($post->ID); ?>" >Read the article</a></h2>
If you want to get the Post Title and excerpt too, you can use WordPress get_post() function:
$your_post = get_post($post->ID); $your_title = $your_post->post_title; $your_excerpt = $your_post->post_excerpt;
Now using this technique, you cane easily create and link the other posts that you may want to link from any post page, putting this all together:
<?php $your_post = get_post($post->ID); $your_title = $your_post->post_title; $your_excerpt = $your_post->post_excerpt; $your_link = get_permalink($post->ID); ?> <div class="post"> <h2><a href="<?php echo $your_link;?>"><?php echo $your_title;?></a></h2> <?php echo $your_excerpt;?> </div>
Hope that helps.
Related posts:
- Include & Display Custom Post Type Records under Categories Posts Listing in WordPress
- WordPress Custom Post Types – Best Plugin for the Job and How to Set it Up
- Resolve Permalinks 404 Error with Custom Post Type using WordPress
- WordPress Custom Post Type Listing by Alphabets with Alphabetical Navigation
- Resolve Pagination Problem for Custom Post Types Listing in WordPress
Recent Comments
(1 days ago)
(1 days ago)
(1 days ago)
(1 days ago)
(1 days ago)
(1 days ago)
(1 days ago)
(1 days ago)
(1 days ago)
(1 days ago)