• Resolved huntz

    (@huntz)


    Hello Guys,

    I want to display a message only on my latest post page, not on the other post pages, does anyone know how?

    Thanks alot

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hard part is figuring out what Template file to change. Use Template Hierarchy to determine what your theme is using for your latest posts, then add to that file, probably just before (or after) ‘the_content’ or ‘the_excerpt’, something as simple as:

    <?php echo "whatever you want" ;?>
    Thread Starter huntz

    (@huntz)

    Hi, you can see my “mymessage()” function at the bottom of my single page. Here is the code from it

    <?php get_header(); ?>
    <div id=”post-entry”>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class=”post-meta” id=”post-<?php the_ID(); ?>”>
    <div class=”top-meta”>
    <div class=”post-title”>
    <h1>
    <?php the_title(); ?>
    </h1>
    <div class=”post-author”>
    <?php _e(‘Posted by’); ?> <?php the_author(); ?>
    on
    <?php the_time(‘l, F jS Y’) ?>
       
    <?php edit_post_link(‘edit’); ?>
    <?php include (TEMPLATEPATH . ‘/submit.php’); ?>
    <?php include (TEMPLATEPATH . ‘/ratings.php’); ?>
    </div>
    </div>
    <div class=”calendar”>
    <?php the_time(‘j’); ?>

    <span class=”c-month”>
    <?php the_time(‘M’); ?>
    </span></div>
    </div>
    <div class=”post-content”>
    <div class=”post-content6″>

    </div>
    <?php the_content(); ?>
    <p class=”enjoyit”> Leave a “>trackback </p>
    </div>
    <?php include (TEMPLATEPATH . ‘/social.php’); ?>
    </div>
    <?php endwhile; ?>
    <?php comments_template(); ?>
    <?php include (TEMPLATEPATH . ‘/paginate.php’); ?>
    <?php else: ?>
    <?php include (TEMPLATEPATH . ‘/result.php’); ?>
    <?php endif; ?>

    <div class=”post-content”>
    <div style=”font-size:12px; color:#000000″>My Message</div>

    <?php echo mymessage(); ?>

    </div>

    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Don’t know what the mymessage() function is…is that from a plugin?

    Thread Starter huntz

    (@huntz)

    Its my own function, all it does is display a message. I just need some simple code to wrap around it so the message only gets displayed on every other post but the most recent. I did have something in my head like.

    $getlatestpost = get_posts(‘numberposts=1&order=DESC&orderby=post_date’);
    $latestpostid = $getlatestpost ->ID;

    If $post->ID == $latestpostid;
    echo mymessage();
    else;
    /* do nothing */
    endif;

    Assuming the post you call lastest post is the first post displayed: here’s a short example of using a count

    <?php
    $count = 0;
    if (have_posts()) {
     while (have_posts()) : the_post();
      $count++;
        if ($count <= 1) {
          the_content();
        } else {
          the_content();
          echo mymessage();
        }
     endwhile;
    }
    ?>

    Thread Starter huntz

    (@huntz)

    Hi, thanks for the code but it doesn’t do what im looking for. No matter what post(single.php) I go through and see I always get the same result.

    What I need to do is compare the post ID of the current post with the post ID of the last post made. If they match i do not want to show the message(or run the function).

    The code i posted above is what i tried but not sure of syntax.

    Thanks for the help

    Thread Starter huntz

    (@huntz)

    Mission Accomplished, might not be tidy but…

    <?php
    global $post;
    $post_ID = $post->ID;

    $postslist = get_posts(‘numberposts=1&order=DESC&orderby=post_date’);
    foreach ($postslist as $post) : setup_postdata($post);
    $latestpostid = get_the_ID();
    endforeach;

    if ($post_ID == $latestpostid) {
    echo ‘MATCH’;
    } else {
    echo ‘NO MATCH’;
    }
    ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Message on latest post.’ is closed to new replies.