【问题标题】:Wordpress query_posts adding two "post-entry" divs, one with "post-thumbnail" and one withoutWordpress query_posts 添加了两个“post-entry”div,一个带有“post-thumbnail”,一个没有
【发布时间】:2011-04-14 01:45:43
【问题描述】:

大家好,我叫安东尼,这是我的第一个问题。我目前正在制作一个 wopress 主题。在循环中,我希望有两个“post-entry” div,一个很小,放在我的 post thumb 旁边,一个没有 thumb。

我知道我需要做一个

<div class="post">
<?php if ( has_post_thumbnail()) { ?><div class="post-thumb">   <?php the_post_thumbnail(); ?>  </div>  <div class="post-entry-1">   <? } else { ?><div class="post-entry-2">  <?php } ?>

任何帮助将不胜感激,因为我已经坚持了几天了。

【问题讨论】:

  • 这对于 StackExchange 的新 WordPress Answers Beta 站点来说是一个很好的问题。
  • 嗨 Chris_O 谢谢你的评论和建议,我会在那里添加:)

标签: wordpress loops thumbnails wordpress-theming


【解决方案1】:

以下是可放置在循环中的可用模板标签供参考:

http://codex.wordpress.org/Template_Tags

听起来你需要使用

the_excerpt(): http://codex.wordpress.org/Function_Reference/the_excerpt

还有the_content():http://codex.wordpress.org/Function_Reference/the_content

也许你需要查看循环:

<!-- Start the Loop. -->
 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

 <!-- The following tests if the current post is in category 3. -->
 <!-- If it is, the div box is given the CSS class "post-cat-three". -->
 <!-- Otherwise, the div box will be given the CSS class "post". -->
 <?php if ( in_category('3') ) { ?>
           <div class="post-cat-three">
 <?php } else { ?>
           <div class="post">
 <?php } ?>

 <!-- Display the Title as a link to the Post's permalink. -->
 <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

 <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
 <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>

 <!-- Display the Post's Content in a div box. -->
 <div class="entry">
   <?php the_content(); ?>
 </div>

 <!-- Display a comma separated list of the Post's Categories. -->
 <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
 </div> <!-- closes the first div box -->

 <!-- Stop The Loop (but note the "else:" - see next line). -->
 <?php endwhile; else: ?>

 <!-- The very first "if" tested to see if there were any Posts to -->
 <!-- display.  This "else" part tells what do if there weren't any. -->
 <p>Sorry, no posts matched your criteria.</p>

 <!-- REALLY stop The Loop. -->
 <?php endif; ?>

【讨论】:

  • 谢谢托德,是的,我正在使用 the_excerpt()。我确实把它放在了帖子里,但它显然没有显示:S
  • 我对其进行了编辑以显示一个循环示例,该示例应为您指明正确的方向。
  • 谢谢托德,我已经设法解决了这个问题。不过,在帮助下,事实证明我有一个额外的东西,不需要在那里。删除后,它又恢复了完整功能。感谢您对托德的帮助!
猜你喜欢
  • 2015-10-24
  • 1970-01-01
  • 1970-01-01
  • 2014-03-24
  • 1970-01-01
  • 2019-03-29
  • 2015-05-23
相关资源
最近更新 更多