[resolved] I need the post slug (8 posts)

  1. Leovenous
    Posted 8 years ago #

    Is the slug queried in the post function so that I can jet it into a link URL as a $ variable?

    What I need to do is make a post link to a page that happens to have it's slug. I'm thinking this is the easiest way to link a dynamic post to pages dynamically.

    So I am picturing something like <?php the_slug(); ?>

    I also was trying to find that cool snippet of PHP that will display all the variables in a session. I wanted to use it to see what WP has floating out there. Anyone know it?

  2. whooami
    Posted 8 years ago #

    you would be better served to upgrade your current 2.0 install to 2.0.11

    In your curiosity, maybe you've missed all this:


    And if you think wordpress blogs arent getting hacked these days, here you go:


    There was one reported just yesterday, and I 'found" one this morning as well where the user wasnt even aware.

  3. Leovenous
    Posted 8 years ago #

    Ummm... I don't know what you're getting at.

  4. Leovenous
    Posted 8 years ago #

    Maybe I'm not being as clear as I could be. Normally when a post is linked it uses the the_permalink tag in an <a href> to link to an archives page. I want it to link to a template page. How to do that, my idea was to use the slug to make the link.

    So I am either asking if there is a variable I can grab the slug with, or if there is a better way to accomplish what I am after.

  5. Leovenous
    Posted 8 years ago #

    I figured it out, there is a function (get_post) that let me pick any part out of it, so I ended up with this code within my 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>

    I still have to figure out why it is displaying the post number on the page.

    Anyway, thank ya'll for your wonderful, helpful, expert advice.

  6. arcab4
    Posted 7 years ago #

    anyone ever figure out how to remove the post #?

  7. arcab4
    Posted 7 years ago #

  8. Darren Turpin
    Posted 7 years ago #

    Cheers Leovenous, that chunk of code was exactly what I've just spent the last 20 minutes searching for... nice one!

    And for anyone else looking for the same functionality, I can confirm that this method holds good for WP 2.5.1.

Topic Closed

This topic has been closed to new replies.

About this Topic