Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Senior Member bamme's Avatar
    Join Date
    Aug 2009
    Posts
    319
    Member #
    19662
    Liked
    1 times
    hi, i am looking to apply styles of elements to specific pages of my wp site only, and wondered if i could somehow assign a unique id to each of my wordpress pages' body tag by getting something like the page title with php and placing it in in an include?? ie

    <body id="<? some php include ?>"

    within header.php

    i havent a clue how youd write it as i dont know php!

    alternatively, does anyone know if i could use this (bolded) below as a unique identifier for styling specific pages, or whether this is likely to change if i edit pages' placement or add new ones:

    <body class="page page-id-408 page-child pa...

    the site im looking at is http://www.winninghealthsolutions.com/new/

    Thanks so much in advance.

  2.  

  3. #2
    Senior Member
    Join Date
    Mar 2011
    Posts
    104
    Member #
    27314
    Liked
    6 times
    hi
    as in my reply to your previous post i did find that every wp page already has a unique id

    $title = isset($_POST['title']) ? stripslashes($_POST['title']) : '';
    $excerpt = isset($_POST['excerpt']) ? stripslashes($_POST['excerpt']) : '';
    $blog_name = isset($_POST['blog_name']) ? stripslashes($_POST['blog_name']) : '';

    so you could do for example
    <body id="<? echo $title ?>"
    just make sure you replace the .css extention of your css files to .php

  4. #3
    Senior Member bamme's Avatar
    Join Date
    Aug 2009
    Posts
    319
    Member #
    19662
    Liked
    1 times
    just make sure you replace the .css extention of your css files to .php
    sorry this last bit confused me, am i meant to place this code somewhere:

    PHP Code:
    $title = isset($_POST['title']) ? stripslashes($_POST['title']) : '';
    $excerpt = isset($_POST['excerpt']) ? stripslashes($_POST['excerpt']) : '';
    $blog_name = isset($_POST['blog_name']) ? stripslashes($_POST['blog_name']) : ''
    and what css file do i change to extension .php?

    sorry..

  5. #4
    Senior Member
    Join Date
    Mar 2011
    Posts
    104
    Member #
    27314
    Liked
    6 times
    Quote Originally Posted by bamme, post: 204029
    sorry this last bit confused me, am i meant to place this code somewhere:

    and what css file do i change to extension .php?
    that code is allready defined in your php files the only code u need to place is
    <body id="<? echo $title ?>" as you suggested yourself

    the css file you need to look for yourself,
    or you could make your own css file with the styles you want
    for that page,..

  6. #5
    Senior Member
    Join Date
    Mar 2011
    Posts
    104
    Member #
    27314
    Liked
    6 times
    basicly you use title in my example to define an id for your css
    you could also use $blog_name
    best is aswell isntead of using

    <body id="<? echo $title ?>"
    to define an id for when id is something different for example:
    Code:
    if($title=='your title here'){
    <body id="<? echo $title; ?>">
    <?
    }else{
    ?>
    <body id="your standard id">
    <?
    }
    ?>

  7. #6
    Member David DiGiovanni's Avatar
    Join Date
    Apr 2011
    Location
    Pure Michigan
    Posts
    66
    Member #
    27642
    Liked
    10 times
    Wordpress already has a function for this exact purpose. It will add a "page-ID" class to each of your pages and other useful classes that you can use. Try using this code:

    PHP Code:
    <body <?php body_class($class); ?>>
    Here's a link to the page in the WP codex - http://codex.wordpress.org/Function_...nce/body_class


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:33 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com