Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在wordpress的热门帖子中显示内容?_Php_Wordpress - Fatal编程技术网

Php 如何在wordpress的热门帖子中显示内容?

Php 如何在wordpress的热门帖子中显示内容?,php,wordpress,Php,Wordpress,我使用的是十大流行帖子插件 我添加了以下行,但它不会显示 $output .= '<li>' .wpautop(wp_trim_words($result["post_content"], 15)). '</li>'; $output.=''.wpautop(wp_trim_words($result[“post_content”],15))。''; 代码: 函数tptn\u pop\u posts($args){ 全局$wpdb、$siteurl、$tablepos

我使用的是十大流行帖子插件

我添加了以下行,但它不会显示

$output .= '<li>' .wpautop(wp_trim_words($result["post_content"], 15)). '</li>';
$output.='
  • '.wpautop(wp_trim_words($result[“post_content”],15))。'';
  • 代码:

    函数tptn\u pop\u posts($args){
    全局$wpdb、$siteurl、$tableposts、$id、$tptnu设置;
    $defaults=数组(
    'is_widget'=>FALSE,
    “每日”=>错误,
    “echo”=>错误,
    “严格限制”=>错误,
    “仅发布”=>错误,
    'is_shortcode'=>FALSE,
    “标题”=>1,
    );
    $defaults=array\u merge($defaults,$tptn\u设置);
    //解析将$args导入数组并将其与$defaults合并
    $args=wp\u parse\u args($args,$defaults);
    //可选:将$args中的每个项声明为其自己的变量,即$type,$before。
    提取($args,EXTR_SKIP);
    若有(每日){
    $table\u name=$wpdb->prefix.“每日前十名”;
    }否则{
    $table_name=$wpdb->前缀“前十名”;
    }
    $limit=($strict\U limit)?$limit:($limit*5);
    $exclude_categories=分解(“,”,$exclude_categories);
    $target\u attribute=($link\u new\u window)?'target=“\u blank”:'';//设置目标属性
    $rel_attribute=($link_nofollow)?'nofollow':'';//设置nofollow属性
    parse_str($post_types,$post_types);//将post类型保存在$post_types变量中
    如果(!$daily){
    $args=array();
    $sql=“选择postnumber、cntaccess作为sumCount、ID、post\u类型、post\u状态”;
    $sql.=“从{$table_name}内部联接“$wpdb->posts.”ON postnumber=ID;
    $sql.=“发布状态='publish'”;
    如果(“”!=$exclude\u post\u ID){
    $sql.=“且ID不在({$exclude_post_ids})”中;
    }
    $sql.=”和(“;
    $multiple=false;
    foreach($post\u type作为$post\u type){
    如果($multiple)$sql.='或';
    $sql.=“post_类型='%s'”;
    $multiple=true;
    $args[]=$post_type;//将post类型添加到$args数组中
    }
    $sql.=”;
    $sql.=“订单数量说明限制%d”;
    $args[]=$limit;
    }否则{
    $current_time=当前_时间('timestamp',0);
    $current_time=$current_time-($daily_range-1)*3600*24;
    $current_date=日期('Y-m-j',$current_time);
    $args=数组(
    $current_date,
    );
    $sql=“选择postnumber、SUM(cntaccess)作为sumCount、dp\u日期、ID、post\u类型、post\u状态”;
    $sql.=“从{$table_name}内部联接“$wpdb->posts.”ON postnumber=ID;
    $sql.=“和发布状态='publish'和发布日期>='%s';
    如果(“”!=$exclude\u post\u ID){
    $sql.=“且ID不在({$exclude_post_ids})”中;
    }
    $sql.=”和(“;
    $multiple=false;
    foreach($post\u type作为$post\u type){
    如果($multiple)$sql.='或';
    $sql.=“post_类型='%s'”;
    $multiple=true;
    $args[]=$post_type;//将post类型添加到$args数组中
    }
    $sql.=”;
    $sql.=“按postnumber分组”;
    $sql.=“订单数量说明限制%d”;
    $args[]=$limit;
    }
    if($posts\u only){//仅当设置了变量时才返回posts数组
    返回apply_filters('tptn_pop_posts_array',$wpdb->get_results($wpdb->prepare($sql,$args),array_A));
    }
    $results=$wpdb->get_results($wpdb->prepare($sql,$args));
    $counter=0;
    $output='';
    $shortcode\u class=$is\u shortcode?'tptn\u posts\u shortcode':'';
    $widget\u class=$is\u widget?'tptn\u posts\u widget':'';
    若有($标题){
    如果(!$daily){
    $output.=''.apply_过滤器('tptn_heading_title',$title);
    }否则{
    $output.=''。应用过滤器('tptn\U标题\U标题',$title\U每日);
    }
    }否则{
    如果(!$daily){
    $output.='';
    }否则{
    $output.='';
    }
    }
    如果(结果){
    $output.=应用过滤器('tptn_在_列表之前',在_列表之前$);
    foreach($results作为$result){
    $sumcount=$result->sumcount;
    $result=get_post(apply_filters('tptn_post_id',$result->id));//让我们使用id获取post
    $categorys=get_the_category(apply_filters('tptn_post_cat_id',$result->id));//获取插件的类别
    $p_in_c=false;//用于检查特定类别中是否存在post的变量
    foreach($categorys as$cat){//循环检查post是否存在于排除的类别中
    $p_in_c=(在_数组中($cat->cat_ID,$exclude_categories))?true:false;
    if($p_in_c)break;//如果在类别中找到post,则结束循环
    }
    $title=tptn\u max\u formatted\u content(获取\u标题($result->ID),$title\u长度);
    如果(!$p_in_c){
    $output.=apply_filters('tptn_在_列表项目之前',$before_列表项目,$result->ID);
    如果('after'=$post\u thumb\u op){
    $output.='';//关闭链接
    }
    如果('inline'=$post_thumb_op | | op |'thumb_only'=$post_thumb_op | op |之后的'inline'=$post_thumb_op | |'thumb_only'=$post_thumb__{
    $output.='';//关闭链接
    }
    if('inline'=$post_thumb_op | | |'text_only'=$post_thumb_op){
    $output.='';
    $output.='';//关闭链接
    }
    如果($show_author){
    $author\u info=get\u userdata($result->post\u author);
    $author\u name=ucwords(修剪(条纹斜杠($author\u info->display\u name));
    $author\u link=get\u author\u posts\u url($author\u info->ID);
    $output.=''.''.''('by',TPTN\U LOCAL\U NAME.'';
    }
    
    function tptn_pop_posts( $args ) {
        global $wpdb, $siteurl, $tableposts, $id, $tptn_settings;
    
        $defaults = array(
            'is_widget' => FALSE,
            'daily' => FALSE,
            'echo' => FALSE,
            'strict_limit' => FALSE,
            'posts_only' => FALSE,
            'is_shortcode' => FALSE,
            'heading' => 1,
        );
        $defaults = array_merge( $defaults, $tptn_settings );
    
        // Parse incomming $args into an array and merge it with $defaults
        $args = wp_parse_args( $args, $defaults );
    
        // OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
        extract( $args, EXTR_SKIP );
    
        if ($daily) {
            $table_name = $wpdb->prefix . "top_ten_daily";
        } else {
            $table_name = $wpdb->prefix . "top_ten";
        }
    
        $limit = ( $strict_limit ) ? $limit : ( $limit * 5 );
    
        $exclude_categories = explode( ',', $exclude_categories );
    
        $target_attribute = ( $link_new_window ) ? ' target="_blank" ' : ' ';   // Set Target attribute
        $rel_attribute = ( $link_nofollow ) ? ' nofollow' : ''; // Set nofollow attribute
    
        parse_str( $post_types, $post_types );  // Save post types in $post_types variable
    
        if ( ! $daily ) {
            $args = array();
            $sql = "SELECT postnumber, cntaccess as sumCount, ID, post_type, post_status ";
            $sql .= "FROM {$table_name} INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
            $sql .= "AND post_status = 'publish' ";
            if ( '' != $exclude_post_ids ) {
                $sql .= "AND ID NOT IN ({$exclude_post_ids}) ";
            }
            $sql .= "AND ( ";
            $multiple = false;
            foreach ( $post_types as $post_type ) {
                if ( $multiple ) $sql .= ' OR ';
                $sql .= " post_type = '%s' ";
                $multiple = true;
                $args[] = $post_type;   // Add the post types to the $args array
            }
            $sql .= " ) ";
            $sql .= "ORDER BY sumCount DESC LIMIT %d";
            $args[] = $limit;
        } else {
            $current_time = current_time( 'timestamp', 0 );
            $current_time = $current_time - ( $daily_range - 1 ) * 3600 * 24;
            $current_date = date( 'Y-m-j', $current_time );
    
            $args = array(
                $current_date,
            );
            $sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
            $sql .= "FROM {$table_name} INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
            $sql .= "AND post_status = 'publish' AND dp_date >= '%s' ";
            if ( '' != $exclude_post_ids ) {
                $sql .= "AND ID NOT IN ({$exclude_post_ids}) ";
            }
            $sql .= "AND ( ";
            $multiple = false;
            foreach ( $post_types as $post_type ) {
                if ( $multiple ) $sql .= ' OR ';
                $sql .= " post_type = '%s' ";
                $multiple = true;
                $args[] = $post_type;   // Add the post types to the $args array
            }
            $sql .= " ) ";
            $sql .= "GROUP BY postnumber ";
            $sql .= "ORDER BY sumCount DESC LIMIT %d";
            $args[] = $limit;
        }
    
        if ( $posts_only ) {    // Return the array of posts only if the variable is set
            return apply_filters( 'tptn_pop_posts_array', $wpdb->get_results( $wpdb->prepare( $sql , $args ) , ARRAY_A ) );
        }
    
        $results = $wpdb->get_results( $wpdb->prepare( $sql , $args ) );
    
        $counter = 0;
    
        $output = '';
    
        $shortcode_class = $is_shortcode ? ' tptn_posts_shortcode' : '';
        $widget_class = $is_widget ? ' tptn_posts_widget' : '';
    
        if ( $heading ) {
            if ( ! $daily ) {
                $output .= '<div id="tptn_related" class="tptn_posts ' . $widget_class . $shortcode_class . '">' . apply_filters( 'tptn_heading_title', $title );
            } else {
                $output .= '<div id="tptn_related_daily" class="tptn_posts_daily' . $shortcode_class . '">' . apply_filters( 'tptn_heading_title', $title_daily );
            }
        } else {
            if ( ! $daily ) {
                $output .= '<div class="tptn_posts' . $widget_class . $shortcode_class . '">';
            } else {
                $output .= '<div class="tptn_posts_daily' . $widget_class . $shortcode_class . '">';
            }
        }
    
        if ( $results ) {
            $output .= apply_filters( 'tptn_before_list', $before_list );
            foreach ( $results as $result ) {
                $sumcount = $result->sumCount;
                $result = get_post( apply_filters( 'tptn_post_id', $result->ID ) ); // Let's get the Post using the ID
    
                $categorys = get_the_category( apply_filters( 'tptn_post_cat_id', $result->ID ) );  //Fetch categories of the plugin
                $p_in_c = false;    // Variable to check if post exists in a particular category
    
                foreach ( $categorys as $cat ) {    // Loop to check if post exists in excluded category
                    $p_in_c = ( in_array( $cat->cat_ID, $exclude_categories ) ) ? true : false;
                    if ( $p_in_c ) break;   // End loop if post found in category
                }
    
                $title = tptn_max_formatted_content( get_the_title( $result->ID ), $title_length );
    
                if ( ! $p_in_c ) {
                    $output .= apply_filters( 'tptn_before_list_item', $before_list_item, $result->ID );
    
                    if ( 'after' == $post_thumb_op ) {
                        $output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
                        $output .= '<span class="tptn_title">' . $title . '</span>'; // Add title if post thumbnail is to be displayed after
                        $output .= '</a>'; // Close the link
                    }
                    if ( 'inline' == $post_thumb_op || 'after' == $post_thumb_op || 'thumbs_only' == $post_thumb_op ) {
                        $output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
                        $output .= tptn_get_the_post_thumbnail( array(
                            'postid' => $result->ID,
                            'thumb_height' => $thumb_height,
                            'thumb_width' => $thumb_width,
                            'thumb_meta' => $thumb_meta,
                            'thumb_html' => $thumb_html,
                            'thumb_default' => $thumb_default,
                            'thumb_default_show' => $thumb_default_show,
                            'thumb_timthumb' => $thumb_timthumb,
                            'thumb_timthumb_q' => $thumb_timthumb_q,
                            'scan_images' => $scan_images,
                            'class' => "tptn_thumb",
                            'filter' => "tptn_postimage",
                        ) );
                        $output .= '</a>'; // Close the link
                    }
                    if ( 'inline' == $post_thumb_op || 'text_only' == $post_thumb_op ) {
                        $output .= '<span class="tptn_after_thumb">';
                        $output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
                        $output .= '<span class="tptn_title">' . $title . '</span>'; // Add title when required by settings
                        // $output .= '<li>' .wpautop(wp_trim_words($result["post_content"], 15)). '</li>';
                        $output .= '</a>'; // Close the link
                    }
                    if ( $show_author ) {
                        $author_info = get_userdata( $result->post_author );
                        $author_name = ucwords( trim( stripslashes( $author_info->display_name ) ) );
                        $author_link = get_author_posts_url( $author_info->ID );
    
                        $output .= '<span class="tptn_author"> ' . __( ' by ', TPTN_LOCAL_NAME ).'<a href="' . $author_link . '">' . $author_name . '</a></span> ';
                    }
                    if ( $show_date ) {
                        $output .= '<span class="tptn_date"> ' . mysql2date( get_option( 'date_format', 'd/m/y' ), $result->post_date ).'</span> ';
                    }
                    if ( $show_excerpt ) {
                        $output .= '<span class="tptn_excerpt"> ' . tptn_excerpt( $result->ID, $excerpt_length ).'</span>';
                    }
                    if ( $disp_list_count ) $output .= ' <span class="tptn_list_count">(' . number_format_i18n( $sumcount ) . ')</span>';
    
                    if ( 'inline' == $post_thumb_op || 'text_only' == $post_thumb_op ) {
                        $output .= '</span>';
                    }
    
                    $output .= apply_filters( 'tptn_after_list_item', $after_list_item, $result->ID );
                    $counter++;
                }
                if ( $counter == $limit/5 ) break;  // End loop when related posts limit is reached
            }
            if ( $show_credit ) {
                $output .= apply_filters( 'tptn_before_list_item', $before_list_item, $result->ID );
                $output .= sprintf( 'Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/" rel="nofollow">Top 10 plugin</a>', TPTN_LOCAL_NAME );
                $output .= apply_filters( 'tptn_after_list_item', $after_list_item, $result->ID );
            }
            $output .= apply_filters( 'tptn_after_list', $after_list );
        } else {
            $output .= ( $blank_output ) ? '' : $blank_output_text;
        }
        $output .= '</div>';
    
        return apply_filters( 'tptn_pop_posts', $output );
    }
    
    to show content in popular post by adding the following line below the code.
    $output .= '<li><p>' .wp_trim_words(get_post($result->ID)->post_content,15). '</p></li>';
    
    top10.php (top10 popular post plugin)
    code:
    if ( 'inline' == $post_thumb_op || 'text_only' == $post_thumb_op ) {
                        $output .= '<span class="tptn_after_thumb">';
                        $output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
                        $output .= '<span class="tptn_title">' . $title . '</span>'; // Add title when required by settings
                        $output .= '</a>'; // Close the link
                        $output .= '<li><p>' .wp_trim_words(get_post($result->ID)->post_content,15). '</p></li>';
                    }