我正在处理这个test site,这是一个WordPress网站(使用版本5.5)并使用Canvas WooTheme。它的首页应该显示今天的日历事件,这些事件由WordPress插件Events Manager提供。
我希望他们做的是显示,例如events page(以及下面的屏幕截图 - 见this screenshot),确实如此。相反,下面的代码以某种方式将模板的其余部分(包括侧边栏)吸入表中,继续将表行和列复制到自身中(如this screenshot所示)。
它射入Firebug的代码如下:
<table cellspacing="0" cellpadding="0" id="current-events"><tbody><tr><td class="startdate_cost_td">
<span class="start_time"><table cellspacing="0" cellpadding="0" id="current-events"><tbody><tr>
<td class="startdate_cost_td">
<span class="start_time">12:00 AM</span><br>
<span class="cost">Free</span>
</td>
<td class="event_image"> <img src="../../../wp-includes/images/default_img.jpg"></td>
<td class="event_title">Sex Addicts Anonymous meeting<br>
<i><span class="location_name">@ No location listed</span></i>
<div id="read_more_wrapper">
<img src="../../../wp-includes/images/little_pink_arrow.jpg"><a class="pink_link" href="http://testbuzz.illinimedia.com/events/sex-addicts-anonymous-meeting-90">READ MORE</a></div></td></tr>
<!--12:00 AM</span><br/><span class='cost'>Free</span></td><td class='event_image'><img src='../../../wp-includes/images/default_img.jpg' /></td><td class='event_title'><a href="http://testbuzz.illinimedia.com/events/sex-addicts-anonymous-meeting-90" title="Sex Addicts Anonymous meeting">Sex Addicts Anonymous meeting</a><br/><i><span class='location_name'>@No location listed</span></i><br />Mind, body, & spirit<div id='read_more_wrapper'><img src='../../../wp-includes/images/little_pink_arrow.jpg' /><a href='http://testbuzz.illinimedia.com/events/sex-addicts-anonymous-meeting-90' class='pink_link'>READ MORE</a></td></tr></div><tr><td class='startdate_cost_td'>
<span class='start_time'>-->
<tr>
<td class="startdate_cost_td">
<span class="start_time">8:30 AM</span><br>
<span class="cost">Free</span>
</td>
<td class="event_image"><img alt=""Inside India" with Larry Kanfer" src="http://testbuzz.illinimedia.com/wp-content/uploads/locations-pics/event-35214.jpg"> </td>
<td class="event_title">“Inside India” with Larry Kanfer<br>
<i><span class="location_name">@ Alice Campbell Alumni Center</span></i>
<div id="read_more_wrapper">
<img src="../../../wp-includes/images/little_pink_arrow.jpg"><a class="pink_link" href="http://testbuzz.illinimedia.com/events/inside-india-with-larry-kanfer-31">READ MORE</a></div></td></tr>
......more events similar to this......
<div class="fix"></div>
<div class="nav-entries">
<a href="http://testbuzz.illinimedia.com/page/2"><span class="nav-prev icon fl">Older posts</span></a> <div class="fix"></div>
</div>
<!-- /#main -->
<div id="sidebar">
<div class="widget widget_woo_search" id="woo_search-3"><div class="search_main">
<form action="http://testbuzz.illinimedia.com/" class="searchform" method="get">
<input type="text" onblur="if (this.value == '') {this.value = 'Search...';}" onfocus="if (this.value == 'Search...') {this.value = '';}" value="Search..." name="s" class="field s">
<input type="image" name="submit" class="submit" alt="Search" src="http://testbuzz.illinimedia.com/wp-content/themes/canvas/images/ico-search.png">
</form>
<div class="fix"></div>
</div>
.... the rest of the content stuck .....
</span></td></tr></tbody></table>
下面是我在我们的子主题template-magazine.php中插入杂志模板的代码,这导致了问题:
<?php
$page = ( !empty($_REQUEST['page']) && is_numeric($_REQUEST['page']) )? $_REQUEST['page'] : 1;
$args = array(
'limit' => 10,
'scope' => 'today',
'pagination' => 1
);
if (isset($_REQUEST['c'])) {
$args['category'] = $_REQUEST['c'];
$args['scope'] = 'future';
}
$args['offset'] = $args['limit'] * ($page-1);
$events = em_get_events_array($args);
$size = sizeof($events)-1;
echo "<h2 id='headding'class='title'>Today's Events</h2>";
echo "<table cellpadding='0' cellspacing='0' id='current-events' >";
for ($i=0;$i<$size;$i++) {
echo "<tr><td class='startdate_cost_td'>
<span class='start_time'>" . $events[$i][0] .
"</span><br/><span class='cost'>" . $events[$i][7] .
"</span></td><td class='event_image'>";
if ($events[$i][8] == '') {
echo "<img src='../../../wp-includes/images/default_img.jpg' />";
}
else {
echo $events[$i][9];
}
echo "</td><td class='event_title'>" . $events[$i][10] .
"<br/><i><span class='location_name'>@". $events[$i][11] .
"</span></i><br />" .$events[$i][12] .
"<div id='read_more_wrapper'>" .
"<img src='../../../wp-includes/images/little_pink_arrow.jpg' /><a href='" . $events[$i][13] . "' class='pink_link'>READ MORE</a></td></tr>" .
"</div>";
}
echo "</table>";
$last_index = count($events) - 1;
echo $events[$last_index][0];
?>
通过删除代码本身,我确保上面的PHP代码是导致主要问题的原因。这似乎成功了!当我尝试将此代码放在template-magazine.php文件的不同部分时,它会重复相同的结果。当我将它移动到我们的子主题中的functions.php文件时,它只是让其他所有内容进一步向下扩展到浏览器的整个宽度。如何摆脱代码中的循环,将所有的副内容都吸入正在创建的表中?
更新:我使用HTML标记注释掉了上面的PHP代码,复制了事件并注释掉了我们希望在页面上显示的表格元素。下面是它的样子截图:https://docs.google.com/open?id=0B2UC67NQiW2yalhMSGxra0FFWGM以及下图中显示的代码(我不想粘贴代码,因为它会很长:
答案 0 :(得分:0)
最终它似乎是在我在插件中创建的事件预览设置中读取。我需要做的只是创建一个for循环,读取该特定页面的每个事件,阻止上面的其余PHP代码。以下是用于读取事件的代码:
for ($i=0;$i<$size;$i++) {
echo $events[$i][0];
}
希望这有助于使用事件管理器插件的人。