WordPress.org

Ready to get started?Download WordPress

Forums

How can I style my posts content separately? (8 posts)

  1. theplastickid
    Member
    Posted 4 years ago #

    I am trying to style my post snipets on my front page differently than my dates and comments links etc...

    Here is the code:

    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    			<p class="date"><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></p>
    			<?php the_content('Read the rest of this entry &raquo;'); ?>
    			<p><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    		</div>

    I have added a class of "date" to the <p> tags surrounding the date. But if I wrap a tag around "<?php the_content('Read..." and then style that is changes the styles of everything.

    I hope this makes sence.

    Many THanks.

  2. theplastickid
    Member
    Posted 4 years ago #

    To follow up and maybe make things simpler I basically need to be able to attach a class or ID to the <p> tag that is auto generated as shown here when the source is viewed after the page loads:

    <p class="date">April 7th, 2007 <!-- by Brett --></p>
    			<p>Lorem ipsum sensibus eleifend reprehendunt
  3. dremeda
    Sucuri Wizard
    Posted 4 years ago #

    Make sure you are using a static home page and then create a page template for it which you can then customize as you did above. It will change the post output only on pages using the template:
    http://codex.wordpress.org/Pages

  4. theplastickid
    Member
    Posted 4 years ago #

    I need my home page to be dynamic though it is a blog so I want my most rescent posts listed not static content.

  5. dremeda
    Sucuri Wizard
    Posted 4 years ago #

    This will enable you to do this.

    A template can make a static home page as dynamic as the default home page.

    Follow the link I sent and it will show you how to accomplish this.

  6. theplastickid
    Member
    Posted 4 years ago #

    I have created a page called "Home" and set it as my home page in the settings but now all of my styling has completly disapeared.

  7. dremeda
    Sucuri Wizard
    Posted 4 years ago #

    Did you also create a template to apply to Home or is it using the default template?

  8. WizardRegis
    Member
    Posted 4 years ago #

    As I understand it (and it's a bit confusing) you want to style the text-part of posts on your front page, but each one individually to each post?

    If that is so, then it's quite easy.

    The code inside the wrapping DIV is actually printing all the info for you. This...

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

    ...turns into this:

    <div class="post-4004 post hentry category-blog tag-theme" id="post-4004">

    It gives the DIV an individual id, individual class, and a class for categories and tags. So all you need to do to style the text for <random post #4004> is this:

    First add a wrapper around the text in each post:

    <div class="post-text"><?php the_content('Read the rest of this entry &raquo;'); ?></div>

    And then add something like this in CSS:

    .post-4004 .post-text { color:red; }

    And it will change the text part on post with ID 4004 to red.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.