首页 > 解决方案 > 在 wordpress 的主页上添加简码时更新失败

问题描述

我正在主页上显示最近的帖子,但出现错误。我无法在主页上保存简码。

我试图hello在主页上显示文本并且正在显示,但是在添加以下代码后它不起作用。

你能帮帮我吗?

在此处输入图像描述

function recentPost_on_home(){
$data='<div class="row">';
            $args = array(
                'posts_per_page' => 5, // your 'x' goes here
                'nopaging' => true
                // possibly more arguments here
            );
            // set up new query
            $tyler_query = new WP_Query( $args );
            // loop through found posts
            if ($tyler_query->have_posts()) {
                while ( $tyler_query->have_posts() ) {
                    $tyler_query->the_post();
                  $data.= '<div class="swiper-slide">
                        <div class="cs-post-item">
                            <div class="cs-post-category-icon">
                                <a href="'.the_permalink().'"></a>
                            </div>
                            <div class="cs-post-thumb">
                                <a href="'.the_permalink().'"><img src="'.the_post_thumbnail_url().'" alt="'.the_title().'"></a>
                            </div>
                            <div class="cs-post-inner">
                                <h3><a href="'.the_permalink().'">'.the_title().'</a></h3>
                            </div>
                        </div>';
                }
            } 
    $data.='</div>';

            return $data;    
}
add_shortcode( 'home_recent_post', 'recentPost_on_home' );

标签: phphtmlwordpressshortcode

解决方案


推荐阅读