Support » Fixing WordPress » slug equivalent for $post->ID ?

  • marenm


    Hi there!
    Can anyone tell me if there is a slug equivalent to $post->ID ?

    Basically I’m dealing with a ton of different stylesheets and it would be great if I could organize them by slug rather than ID.

    I’m using this code/method in my functions.php file:

    function artStyle() {
        global $post;
        if (is_single()) {
            $currentID = $post->ID;
            $serverfilepath = TEMPLATEPATH.'/art-direction/style-'.$currentID.'.css';
            $publicfilepath = get_bloginfo('template_url');
            $publicfilepath .= '/art-direction/style-'.$currentID.'.css';
            if (file_exists($serverfilepath)) {
                echo "<link rel='stylesheet' type='text/css' href='$publicfilepath' media='screen' />"."\n";
    add_action('wp_head', 'artStyle');

    from this source:

Viewing 1 replies (of 1 total)
  • michael.mariart


    If you look at the database table for wp_posts, you’ll find this easily. it’s $post->post_name;. You should be able to use this anywhere that you have a $post object.

Viewing 1 replies (of 1 total)
  • The topic ‘slug equivalent for $post->ID ?’ is closed to new replies.