• Resolved mlevy

    (@mlevy)


    How to link (a href) to thumbnail & title?

    code:

    <?php
    			// Show a selected number of posts per row
    			$posts_per_row = 4;
    			$posts_per_page = 4;
    			$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    			$args = array(
       			'posts_per_page' => $posts_per_page,
       			'paged' => $paged,);
    			query_posts('cat=3');
    			if (have_posts()) {
      			while (have_posts()) {
         		the_post();
          		if ((++$post_counter % $posts_per_row) == 1  || $posts_per_row == 1) {
             	if ($post_counter > 1) {
                echo "</div><!-- End of post_row -->\n";  // End previous row
             	}
            	echo "<div class='post_row'>\n ";  // Start a new row
         		}
          		echo "<div class='post_class' >\n";  // Start one post
    
    	 		echo get_the_post_thumbnail($page->ID, array(160,87));
    
            	echo '<h3 style="font-size:15px; text-transform: uppercase; margin-top:5px;">';the_title();'</h3>';
          		echo "</div><!-- End of post_class -->\n";  // End of post
       			} ?>
       			</div><!-- End of post_row -->
       			<div class='clear'></div>
    			<?php } else {
       			// Code for no posts found
    			}
    			?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • I don’t know how to write it with echo, but you have to wrap the_ title in the_permalink

    <a href="<?php the_permalink(); ?>">
    <?php the_title();?></a>

    You can do the same to the thumbnail.

    Thread Starter mlevy

    (@mlevy)

    thx
    but not work, how to write it without echo?

    Coincidently, I’m using the same post rows code. This is what I use:

    // Output post data here
    ?>
    
    <a href="<?php the_permalink(); ?>">
    <?php the_title();?>
    <?php the_post_thumbnail();?>
    </a>
    Thread Starter mlevy

    (@mlevy)

    in which line? 🙁

    place it directly after:

    echo "<div class='post_class' >\n";  // Start one post

    like this:

    echo "<div class='post_class' >\n";  // Start one post
    // Output post data here
    ?>
    
    <a href="<?php the_permalink(); ?>">
    <?php the_title();?>
    <?php the_post_thumbnail();?>
    </a>
    
    <h3 style="font-size:15px; text-transform: uppercase; margin-top:5px;">';the_title();'
    </h3>';

    then the rest of the code stays as is.
    But you have different thumnbail code so you have to adjust for that.

    I think this will work but it’s hard to know if I switched from echo correctly at the end, I can’t test it right now, you may have to play with it. As I said, I don’t understand much about echo, I feel lame telling you to do it this way. 🙁

    Thread Starter mlevy

    (@mlevy)

    ok, i got it:

    <?php
    			// Show a selected number of posts per row
    			$posts_per_row = 4;
    			$posts_per_page = 4;
    			$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    			$args = array(
       			'posts_per_page' => $posts_per_page,
       			'paged' => $paged,);
    			query_posts('cat=4');
    			if (have_posts()) {
      			while (have_posts()) {
         		the_post();
          		if ((++$post_counter % $posts_per_row) == 1  || $posts_per_row == 1) {
             	if ($post_counter > 1) {
                echo "</div><!-- End of post_row -->\n";  // End previous row
             	}
            	echo "<div class='post_row'>\n ";  // Start a new row
         		}
          		echo "<div class='post_class' >\n";  // Start one post?>
    			<a href="<?php the_permalink(); ?>">
    			<?php the_post_thumbnail();?>
    			<h3 style="font-size:15px; text-transform: uppercase; margin-top:5px;"><?php the_title();?></h3>
    			</a>
    			<?php
          		echo "</div><!-- End of post_class -->\n";  // End of post
       			} ?>
       			</div><!-- End of post_row -->
       			<div class='clear'></div>
    			<?php } else {
       			// Code for no posts found
    			}
    			?>

    🙂 thx

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘posts thumbnails & title with link’ is closed to new replies.