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

时间:2016-02-08 04:54:39

标签: php wordpress plugins call

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

以下代码未将每个“过去事件”图像与其相关事件相关联。相反,它链接回主页。

事件的标题确实链接到了正确的位置,但两个地方都使用了相同的代码,所以我很难过。

有什么想法吗?

<?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>

虽然它为UPCOMING TOURS生成了这个

    <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>

因此图像功能会抛出主页链接...

2 个答案:

答案 0 :(得分:0)

你必须改变:::: 从<?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 } ?>

答案 1 :(得分:0)

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

我替换了

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

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