WordPress 精选帖子

发布于 2024-09-16 17:40:31 字数 993 浏览 4 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁吢 2024-09-23 17:40:31

您的问题中的代码仅循环遍历针对当前视图进行的查询返回的帖子(在单个帖子视图为一篇帖子的情况下)。您想要执行一个新查询来检索具有所需元值的所有帖子:

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

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; ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文