How to wrap echo div in <a href>


How to wrap echo div in <a href>

我在将Wordpress归档页面转移到页面模板时遇到了两个问题。

<?php $args = array( 'post_type' => 'casestudies', 'posts_per_page' => 12 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="casestudy">'.get_the_post_thumbnail( $post->ID, '180,180' ).'</div>';

首先,我需要用链接包裹缩略图的回声,以便触发css操作:

'<a href="'.the_permalink().'" class="anchor-hover">';

当我添加a href行时,它只打印链接,而不包装回显。

然后a href应该在缩略图框上打印标题和摘录:

 '<span class="details"><div class="anchor-hover details-h3"><?php the_title(); ?></div>';
 '<p class="desc"><?php echo get_post($post_id)->post_excerpt; ?></p></span></a>';
endwhile; ?>
        <div class="clear"></div>
        </div></div>

在wordpress中,有两种类型的函数。一个是返回结果,另一个是响应结果。

您使用的是the_permalink();,它已经在回显它的结果。

您需要使用get_the_permalink();,因为您正试图在模板中回显它。

get_permink为a href工作,谢谢,但我如何才能让php the_title()和php echo get_post($post_id)->post_except显示在光标悬停上?

如果你在循环中,这个代码应该可以工作

<a href="#" title="<?php echo get_the_title() . ' - ' . get_the_excerpt(); ?>">LINK</a>

WordPress中的get方法只会给你字符串。

http://codex.wordpress.org/Function_Reference/get_the_excerpthttp://codex.wordpress.org/Function_Reference/get_the_title