bellow is my code working nice but problem is don’t coming with html tag.. like etc… no idea why…
<?php $recent = new WP_Query("page_id=2"); while($recent->have_posts()) : $recent->the_post();?>
<?php
echo substr(get_the_excerpt(), 0,450);
?>
<a href="<?php the_permalink() ?>" rel="bookmark">
More About Us
</a>
bellow is another code which is html tag and everything ok.. but i can’t figure out how to permalink do there.. the permalink i put there i not work.
<?php
$my_id = 2;
$page_id = get_post($my_id);
$content = $page_id->post_content;
echo substr($content, 0, 450);
?>
<a href="<?php the_permalink() ?>" >More About Us</a>
also what is best way to get specific page content like bellow way
<h2>title</h2>
<div>featured image </div>
<div>content</div>
<a href="<?php the_permalink() ?>" rel="bookmark">
Rather than call
WP_Query()
you can useget_post()
and “set up” theglobal $post
. This is probably a little more efficient than @tf’s answer, though the ideas are broadly the same.Please note, in both cases you should reset the post data afterwards.
Source: http://stephenharris.info/get-post-content-by-id/
(get_)the_excerpt()
strips HTML tags – that’s why you don’t have HTML tags. 😉Just use
the_content()
instead ofthe_excerpt()
if you want to show the full content.As for the best way of outputting post data, you should have a look at this.