首页 > 解决方案 > 不能在while循环中内爆最后一个逗号

问题描述

请帮助无法解决此问题。我想添加谷歌丰富的片段,这就是为什么尝试创建 json 但我无法删除最后一个逗号。即使 implode 也不显示任何逗号我尝试了很多东西,但没有一个解决了我的问题。请帮忙

$carisirket = get_queried_object();
$args = array(
    'post_type' => 'MYPOSTTYPE',
    'posts_per_page' => 10,
    'tax_query' => array(
        array(
            'taxonomy' => 'MYTAX',
            'field' => 'slug',
            'terms' => $carisirket->slug,
        )
    )
);
$qq = new WP_Query($args);

 if($qq->have_posts()) {
    while($qq->have_posts()) : $qq->the_post();
  ?>
  
  {
    "@type" : "Review",
     "headline": "<?php  echo get_the_title();?>",
    "itemReviewed": {
                    "@type": "Thing",
                    "name": "<?php echo $term->name;?>"
                },
    
    "author" : {
      "@type" : "Person",
      "name" : "<?php echo get_the_author();?>",
      "url": ""
    },
    
    
    "reviewBody" : "<?php  echo get_the_title() ; ?>",
    "datePublished" : "<?php echo get_the_date();  ?>",
    
    "reviewRating" : {
      "@type" : "Rating",
      "ratingValue" : "<?php  echo get_post_meta(get_the_ID(), 'ratings_3421372395', true);  ?>",
      "bestRating" : "5",
      "worstRating" : "0"
    },
   "publisher": {
                    "@type": "Organization",
                    "name": "Şikayetimvar.az",
                    "sameAs": "https://sikayetimvar.az",
                    "logo": {
                        "@type": "ImageObject",
                        "url": "https://XXXXXX.COM/wp-content/uploads/2021/01/logo.png",
                        "width": 200,
                        "height": 50
                    }
                }
   
  } <?php echo implode(',', $qq); endwhile;} ?>

标签: while-loopcommaimplode

解决方案


推荐阅读