我有一个有点复杂的WordPress模板,它会变得越来越复杂,因为客户希望它在一种条件下以这种方式工作,在另一种条件下以另一种方式工作,等等。
主页有两列单元格,包含4种类型的内容。
每个即将召开的会议都有一段代码。这些是第一个细胞。
会议服务有一个代码块。如果会议数量不均衡,这将占用最后一个单元格。这意味着,如果页面显示,该内容将始终位于页面的右侧。
有一块内容是尚未获得完整信息的会议观察列表。此块将显示是否已发布,即列表中是否有会议。
如果会议数量为奇数,则它将显示在右栏,即会议之后;如果会议数量为偶数,则它将显示在左侧,即会议之后。
在线研讨会系列有一个内容块,总是显示在观察列表之后、会议之后、如果观察列表未显示,以及会议服务之前,如果有一个奇数单元格,则该内容块会显示在观察列表之后
问题是有一个查询从一个特定的帖子中提取内容字段。我希望查询在函数之外,但foreach抛出了一个错误,因此我猜测函数实际上是在模板文件中的代码之前处理的。是否有方法在函数中调用函数。php在哪里php进程与模板的其余部分内联?
为澄清添加了代码。这是页面上可能出现的三个移位代码块之一。我包含的代码比我想在函数中输入的代码还要多。php用于上下文。我要移出的代码以echo“”开头;并以单元格关闭结束。
***请注意,此代码很快将更改以删除表结构,但这不是此问题的一部分。
/* WATCH LIST AVAILABLE?:
To decide whether to add a Watch List cell before the Webinar Series cell, check whether the Watch List post is published
*/
query_posts( \'p=1684&posts_per_page=1\');
if ( get_post_status ( \'1684\' ) == \'publish\' )
{
/* CHECK WHETHER WATCH LIST AND WEBINAR WILL BE IN SAME ROW */
if(($NumberConferences % 2) == 0)
{
echo \'<tr>\';
while( have_posts() ) : the_post();
echo \'<td>\';
echo \'<div class="RightBorderLayer">\';
echo \'<div class="HomeLeftCell">\';
$HomeWatchListImage = types_render_field("watch-list-home-page-image", array("raw"=>"true"));
if($HomeWatchListImage != \'\')
echo \'<a href="\'.get_permalink().\'"><img src="\'.$HomeWatchListImage.\'"></a>\';
$WatchListTitles = get_post_meta($post->ID, \'wpcf-watch-list-title\', false);
$i = 1;
foreach($WatchListTitles as $WatchListTitle)
{
echo \'<li style="text-align: left;"><strong>Workshop \'.$i.\'</strong>: \'.$WatchListTitle.\'</li>\';
$i++;
} // End foreach
echo \'<div class="HomePageCellNote">If you are interested in any of these events and are not regularly receiving WFCA notices, signup for our email list in the bottom left of this page. All regular WFCA subscribers will receive notice of these events as available.</div>\';
echo \'<div style="clear: both;"></div>\';
echo \'</div><!-- End Home Left Cell div -->\';
echo \'</div><!-- End Right Border Layer -->\';
echo \'</td>\';
endwhile;
wp_reset_postdata();