How to get title and content on another page?

Asked

Viewed 1,030 times

1

I wonder if it is possible to take the title and content of a page created on another page.

For example; I created a page called Home and also created a template for that page, and did the same for the one page called quem somos.

On the page home i would like to show a brief description of the content of the page quem somos.

That’s possible?

  • I don’t know if I got it right but you want to display a preview of a page’s content ? You will have to do it by hand, because there is no way you can display a 'preview' of your page. But search on the use of 'Iframes', with them you can display a page inside it.

1 answer

1


You can, in the page template "home", create a loop specific searching page information "who we are". Something like that

$query = new WP_Query(array( 'pagename' => 'quem-somos' ));

if($query->have_posts()){
    while($query->have_posts()){
        $query->the_post();

        $titulo = the_title();
        $conteudo = the_content();

        # code....
    }
}

wp_reset_postdata(); // restaurando a global $post

should meet your need. Some points that deserve attention:

  1. A page, in WP, is also a type of post. Therefore, the loop works. As there is only one page with the name "who we are", there will only be one return.
  2. The parameter of the Wp_query (you can see all the various parameters here) is a array associative, and the key "pagename" must comply with Slug page. See, the Slug, not the name. You can read more about slugs here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.