WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Add image on top of first post only (14 posts)

  1. icyville
    Member
    Posted 6 years ago #

    How do I do this?
    I want to add an image on top of the first post only here
    http://www.woodencotton.com/test1

    Here's my index code

    <?php get_header(); ?>
    
    <?php get_sidebar(); ?>
    
    <div id="content">
    
      <?php if (have_posts()) : ?>
    
      <?php $post = $posts[0];  ?>
    
      <?php if (is_category()) { ?>
    
      <h2 class="pagetitle">‘
    
        <?php single_cat_title(); ?>
    
        ’
    
        <?php _e('category archive','Passit')?>
    
      </h2>
    
      <?php  } elseif (is_day()) { ?>
    
      <h2 class="pagetitle">
    
        <?php _e('Archive for','Passit')?>
    
        <?php the_time('F jS, Y'); ?>
    
      </h2>
    
      <?php  } elseif (is_month()) { ?>
    
      <h2 class="pagetitle">
    
        <?php _e('Archive for','Passit')?>
    
        <?php the_time('F, Y'); ?>
    
      </h2>
    
      <?php } elseif (is_year()) { ?>
    
      <h2 class="pagetitle">
    
        <?php _e('Archive for','Passit')?>
    
        <?php the_time('Y'); ?>
    
      </h2>
    
      <?php  } elseif (is_search()) { ?>
    
      <h2 class="pagetitle">
    
        <?php _e('Search results for','Passit')?>
    
        ‘‘<?php echo($s); ?> ’’ </h2>
    
      <?php } ?>
    
      <?php while (have_posts()) : the_post(); ?>
    
    <div class="date">
    
            <?php the_time('M', '', ''); ?>
    
            <div>
    
              <?php the_time('d', '', ''); ?>
    
            </div>
    
          </div>
    
      <div class="post" id="post-<?php the_ID(); ?>">
    
        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e('Permanent Link to','Passit')?> <?php the_title(); ?>">
    
          <?php the_title(); ?>
    
          </a></h2>
    
        <?php if(!is_page()) {  ?>
    
        <small>
    
        <?php edit_post_link('e', ' - ', '  '); ?>
    
        </small>
    
        <?php }  ?>
    
        <?php if(!is_search()) :  ?>
    
        <div class="entry">
    
          <?php the_content(__('Read the rest of this entry &raquo;')); ?>
    
        </div>
    
        <?php endif;  ?>
    
        <?php if(!is_page()) {  ?>
    
        <?php if(is_single()) : ?>
    
        <ul class="postmetadata alt">
    
          <li class="details_summary"> <strong>
    
            <?php _e('Date')?>
    
            </strong>
    
            <?php the_time('l, d M y') ?>
    
            <?php _e('at')?>
    
            <?php the_time() ?>
    
          </li>
    
          <li class="details_summary"><strong>
    
            <?php _e('Under')?>
    
            </strong>
    
            <?php the_category(', ') ?>
    
          </li>
    
          <li class="details_summary">
    
            <?php _e('You can follow any responses to this entry through the','Passit')?>
    
            <?php comments_rss_link('RSS 2.0'); ?>
    
            <?php _e('feed')?>
    
            .</li>
    
          <?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
    
    							?>
    
          <li class="details_summary">
    
            <?php _e('You can')?>
    
            <a href="#respond">
    
            <?php _e('leave a response')?>
    
            </a>,
    
            <?php _e('or','Passit')?>
    
            <a href="<?php trackback_url(true); ?>" rel="trackback">trackback</a>
    
            <?php _e('from your own site')?>
    
            . </li>
    
          <?php } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
    
    							 ?>
    
          <li class="details_l">
    
            <?php _e('Responses are currently closed, but you can')?>
    
            <a href="<?php trackback_url(true); ?> " rel="trackback">trackback</a>
    
            <?php _e('from your own site')?>
    
            .</li>
    
          <?php } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
    
    							 ?>
    
          <li class="details_l">
    
            <?php _e('You can skip to the end and leave a response. Pinging is currently not allowed')?>
    
            .</li>
    
          <?php } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
    
    							 ?>
    
          <li class="details_l">
    
            <?php _e('Both comments and pings are currently closed')?>
    
            .</li>
    
          <?php } ?>
    
        </ul>
    
        <?php else :  ?>
    
        <ul class="postmetadata">
    
          <li class="details_r">
    
            <?php comments_popup_link(__('No Comments'),__('1 Comment'),__('% Comments')); ?>
    
          </li>
    
          <li class="details_l">
    
            <?php _e('Posted in')?>
    
            <?php the_category(', ') ?>
    
          </li>
    
        </ul>
    
        <?php endif; ?>
    
        <?php }  ?>
    
      </div>
    
      <?php if(is_single()) :   ?>
    
      <?php comments_template(); ?>
    
      <?php endif;  ?>
    
      <?php endwhile; ?>
    
      <?php if(is_single() || is_page() ) :  ?>
    
      <?php else: ?>
    
      <div class="navigation">
    
        <div class="alignleft">
    
          <?php next_posts_link(__('Previous Entries')); ?>
    
        </div>
    
        <div class="alignright">
    
          <?php previous_posts_link(__('Next Entries')); ?>
    
        </div>
    
      </div>
    
      <?php endif;  ?>
    
      <?php else : ?>
    
      <?php include (TEMPLATEPATH . '/notfound.php');?>
    
      <?php endif; ?>
    
    </div>
    
    <?php include (TEMPLATEPATH . "/sidebartwo.php"); ?>
    
    <?php get_footer(); ?>
  2. icyville
    Member
    Posted 6 years ago #

    the image can go at the top of the first post or just at the top of the posts in general but it can't appear on any other pages.

  3. Khairil Zhafri
    Member
    Posted 6 years ago #

    Put it before <?php while (have_posts()) : the_post(); ?>

  4. icyville
    Member
    Posted 6 years ago #

    wait, what? put what before that

  5. Khairil Zhafri
    Member
    Posted 6 years ago #

    Put the image lah.

  6. icyville
    Member
    Posted 6 years ago #

    lah?

  7. Khairil Zhafri
    Member
    Posted 6 years ago #

    You might want to use conditional tag is_home() so that it only appears in the home page.

  8. icyville
    Member
    Posted 6 years ago #

    interesting, i no nothing about php though, could help me out and tell me how to use this conditional home tag?

    or just how to get this image to appear at the top of just the posts

  9. Khairil Zhafri
    Member
    Posted 6 years ago #

    Sorry about the lah. Didn't realize I typed that.

    Replace <?php while (have_posts()) : the_post(); ?>

    with

    <?php while (have_posts()) : ?; ?>
    
    <?php if(is_home()) {  ?>
    <img src="whateverurltotheimage" alt="alternatetexttotheimage">
    <?php }  ?>
    
    <?php the_post(); ?>
  10. icyville
    Member
    Posted 6 years ago #

    ok, its cool.

    I get this error now
    Parse error: syntax error, unexpected T_ENDWHILE in /home/backerm2/public_html/woodencotton/test1/wp-content/themes/wc/index.php on line 487

  11. Khairil Zhafri
    Member
    Posted 6 years ago #

    Whoops. Actually just replace everything I suggested into:

    <?php if(is_home()) { ?>
    <img src="whateverurltotheimage" alt="alternatetexttotheimage">
    <?php } ?>
    
    <?php while (have_posts()) : the_post(); ?>

    There were a little misunderstanding and little error in the earlier code.

  12. icyville
    Member
    Posted 6 years ago #

    it works, thanks!!!

  13. icyville
    Member
    Posted 6 years ago #

    one last question, how to i make the link relative so that I don't have to type the whole url (so when i transfer everything to a different folder it still works)

  14. icyville
    Member
    Posted 6 years ago #

    nvm got it

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags