Support » Plugins » How to insert an image between 2 posts

  • I would like to insert an image between the first and second post on my homepage.

    I’ve got the following index code:

    <?php get_header(); ?>
    
    <div id="main_content" class="clearfix">
    	<div id="left_area">
    		<?php get_template_part('includes/breadcrumbs', 'index'); ?>
    		<?php get_template_part('includes/entry', 'index'); ?>
    	</div> <!-- end #left_area -->
    
    	<?php get_sidebar(); ?>
    </div> <!-- end #main_content -->
    
    <?php get_footer(); ?>

    And the following loop page code:

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    	<article class="entry post clearfix">
    		<h1 class="main_title"><?php the_title(); ?></h1>
    
    		<div class="post-content clearfix">
    			<?php
    				$thumb = '';
    				$width = (int) apply_filters('et_image_width',553);
    				$height = (int) apply_filters('et_image_height',240);
    				$classtext = '';
    				$titletext = get_the_title();
    				$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Page');
    				$thumb = $thumbnail["thumb"];
    			?>
    			<?php if ( '' != $thumb && 'on' == get_option('trim_page_thumbnails') ) { ?>
    				<div class="featured_box">
    					<a>">
    						<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
    					</a>
    				</div> 	<!-- end .featured_box -->
    			<?php } ?>
    
    			<div class="entry_content">
    				<?php the_content(); ?>
    				<?php wp_link_pages(array('before' => '<p><strong>'.esc_attr__('Pages','Trim').':</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    				<?php edit_post_link(esc_attr__('Edit this page','Trim')); ?>
    			</div> <!-- end .entry_content -->
    		</div> <!-- end .post-content -->
    	</article> <!-- end .post -->
    <?php endwhile; // end of the loop. ?>

    What do I have to change in the code(s) to insert an image (by url)?

    Hopefully somebody can help me on this.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    before this line <?php endwhile; // end of the loop. ?> insert for example:

    <?php if( is_home() && $wp_query->current_post == 0 ) { ?>
    <!--YOUR HTML IMAGE CODE HERE-->
    <?php } ?>

    is it always the same image/banner?
    where is the image going to be located?

    Dear Alchymyth,

    Thank you for helping me out.

    The image will change from time to time, but would like to change it by entering (for example) a html code in it.

    The image will be located between the first and second post.

    If I’m right and read some other posts, I should change “current_post == 1” if I would like to post the image after the first post, right?

    Michael

    (@alchymyth)

    Forum Moderator

    I should change “current_post == 1” if I would like to post the image after the first post, right?

    no – the location of the suggested edit is directly after the output of the post, so you would need to check for the first post which is ->current_post == 0 (loop counter starts with 0 zero for the first post).

    if you move the suggested code to directly after the first line <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> i.e. to before the output of the post, then you would need to check for post number two which is ->current_post == 1.

    Somehow it doesn’t work.

    I’m using the “Trim” theme from Elegant Themes.

    There is also “Loop-single” file on the server:

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    	<?php if (get_option('trim_integration_single_top') <> '' && get_option('trim_integrate_singletop_enable') == 'on') echo (get_option('trim_integration_single_top')); ?>
    
    	<article class="entry post clearfix">
    		<?php if ( 'on' == get_option('trim_show_date_icon_single') ) { ?>
    			<span class="post-meta"><?php echo get_the_time( 'D' ); ?><span><?php echo get_the_time( 'd' ); ?></span></span>
    		<?php } ?>
    
    		<h1 class="main_title"><?php the_title(); ?></h1>
    
    		<?php
    			$index_postinfo = get_option('trim_postinfo2');
    			if ( $index_postinfo ){
    				echo '<p class="meta">';
    				et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
    				echo '</p>';
    			}
    		?>
    
    		<div class="post-content clearfix">
    			<?php
    				$thumb = '';
    				$width = (int) apply_filters('et_image_width',481);
    				$height = (int) apply_filters('et_image_height',230);
    				$classtext = '';
    				$titletext = get_the_title();
    				$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
    				$thumb = $thumbnail["thumb"];
    			?>
    			<?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails') ) { ?>
    				<div class="featured_box">
    					<a href="<?php the_permalink(); ?>">
    						<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
    					</a>
    				</div> 	<!-- end .featured_box -->
    			<?php } ?>
    
    			<div class="entry_content">
    				<?php the_content(); ?>
    				<?php wp_link_pages(array('before' => '<p><strong>'.esc_attr__('Pages','Trim').':</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    				<?php edit_post_link(esc_attr__('Edit this page','Trim')); ?>
    			</div> <!-- end .entry_content -->
    		</div> <!-- end .post-content -->
    	</article> <!-- end .post -->
    
    	<?php if (get_option('trim_integration_single_bottom') <> '' && get_option('trim_integrate_singlebottom_enable') == 'on') echo(get_option('trim_integration_single_bottom')); ?>
    
    	<?php
    		if ( get_option('trim_468_enable') == 'on' ){
    			if ( get_option('trim_468_adsense') <> '' ) echo( get_option('trim_468_adsense') );
    			else { ?>
    			   <a href="<?php echo esc_url(get_option('trim_468_url')); ?>"><img src="<?php echo esc_attr(get_option('trim_468_image')); ?>" alt="468 ad" class="foursixeight" /></a>
    	<?php 	}
    		}
    	?>
    
    	<?php
    		if ( 'on' == get_option('trim_show_postcomments') ) comments_template('', true);
    	?>
    <?php endwhile; // end of the loop. ?>

    Michael

    (@alchymyth)

    Forum Moderator

    any error messages?
    too many images?
    no images?
    image at the wrong location?

    unfortunately, as you are using a commercial theme, this forum cannot really help much; http://codex.wordpress.org/Forum_Welcome#Commercial_Products

    please contact elegantthemes for support with the problem.

    I didn’t get anything on the homepage, tried to get some help through the elegantthemes support, but it really takes a long time.

    But I’ll stick to the rules of this forum.

    Yet again thanks for your help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to insert an image between 2 posts’ is closed to new replies.