我创建了自定义帖子类型名称“agencies”,以及一个名为“single-agencies.php”的文件。
出于某种原因,the_content()
不起作用,而the_title()
确实有效。
以下是代码:
<?php get_header( 'agency' ); ?>
<div class="popup-container">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
the_title("<div class='entry-title'><h2>", "</h2></div>");
the_content();
var_dump(get_the_content()); // this outputs "String(0)"
?>
<div id="carousel" class="flexslider">
<ul class="slides">
<?php
if( have_rows('agencies_repeater') ):
while( have_rows('agencies_repeater') ): the_row();
$img_url = get_sub_field('agencies_add_img');
echo "<li><img src= '" . $img_url['url'] . "'/></li>";
endwhile;
else :
echo "no rows found";
endif;
?>
</ul>
</div><!--.flexslider-->
<div id="slider" class="flexslider">
<ul class="slides">
<?php
if( have_rows('agencies_repeater') ):
while( have_rows('agencies_repeater') ): the_row();
$img_url = get_sub_field('agencies_add_img');
echo "<li><img src= '" . $img_url['url'] . "'/></li>";
endwhile;
else :
echo "no rows found";
endif;
?>
</ul>
</div><!--.flexslider-->
</article>
</div><!--.popup-container-->
这里发生了什么?
答案 0 :(得分:0)
检查the_id()是否给出了帖子ID,如果是,那么我们可以通过帖子ID获取内容,如下所示
<?php
$post_id=get_the_id(); // or $post_id='9' where 9 is the post id custom
$welcome=get_post(9);
$welcomcontent=$welcome->post_content;
$welcomtitle=$welcome->post_title;
$welcomcontent=$welcome->post_content;
$welcomcontent=apply_filters('the_content',$welcomcontent);
$welcomcontent=str_replace(']]>',']]>', $welcomcontent);
?>
<?php echo get_the_post_thumbnail($post_id);?>//thumbnial on post
<h2><?php echo $welcomtitle;?></h2>//post title
<span><?php echo $welcomcontent;?></span>//post_content