Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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,循环遍历每个子页面_Php_Wordpress - Fatal编程技术网

php,循环遍历每个子页面

php,循环遍历每个子页面,php,wordpress,Php,Wordpress,我是php的新手,所以如果这是一个愚蠢的问题,请原谅我 我想要的是:获取当前页面id(即父页面),找到该特定父页面的所有子页面 并为每个子页面输出永久链接和标题 下面的代码可以工作,除了它是针对一个类别,而不是父页面(我必须手动添加类别页面id) 如果有人能帮我,我将不胜感激(我不太懂php,但我确实需要解决这个问题) 编辑: 这就是我得到的(thnx用于wordpress评论)(这很有效) 例如,排除第8020页和第9021页的最佳方式是什么 <?php $args = arr

我是php的新手,所以如果这是一个愚蠢的问题,请原谅我

我想要的是:获取当前页面id(即父页面),找到该特定父页面的所有子页面 并为每个子页面输出永久链接和标题

下面的代码可以工作,除了它是针对一个类别,而不是父页面(我必须手动添加类别页面id)


  • 如果有人能帮我,我将不胜感激(我不太懂php,但我确实需要解决这个问题)

    编辑: 这就是我得到的(thnx用于wordpress评论)(这很有效)

    例如,排除第8020页和第9021页的最佳方式是什么

    <?php
    
    $args = array(
        'post_type'      => 'page',
        'posts_per_page' => -1,
        'post_parent'    => $post->ID,
        'order'          => 'ASC',
        'orderby'        => 'menu_order'
     );
    
    
    $parent = new WP_Query( $args );
    
    if ( $parent->have_posts() ) : ?>
    
        <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
    
    
    
    
    
    <?php the_permalink(); ?> <?php the_title(); ?>
    
    
    
        <?php endwhile; ?>
    
    <?php endif; wp_reset_postdata(); ?>
    
    
    
    父id在哪里,这意味着它在URL部分或您从其他地方获取?这看起来像WordPress,所以您应该尽可能使用WP功能。检查,或者寻找最初的灵感。可能重复:@evisempire这是Wordpress和@javanewby使用Wordpress时,请记住Wordpress几乎为所有内容提供了实用功能。如果没有核心功能可以帮助您解决问题。
    <?php
    
    $args = array(
        'post_type'      => 'page',
        'posts_per_page' => -1,
        'post_parent'    => $post->ID,
        'order'          => 'ASC',
        'orderby'        => 'menu_order'
     );
    
    
    $parent = new WP_Query( $args );
    
    if ( $parent->have_posts() ) : ?>
    
        <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
    
    
    
    
    
    <?php the_permalink(); ?> <?php the_title(); ?>
    
    
    
        <?php endwhile; ?>
    
    <?php endif; wp_reset_postdata(); ?>