【问题标题】:WordPress Related Posts thumbnails work but permalink errorWordPress 相关帖子缩略图有效,但永久链接错误
【发布时间】:2020-08-15 11:36:23
【问题描述】:

我试图在每个 WP 帖子下方显示 4 个相关帖子。缩略图正常工作,拉入特征图像和标题,但永久链接没有。它以“http://example.com/original-post-name//”的形式出现(添加了空格)并且是可点击的,但当然没有找到内容。这个确切的代码在我的另一个站点上运行良好,但不是这个新站点。我确信它可以改进 - 我对 wordpress 主题相当陌生。

 <?php
 // Default arguments
  $args = array(
 'posts_per_page' => 4,
 'post__not_in'   => array( get_the_ID() ),
 'no_found_rows'  => true,
 );

$cats = wp_get_post_terms( get_the_ID(), 'category' ); 
$cats_ids = array();  
foreach( $cats as $wpex_related_cat ) {
$cats_ids[] = $wpex_related_cat->term_id; 
}
if ( ! empty( $cats_ids ) ) {
$args['category__in'] = $cats_ids;
}

// Query posts
$wpex_query = new wp_query( $args );

// Loop through posts
foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>

<!--<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 
'echo=0' ) ); ?>"><?php the_title(); ?></a>-->
<div class="relatedthumb">
<a rel="external" href="<?the_permalink()?>"><?php the_post_thumbnail(array(150,100)); ?><br 
/>
<?php the_title(); ?>
</a>
</div>

<?php
// End loop
endforeach;

// Reset post data
wp_reset_postdata(); ?>

抱歉,如果之前有人问过这个问题 - 我已经尝试过搜索并希望这是一个简单的解决方案。谢谢!

【问题讨论】:

    标签: php html wordpress wordpress-theming thumbnails


    【解决方案1】:

    您使用了错误的 php 开始标签

    <a rel="external" href="<?php the_permalink(); ?>">
    

    原来是错别字

    【讨论】:

      猜你喜欢
      • 2018-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-22
      • 2012-04-06
      • 2015-08-21
      • 2012-09-11
      • 2012-07-01
      相关资源
      最近更新 更多