将ID传递到URL时如何发布the_content

时间:2019-03-03 18:34:34

标签: php wordpress

因此,我在本地安装了wordpress,使用自己的首页和单页博客文章。我想做的是使用帖子ID转到单个博客帖子。这是我所掌握的-但是单击链接时我什么也没有。

从a href传递的网址看起来不错-blogpost.php?postid = 1我只需要它就可以使用该ID提取博客文章数据?

<?php
    global $post;
    $args = array( 'posts_per_page' => 3 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :  setup_postdata($post); ?>
    <div class="col-sm-4" style="padding-left:50px; padding-right:50px;">
    <div class="media">
        <a href="blogpost.php?postid=<?php echo $id; ?>"><?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
        <div id="custom-bg" style="background-image: url('<?php echo $image[0]; ?>'); background-size:cover;">
        <h1 style="padding:50px;"><?php the_title(); ?></h1></a>
        </div>
    </div>
    <div class="media-body" style="background-color:white; padding:20px;">
        <h4 style="color:#000"><?php the_excerpt(); ?></h4>
    </div>
</div>
<?php endforeach; ?>

1 个答案:

答案 0 :(得分:0)

想通了

<?php
$post = $_GET['postid'];
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
?>
<img src="<?php echo $image[0]; ?>" height=100% width=100%>
<h1 style="padding:50px;"><?php the_title(); ?></h1>
</div>
<?php>
$post = $_GET['postid'];  
$include = get_posts("include=$post");
$content = apply_filters('the_content',$include[0]->post_content);
echo $content;
?>