• Resolved icyville

    (@icyville)


    How do I do this?
    I want to add an image on top of the first post only here
    https://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(); ?>

Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter icyville

    (@icyville)

    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.

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

    Thread Starter icyville

    (@icyville)

    wait, what? put what before that

    Put the image lah.

    Thread Starter icyville

    (@icyville)

    lah?

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

    Thread Starter icyville

    (@icyville)

    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

    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(); ?>
    Thread Starter icyville

    (@icyville)

    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

    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.

    Thread Starter icyville

    (@icyville)

    it works, thanks!!!

    Thread Starter icyville

    (@icyville)

    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)

    Thread Starter icyville

    (@icyville)

    nvm got it

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Add image on top of first post only’ is closed to new replies.