我正在一个单页网站上工作,我在该单页上显示来自其他页面的内容。为此,我添加了一个允许我使用<?php echo getPageContent(ID); ?>
它的功能,它工作正常,除非我需要显示短代码中的内容,它只是将代码作为文本吐回。有解决办法的想法吗?
问问题
1567 次
2 回答
4
要获得正确的格式并替换短the_content
代码,您需要应用挂钩到标签的过滤器,如下所示:
echo apply_filters('the_content', getPageContent(ID));
于 2011-05-26T21:13:42.327 回答
0
您选择这种策略来显示内容是否有原因?使用更符合正常 wordpress 页面开发和模板系统的东西可能会解决您的问题。我建议使用 get_posts() 和 setup_postdata() 的组合
来自 WordPress 的文档:
<?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;
?>
于 2011-05-26T20:55:49.910 回答