【问题标题】:Problems with the call to the function array_splice php调用函数array_splice php的问题
【发布时间】:2019-05-18 06:42:51
【问题描述】:

不久前我正在学习 PHP 语言,我正在尝试执行一些功能,它以一种奇怪的方式工作

我想在单个帖子的文本之间显示相关帖子,对它的函数的调用但在文本上方,array_splice 似乎不起作用

我做错了什么??

add_filter( 'the_content', 'related_inside_content' );
function related_inside_content( $content ) {
          $ads = postss(); //CALL FUNCTION!
          $p_arrayx = explode('</p>', $content );
          $p_count = 10;
          if( !empty( $p_arrayx ) ){
              array_splice( $p_arrayx, $p_count, 0, $ads );
              foreach( $p_arrayx as $key=>$value ){
                  $output .= $value;
               }
          }

      return $output;
 }

调用函数

function postss(){
$tags = wp_get_post_terms( get_queried_object_id(), 'customtags', ['fields' => 'ids'] );
$args = [
    'post__not_in'        => array( get_queried_object_id() ),
    'posts_per_page'      => 2,
    'ignore_sticky_posts' => 2,
    'orderby'             => 'relevance',
    'tax_query' => [
        [
            'taxonomy' => 'customtags',
            'terms'    => $tags
        ]
    ]
];
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {
        while( $my_query->have_posts() ) :
            $my_query->the_post();
            $title =  get_the_title(); 
            $image =  get_the_post_thumbnail_url(get_the_ID(),'posts-thumb'); 
            $imagehtml = '<li>'.'<img src="'.$image . '">'.'<span class="overlayer"></span>'.'<span class="title">'. $title. '</span>'.'</li>'; 
            echo $imagehtml;
            wp_reset_postdata();
          endwhile;
 }  

}

【问题讨论】:

    标签: php wordpress function content-management-system


    【解决方案1】:

    我想只需添加您的循环echo get_the_content()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-30
      • 2011-02-09
      • 2015-09-14
      相关资源
      最近更新 更多