【问题标题】:simplepie: use my own thumbnail per feed in a multifeed pagesimplepie:在多页进纸页面中使用我自己的缩略图
【发布时间】:2013-04-02 20:20:29
【问题描述】:

我四处寻找,但没有找到问题的答案:如何在多页馈送页面中为每个馈送使用自己的缩略图?如果我忽略了答案,那将是由于错误的搜索键,我提前道歉。

到目前为止,我得到了以下代码(不多):

<?php
include_once('autoloader.php');
include_once('idn/idna_convert.class.php');

date_default_timezone_set('Europe/Amsterdam');
setlocale(LC_TIME, 'nld_nld');

$feed = new SimplePie();
$urls = (array(
    'http://myfeedurla.com' => 'descriptiona', 
    'http://myfeedurlb.com' => 'descriptionb',
    'http://myfeedurlc.com' => 'descriptionc'
    ));
$feed->set_feed_url(array_keys($urls)); // this should get parse only the URLS
$feed->set_cache_location('cache/');
$feed->init();

$feed->handle_content_type();
?>

// As from here I'm using the standard simplepie code to show multiple feeds and order them by day

      <?php

      // Set up some variables we'll use.
      $stored_date = '';
      $list_open = false;

      // Go through all of the items in the feed
      foreach ($feed->get_items() as $item) 
      {
        // What is the date of the current feed item?
        $item_date = $item->get_date('M jS');

        // Is the item's date the same as what is already stored?
        // - Yes? Don't display it again because we've already displayed it for this date.
        // - No? So we have something different.  We should display that.
        if ($stored_date != $item_date)
        {
            // If there was already a list open from a previous iteration of the loop, close it
            if ($list_open)
            {
                echo '</ol>' . "\r\n";
            }

            // Since they're different, let's replace the old stored date with the new one
            $stored_date = $item_date;

            // Display it on the page, and start a new list
            echo '<h1>' . $item->get_local_date('%A %d %B %Y') . '</h1><hr>' . "\r\n";
            echo '<ol>' . "\r\n";

            // Let the next loop know that a list is already open, so that it will know to close it.
            $list_open = true;
        }

        // Display the feed item however you want...
        echo '<li>' . $item->get_local_date('%H:%M') . ' | <h4><a href="' . $item->get_permalink() . '">' . $item->get_title() . '</a></h4></li>' . "\r\n";
      }
      ?>

我想在 HTML 中的某处添加 'img scr=" . . "' 等。它应该只引用名称为 'descriptiona'.png 和 'descriptionb'.png 等的图像,每个提要.这可能吗?如果是,如何?

如果我应该更清楚,请不要犹豫。在此先感谢您的帮助! 最好的问候,

【问题讨论】:

    标签: image feed simplepie


    【解决方案1】:

    好的,到目前为止我有一个解决方案 :) 我在 img 文件名中使用各个提要的标题。我添加了以下代码:

    <img src="images/' . $item->get_feed()->get_title() . '.png" width="12" height="12" />
    

    现在我只希望提要不会在其标题中使用 / 或其他内容...如果有人有更好的方法来做到这一点,例如。如果能够为每个提要添加个人标题,那将是非常受欢迎的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-29
      • 2014-09-12
      • 1970-01-01
      • 2012-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-24
      相关资源
      最近更新 更多