我在一个帖子页面上,此外,我想显示标题为"赞助商"的类别中所有帖子的缩略图、标题和链接。我能够显示缩略图和标题:
<a <?php echo ( !wp_is_mobile() )? 'target="_blank"' : '' ?> href="<?php _s( get_the_ID()) ?>">
<?php
query_posts( array( 'category_name' => 'sponsor' ) );
if ( have_posts() ) while ( have_posts() ) : the_post();
echo '<li>';
the_post_thumbnail( 'big-thumb', array( 'alt' => get_the_title(), 'class' => 'img-responsive post-cover' ) );
the_title();
echo '</li>';
endwhile;
wp_reset_query();
?>
</a>
但是,我无法成功地获得正确的链接的类别内的帖子"赞助商"。我试着使用get_the_ID,但它使用了我所在的帖子页面中的链接。根据我的研究,我认为这是因为我需要在循环之外获得页面ID。
当涉及到PHP时,我是一个新手,所以任何帮助都将不胜感激。
只需尝试通过他们的id 为帖子创建启用链接
<?php
query_posts( array( 'category_name' => 'sponsor' ) );
if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<a <?php echo ( !wp_is_mobile() )? 'target="_blank"' : '' ?> href="<?php _s( get_the_ID()) ?>">
<?php
echo '<li>';
the_post_thumbnail( 'big-thumb', array( 'alt' => get_the_title(), 'class' => 'img-responsive post-cover' ) );
the_title();
echo '</li>';
echo '</a>';
endwhile;
wp_reset_query();
?>