显示类别ID下的所有页面

时间:2019-05-23 作者:Harjinder Banga

实际上,我试着制作一个旋转木马,我想得到分类ID为4的所有页面的特征图像。下面的代码获取所有添加的页面,但不显示页面的标题。你们谁能告诉我代码里出了什么问题吗

 <?php
            $args = array(\'posts_per_page\' => -1,
                \'offset\' => 1,
                \'category\' => 4,
                \'numberposts\' => -1
            );
            $pages = get_pages($args);
            $i = 1;
            foreach ($pages as $page) {
                setup_postdata($page);


                if ($i == 1) {
                    ?>

                    <div class="carousel-item active"
                         style="background-image: url(\'<?php echo get_bloginfo(\'template_url\'); ?>/img/intro-carousel/1.jpg\');">
                        <div class="carousel-container">
                            <div class="carousel-content">


                                <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($page->ID), \'optional-size\'); ?>
                                <h2><?php echo $page->post_title; ?></h2>
                                <p>
                                    <?php echo strip_tags(get_the_excerpt()); ?>
                                    <span>Convert Visitors Into Customers And Generate More Sales</span>
                                </p>
                                <a href="#about" class="btn-get-started scrollto"><img
                                            src="<?php echo $image[0]; ?>" alt="arrow"/></a>


                            </div>
                        </div>
                    </div>
                <?php } else { ?>
                    <div class="carousel-item"
                         style="background-image: url(\'<?php echo get_bloginfo(\'template_url\'); ?>/img/intro-carousel/1.jpg\');">
                        <div class="carousel-container">
                            <div class="carousel-content">


                                <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($page->ID), \'optional-size\'); ?>
                                <h2><?php echo $page->post_title; ?></h2>
                                <p>
                                    <?php echo strip_tags(get_the_excerpt()); ?>
                                    <span>Convert Visitors Into Customers And Generate More Sales</span>
                                </p>
                                <a href="#about" class="btn-get-started scrollto"><img
                                            src="<?php echo $image[0]; ?>" alt="arrow"/></a>


                            </div>
                        </div>
                    </div>


                <?php }
                $i++;
            }
            ?>

1 个回复
最合适的回答,由SO网友:Gopala krishnan 整理而成

Use this code ,

<?php
$args = array(
    \'posts_per_page\' => -1,
    \'offset\' => 1,
    \'category\' => 4,
    \'numberposts\' => -1
);
$pages = get_pages($args);
$i = 1; 
    foreach ($pages as $page) {
        if ($i == 1) { ?>
            <div class="carousel-item active" style="background-image: url(\'<?php echo get_bloginfo(\'template_url\'); ?>/img/intro-carousel/1.jpg\');">
                <div class="carousel-container">
                    <div class="carousel-content">
                        <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($page->ID), \'optional-size\'); ?>
                        <h2><?php echo $page->post_title; ?></h2>
                        <p>
                            <?php echo strip_tags(get_the_excerpt()); ?>
                            <span>Convert Visitors Into Customers And Generate More Sales</span>
                        </p>
                            <a href="#about" class="btn-get-started scrollto">
                                <img src="<?php echo $image[0]; ?>" alt="arrow"/>
                            </a>
                    </div>
                </div>
            </div>
        <?php } else { ?>
            <div class="carousel-item" style="background-image: url(\'<?php echo get_bloginfo(\'template_url\'); ?>/img/intro-carousel/1.jpg\');">
                <div class="carousel-container">
                    <div class="carousel-content">
                        <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($page->ID), \'optional-size\'); ?>
                            <h2><?php echo $page->post_title; ?></h2>
                            <p>
                                <?php echo strip_tags(get_the_excerpt()); ?>
                                <span>Convert Visitors Into Customers And Generate More Sales</span>
                            </p>
                            <a href="#about" class="btn-get-started scrollto">
                                <img src="<?php echo $image[0]; ?>" alt="arrow"/>
                            </a>
                    </div>
                </div>
            </div>
        <?php }
        $i++;
    }
    wp_reset_query();
?>

相关推荐

404 of wp-admin pages

我有一个网站出现了问题(几个月来一直没有被修改过,所以没有做任何修改来破坏它)登录时,登录页面未设置样式,位于左上角。我可以正常登录,但当我尝试访问仪表板或任何/wp admin/。。。我得到404页。(网站加载公共内容罚款)我已经尽我所能搜索并尝试了一切。禁用所有插件,默认为menew。htaccessphpmyadmin重命名站点地址以前有没有人经历过这种情况,有没有其他想法?