WordPress.org

Ready to get started?Download WordPress

Forums

Custom First Post (9 posts)

  1. Demetreas
    Member
    Posted 4 years ago #

    I trying to create a layout that displays the first latest post differently to the other posts but only on the home page. kind of like a featured post but without the need to add it to a specific category.

    I have found ways to do it via a specific category and how to change a class on the surrounding div of the first post, but I want to change the things displayed for the first post. (i.e. I want to display a bigger image for the first post but on all other posts I will want to display a thumb nail image)

    I have mocked up a static site of how I want it to look
    http://www.elucidation-art.com/webdev/blog.php

    Thanks
    Dee.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    Set up a simple counter variable that increments during each pass of the Loop. Then test the variable to determine which post is currently being process. Once you have the right post, you can output it using different markup, template tags etc.

    <?php $c =0;
     if (have_posts()) : while (have_posts()) : the_post();
    $c++;?>
    
    <?php if($c == 1) :?>
    [ markup for first post ]
    <?php else:?>
    [ standard markup for the rest of the posts ]
    <?php endif;?>
    
    <?php endwhile; ?>
    [...]
    <?php endif; ?>
  3. Demetreas
    Member
    Posted 4 years ago #

    Thank you that worked PERFECTLY!!!

  4. Demetreas
    Member
    Posted 4 years ago #

    that worked perfectly, but now I am trying to just have that on the home page I've tried the "php if (is_home)" but I think I'm doing it wrong because I keep getting an error.

    I kind of want it to work like this
    Home Page: http://www.elucidation-art.com/webdev/blog.php
    page two: http://www.elucidation-art.com/webdev/archive.php

    and when you get go to page two off the home page to look like the above (except without the "Archive Title Or Category Title" and paragraph at the top of the page.

  5. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    http://codex.wordpress.org/Conditional_Tags#A_Paged_Page

    <?php if( ($c == 1) && !is_paged() ) :?>

  6. Demetreas
    Member
    Posted 4 years ago #

    thank you, using the !is_page() tag I've managed to get ride of the featured post on the pages after the home page, still having a slight problem getting the second style to change.

    <?php  $c =0;
     if (have_posts()) : while (have_posts()) : the_post();
    $c++;?>
    
    <?php if( ($c == 1) && !is_paged(page) ) :?>
    //FEATURE POST MARKUP
    
    <?php elseif (!is_page(page))  :?>
    //HOME PAGE POST MARK UP
    
    <?php else :?>
    //ALL OTHER PAGES STYLES
    
    <?php endif;?>
    <?php endwhile; ?>

    this ignores the last else and just replicates the //home page post mark up on the second page.

  7. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    the general usage is is_paged() with empty brackets; i don't know if having something in the bracket will interfere with the result.

    also, instead of:

    <?php else :?>
    //ALL OTHER PAGES STYLES

    you could try explicitely:

    <?php elseif (is_paged()) :?>
    //ALL OTHER PAGES STYLES
  8. Demetreas
    Member
    Posted 4 years ago #

    no it doesn't seem to affect anything its still showing home page post style on the second page.

    EDIT:

    I've done it.... although its not perfect it does work, so if anyone else had any ideas to do it better without the n00b php here is what I've done.

    <?php  $c =0;
     if (have_posts()) : while (have_posts()) : the_post();
    $c++;?>
    
    <?php if( ($c == 1) && !is_paged(page) ) :?>
    
    //FEATURED POST MARKUP
    
    <?php elseif (($c = 7) && !is_paged(page))  :?>
    
    //HOME PAGE POST DISPLAY MARK UP, UP TO 7 POSTS ($c = 7) IS WHERE I PUT THE AMOUNT OF POSTS I WANTED TO DISPLAY ON THE HOME PAGE.
    
    <?php else :?>
    // MARK UP FOR ALL OTHER PAGES
    
    <?php endif;?>
    <?php endwhile; ?>
  9. grollaz
    Member
    Posted 3 years ago #

    hello, you found a solution to your needs?
    I would have the same need but do not know how.
    Thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic