I want to show page items in my wordpress theme and this is the code:
<section id="two">
<div class="inner">
<?php
$pagesargs = array(
'posts_per_page'=> 2,
'offset'=> 0,
'category' => '',
'category_name' => '',
'orderby' => 'post_date' ,
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'page',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true,
);
$my_pages = get_pages($pagesargs);
foreach ($my_pages as $page){
?>
<article>
<div class="content">
<header>
<h3><?php the_title() ?></h3>
</header>
<div class="image fit">
<img src="<?php bloginfo('template_url')?>/style/images/pic01.jpg" alt="" />
</div>
<p><?php the_excerpt(); ?></p>
</div>
</article>
<?php } ?>
</div>
</section>
but in index just show posts!!how can I change it and show posts?
I want to show page items in my wordpress theme and this is the code:
<section id="two">
<div class="inner">
<?php
$pagesargs = array(
'posts_per_page'=> 2,
'offset'=> 0,
'category' => '',
'category_name' => '',
'orderby' => 'post_date' ,
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'page',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true,
);
$my_pages = get_pages($pagesargs);
foreach ($my_pages as $page){
?>
<article>
<div class="content">
<header>
<h3><?php the_title() ?></h3>
</header>
<div class="image fit">
<img src="<?php bloginfo('template_url')?>/style/images/pic01.jpg" alt="" />
</div>
<p><?php the_excerpt(); ?></p>
</div>
</article>
<?php } ?>
</div>
</section>
but in index just show posts!!how can I change it and show posts?
Share Improve this question asked Jun 16, 2020 at 7:48 hadishadis 212 bronze badges2 Answers
Reset to default 0If you want posts, try using get_posts
, https://developer.wordpress/reference/functions/get_posts/
You can check if the page is the Front or Home page Depending on the site’s "Front page displays" Reading Settings show_on_front
and page_on_front
.
There, you will be able to display Posts on your index and Pages on other places:
<section id="two">
<div class="inner">
<?php
if ( is_home() || is_front_page() ) {
$post_type="post";
}
else {
$post_type="page";
}
$pagesargs = array(
'posts_per_page'=> 2,
'offset'=> 0,
'category' => '',
'category_name' => '',
'orderby' => 'post_date' ,
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => $post_type,
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true,
);
if ( is_home() || is_front_page() ) {
$my_pages = get_posts($pagesargs);
}
else {
$my_pages = get_pages($pagesargs);
}
foreach ($my_pages as $page){
?>
<article>
<div class="content">
<header>
<h3><?php the_title() ?></h3>
</header>
<div class="image fit">
<img src="<?php bloginfo('template_url')?>/style/images/pic01.jpg" alt="" />
</div>
<p><?php the_excerpt(); ?></p>
</div>
</article>
<?php } ?>
</div>
</section>