Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.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
在WordPress中通过PHP显示同级页面_Php_Wordpress - Fatal编程技术网

在WordPress中通过PHP显示同级页面

在WordPress中通过PHP显示同级页面,php,wordpress,Php,Wordpress,我不懂PHP,所以这个问题已经解决了 但我想要的是: 对于与当前页面具有相同父级的每个页面(因此同级页面)显示: 但只循环12次 如果有人能帮我,我会非常感激。获取父ID,然后使用该ID获取子帖子。将它们限制为12篇帖子,排除当前ID。然后迭代结果 <?php $parentId = wp_get_post_parent_id( get_the_ID() ); $children = get_posts( [ 'posts_per_page' => 12, 'p

我不懂PHP,所以这个问题已经解决了

但我想要的是:

对于与当前页面具有相同父级的每个页面(因此同级页面)显示:


但只循环12次


如果有人能帮我,我会非常感激。

获取父ID,然后使用该ID获取子帖子。将它们限制为12篇帖子,排除当前ID。然后迭代结果

<?php
$parentId = wp_get_post_parent_id( get_the_ID() );

$children = get_posts( [
    'posts_per_page' => 12,
    'post_parent'    => $parentId,
    'post__not_in'   => [ get_the_ID() ] // exclude current page
] );
?>
<ul class="section-nav">
    <?php foreach( $children as $child ): ?>
        <li class="section-nav-item">
            <a href="<?= get_the_permalink( $child->ID ); ?>">
                <?= get_the_title( $child->ID ); ?>
            </a>
        </li>
    <?php endforeach; ?>
</ul>


是WordPress吗?如果是这样,用“WordPress”标记,你可能会找到更多的帮助。你只想循环上面的函数12次?是的,是WordPress,我添加了标记@GrumpyCrouton我希望输出12次(对于12个同级页面),如果这有意义的话,那么parent1->child1就是在上面运行的,我想为parent1-child2/13显示这些输出,非常感谢。我自己也很接近解决方案,但一直被排除在当前帖子之外。所以“'post_unot_in'=>[get_the_ID()]”为我解决了这个问题:P
<?php
$parentId = wp_get_post_parent_id( get_the_ID() );

$children = get_posts( [
    'posts_per_page' => 12,
    'post_parent'    => $parentId,
    'post__not_in'   => [ get_the_ID() ] // exclude current page
] );
?>
<ul class="section-nav">
    <?php foreach( $children as $child ): ?>
        <li class="section-nav-item">
            <a href="<?= get_the_permalink( $child->ID ); ?>">
                <?= get_the_title( $child->ID ); ?>
            </a>
        </li>
    <?php endforeach; ?>
</ul>