• Resolved pedenski

    (@pedenski)


    simply, i wanted to put all recently posted or new posts to be <h1>
    and all old posts to be <h2>

    this highlights all new posts only;
    how do i alter the behavior of the loop to make it work like i wanted?

Viewing 7 replies - 1 through 7 (of 7 total)
  • You can use offset within your loop to call older posts. How many new posts are you displaying and how many old posts would you like to display?

    So try something like

    <?php
    $args = array( 'numberposts' => 10, 'offset' => 10 );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>

    Where you replace numberposts with how many posts you want to display and offset with the amount of newer posts there are.

    https://codex.www.ads-software.com/Template_Tags/get_posts

    Thread Starter pedenski

    (@pedenski)

    if i put 5 numberposts and 1 offset this displays the previous 5 post.

    how do i show the 1 current new post?

    The current new post would be the same code but you would just change numberposts to 1 and remove the offset.

    Thread Starter pedenski

    (@pedenski)

    oh! how clever, thanks!

    using ‘offset’ will cause problems with pagination.

    alternative 1 (assuming that h1/h2 refers to the h tag of the post title):

    <?php $tag = ($wp_query->current_post || is_paged()) ? 'h2' : 'h1'; ?>
    <<?php echo $tag; ?>><?php the_title(); ?></<?php echo $tag; ?>>

    that would replace the existing:

    <h1><?php the_title(); ?></h1>

    alternative 2 (assuming that your theme uses post_class() in the post div); add this to functions.php:

    add_filter('post_class','last_post_marker');
    function last_post_marker( $classes ) {
    global $wp_query;
    if( !is_singular() && !is_paged && $wp_query->current_post == 0 ) $classes[] = 'last-post';
    return $classes;
    }

    in style.css, add:

    .last-post h1 { font-size: 300%; /*some different formatting from normal*/ }

    Thread Starter pedenski

    (@pedenski)

    when i use this, it displays the oldest post. how do make it show the newest?

    can you post a link to your site where the problem can be seen?

    none of my suggested codes should change the posts order;
    possibly the order of your posts is set in some other way?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘how to make new posts then old post’ is closed to new replies.