WordPress 精选帖子
我正在尝试使用 WordPress 创建一个作品集网站,
其值为“特色”或“非特色”
每个帖子都有视图 Costum 字段,其中之一称为类型 -现在当用户单击帖子标题时, - 他们会去使用 single.php 来查看整个帖子,在这里我很乐意显示
我尝试过的
<?php while ( have_posts() ) : the_post() ?>
<?php if(get_post_meta($post->ID, 'type', true) == "featured") {; ?>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark">
<img src="<?php echo get_post_meta($post->ID, 'intro_thump', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" />
</a></h2>
<?php }; ?>
<div class="entry-content">
</div><!– .entry-content –>
<?php endwhile; ?>
所有特色缩略图(此代码与我在 INDEX.PHP 中使用的代码相似,并且它确实有效,在这里在 SINGLE.PHP 中它确实有效)不起作用)
但这不会显示所有缩略图(仅显示当前帖子的缩略图(是专题帖子))
这是我第一次尝试从空白创建主题,所以我不确定错误可能是什么
感谢您的帮助
i'm trying to create a portfolio website using wordpress,
each post has view costum fields, one of which is called type - with the value of "featured" or "not-featured"
now when user clicks on the post title - they go the the single.php to see the entire post, here i would love to display all featured thumbnails
i tried this
<?php while ( have_posts() ) : the_post() ?>
<?php if(get_post_meta($post->ID, 'type', true) == "featured") {; ?>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark">
<img src="<?php echo get_post_meta($post->ID, 'intro_thump', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" />
</a></h2>
<?php }; ?>
<div class="entry-content">
</div><!– .entry-content –>
<?php endwhile; ?>
(THIS CODE IS SIMILAR TO THE CODE I USE AT INDEX.PHP AND THERE IT DOES WORK, HERE AT SINGLE.PHP IT DOES NOT WORK)
but this does not display all the thumbnails (only the current posts' thumbnail (is it's a feature post))
this is my first attempt of trying to create a theme from blank so i'm not sure what the error could be
thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题中的代码仅循环遍历针对当前视图进行的查询返回的帖子(在单个帖子视图为一篇帖子的情况下)。您想要执行一个新查询来检索具有所需元值的所有帖子:
The code in your question only loops through the posts returned by the query made for the current view, in the case of a single post view that is one post. You want to perform a new query to retrieve all the posts that have the required meta value: