WordPress.org

Ready to get started?Download WordPress

Forums

Front page with page content and articles (2 posts)

  1. schwipps
    Member
    Posted 1 year ago #

    Hi there,
    I'm trying to build a front page for a corporate website, on which I want to put a introduction text, plus last 3 articles published.

    So, I created a front page specific page model, based on single.php, and where I inserted the following code :

    <ul>
                <?php
                    $args = array( 'numberposts' => '1', 'post_status'=> 'publish' );
                    $recent_posts = wp_get_recent_posts( $args );
                        foreach( $recent_posts as $recent ){
                                echo
                               '
                               <h2>
                                    <a href="'.get_permalink($recent["ID"]).'"
                                       title="'.esc_attr($recent["post_title"]).'"
                                    >'.$recent["post_title"].'
                                    </a>
                               </h2>
                               '
                               .get_the_excerpt($recent["ID"]);
                        }
                ?>
            </ul>

    Now the point is that this function returns the content of the page article in place of the first post.

    How can I prevent this ? Is there a solution to filter pages from posts ?

    Thanks.

  2. schwipps
    Member
    Posted 1 year ago #

    This is very weird... I figured that the shown title is the right one, but the excerpt is not : it's always the content of the page.

    Can somebody explain me what goes wrong here ?

Topic Closed

This topic has been closed to new replies.

About this Topic