如何在类别页面上显示帖子特色图片?

时间:2014-08-28 05:53:51

标签: php mysql

嗨,这是我在类别页面上显示帖子详细信息的查询。我展示了贴瓷砖&发布内容。我不知道如何显示帖子图片..任何人都可以帮忙吗?

<?php if(isset($_REQUEST['datepost']))
 {
 $date = $_POST['date'];

 $res=mysql_query("SELECT * FROM  `wp_posts` WHERE DATE_FORMAT(post_date,  '%m/%d/%Y' ) =  '".$date."' AND post_type = 'post' AND post_status='publish'  ORDER BY post_date DESC");


 while($pageposts=mysql_fetch_array($res))
 {
 echo $pageposts['post_title'];
 echo "\n<br />";
 echo $pageposts['post_content'];
 echo "\n<br />";

 }

 exit();
 }
 ?>

1 个答案:

答案 0 :(得分:0)

你可以这样做:

<?php if(isset($_REQUEST['datepost']))
 {
 $date = $_POST['date'];

 $res=mysql_query("SELECT * FROM  `wp_posts` WHERE DATE_FORMAT(post_date,  '%m/%d/%Y' ) =  '".$date."' AND post_type = 'post' AND post_status='publish'  ORDER BY post_date DESC");


 while($pageposts=mysql_fetch_array($res))
 {
 echo $pageposts['post_title'];
 echo "\n<br />";
 echo $pageposts['post_content'];
 echo "\n<br />";
 echo get_the_post_thumbnail($pageposts['ID'], 'thumbnail' ); 
 }

 exit();
 }
 ?>

或者如果你想要图像的src,你可以使用

wp_get_attachment_image_src( get_post_thumbnail_id( $pageposts['ID'] ), 'thumbnail' );

REFER get_the_post_thumbnail

你可以使用Wordpress Loop

这样做更好的方法
<?php 
if ( have_posts() ) {
    while ( have_posts() ) {
        $post=the_post(); 
        the_title(); 
        echo "\n<br />";
        the_content();
        get_the_post_thumbnail();

    } 
}
?>

WordPress loop