I need the post slug…
March 1st, 2011 at 12:44am Jason 200 views
There is a function (get_post) that let us pick any part out of it, so we can end up with this code within the loop.
<?php // Get the Slug to use as the link $extrapostdata = get_post(the_ID(), ARRAY_A); $slug = $extrapostdata['post_name']; ?> <h2><a href="/<?php echo($slug); ?>"><?php the_title(); ?></a></h2>
Another Codes: Here is a function that gives you the actual slug
function the_slug() { $post_data = get_post($post->ID, ARRAY_A); $slug = $post_data['post_name']; return $slug; }
Put the above code in your templates function.php, then you can use:
<?php echo the_slug(); ?>
in your template to get the slug.
via-1: http://wordpress.org/support/topic/i-need-the-post-slug
via-2: http://wordpress.org/support/topic/solved-slug-as-string?replies=6
via-3: http://www.joshstauffer.com/get-post-slug-in-wordpress/
Entry Filed under: WordPress Tagged with: slug wordpress
Hot Posts Hot Comments Hot Tags
- apartment bbpress blog class CMS code CSS div dream english friends girl Google hot Hot Dog html job JS life lines love Madonna menu Michael Jackson movie oral english PHP plugin saying school sexy site student students submenu success tags teacher teaching txt university video website widget wordpress





1 Comment Add your own
1. fendi ahmad | April 24th, 2011 at 3:59 pm
I was googling then I found this tutorial is most relevant to get parent slug of my post, easy to understand. Thank You.
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
Trackback this post | Subscribe to the comments via RSS Feed