The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

slug equivalent for $post->ID ? (2 posts)

  1. marenm
    Posted 3 years ago #

    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: http://digwp.com/2010/02/custom-css-per-post/

  2. michael.mariart
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic