Wordpress使用AJAX加载更多帖子

时间:2016-01-07 21:05:24

标签: javascript php jquery ajax wordpress

目前,当用户滚动到特定的ajax时,我正在尝试加载更多帖子。我正在调用admin-ajax.php,其中有一个位于我的主题fumctions.php中的动作,它看起来像这样:

function loadMore()
{
    $params = array(
        'posts_per_page' => 1,
        'post_type' => 'post'
    );

    // The Query
    $the_query = new WP_Query( $params );

    // The Loop
    if ( $the_query->have_posts() ) {
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
            $the_permalink = the_permalink();

           $output = "<a class='article fade' href='$the_permalink'></a>";

            echo $output;

        }
    }

    wp_reset_postdata();

    die('');

}

所以一切正常,我从ajax调用得到一个响应,而我正在尝试追加数据,唯一的问题是出于某种原因,href搞砸了输出看起来像:

<a class="article fade" href=""></a>
/url/that/should/be/inside/the/href

任何人都知道我做错了什么?

提前致谢!

1 个答案:

答案 0 :(得分:0)

已经知道了!

应该使用

get_the_permalink()

因为这个函数实际上返回了一些东西,

the_permalink()

只有echo的

相关问题