PHP script to include page and post using WordPress excerpt
In the PHP we are using the following function to include the page.
1 2 3 4 |
include('filename'); include_once('filename'); require('filename'); require_once('filename'); |
WordPress is a CMS and many developers has no ideas how to include one page or post into other page using code. In generally we are using readymade plugins and its shortcode to include the pages and post. But sometimes included page will not show the updated content . So, Today I will explain to you how to include page and post into an
So, Today I will explain to you how to include page and post into the other page using WordPress excerpt.Use the following code to do the same.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function intro_text($length){ $postid = 1;//This is page id or post id $content_post = get_post($postid); $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $length= 150; if (strlen($content) > $length){ $content = substr($content,0,strpos($content,' ',$length)) . ' ... <a href=""' . get_permalink(2) . '"">Read more.</a>'; } return apply_filters('the_excerpt',$content); } echo intro_text($length); |
In the above code replace the $post id with the current page or post id. and $length will be dependent on you choice.
You just need to put above function in the function.php file or anywhere and you need to use following code where you want to show included content.
1 |
echo intro_text($length) |
Make sure that you are using this function and code into PHP files and not in the WordPress default editor.
I hope this will help you a lot while developing the site. Let me know if you any queries related to this.
Yes it’s working on my site.
really thank you.
keep it.
That’s great