我使用事件管理器来控制我的事件,但基本网格可以在整个网站的不同位置显示这些事件的预览。这方面的一个例子是http://staging-dbmax.transitiongraphics.co.uk/events/.
本质上,我是在尝试获取基本网格,以识别事件的日期字段,并相应地对网格进行排序。同时隐藏过去的事件。
到目前为止,通过研究,我成功地隔离了网格并提取了日期,同时隐藏了旧事件。然而,这并不完全有效。某些事件未正确放置在网格中。
为了实现我目前的目标,我做了以下工作:
在基本网格的源选项卡下添加了参数字段:
( \'meta_query\' => array( array( \'meta_key\' => \'_event_start_date\' , \'meta_value\' => $today, \'compare\' => \'>=\' , \'type\' => \'date\')) , \'orderby\' => \'meta_value\' , ) ); ?>
在我的函数PHP文件中添加了以下内容:
add_filter(\'essgrid_query_caching\', \'eg_disable_caching\', 10, 2);
function eg_disable_caching($do_cache, $grid_id){ //disable caching for the particular grid
if($grid_id == 43 || $grid_id == 48 || $grid_id == 50){ //replace 1 with your desired grid id
return false;
}
return true;
}
add_filter(\'essgrid_get_posts\', \'eg_modify_query\', 10, 2);
function eg_modify_query($query, $grid_id){
if($grid_id == 43 || $grid_id == 48){ //replace 1 with your desired grid id
$query[\'meta_query\'] = array( \'key\' => \'_start_ts\', \'value\' => current_time(\'timestamp\'), \'compare\' => \'>=\', \'type\'=>\'numeric\' );
$query[\'meta_key\'] = \'_start_ts\';
$query[\'meta_value\'] = current_time(\'timestamp\');
$query[\'meta_value_num\'] = current_time(\'timestamp\');
$query[\'meta_compare\'] = \'>=\';
}
if($grid_id == 50){ //replace 1 with your desired grid id
$query[\'meta_query\'] = array( \'key\' => \'_start_ts\', \'value\' => current_time(\'timestamp\'), \'compare\' => \'<=\', \'type\'=>\'numeric\' );
$query[\'meta_key\'] = \'_start_ts\';
$query[\'meta_value\'] = current_time(\'timestamp\');
$query[\'meta_value_num\'] = current_time(\'timestamp\');
$query[\'meta_compare\'] = \'<=\';
}
return $query;
}
最后,这个HTML进入网格皮肤,从事件管理器中提取日期:
[event post_id="%post_id%"]#_EVENTDATES[/event]
很明显,如果有人有更好的解决方案,我很乐意使用它,否则,上面有什么东西排序不正确吗?
SO网友:Marc
在对此进行了大量研究之后,我设法在Essential Grid plugin.
如果从上述解决方案开始,可以删除基本网格的“源”选项卡下添加的参数字段,不再需要该字段。
这就是我所拥有的functions.php
. Note: 我有网格1和;2用于当前事件,并按升序“事件开始日期”排序,我想网格99将按降序用于过去的事件,但我没有测试它。
/******************************************************************
* Querry for Essential Grid to work with events
******************************************************************/
add_filter(\'essgrid_query_caching\', \'eg_disable_caching\', 10, 2);
function eg_disable_caching($do_cache, $grid_id){ //disable caching for the particular grid
if($grid_id == 1 || $grid_id == 2 || $grid_id == 99){ //replace 99 with other grid id - see below
return false;
}
return true;
}
add_filter(\'essgrid_get_posts\', \'eg_modify_query\', 10, 2);
//This is for future events
function eg_modify_query($query, $grid_id){
if($grid_id == 1 || $grid_id == 2){ //replace with your grid id
$query[\'meta_query\'] = array( \'key\' => \'_start_ts\', \'value\' => current_time(\'timestamp\'), \'compare\' => \'>=\', \'type\'=>\'numeric\' );
$query[\'meta_key\'] = \'_start_ts\';
$query[\'meta_value\'] = current_time(\'timestamp\');
$query[\'meta_value_num\'] = current_time(\'timestamp\');
$query[\'meta_compare\'] = \'>=\';
$query[\'order\'] = \'ASC\';
$query[\'orderby\'] = \'meta_value\';
}
//This is for past events
if($grid_id == 99){ //replace 99 with your desired grid id
$query[\'meta_query\'] = array( \'key\' => \'_start_ts\', \'value\' => current_time(\'timestamp\'), \'compare\' => \'<=\', \'type\'=>\'numeric\' );
$query[\'meta_key\'] = \'_start_ts\';
$query[\'meta_value\'] = current_time(\'timestamp\');
$query[\'meta_value_num\'] = current_time(\'timestamp\');
$query[\'meta_compare\'] = \'<=\';
$query[\'order\'] = \'DESC\';
$query[\'orderby\'] = \'meta_value\';
}
return $query;
}
这是我的网格中用来获取事件内容的HTML:
[event post_id=\'%post_id%\']
<span style="font-weight: bold;color: #597eba;">Date:</span> #_EVENTDATES<br>
<span style="font-weight: bold;color: #597eba;">Time:</span> #_EVENTTIMES<br>
<span style="font-weight: bold;color: #597eba;">Location:</span> #_LOCATIONTOWN (#_LOCATIONSTATE)
[/event]
您可以对中的事件或位置使用任何事件管理器短代码
[event]
标签。
我希望这对其他人有用。