首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress子页面包含特色图像

问Wordpress子页面包含特色图像
EN

Stack Overflow用户
提问于 2018-12-17 17:59:11
回答 1查看 29关注 0票数 0

这是我的代码,它显示了子页面的所有标题,但我还想要子页面的所有精美图像。我不知道如何做到这一点。我有包含page.php和我的function.php脚本。我知道很多人都问过这样的问题,但我似乎想不通。

Page.php

代码语言:javascript
复制
 <?php 

    get_header();

    if(have_posts()) :
        while (have_posts()) : the_post(); ?>


    <article class="post page">

        <?php 

        if ( has_children() OR $post->post_parent > 0 ) { ?>

        <nav class="site-nav children-links clearfix">

    <span class="parent-link"><a href="<?php echo get_the_permalink(get_top_anestor_id); ?>"><?php echo get_the_title(get_top_ancestor_id()); ?> </a> </span>
        <ul>
            <?php

            $args = array( 
                'child_of' => get_top_ancestor_id(),
                'title_li' => ''
                );

            ?>
            <?php wp_list_pages($args); ?>

        </ul>
    </nav>
    <?php } ?>

    </article>  
        <?php endwhile;

        else :
        echo '<p> No content found</p>';

        endif;

    get_footer();

    ?>

Function.php

代码语言:javascript
复制
function get_top_ancestor_id() {

    global $post;

    if ($post->post_parent) {
        $ancestors = array_reverse(get_post_ancestors($post->ID));
        return $ancestors[0];
    }

    return $post->ID;

}

// Does page have children?

function has_children() {

        global $post;

        $pages = get_pages('child_of=' . $post->ID);
        return count($pages);

}
EN

回答 1

Stack Overflow用户

发布于 2018-12-18 19:55:57

所以我终于找到了同样步履蹒跚的人的答案:

代码语言:javascript
复制
<?php 
        $args = array( 
            'child_of' => get_top_ancestor_id(),
            'title_li' => ''
            );

        ?>
           <?php $our_pages = get_pages($args); ?>
           <?php if (!empty($our_pages)): ?>
            <?php foreach ($our_pages as $key => $page_item): ?>
                <div class="col-*-* product-object">
                <a class="product-article" href="<?php echo esc_url(get_permalink($page_item->ID)); ?>">
                <div class="product-image" style="background: url(<?php echo get_the_post_thumbnail_url($page_item->ID,'product-image');?>); ">
                <h2 class="product-h2"><?php echo $page_item->post_title ; ?></h2>  
                </div>
                </a>
                </div>
            <?php endforeach ?>
           <?php endif ?>
</article>  
</div>
<?php 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53812795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档