• hi.

    i would like some help on how to color code the site.
    i have 5 parent pages, each with unknown ammount of sub and subsub pages.
    i would like to use separate css on each page with different main parent.
    is there a way to set it dynamically? i assume that top parents would be called by using permalinks? like site/title-1 or their id in the worst case could be left unchanged.
    at the present moment of course i can create Page Template for each type of pages and then i would have to specify that in the write page interface.
    i would like to figure out a way, by attaching css to the top parent that the sub pages could dynamically pick up the css used by parent and use that.

    thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • You could define 5 different CSS styles with names like style1, style2, etc, with each trailing number equating to one of your five Page Parent’s IDs.

    Now let’s assume you’re using the default template. Open your page.php file and find the following line of code:

    <div class="post" id="post-<?php the_ID(); ?>">

    And replace it with the following:

    <div class="post style<?php echo ($post->post_parent); ?>" id="post-<?php the_ID(); ?>">

    That bit of PHP after the “style” piece I added will get the Parent ID of the current page and add it directly after the word “style”. So you’ll have your various style1, style2, style3, style4, etc.

    From there you can define those styles as you’d like in your stylesheet.

    That should be enough to get you started.

    Thread Starter hardijs

    (@hardijs)

    thanks.
    the idea is not to be dependant on the ids, as pages might be added and deleted and the id i wont be able to get back.
    i imagine i could try to use permalink as refering to the page.
    or maybe there is even a better way how to do that?
    could i specify it somewhere in the page template so i could choose different stylesheets? i would not want to put in one file and do all the additional markup.
    separate stylesheets sounds better, doesnt it?

    thanks,

    h

    Hmmm, I was under the impression from your original post that you were going to have 5 main pages, and the rest would be subpages and subsubpages, so doing it the way I specified would eliminate you from having to use page templates and page parents.

    If you want/need to use page templates then you can define any CSS you want with the different page templates.

    Hi clicknathan,
    I’m designing The Real Fight Club’s new website and I want different header images for each section of the site and i9ts respective sub-pages. That snippet of code is exactly what I was looking for!

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘custom css for each parent page id’ is closed to new replies.