Need help to link featured image to post permalink
-
Hi. Before I be asked, I already read related topics, but the solutions didn’t work for me.
I found a code to be put inside the loop as follow:
<?php if ( has_post_thumbnail()) { echo '<a href="' . get_permalink($post->ID) . '" >'; the_post_thumbnail(); echo '</a>'; } ?>
The problem is: after I save, all my featured images are doubled. The top one links to post permalink, while the other is still showing the larger image when clicked, but it doesn’t matter, because I can’t have two featured images per post.
The page: daniloleonardi.com/blog
Thanks in advance!
Viewing 1 replies (of 1 total)
-
The template of the page:
<?php $canon_options_post = get_option('canon_options_post'); $default_excerpt_length = 450; ?> <!-- MAIN LOOP --> <?php while ( have_posts() ) : the_post(); ?> <?php $post_format = get_post_format(); $result_cmb_alignment = get_post_meta(get_the_ID(), 'cmb_alignment', true); $result_cmb_excerpt = get_post_meta(get_the_ID(), 'cmb_excerpt', true); $result_cmb_media_link = get_post_meta(get_the_ID(), 'cmb_media_link', true); $result_cmb_use_media_link = get_post_meta(get_the_ID(), 'cmb_use_media_link', true); $result_cmb_quote_is_tweet = get_post_meta($post->ID, 'cmb_quote_is_tweet', true); ?> <?php //STANDARD POST if ( ($post_format === false) && (has_post_thumbnail(get_the_ID())) ) { ?> <div <?php post_class("clearfix"); ?>> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="meta clearfix"> <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6> <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6> </div> <?php if (!empty($result_cmb_use_media_link) && !empty($result_cmb_media_link)) { echo ' <div>'; echo $result_cmb_media_link; echo '</div>'; } else { echo ' <div class="mosaic-block fade">'; $post_thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full'); $img_alt = get_post_meta(get_post_thumbnail_id(get_the_ID()), '_wp_attachment_image_alt', true); $img_post = get_post(get_post_thumbnail_id(get_the_ID())); printf('<a href="%s" class="mosaic-overlay fancybox" data-fancybox-group="gallery" title="%s"></a>', esc_url($post_thumbnail_src[0]), esc_attr($img_post->post_title)); printf('<div class="mosaic-backdrop"><img src="%s" alt="%s" /></div>', esc_url($post_thumbnail_src[0]), esc_attr($img_alt)); echo '</div>'; } ?> <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p> <p><a href="<?php the_permalink(); ?>" class="more"><?php _e('Leia Mais','loc_canon'); ?></a></p> </div> <hr/> <?php } //QUOTE if (($post_format == "quote") && ($result_cmb_quote_is_tweet != "checked")) { ?> <div <?php post_class("clearfix"); ?>> <div class="quote"> <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p> <div class="meta clearfix"> <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6> <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6> </div> </div> </div> <hr/> <?php } //TWEET if (($post_format == "quote") && ($result_cmb_quote_is_tweet == "checked")) { ?> <div <?php post_class("clearfix"); ?>> <div class="tweet"> <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p> <div class="meta clearfix"> <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6> <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6> </div> </div> </div> <hr/> <?php } //VIDEO POST if ($post_format == "video") { ?> <div <?php post_class("clearfix"); ?>> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="meta clearfix"> <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6> <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6> </div> <?php if (!empty($result_cmb_use_media_link) && !empty($result_cmb_media_link)) { echo ' <div>'; echo $result_cmb_media_link; echo '</div>'; } else { echo ' <div class="mosaic-block fade">'; $post_thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full'); $img_alt = get_post_meta(get_post_thumbnail_id(get_the_ID()), '_wp_attachment_image_alt', true); $img_post = get_post(get_post_thumbnail_id(get_the_ID())); printf('<a href="%s" class="mosaic-overlay fancybox" data-fancybox-group="gallery" title="%s"></a>', esc_url($post_thumbnail_src[0]), esc_attr($img_post->post_title)); printf('<div class="mosaic-backdrop"><img src="%s" alt="%s" /></div>', esc_url($post_thumbnail_src[0]), esc_attr($img_alt)); echo '</div>'; } ?> <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p> <p><a href="<?php the_permalink(); ?>" class="more"><?php _e('Leia Mais','loc_canon'); ?></a></p> </div> <hr/> <?php } //AUDIO POST if ($post_format == "audio") { ?> <div <?php post_class("clearfix"); ?>> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="meta clearfix"> <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6> <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6> </div> <?php if (!empty($result_cmb_use_media_link) && !empty($result_cmb_media_link)) { echo ' <div>'; echo do_shortcode($result_cmb_media_link); echo '</div>'; } else { echo ' <div class="mosaic-block fade">'; $post_thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full'); $img_alt = get_post_meta(get_post_thumbnail_id(get_the_ID()), '_wp_attachment_image_alt', true); $img_post = get_post(get_post_thumbnail_id(get_the_ID())); printf('<a href="%s" class="mosaic-overlay fancybox" data-fancybox-group="gallery" title="%s"></a>', esc_url($post_thumbnail_src[0]), esc_attr($img_post->post_title)); printf('<div class="mosaic-backdrop"><img src="%s" alt="%s" /></div>', esc_url($post_thumbnail_src[0]), esc_attr($img_alt)); echo '</div>'; } ?> <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p> <p><a href="<?php the_permalink(); ?>" class="more"><?php _e('Leia Mais','loc_canon'); ?></a></p> </div> <hr/> <?php } //GALLERY POST if ($post_format == "gallery") { $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => get_the_ID() ); $project_attachments = get_posts( $args ); //var_dump($project_attachments); ?> <div <?php post_class("clearfix"); ?>> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="meta clearfix"> <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6> <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6> </div> <div class="flexslider gallery-post-type"> <ul class="slides"> <?php if (has_post_thumbnail(get_the_ID())) { $post_thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full'); $img_post = get_post(get_post_thumbnail_id(get_the_ID())); printf("<li><a href='%s' title='%s'><img src='%s'></a></li>", esc_url($post_thumbnail_src[0]), esc_attr($img_post->post_title), esc_url($post_thumbnail_src[0])); } ?> <?php for ($i = 0; $i < count($project_attachments); $i++) { if (get_post_thumbnail_id(get_the_ID()) != $project_attachments[$i]->ID) { $attachment_src = wp_get_attachment_image_src($project_attachments[$i]->ID, 'full'); $img_post = get_post($project_attachments[$i]->ID); printf("<li><a href='%s' title='%s'><img src='%s'></a></li>", esc_url($attachment_src[0]), esc_attr($img_post->post_title), esc_url($attachment_src[0])); } } ?> </ul> </div> </div> <hr/> <?php } //NO FEAT IMAGE POST if (($post_format === false) && (!has_post_thumbnail(get_the_ID()))) { ?> <div <?php post_class("clearfix"); ?>> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="meta clearfix"> <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6> <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6> </div> <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p> <p><a href="<?php the_permalink(); ?>" class="more"><?php _e('Leia Mais','loc_canon'); ?></a></p> </div> <hr/> <?php } ?> <?php endwhile; ?> <!-- END LOOP --> <!-- PAGINATION --> <?php get_template_part("inc/templates/template_paginate_links"); ?> <!-- Finish Main Content --> </div> </div> <!-- SIDEBAR --> <?php get_sidebar(); ?> </div> <!-- #main --> </div> <!-- #main-container -->
Viewing 1 replies (of 1 total)
- The topic ‘Need help to link featured image to post permalink’ is closed to new replies.