• Hi!

    I have a site that have profile pages, where the url and slug are the same. I can change the body tag, but this only works if the pages have different slugs/urls. Is it possible to achieve total unique id′s regardless slug/url?

    Thanks!

Viewing 7 replies - 16 through 22 (of 22 total)
  • Thread Starter jerryskate

    (@jerryskate)

    Well it does work. Im trying to set a unique header for profile pages trough css, and i can use the page name for that. But a profile page has a few categories attached, profile, messages, notifications, activity, and all have their own slug, which is universal. So name is the only unique slug. If i change the header it looks good when a user lands on the page, but as soon as they click around on the profile the header changes to the old one again. It basically looks like this:

    community/members/jerry/
    community/members/jerry/profile/
    community/members/jerry/activity/

    Casey Driscoll

    (@caseypatrickdriscoll)

    Oh I see. I assume at that time the name becomes ‘profile’ and ‘activity’?

    Can you post the array output for either of those two?

    I would venture to guess that post_parent becomes populated as you move deeper.

    If it’s all one level down, you can also use that to grab the users name.

    Probably.

    Either way, the data is retained, I’m sure of it.

    Thread Starter jerryskate

    (@jerryskate)

    Yeah thats correct, the name changes.

    Here′s the output:

    Array
    (
        [page] => 0
        [pagename] => profile
        [error] =>
        [m] =>
        [p] => 0
        [post_parent] =>
        [subpost] =>
        [subpost_id] =>
        [attachment] =>
        [attachment_id] => 0
        [name] => profile
        [static] =>
        [page_id] => 0
        [second] =>
        [minute] =>
        [hour] =>
        [day] => 0
        [monthnum] => 0
        [year] => 0
        [w] => 0
        [category_name] =>
        [tag] =>
        [cat] =>
        [tag_id] =>
        [author] =>
        [author_name] =>
        [feed] =>
        [tb] =>
        [paged] => 0
        [comments_popup] =>
        [meta_key] =>
        [meta_value] =>
        [preview] =>
        [s] =>
        [sentence] =>
        [fields] =>
        [menu_order] =>
        [category__in] => Array
            (
            )
    
        [category__not_in] => Array
            (
            )
    
        [category__and] => Array
            (
            )
    
        [post__in] => Array
            (
            )
    
        [post__not_in] => Array
            (
            )
    
        [tag__in] => Array
            (
            )
    
        [tag__not_in] => Array
            (
            )
    
        [tag__and] => Array
            (
            )
    
        [tag_slug__in] => Array
            (
            )
    
        [tag_slug__and] => Array
            (
            )
    
        [post_parent__in] => Array
            (
            )
    
        [post_parent__not_in] => Array
            (
            )
    
        [author__in] => Array
            (
            )
    
        [author__not_in] => Array
            (
            )
    
        [ignore_sticky_posts] =>
        [suppress_filters] =>
        [cache_results] => 1
        [update_post_term_cache] => 1
        [update_post_meta_cache] => 1
        [post_type] =>
        [posts_per_page] => 10
        [nopaging] =>
        [comments_per_page] => 50
        [no_found_rows] =>
        [order] => DESC
    )

    Casey Driscoll

    (@caseypatrickdriscoll)

    Bah, I’m not sure, but I’m not giving up. I may need to sleep on it though.

    Thread Starter jerryskate

    (@jerryskate)

    Haha fair enough. Very thankful for the help though. Need to sleep too, so ill pursuit this tomorrow. If you find a solution, let me know!

    Cheers

    Hey! So wasn’t sure if you wanted a really short answer, but this is what I add to my functions.php (at the very end).

    If there is a closing ‘?>’ at the end of functions.php, then add below code before that.

    The code:
    // Add page slug (name) to body class
    function add_slug_body_class( $classes ) {
    global $post;
    if ( isset( $post ) ) {
    $classes[] = $post->post_name;
    }
    return $classes;
    }
    add_filter( ‘body_class’, ‘add_slug_body_class’ );

    This will add your page slug name (which IS the page url) to your body’s class attribute (for that page). So if you’re on the about page (with slug …/about-me), it will add the class about-me to your body tag.

    If you’re trying to have unique slugs, not numbers, go to Settings->Permalinks
    Then set Custom Structure to ‘/%postname%’

    Thread Starter jerryskate

    (@jerryskate)

    Hi and thanks for the reply. The problem is that the last part of the url, the slug isn’t unique for all my profile pages. If you look at the output earlier in thread you can see that the slug isn’t enough. And I’m using buddy press in a multisite and that does′t allow me to use dirt permalinks.

Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘Give pages truly unique id′s, classes, possible?’ is closed to new replies.