• andybru

    (@andybru)


    Hi

    I’m building a custom site locally at present so cannot link to it im afraid.

    I have a ‘news’ page that displays posts with a news category as a grid 3 x 3 it currently displays all posts with an excerpt.

    I would like to know if its possible to have it so the first three posts (most recent) can be displayed with the excerpt and the following posts display just the post title.

    I’m presuming I can do this with wp query & the loop in that category specific php file but don’t have enough coding skill to figure out how.

    any help or pointing towards relevant info would be greatly appreciated

Viewing 1 replies (of 1 total)
  • Moderator Marius L. J.

    (@clorith)

    Hi,

    This is certainly doable. What I tend to do in these cases is create a variable outside of The Loop, I like to go with $post_number = 1;.

    Now, at the end of The Loop, I put in a $post_number++; this makes the counter go up by one every time we’ve displayed a post (I started it at 1 since we’ll start with the first post).

    At the bit thatdisplays the excerpt, add an IF conditional and check if ( $post_number <= 3 ) { the_excerpt(); }, that will only display the excerpt if you are on post 3 number or earlier.

    Of course, these are rough examples, but should hopefully get you going in the right direction.

Viewing 1 replies (of 1 total)
  • The topic ‘Help with custom post excerpt display’ is closed to new replies.