【问题标题】:Wordpress: Showing 5 attachments per postWordpress:每个帖子显示 5 个附件
【发布时间】:2011-09-04 00:59:07
【问题描述】:

我知道这可能是一个简单的问题,但我是 Wordpress 编码和 PHP 的初学者。我希望在我网站上的每个帖子中嵌入五个附件,所以我知道这与在 single.php 或 loop.php 中插入一些内容有关。因此,假设我在帖子中附加了 8 或 10 张照片,我希望单个帖子页面显示其中 5 张照片并具有指向“图库”/attachment.php 页面的链接。类似于本网站在此页面上所做的事情,帖子条目末尾的 6 张照片 (http://www.celebuzz.com/2011-05-27/kim-kardashian-kris-humphries-makes-first-post -engagement-public-appearance-photos/)

我尝试过使用 wordpress [gallery] 插入,但它所做的只是显示所有图片,我不想使用插件,因为我觉得它太过分了,只需要一些代码来调用 5附照片。希望有人可以提供帮助。提前致谢

【问题讨论】:

    标签: wordpress gallery photo attachment


    【解决方案1】:

    尝试使用自定义字段模板插件 http://wordpress.org/extend/plugins/custom-field-template/

    【讨论】:

    • 我检查了那个插件,它看起来有点矫枉过正而且太复杂了。我想尝试只使用代码来保持查询等等
    【解决方案2】:

    我知道你不想使用插件。但是,为了这些问题,我知道最终会有人从搜索引擎登陆这里。

    您可以使用attachment 插件。这个插件非常简单直接。

    安装后,它将在帖子创建页面上添加新的元框。

    您可以添加任意数量的图片和模板页面的the loop 部分,您添加这个sn-p:

    <?php
      if( function_exists( 'attachments_get_attachments' ) )
      {
        $attachments = attachments_get_attachments();
        $total_attachments = count( $attachments ) > 5 : 5 : count( $attachments );
        if( $total_attachments ) : ?>
          <ul>
          <?php for( $i=0; $i<$total_attachments; $i++ ) : ?>
            <li><img src="<?php echo $attachments[$i]['location']; ?>" alt="<?php echo $attachments[$i]['title']; ?>" /></li>
          <?php endfor; ?>
          </ul>
        <?php endif; ?>
    <?php } ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多