posts - Get content from one page and show it on another page

So, I've been googling and reading and testing and failing. I'm fairly new to php, so don't expect to muc

So, I've been googling and reading and testing and failing.

I'm fairly new to php, so don't expect to much :)

I'm working on a new design, and I want to show content from the about page on my homepage, which is dynamic. So, I've been looking into that the_content thing, but I havent gotten any luck so far.

<?php
   $id=about;
   $post = get_page($id=);
   $content = apply_filters('the_content', $post->post_content);
   echo $content;
?>

the ID of the page is "about", if that is any help.

Please get back to me :)

So, I've been googling and reading and testing and failing.

I'm fairly new to php, so don't expect to much :)

I'm working on a new design, and I want to show content from the about page on my homepage, which is dynamic. So, I've been looking into that the_content thing, but I havent gotten any luck so far.

<?php
   $id=about;
   $post = get_page($id=);
   $content = apply_filters('the_content', $post->post_content);
   echo $content;
?>

the ID of the page is "about", if that is any help.

Please get back to me :)

Share Improve this question edited Nov 10, 2011 at 6:58 Sterling Hamilton 8894 silver badges10 bronze badges asked Nov 10, 2011 at 1:28 StianStian 1131 gold badge1 silver badge4 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 11

First off: The ID of a post or page is always an integer. "about" is either your about page's title, slug or both.

Including the following in your "homepage's" page template or in the sidebar combined with conditional tag(s) will display the about page's content:

<?php
    // query for the about page
    $your_query = new WP_Query( 'pagename=about' );
    // "loop" through query (even though it's just one page) 
    while ( $your_query->have_posts() ) : $your_query->the_post();
        the_content();
    endwhile;
    // reset post data (important!)
    wp_reset_postdata();
?>

Edit: The above works, IFF your page's slug is indeed "about", otherwise adjust accordingly.

I wanted something similar but with page Title, this is how I achieved it:

$args = array(
    'post_type' => 'page',
    'title' => 'The title of the page you want'
);

$your_query = new WP_Query( $args );
while ( $your_query->have_posts() ) : $your_query->the_post();
    the_content();
endwhile;

The codex is your friend!

http://codex.wordpress/Function_Reference/get_post

<?php
    $post_id = 7;
    $post = get_post($post_id, ARRAY_A);
    $title = $post['post_title'];
    $content = $post['post_content'];
?>

(ARRAY_A - Returns an associative array of field names to values)

It's a start.

Best way to get the current page content

global $post;
echo $post->post_content;

or

global $wp_query;
echo $wp_query->post->post_content;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745221922a4617286.html

相关推荐

  • posts - Get content from one page and show it on another page

    So, I've been googling and reading and testing and failing. I'm fairly new to php, so don't expect to muc

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信