0

目前我正在为我的客户制作自定义主题,但我不是这方面的专家。我的问题是如何为同一类别的帖子制作不同的风格。目前在我的主题中

为第一篇文章启动新查询

<?php query_posts('showposts=1&cat=videos&offset=0'); if (have_posts()) : ?><?php      while (have_posts()) : the_post(); ?>
<div class="first-news">
<h2><a href="<?php the_permalink() ?><?php the_title(); ?></a></h2>
<?php if( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('video-thumb');?</a><?php} ?> 
<?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,8); ?>
</div>
<?php endwhile; else: endif; ?> 

然后再次使用另一个 div 和样式对剩余 4 个帖子开始相同的查询

<?php query_posts('showposts=4&cat=videos&offset=1'); if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<div class="second-news">
<h3><a href="<?php the_permalink() ?><?php the_title(); ?></a></h3>
<?php if( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('news-thumb'); ?></a><?php } ?> 
<?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,8); ?>
</div>
<?php endwhile; else: endif; ?> 

这完美地工作,这是正确的吗?我认为可能有一个很好的解决方案,它只查询一次帖子并从同一类别中获取所需数量的不同风格的帖子。我想要的是下图。 当前主题截图

4

2 回答 2

0

您应该使用 wordpress 中的类别模板

在加载页面之前,wordpress 会查找特定模板的存在,例如来自上面链接的页面。

   1. category-slug.php
   2. category-ID.php
   3. category.php
   4. archive.php
   5. index.php 
于 2012-07-13T06:23:57.780 回答
0

为了在 WordPress 3.1+ 中激活“帖子格式”,您需要打开主题的 functions.php 文件并粘贴以下代码:

add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );

注意:除此之外,画廊并不是唯一可用的帖子格式。可用的帖子格式列表是:

搁置 – 典型风格的博客格式。

聊天 - 聊天记录。

画廊 - 图片画廊。

链接——指向另一个站点的链接。

图像 - 单个图像。

报价 - 报价。

status – 简短的状态更新,通常限制为 140 个字符。类似于 Twitter 状态更新。

视频 - 单个视频。

有关帖子格式的完整列表,请参阅 WordPress Codex。添加此代码后,您将在您看到发布的右侧列中的帖子写入面板中看到一个新字段。

撰写帖子后,您可以更改格式并点击发布。这将允许您以预先设置的格式显示您的帖子。

编辑您的帖子循环。

假设在您的情况下视频类别帖子格式是视频

我们将使用条件标签:has_post_format()

if ( has_post_format( 'video' ) {

  // Blog Category format

} 
else 
{

   // Normal Formate

}

我希望这能帮到您。更多信息...

于 2012-07-13T06:29:01.147 回答