开发者

Using WordPress shortcodes when <?php echo getPageContent(); ?> is used to display content

I am working on a single page site where I am displaying content from other pages on this single page. To do this I added a function that开发者_C百科 allows me to use <?php echo getPageContent(ID); ?> this is working fine except when I need to display content from a shortcode it just spits back the code as text instead. Any idea of a work around?


To get the correct formatting and to have shortcodes replaced you need to apply the filters hooked into the the_content tag, something like this:

echo apply_filters('the_content', getPageContent(ID));


Is there a reason that you've chosen this strategy to display the content? Using something more in line with the normal wordpress page development and templating system will likely fix your problem. I recommend using a combination of get_posts() and setup_postdata()

From WordPress' docs:

<?php
global $post;
$tmp_post = $post;
$args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
<?php $post = $tmp_post;
?>

See: http://codex.wordpress.org/Template_Tags/get_posts

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜