我想链接the_post_thumbnail
通过使用the_permalink
.
我这样做(It Works without link)
<?php $args = array( \'post_type\' => \'xyz\', \'posts_per_page\' => -1, \'orderby\' => \'rand\' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_post_thumbnail(\'wine-flow\', array(\'class\' => \'item\'));
endwhile; ?>
我想进一步做到这一点:(
Syntax Error)
<?php $args = array( \'post_type\' => \'xyz\', \'posts_per_page\' => -1, \'orderby\' => \'rand\' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail(\'wine-flow\', array(\'class\' => \'item\')); ?>
</a>
endwhile; ?>
谢谢ogni
最合适的回答,由SO网友:pixelngrain 整理而成
这是因为在anchor标记之前没有关闭php
<?php $args = array( \'post_type\' => \'xyz\', \'posts_per_page\' => -1, \'orderby\' => \'rand\' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail(\'wine-flow\', array(\'class\' => \'item\')); ?>
</a>
<?php
endwhile; ?>
SO网友:Just Thomas Misund
调用后需要跳出PHP$loop->the_post()
, 因为在那之后,您正在编写HTML。您还需要在之前跳回PHPendwhile;
因为那是PHP而不是HTML。
<?php $args = array( \'post_type\' => \'xyz\', \'posts_per_page\' => -1, \'orderby\' => \'rand\' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail(\'wine-flow\', array(\'class\' => \'item\')); ?>
</a>
<?php endwhile; ?>