0

I am trying to get the first paragraph on a page where page ID=2 and blog ID=1. I want to display this paragraph on a page in blog id=2. I have added the following code to the template page.

//gets active blog
global $blog_id;
switch_to_blog(1);
$pageid = 2; //author page
$post = get_post( $pageid ); 
$excerpt = get_the_excerpt( $pageid );
//$content = apply_filters('the_content', $post->post_content);  //filters just the post content
echo "<div id='about-alandracl'>";
echo $excerpt;
//echo $content;
echo "</div>";
restore_current_blog();

I have the following in the functions.php file of each theme:

function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 206 );

This is the page where I am grabbing the content from: http://alandracl.com/author/ This is the page I want to display the first paragraph (without the image) on: http://alandracl.com/the-sussex-deal/ (under the about section on this page).

Thank you for your help in advance.

0

you already called get_post() then why you are not getting the excerpt from post data, like this.

$post = get_post( $pageid ); 
$excerpt = $post->post_excerpt;

// get post content
$content = $post->post_content;

for more information about get_post() see the WordPress codex

0

I used substr in php to limit the characters. Here is the code that solved my problem:

//gets active blog
global $blog_id;
switch_to_blog(1);

$pageid = 2;
$post = get_post( $pageid ); 
$content = $post->post_content;
echo "<div id=''>";
echo substr( $content, 0, 380);
echo "</div>";
restore_current_blog();

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.