WordPress 查询帮助

发布于 2024-11-29 16:51:15 字数 1468 浏览 0 评论 0原文

对于 Wordpess,我算是个菜鸟。我最近才开始构建主题,但遇到了困难。我试图使用 wpquery 在我的网站顶部展示 3 篇不同的文章,但由于某种原因它只显示一篇。我将在下面包含我的代码,如果有人可以帮助我找出问题所在,我将非常感激!

Pastebin中包含的代码: http://pastebin.com/1DB7vent

<div class="site_width">
  <ul>
     <?php
     $args = array( 'tag' => 'featured', 'posts_per_page' => '3' );
     $recent_posts = wp_get_recent_posts( $args );
     ?>
     <li>
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="nofollow">
           <?php the_post_thumbnail('featured', array( 'title'  => '' )); ?>
        </a>
        <label>
           <a href="<?php the_permalink(); ?>" rel="bookmark">
               <?php the_title(); ?>
           </a>
        </label>
     </li>
     <?php wp_reset_query(); ?>
  </ul>
</div>

我希望“li”再重复两次总共三个。我正在尝试获得与此类似的设置:

 <div class="site_width">
   <li>
      <a href="feat.article1.permalink" title="feat.article1.title">
         <img src="feat.article1.featured.image">
      </a>
      <label>
         <a href="feat.article1.permalink" title="feat.article1.title">
            "Featured Article 1 Title"
         </a>
      </label>
   </li>
   <REPEAT 'LI' ABOVE TWICE MORE BELOW>
 </div>

I'm sort of a noob when it comes to Wordpess; I've only recently started building themes and I've run into a wall. I'm trying to feature 3 different articles at the top of my site using wpquery and for some reason it's only displaying one. I'll include my code below and if anyone can help my figure out what's wrong I would be very grateful!

Code included in pastebin: http://pastebin.com/1DB7vent

<div class="site_width">
  <ul>
     <?php
     $args = array( 'tag' => 'featured', 'posts_per_page' => '3' );
     $recent_posts = wp_get_recent_posts( $args );
     ?>
     <li>
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="nofollow">
           <?php the_post_thumbnail('featured', array( 'title'  => '' )); ?>
        </a>
        <label>
           <a href="<?php the_permalink(); ?>" rel="bookmark">
               <?php the_title(); ?>
           </a>
        </label>
     </li>
     <?php wp_reset_query(); ?>
  </ul>
</div>

I want the "li" to repeat 2 more times for a total of three. I'm trying to get a setup similar to this:

 <div class="site_width">
   <li>
      <a href="feat.article1.permalink" title="feat.article1.title">
         <img src="feat.article1.featured.image">
      </a>
      <label>
         <a href="feat.article1.permalink" title="feat.article1.title">
            "Featured Article 1 Title"
         </a>
      </label>
   </li>
   <REPEAT 'LI' ABOVE TWICE MORE BELOW>
 </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

嘿嘿嘿 2024-12-06 16:51:15

查看当前主题目录中的loop.php。您需要循环查询结果并显示它们。一般结构是这样的:

<?php while ( have_posts() ) : the_post(); ?>
    <li>
       <?php //show your post  ?>
    </li>
<?php endwhile; // End the loop. Whew. ?>

Take a look in current theme's directory at loop.php. You need to loop through your query results and display them. The general structure is like so:

<?php while ( have_posts() ) : the_post(); ?>
    <li>
       <?php //show your post  ?>
    </li>
<?php endwhile; // End the loop. Whew. ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文