Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 如何获取特定页面内容?_Wordpress - Fatal编程技术网

Wordpress 如何获取特定页面内容?

Wordpress 如何获取特定页面内容?,wordpress,Wordpress,下面的代码工作得很好,但是没有HTML标记,比如,,,等等 <?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="bookmar

下面的代码工作得很好,但是没有HTML标记,比如
,等等

<?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>

这是另一个输出HTML标记和一切正常的代码,但我不知道如何在那里做永久链接。我放在那里的永久链接不起作用

<?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>

另外,获取特定页面内容的最佳方式是什么,如下面的示例中所示

<h2>title</h2>
<div>featured image </div>
<div>content</div>
<a href="<?php the_permalink() ?>" rel="bookmark">
标题
特色形象
内容
使用

根据你的其他要求

标题

$title = $page_id->post_title;
缩略图()

内容

$content = $page_id->post_content;
我刚找到解决办法

 <?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>
    <?php endwhile; ?>

我使用了
substr(获取内容)而不是获取摘录
现在工作正常

$content = $page_id->post_content;
 <?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>
    <?php endwhile; ?>