微信咨询

微信咨询

13610*910*9

服务热线 7*24小时

电话咨询

wordpress获取同分类下其它文章

iamdu2024-08-26 23:45:58 浏览: 705385
 <?php
$posts  = get_posts(array(
      'numberposts'=> 10,
      'category'=>get_the_category()[0]->cat_ID,
      'orderby' => 'date',
      'order'=> 'ASC',
      'exclude'=>array(get_the_ID())

    ));
    ?>
    <div class="widget br card">
	<h2 class="wp-block-heading">同类文章</h2>
    
    <?php
    foreach ($posts as $key => $value) {
      echo '
      <li class="list-line">      
        <a href="'.get_permalink($value->ID).'" target="_blank">
        '.$value->post_title.'
        </a>
      </li>
      ';}
    ?>
    </div>