我正在使用 php 脚本来获取一些外部数据以显示在我的 wordpress 网站上。这已经完美运行了一年,但是当我不得不重新排列首页上的 som 元素时,循环中的帖子缩略图突然停止显示。
经过一些研究,我发现如果我在循环之后包含我的 php 脚本,则会出现帖子缩略图,但如果它包含在循环之前,则帖子缩略图会神秘地消失。
PHP 日志没有给我任何提示,当循环之前包含脚本时,Wordpress 只会在后缩略图块中生成 NO html。
任何人有任何想法为什么会发生这种情况?我怎么能绕过它?
(PS。我需要在循环之前包含脚本的原因是样式/ css 的问题。我想我可以做一些 CSS-hacking 以使其在循环之后工作,但我宁愿找出导致问题的原因。)
这是这样的代码:
我的 index.php 应该出现帖子缩略图(这不起作用):
<!-- ### This includes the php script, and works if it's placed bellow the loop/#leftcontent ### -->
<div id="rightcontent">
<?php include("rightcontentreleases.php"); ?>
</div>
<!-- ### Standard wordpress loop ### -->
<div id="leftcontent">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post">
<h2 class="posttitle"><a
href="<?php the_permalink() ?>"
rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<!-- ### The post thumbnail ### -->
<a href="<?php the_permalink() ?>" ><?php if (has_post_thumbnail()) {the_post_thumbnail();}?></a>
<div class="entry">
<?php the_excerpt(); ?><a class="readmore" href="<?php the_permalink() ?>">Read more</a>
</div>
</div><!-- .post -->
<?php endwhile; else: ?><p>Sorry, no posts matched your criteria.</p><?php endif; ?>
</div><!-- #leftcontent -->
这有效:
<!-- ### Standard wordpress loop ### -->
<div id="leftcontent">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post">
<h2 class="posttitle"><a
href="<?php the_permalink() ?>"
rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<!-- ### The post thumbnail ### -->
<a href="<?php the_permalink() ?>" ><?php if (has_post_thumbnail()) {the_post_thumbnail();}?></a>
<div class="entry">
<?php the_excerpt(); ?><a class="readmore" href="<?php the_permalink() ?>">Read more</a>
</div>
</div><!-- .post -->
<?php endwhile; else: ?><p>Sorry, no posts matched your criteria.</p><?php endif; ?>
</div><!-- #leftcontent -->
<!-- ### This includes the php script, and works if placed after the loop like this ### -->
<div id="rightcontent">
<?php include("rightcontentreleases.php"); ?>
</div>
外部脚本简单地遍历外部数据库,并显示一些标准 html:
<?php // this script connects to the external database, and defines some functions fetching the data ?>
<?php include_once("tigernet.php"); tigernetmysql(); get3upcoming(); ?>
<?php if (mysql_fetch_assoc($resultupcoming) > 0): ?>
<div class="rightcontentreleases" id="upcomingreleases">
<h2 class="head">Upcoming Releases</h2>
<?php while ($row = mysql_fetch_assoc($resultupcoming)) { ?>
<div class="onelatestrelease">
<a href="<?php bloginfo( 'wpurl' ); ?>/releases"><img class="albumartwork" src="http://media.tigernet.no/images/item/full/<?= $row["code"] ?>.jpg" /></a>
<h2 class="artist"><?= $row["artist"] ?></h2><br/>
<h3 class="title"><?= $row["title"] ?></h3><br/>
<?php if (isset($row['url'])): ?><div class="soundcloudplayer_right">
<object height='18'><param name='movie'value='http://player.soundcloud.com/player.swf?url=<?= $row['url'] ?>&auto_play=false&player_type=tiny&show_duration=false&show_user=false&show_playcount=false&font=Arial&color=92140e'>
<param name='allowscriptaccess' value='always'>
<param name='wmode' value='transparent'>
<embed wmode='transparent' allowscriptaccess='always' height='18' src='http://player.soundcloud.com/player.swf?url=<?= $row['url'] ?>&auto_play=false&player_type=tiny&show_duration=false&show_user=false&show_playcount=false&font=Arial&color=92140e' type='application/x-shockwave-flash'>
</object>
</div><?php endif; ?>
</div><!-- .onelatestrelease -->
<?php } ?>
</div><!-- #latestreleases -->
<?php endif; ?>