WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Displaying first paragraph of a page on another page? (7 posts)

  1. emileey
    Member
    Posted 1 year ago #

    I'm trying to display the first paragraph from one of my Pages on another Page. So for example, I have a page that has three paragraphs containing my biography and I want to put ONLY the first paragraph of that page on my static homepage.

    I got the page to display on the homepage using this:

    <?php
    $include = get_pages('include=205');
    $content = apply_filters('the_content',$include[0]->post_content);
    echo $content;
    ?>

    But I don't know how to make it display only the first paragraph because that code displays everything that is on the page. Help!

  2. Jay
    Member
    Posted 1 year ago #

    You can use str_replace

  3. emileey
    Member
    Posted 1 year ago #

    Hi Jay, sorry I'm kind of a newbie when it comes to PHP. How do I implement str_replace to display only the first paragraph? Thank you!

  4. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

    I don't think that's what you want, emileey. This might be relevant:

    http://codex.wordpress.org/Customizing_the_Read_More

  5. emileey
    Member
    Posted 1 year ago #

    Thanks WPyogi :-), I will take a look and hopefully figure this out!

  6. Jay
    Member
    Posted 1 year ago #

    <?php
       $search = get_pages('include=205');
       $find = apply_filters('the_content',$search[0]->post_content);
       $replace = "Put your paragraph in your want to display";
       echo str_replace($find,'', $replace);
    ?>

    Im sure there is a better method and even a proper method, but this will work. Although it is basically the same as just pasting in the paragraph. You could also save the paragraph you are wanting to display as the excerpt or another value and echo it that way.

  7. emileey
    Member
    Posted 1 year ago #

    Thanks, guys! I got it working by enabling excerpts for pages, then using the_excerpt instead of the_content. Works perfectly for what I need.

Topic Closed

This topic has been closed to new replies.

About this Topic