我正在与php结构作斗争。我需要如何重写代码才能获得自定义帖子标题和缩略图的链接?
<ul class="thumbnails">
<?php $pfportfolio = new WP_Query( \'post_type=portfolio\', \'posts_per_page=-1\' );?>
<?php while ( $pfportfolio->have_posts() ) : $pfportfolio->the_post();?>
<?php
echo \'<li class="span4" data-id="post-\'.get_the_ID().\'" data-type="\'.$terms_as_text = strip_tags( get_the_term_list( $post->ID, \'location\', \'\', \' \', \'\' ) ).\'">\';
**echo \'<span class="projekte-title">\';
the_title();
echo \'</span>\';
echo \'<div class="thumbnail">\';
the_post_thumbnail(\'home-feat\');
echo \'</div>\';**
echo \'</li>\';?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</ul>
我想我需要以某种方式整合
<a href="<?php echo get_permalink(); ?>"></a>
但不幸的是,我不明白怎么做:(。非常感谢你的帮助!
SO网友:Krzysiek Dróżdż
像这样的事情应该可以解决你的问题。。。
<?php $pfportfolio = new WP_Query( array(\'post_type\'=>\'portfolio\', \'posts_per_page\'=>-1) ); ?>
<?php if ( $pfportfolio->have_posts() ): ?>
<ul class="thumbnails">
<?php while ( $pfportfolio->have_posts() ) : $pfportfolio->the_post(); ?>
<li class="span4" data-id="post-<?php echo esc_attr(get_the_ID()); ?>" data-type="<?php echo esc_attr(strip_tags( get_the_term_list( $post->ID, \'location\', \'\', \' \', \'\' ) ) ); ?>">
<a href="<?php the_permalink(); ?>"><span class="projekte-title"><?php the_title(); ?></span></a>
<div class="thumbnail"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(\'home-feat\'); ?></a></div>
</li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</ul>
<?php endif; ?>