完全相同 PHP 只产生一次正确的输出而不是两次

Exact same PHP only produces correct output once instead of twice

正在使用的插件是 The Events Calendar PRO,网站是 WordPress。

下面的这段代码并未 link 将每个 'Past Event' 图像与其相关事件关联起来。相反,它 link 返回主页。

事件的标题确实 link 到正确的地方,但是两个地方使用相同的代码,所以我很困惑。

有什么想法吗?

<?php foreach( $events as $event ) : ?>
<div class="tribe-mini-calendar-event">
    <div class="list-info">
        <div class="tribe-events-event-image">
            <a href="<?php tribe_event_link( $event ); ?>"><?php echo tribe_event_featured_image( $event, 'medium' ); ?></a>
        </div>
        <h2 class="tribe-events-title"><a href="<?php tribe_event_link( $event ); ?>"><?php echo $event->post_title; ?></a></h2>
        <div class="tribe-events-duration">
            <?php echo date_i18n( get_option('date_format' ), strtotime( $event->EventStartDate ) ); ?>
        </div>
    </div>
</div>
<?php endforeach; ?>

提前致谢。

========================更新

HTML 页面为过去的事件生成这个

      <div class="tribe-events-event-image">
        <a href="http://touring.valhallatavern.com/event/fimbulwinter-mmxiv/"></a>
        <a href="http://touring.valhallatavern.com/"><img width="212" height="300" src="http://touring.valhallatavern.com/wp-content/uploads/2016/02/fimbulwinterMMXIV-212x300.jpg" class="attachment-medium size-medium wp-post-image" alt="Fimbulwinter MMXIV" srcset="http://touring.valhallatavern.com/wp-content/uploads/2016/02/fimbulwinterMMXIV-212x300.jpg 212w, http://touring.valhallatavern.com/wp-content/uploads/2016/02/fimbulwinterMMXIV-768x1087.jpg 768w, http://touring.valhallatavern.com/wp-content/uploads/2016/02/fimbulwinterMMXIV-724x1024.jpg 724w, http://touring.valhallatavern.com/wp-content/uploads/2016/02/fimbulwinterMMXIV.jpg 851w"
          sizes="(max-width: 212px) 100vw, 212px"></a>
      </div>

虽然它为即将到来的旅行生成此内容

    <div class="tribe-events-event-image">
      <a href="http://touring.valhallatavern.com/event/between-the-buried-and-me-nz-tour-2016/">
      <img width="212" height="300" src="http://touring.valhallatavern.com/wp-content/uploads/2016/02/BTBM-212x300.jpg" class="attachment-medium size-medium wp-post-image" alt="BTB&amp;M" srcset="http://touring.valhallatavern.com/wp-content/uploads/2016/02/BTBM-212x300.jpg 212w, http://touring.valhallatavern.com/wp-content/uploads/2016/02/BTBM-768x1086.jpg 768w, http://touring.valhallatavern.com/wp-content/uploads/2016/02/BTBM-724x1024.jpg 724w, http://touring.valhallatavern.com/wp-content/uploads/2016/02/BTBM.jpg 1500w"
        sizes="(max-width: 212px) 100vw, 212px"></a>
    </div>

所以有一个主页link被图像功能抛出...

你必须改变::: 从 <?php tribe_event_link( $event ); ?> ::: 到 <?php echo tribe_event_link( $event ); ?>

<?php foreach( $events as $event ) : ?>
<div class="tribe-mini-calendar-event">
    <div class="list-info">
        <div class="tribe-events-event-image">
            <a href="<?php echo tribe_event_link( $event ); ?>"><?php echo tribe_event_featured_image( $event, 'medium' ); ?></a>
        </div>
        <h2 class="tribe-events-title"><a href="<?php echo tribe_event_link( $event ); ?>"><?php echo $event->post_title; ?></a></h2>
        <div class="tribe-events-duration">
            <?php echo date_i18n( get_option('date_format' ), strtotime( $event->EventStartDate ) ); ?>
        </div>
    </div>
</div>
<?php endforeach; ?>

试试这个代码 2

<?php foreach( $events as $event ) { ?>
<div class="tribe-mini-calendar-event">
    <div class="list-info">
        <div class="tribe-events-event-image">
            <a href="<?php echo tribe_event_link( $event ); ?>">
                <?php echo tribe_event_featured_image( $event, 'medium' ); ?>
            </a>
        </div>
        <h2 class="tribe-events-title">
            <a href="<?php echo tribe_event_link( $event ); ?>">
                <?php echo $event->post_title; ?>
            </a>
        </h2>
        <div class="tribe-events-duration">
            <?php echo date_i18n( get_option('date_format' ), strtotime( $event->EventStartDate ) ); ?>
        </div>
    </div>
</div>
<?php } ?>

函数 tribe_event_featured_image 需要 link 的布尔参数。因为我没有给它一个真值或假值,所以它在主页上生成了一个 link。它将 link 放在我自己的 link 中,从而取消了它。我修改了我的代码如下:

我换了

<?php tribe_event_featured_image( $event, 'medium' ); ?>

<?php tribe_event_featured_image( $event, $size = medium, $link = false ); ?>