【问题标题】:Exact same PHP only produces correct output once instead of twice完全相同的 PHP 只产生一次正确的输出而不是两次
【发布时间】:2016-02-08 04:54:39
【问题描述】:

使用的插件是 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>

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

【问题讨论】:

  • 您的 HTML 页面生成两个锚链接...一个带有正确的链接,另一个重定向到主页
  • 是的,这就是我要解决的问题。 HTML 由上面的 PHP 输出。相同的 PHP,不同的输出。我不明白。
  • 时间提示 ;) 我们应该经常整理我们的代码,以防止浪费时间和宝贵的头痛 ;)
  • 请问?它甚至不是我的代码。去整理你自己的代码... ;) ;) ;)

标签: php wordpress plugins call


【解决方案1】:

你必须改变 :::: 从&lt;?php tribe_event_link( $event ); ?&gt;:::: 到&lt;?php echo tribe_event_link( $event ); ?&gt;

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

【讨论】:

【解决方案2】:

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

我换了

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

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

【讨论】:

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