Applying a css command only relevant to a certain page

Hi all

I was looking for a pointer in the right direction of getting a bit of code to work only on one particular page. {
position: absolute; }

This doesnt work but what I am trying to achieve is to get .cf-image to be absolute only on the classified page.

I do not want .cf-image to be absolute on any other pages such as when a member clicks on the ad.

Is it possible to get the css to apply to the classifieds page only?

Kind regards

  • Vaughan


    thanks for posting.

    you would most likely need to edit the header.php template in your theme for this to work.

    the idea is you require a bit of code to grab the page id/slug.

    then you put a condition round the body element in the template

    inside the loop it's easy. outside, it varies depending on if you're on an archive page or a signle page.

    you could try in header.php

    $page_object = get_queried_object();
    $page_id     = get_queried_object_id();
    if ($page_id == 53) {
        <body class="classifieds">

    you'll need to know the post id for the classifieds page, so goto Dashboard > pages > then hover over the edit link for the Classifieds page. you'll see the postID in the url like wp-admin/post.php?post=53&action=edit

    so in my case, the classifieds page has an id of 53. change the above code to match yours.

    then you can use in your CSS

    body.classifieds .cf-image {
    position: absolute;

    because you've made it conditional on the body tag, only the page where the body has the class set will trigger that CSS value.

    hope this helps.


  • mark_bonito

    Thanks for your reply Vaughan.

    I think I might wait for my reply on a previous thread as it looks like there is a clash with my theme and the classified plugin.
    It throws the image-cf out on the listing page and if I correct it with absolute it throws it out on the main item listing page.

    I will bump the thread and see if anyone has an idea of whats going wrong.

    Kind regards

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.