admin管理员组文章数量:1433154
Actually, I try to make a carousel and I want to get the featured image of all the page which comes under category ID 4. There are problems the below code fetches all the pages added and not displaying the title of the page. Can anyone of you tell me what is wrong in the code
<?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++;
}
?>
Actually, I try to make a carousel and I want to get the featured image of all the page which comes under category ID 4. There are problems the below code fetches all the pages added and not displaying the title of the page. Can anyone of you tell me what is wrong in the code
<?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++;
}
?>
Share
Improve this question
edited May 28, 2019 at 10:50
fuxia♦
107k39 gold badges255 silver badges459 bronze badges
asked May 23, 2019 at 19:12
Harjinder BangaHarjinder Banga
214 bronze badges
1 Answer
Reset to default 0Use 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();
?>
本文标签: Displaying all pages which comes under a category id
版权声明:本文标题:Displaying all pages which comes under a category id 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745457432a2659168.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论