• Hi,

    I’m struggling to find a tag to identify my current page.

    I am trying to dynamically insert an id into my HTML <body> tag so that horizontal menus can pick up unique css selectors, and render the relevant menu tab with a different background colour (as can be seen on http://binarybonsai.com). The tag would read differently depending what page I am on e.g. <body id=about>

    as codex has been down for some time, I've relied on the wiki docs for tags, which make no reference to any page tags. All I can find is the wp_title tag, but this seems to have some spaces padding the text. I'm not a PHP developer (if only WP were written in Java!). I've tried trimming the white space but this seems to give me an empty string :-( This is what I tried.

    <body id=”<?php trim(wp_title(”, TRUE)); ?>”>`

    Is there a tag to identify the page name or ideally the page-slug name?

    BTW, WP is a great application.. Well done. If only I had a time to learn PHP!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The WordPress Codex – the Guide to WordPress is down right now undergoing repairs and maintenance to be better than ever, but you can still view the pages from there in Google’s cache pages to help you find the help you need. I believe you can find help at the
    this cached page….boy, I hope this works. If not, do a search on Google for “wordpress codex post slugs”.

    Thread Starter howie

    (@howie)

    Thanks Lorelle. Codex is back up. But the link is not really what I’m after. Seems awfully messy having to breakdown the URL just to get it’s slug. I’ll stick with using the page title and keep it to one word.

    Still far from perfect. There basically seems to be a complete lack of tags relating to pages. All the examples talk about post tags and loops. I’m new to WP and PHP, but why/how would I have a loop around content for a unique page?

    If my template is rendering a page it should know that a) it is a page and b) the name of the page. simple.

    Also, can’t understand why a post title is automatically padded with 2 spaces!

    I’ve got a solution in place, but what I need now is a tag to tell my template/header.php that the current content is a page. Otherwise every time I add a page through WP, I need to also change my template for the CSS to work 🙁 Code is as follows:

    <?php
    $title = trim(single_post_title('', FALSE));
    if($title != "photos" && $tempTitle != "links" && $tempTitle != "about" && $tempTitle != "contact") {
    $tempTitle = "home";
    }
    echo "<body id=\"$tempTitle\">";
    ?>

    Wonder how http://www.binarybonsai.com does this?

    Thread Starter howie

    (@howie)

    um… $tempTitle should read $title` oops!

    howie, with custom permalinks set up to show the postname (i.e. slug) in the url, you could use this to display it as your body id:

    <body id="<?php echo get_query_var('name'); ?>">

    More an internal function you’re making use of here than a template tag, but works just as well.

    Thread Starter howie

    (@howie)

    Thanky uo Kafkaesqui. That worked a treat.

    I won’t even ask how one learns about WP internal functions. Read through the code I guess? I reckon the PHP deve team needs to work on auto-generation of API docs, just like Java does

    thanks again

    howie

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘is there a page-title tag or page-slug tag?’ is closed to new replies.