[[[Remove shortcode循环中的标签

问题描述 投票:1回答:1

我具有生成帖子列表的简码,但是帖子会自动包装在<pre>标签中,并且我不确定如何删除它们。示例:

<pre><li><a href=''><img src=''></a></li></li><pre>

这是简码:

[loop the_query="tag=news"]

这是功能:

 function custom_query_shortcode($atts) {

   extract(shortcode_atts(array(
      "the_query" => ''
   ), $atts));

   $the_query = preg_replace('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))',   $the_query);
   $the_query = preg_replace('~&#0*([0-9]+);~e', 'chr(\\1)', $the_query);

   query_posts($the_query);

   $output = '';
   $temp_title = '';
   $temp_link = '';
   $temp_thumb = '';

   if (have_posts()) : while (have_posts()) : the_post();

      $temp_title = get_the_title($post->ID);
      $temp_link = get_permalink($post->ID);
      $temp_thumb = the_post_thumbnail( 'side-thumb' );

      $output .= "<li><a href='$temp_link'>$temp_title <img src='$temp_thumb'></a></li>";

   endwhile; else:

      $output .= "nothing found.";

   endif;

   wp_reset_query();
   return $output;

}
add_shortcode("loop", "custom_query_shortcode");
php html wordpress shortcode pre
1个回答
1
投票

我将看以下内容:

  • 您在做什么正则表达式位?他们有必要吗?
  • 缺少ul标签可能是一个问题
  • query_posts对于这样的事情总体来说有点狡猾,您真的应该更改为使用WP_Query以避免各种伏都教作弊,这是运行多个循环的更好方法,我怀疑,因为query_posts劫持了主查询,本质上是这样做另一个循环内部可能是导致各种汤姆傻瓜的原因。

祝你好运。>>

© www.soinside.com 2019 - 2024. All rights reserved.