0

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?

0

If you want posts, try using get_posts, https://developer.wordpress.org/reference/functions/get_posts/

| improve this answer | |
0

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>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.