WordPress的特色文章 [英] wordpress featured posts

查看:94
本文介绍了WordPress的特色文章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用wordpress创建一个投资组合网站,

i'm trying to create a portfolio website using wordpress,

每个帖子都有view costum字段,其中之一称为type-值为 featured 或未功能化

each post has view costum fields, one of which is called type - with the value of "featured" or "not-featured"

现在,当用户单击帖子标题时,他们将通过single.php查看整个帖子,在这里我想展示所有精选缩略图

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

我尝试了

         <?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在这里起作用了

(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

感谢您的帮助

推荐答案

问题中的代码仅循环遍历当前视图查询返回的帖子,如果是一个帖子,则为一个帖子。您想执行一个新查询以检索具有所需元值的所有帖子:

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:

<?php
  query_posts(array("meta_key" => "type", "meta_value" => "featured"));
  if (have_posts()) : while (have_posts()) : the_post();
?>
  <!-- Display thumbnails -->
<?php endwhile; endif; ?>

这篇关于WordPress的特色文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆