WordPress.org

Support

Support » Themes and Templates » ID for post (css php)

ID for post (css php)

  • So i’m on a part of styling and coding the post part on the homepage (index.php), like doing the title, read more links and stuff. And then i noticed this line of code thats already in theme:
    <div <?php post_class() ?> id=”post-<?php the_ID(); ?>”>
    I don’t know what is this for and in what advantage do I use it, and why would this be placed in a blank theme ? If anyone can explain thanks 🙂

    To note there are also div tags like footer,entry,metalinks,header placed in blank theme.

    I used blank theme by Chris Coyer

Viewing 3 replies - 1 through 3 (of 3 total)
  • paulwpxp

    @paulwp

    Font hero

    Thank you for the link.

    This explained it:

    .post {
    /* styles for all posts */
    }
    .post-4564 {
    /* styles for only post ID number 4564 */
    }
    .category-dancing {
    /* styles for all posts within the category of dancing */

    About what to target when coding, is there any similar stuff in wordpress to this, cause for example i really love targeting a certain category.

    This I don’t understand:
    Display Posts Outside of the Loop

    For displaying posts outside the Loop or in an alternate Loop, the second parameter to the post_class function can be the post ID. Classes will then be determined from that post.

    <?php post_class(”,$post_id); ?>

    I used the <?php post_class(”,$post_id); ?> in footer(just to test) for example and nothing changed

    paulwpxp

    @paulwp

    Font hero

    To answer your second question, you should also review body_class
    http://codex.wordpress.org/Function_Reference/body_class

    The implementation of post_class() is for each post ( each content ) being on its own like single.php or in listing like archive.php, but for the whole page altogether you would use the body_class() to help target the elements in that page.

    I used the <?php post_class('',$post_id); ?> in footer(just to test) for example and nothing changed

    The $post_id is integer, the id of the post. You have to either put the number in manually or get the id outside the loop (in this case) and give to it, otherwise there will be no id for the function to use.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘ID for post (css php)’ is closed to new replies.
Skip to toolbar