我想显示我的安全类别的最新十个职位与日期和帖子标题和发布缩略图。 为了显示我遇到的问题。根据这篇文章显示十个发布缩略图
http://www.wpbeginner.com/beginners-guide/how-to-add-featured-image-or-post-thumbnails-in-wordpress/ 当我们想首先的显示缩略图,我们应该有下面的代码复制到function.php文件
add_theme_support('post-thumbnails');
,并使用
<?php the_post_thumbnail(); ?>
为了显示帖子的图片,我使用这段代码进入循环,但它不起作用。我的代码在这里:
<?php query_posts('securitysoft=CATEGORYNAME&showposts=10');
while (have_posts()) : the_post(); ?>
<br/>
<?php
php the_post_thumbnail();
?>
<br/>
<?php the_time(__('j/F/ Y','kubrick')) ?>
<br/>
<?php the_title();?>
<?php endwhile; ?>
主要问题是图片不显示。为了证明这一点,我服用后的ID有缩略图(292)的帖子是这样的:
<?php if (has_post_thumbnail(292))
{
echo "<script type='text/javascript'>alert('yes')</script>";
has_post_thumbnail(292);
}
else
{
echo "<script type='text/javascript'>alert('no')</script>";
has_post_thumbnail(292);
}
> 注:292的帖子ID 以上代码的结果是否定的。 我已经取代了php the_post_thumbnail();用下面的代码中的每一个,但不工作:
get_the_post_thumbnail($post->ID);
echo get_the_post_thumbnail($post->ID);
get_the_post_thumbnail($post_id, 'thumbnail');
echo get_the_post_thumbnail($post_id, 'thumbnail');
<?php echo get_the_post_thumbnail($post_id, 'thumbnail', array('class' => 'alignleft')); ?>
这是我function.php:
<?php
add_theme_support('post-thumbnails');
if (function_exists('register_sidebar'))
register_sidebar();
?>
更改securitysoft = CATEGORYNAME到category_name = securitysoft在您的post参数中securitysoft更改您的类别名称感谢, –
问题不在categoryname中(因为循环的结果是正确的,因此我现在改变了)我收到了帖子标题,但唯一的问题是缩略图。谢谢 –
改变,但没有工作query_posts('securitysoft = category_name&showposts = 10'); –