wordpress如何调用指定文章或者页面的内容

wordpress如何调用指定文章或者页面的内容,代码如下:

<?php
$my_postid = 542;//This is page id or post id
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
echo $content;
?>

 

其中544为调用文章或者页面的ID

带调用焦点图版本:

<?php
                        $args = array(
                            'include' => '8',//调用指定id,可以多id
                            'post_type' => 'page',
                            'post_status' => 'publish'
                        );
                        $pages = get_pages($args);
                        foreach ( $pages as $post ) : setup_postdata( $post ); ?>
                        
                             <div class="text_machenike col-6">
                       <?php 
					   $the_content = apply_filters('the_content', get_the_content());
                       if ( !empty($the_content) ) {echo $the_content;}
					   ?>
                       <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                       </div>
                        
                       <div class="col-6">
                       <?php if ( has_post_thumbnail() ) { the_post_thumbnail();} else {}?>
                       </div>
                  
                        <?php endforeach;
                        wp_reset_postdata();
                        ?>

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注