正确的方式来获得页面内容
我一定要得到特定页面的内容(如第(12))正确的方式来获得页面内容
我用的是:
<?php $id=47; $post = get_page($id); echo $post->post_content; ?>
工作不错execpt与qtranslate兼容性使其返回法语和英语文字
但循环是好的,只返回了良好的语言版本
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div id="post">
<?php the_content(); ?>
</div> <!-- .post -->
所以的问题....如何获得一个特定的页面内容insite循环...
我已经回答了我自己的问题。致电apply_filter
,你去了。
<?php
$id=47;
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>
获取页面内容的页面名称:
<?php
$page = get_page_by_title('page-name');
$content = apply_filters('the_content', $page->post_content);
echo $content;
?>
也''get_page_by_path'可能会有用。 – Guss 2016-03-27 18:08:36
一个简单,快捷的方式获得通过ID内容:
echo get_post_field('post_content', $id);
如果你想获得格式化的内容:
echo apply_filters('the_content', get_post_field('post_content', $id));
与页面,post s &自定义帖子。
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('prev_text' >' Previous','post_type' => 'page', 'posts_per_page' => 5, 'paged' => $paged);
$wp_query = new WP_Query($args);
while (have_posts()) : the_post();
//get all pages
the_ID();
the_title();
//if you want specific page of content then write
if(get_the_ID=='11')//make sure to use get_the_ID instead the_ID
{
echo get_the_ID();
the_title();
the_content();
}
endwhile;
//如果你想要的特定内容页,然后在循环
if(get_the_ID=='11')//make sure to use get_the_ID instead the_ID
{
echo get_the_ID();
the_title();
the_content();
}
这不回答这个问题; 'get_the_ID'获取当前帖子的ID - 问题是在循环内寻找一个* specific *页面。 – vicvicvic 2015-02-23 11:03:48
如果你可以请编辑你的答案,并解释你所展示的代码是做什么的,为什么/如何代码回答这个问题,它可以真正帮助。 自己的代码块通常不是有用的答案。 – 2015-02-24 06:54:47
我用这个写:
<?php echo get_post_field('post_content', $post->ID); ?>
,这更简洁:
<?= get_post_field('post_content', $post->ID) ?>
wp_trim_words函数也可以限制字符通过改变$ num_words变量。对于任何可能有用的人。
<?php
$id=58;
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content);
$customExcerpt = wp_trim_words($content, $num_words = 26, $more = '');
echo $customExcerpt;
?>
只需复制并粘贴此代码即可获取您的网页内容。
<?php
$pageid = get_the_id();
$content_post = get_post($pageid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
?>
一个内胆:
<? if (have_posts()):while(have_posts()): the_post(); the_content(); endwhile; endif; ?>
快速和优雅。 – Mina 2012-04-23 22:33:42
get_page已被弃用:http://codex.wordpress.org/Function_Reference/get_page。改用get_post。 – manishie 2013-10-08 16:24:40
+1谢谢!当在循环中使用wp_mail时,这很方便。 'get_the_content();'没有把格式。这给了我很大的时间! – Davis 2014-03-26 17:07:20