WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] posts thumbnails & title with link (7 posts)

  1. mlevy
    Member
    Posted 1 year ago #

    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
    			}
    			?>
  2. deepbevel
    Member
    Posted 1 year ago #

    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.

  3. mlevy
    Member
    Posted 1 year ago #

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

  4. deepbevel
    Member
    Posted 1 year ago #

    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>
  5. mlevy
    Member
    Posted 1 year ago #

    in which line? :(

  6. deepbevel
    Member
    Posted 1 year ago #

    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. :(

  7. mlevy
    Member
    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic