Wordpress:显示所有页面


Wordpress: Display all pages

我想在短代码中显示Wordpress中的所有页面。我的代码如下:

function createTilesFromSites() {
$args = array(
    'sort_order' => 'ASC',
    'sort_column' => 'post_title',
    'hierarchical' => 1,
    'exclude' => '',
    'include' => '',
    'meta_key' => '',
    'meta_value' => '',
    'authors' => '',
    'child_of' => 0,
    'parent' => -1,
    'exclude_tree' => '',
    'number' => '',
    'offset' => 0,
    'post_type' => 'page',
    'post_status' => 'publish'
); 
$pages = get_pages($args);
foreach ($pages as $page_data) {
    $content = apply_filters('the_content', $page_data->post_content);
    $title = $page_data->post_title;
    $slug = $page_data->post_name;
    echo "$title <br />";
}
}
add_shortcode('createTiles', 'createTilesFromSites');

现在,它向我显示页面(我的页面被称为"1"、"2"、"3"、"4"answers"博客")。所以它应该给我一些类似的东西:"1234博客"。它给我打印了这个,但不止一次它做了2658次(至少chrome用cmd+f表示,无论如何,它是超长的)。所以我的输出看起来是这样的:"1234Blog1234Blog234Blog1234 Blog1234"例如

代码有问题吗?这可能是Wordpress安装程序的问题吗?

谢谢你的帮助。

我认为您的apply_filters代码将再次调用您的短代码,因此它将处于循环中。因此,你可以尝试在不应用过滤器的情况下获取内容,或者从内容中去掉短代码,或者调用remove_shortcode("createTiles");