Style first post differently

Community Forums Forums Design Tips and Tricks Style first post differently

This topic is: not resolved

This topic contains 12 replies, has 6 voices, and was last updated by  Spanka 1 year, 4 months ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #53926

    Jummul
    Participant
    Post count: 40

    I’ve tried to ask this in the common WordPress forums without succes. There are essentially two things I want to achieve.

    1. I want the first post to have a different styling than the other. For instance a slight background change.
    2. Secondly, I want the first post to IGNORE the More Tag. Exactly what I want to do, and it’s explanation, is right here: http://wordpress.org/support/topic/can-wp-ignore-lt-more-gt-tag-on-most-recent-post I just can’t get it to work; and I think it has something to do with the framework.

    I’ve got a lot of CSS experience, but practically no PHP experience.

    Anyone can help me out?

    http://www.acupoflife.nl
    #53951

    AC
    Blocked
    Post count: 7712

    For #1, you are using the Pretty Young Thing theme which doesn’t come with a widgetized home page. You could add a Home Page widget to the top using Brian Gardner’s instructions – http://www.briangardner.com/home-widget-area-eleven40/. Although for eleven40, it will work for Pretty Young Thing. Then you could use a Featured Posts for the top – and style that area any way you want using CSS and leave the grid part just as it is.

    If you decide you want the Featured area to show FULL CONTENT, you can set that which eliminates then need for the more tag.

    #54066

    Jummul
    Participant
    Post count: 40

    I might understand your answer wrong, or you might understand the question wrong – I’m not sure. Your answer doesn’t the way to go. Let me clarify.

    I use Pretty Young Thing, yes. BUT! My home.php doesn’t look anything like the original. I wanted to disable the grid-style layout of Pretty, and just return to the standard genesis loop in which you just have the_content from every post. No grid, no excerpts.

    In order to keep my homepage clean I use a more tag on posts. But I want the more tag to be ignored on the first post of the first page only!

    My home.php now looks like this:

    <?php
    
    // remove_action( 'genesis_loop', 'genesis_do_loop' );
    // add_action( 'genesis_loop', 'pretty_grid_loop_helper' );
    
    /** Remove the post meta function for front page only */
     remove_action( 'genesis_after_post_content', 'genesis_post_meta' );
    
    genesis();

    Now on the support forums I’ve found a similar question, http://wordpress.org/support/topic/can-wp-ignore-lt-more-gt-tag-on-most-recent-post,

    But when I use their advice, and add

    global $more;
    if($post == $posts[0]) $more = 0;
    else $more = 1;
    the_content();

    before the loop, nothing happens.

    When I change $post[0] to [1], thus having

    global $more;
    if($post == $posts[1]) $more = 0;
    else $more = 1;
    the_content();

    ALL the posts ignore the More Tag I’ve given them.

    So, the ignoring-of-the-more-tag-part works. Now for the making-sure-it-only-applies-to-the-first-post-of-the-first-page-part.

    Any ideas?

    #54087

    angieatc
    Participant
    Post count: 80

    Not sure how to style the first post the way you want it but if you are wanting just posts on the page and not the grid I would remove the home.php file and then you just have posts. Is that what you are wanting?

    #54089

    AC
    Blocked
    Post count: 7712

    @jummel, I wasn’t confused. I based my answer on what you wrote initially. If you had mentioned all of the other stuff, I might have presented a different answer.

    The link you provided is 5 years old and given for a non-genesis theme.

    @angieatc, they want the first post only to be styled differently than the remainder of the blogs. Based on the initial question, what I provided them will work, but they want something totally different.

    #54095

    Debra Scott
    Moderator
    Post count: 132

    if you code your homepage as such

    [php]<?php

    remove_action( ‘genesis_loop’, ‘genesis_do_loop’ );
    add_action( ‘genesis_loop’, ‘pretty_home_loop_helper’ );

    global $more;
    if($post == $posts[0]) $more = 0;
    else $more = 1;
    the_content();

    /**
    * Add widget support for homepage. If no widgets active, display the default loop.
    *
    */
    function pretty_home_loop_helper() {

    if ( is_active_sidebar( ‘home’ ) ) {
    echo ‘<div id="home">';
    dynamic_sidebar( ‘home’ );
    echo ‘</div><!– end #home–>';
    }

    else {
    genesis_standard_loop();
    }

    }

    genesis();
    [/php]

    then register it in functions.php

    [php]genesis_register_sidebar( array(
    ‘id’ => ‘home’,
    ‘name’ => ‘HOME’,
    ‘description’ => ‘This is a sidebar that shows on homepage.’,
    ) );[/php]

    Now pull two featured post widgets into your new sidebar. The first will show 1 post full content

    the second will show say 4 posts and offset by 1 post and also show full content.

    this will now give you the layout you want.

    For the styling go to view source on your page find the widget info for the first full post widget.

    mine was #featured-post-6 so in my style.css I would put

    #featured-post-6 {
    background: #eee;
    }

    and so on..


    need help with your business or personal website? Contact me at Fat Cat Designs

    • This reply was modified 1 year, 4 months ago by  Debra Scott.
    • This reply was modified 1 year, 4 months ago by  Debra Scott.
    • This reply was modified 1 year, 4 months ago by  Debra Scott.
    • This reply was modified 1 year, 4 months ago by  Debra Scott.
    #54125

    Jummul
    Participant
    Post count: 40

    Thanks Debra for your easy to follow instructions, yes that worked. But not quite.

    For whatever reason the first post still has an active More Tag.

    if($post == $posts[0]) $more = 0; just doesn’t seem to work..

    #54126

    Debra Scott
    Moderator
    Post count: 132

    try this one instead

    replace all of this

    [php]
    global $more;
    if($post == $posts[0]) $more = 0;
    else $more = 1;
    the_content();

    [/php]

    with this

    [php]
    if ($more == -1) { //do not use the more tag on the first one.
    the_content();
    $more = 0; //prevent this from happening again. use the more tag from now on.
    }
    else { //use the more tag
    the_content(__(‘Read more…’));
    }
    [/php]


    need help with your business or personal website? Contact me at Fat Cat Designs

    #54135

    Jummul
    Participant
    Post count: 40

    No joy. When I change -1 to 1 it ignores the More Tag on the posts. To me this seems like the posts are not correctly numbered – it sees all the posts as the first post. I’m not sure though.

    Thanks for your time and help by the way!

    #54182

    Debra Scott
    Moderator
    Post count: 132

    I don’t know why none of the codes aren’t working. I wonder if there is a plugin or other code interferring?


    need help with your business or personal website? Contact me at Fat Cat Designs

    #54184

    braddalton
    Participant
    Post count: 10678

    I wrote about the answer to the first question a few months ago and the solution works perfectly using PHP code.

    You could also use the code to remove the more tag on the latest post by adding the remove action or filter to the function.


    #54452

    Jummul
    Participant
    Post count: 40

    I tried:

    global $more;
    if($post == $posts[0]) $more = 0;
    else $more = 1;
    the_content();

    and

    if($post == $posts[-1]) $more = 0;

    and I tried widgitizing the home page and adding a Featured Post

    and I tried

    if ($more == -1) { //do not use the more tag on the first one.
        the_content();
        $more = 0; //prevent this from happening again. use the more tag from now on.
    }
    else { //use the more tag
        the_content(__('Read more...'));
    }

    And I also tried repeating all of this with all plugins disabled. Still. No. Luck.

    I think I’ll become a farmer and live a happy life.

    #54467

    Spanka
    Participant
    Post count: 30

    I don’t know about removing the MORE tag, but the styling should be easy enough – use the first-child selector.

    I don’t know what your HTML looks like, but here’s a general idea

    
    <div id=wrap>
    <div id=post-1 class=genesis-post>
    ---- some stuff
    </div>
    <div id=post-2 class=genesis-post>
    ---- some stuff
    </div>
    <div id=post-3 class=genesis-post>
    ---- some stuff
    </div>
    </div>
    

    Each of your posts will be wrapped in a div that has a common class. To format the first one differently, do this:

    
    .genesis-post:first-child {
      /* some formatting here */
    }
Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.