【问题标题】:Wordpress pulling in content from sub pagesWordpress 从子页面中提取内容
【发布时间】:2014-03-11 10:43:11
【问题描述】:

我正在使用高级自定义字段并尝试将内容从子页面拉到主页上

我似乎无法让下面的工作,有人知道为什么它不工作吗?

页面设置如下:

-父页面(页面id = 4)

--子页面

--子页面

<ul>
    <?php
    $children = get_children( array( 'post_parent' => get_the_ID(4) ) );
    if ( $children ) {
        foreach( $children as $child ) { ?>
            <li>
                <?php echo get_the_title($child->ID); ?>
                <?php the_field( 'content', $child->ID ); ?>
            </li>
    <?php } } ?>
</ul>

【问题讨论】:

    标签: wordpress advanced-custom-fields


    【解决方案1】:

    “get_the_ID()”函数使用不正确,可以省略。你的代码变成:

    $children = get_children( array( 'post_parent' => 4 ) );
    

    您可能还想指定 post_type 参数。现在您的函数也将返回附件。

    $children = get_children( array( 'post_parent' => 4, 'post_type' => 'page' ) );
    

    【讨论】:

    • 啊完美!非常感谢
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      • 2018-03-22
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      相关资源
      最近更新 更多