是否可以添加此筛选器
add_filter("the_content", "magicalender_get_event_page");
但仅限于一个特定页面,例如
if($post->post_name == "magicalenderpage")
如果我将If语句放在函数中,那么在任何其他页面上都不会显示内容,并且之后会使用else语句回显页面的内容,否则我会遇到问题,因为它会干扰其他插件,这些插件也会处理
add_filter("the_content", "foo");
magicalender\\u get\\u event\\u page函数如下
function magicalender_get_event_page(){
global $wpdb;
global $post;
if($post->post_name == "magicalenderpage"){
echo "<div class=\\"magi_calender\\">";
for($i = 0; $event = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."magicalender", ARRAY_A, $i); $i++){
echo"
<div class=\\"event\\">
<h1>".$event[\'event\']."</h1>
<h2>".date(\'m/d/Y\', strtotime($event[\'dmy\']))."</h2>
<div>".str_replace("&", "&", str_replace("'", "\'", str_replace(""", "\\"", $event[\'desc\'])))."</div>
</div>
";
}
echo "</div>";
$o = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."magioptions", ARRAY_A);
echo"
<script type=\\"text/javascript\\">
var priority = \'".$o[\'dm\']."\';
var customDays = new Array(\'".$o[\'monday\']."\', \'".$o[\'tuesday\']."\', \'".$o[\'wednesday\']."\', \'".$o[\'thursday\']."\', \'".$o[\'friday\']."\', \'".$o[\'saturday\']."\', \'".$o[\'sunday\']."\');
var customMonths = new Array(\'".$o[\'january\']."\', \'".$o[\'february\']."\', \'".$o[\'march\']."\', \'".$o[\'april\']."\', \'".$o[\'may\']."\', \'".$o[\'june\']."\', \'".$o[\'july\']."\', \'".$o[\'august\']."\', \'".$o[\'september\']."\', \'".$o[\'october\']."\', \'".$o[\'november\']."\', \'".$o[\'december\']."\');
var customMonthsShort = new Array(\'".$o[\'jan\']."\', \'".$o[\'feb\']."\', \'".$o[\'mar\']."\', \'".$o[\'apr\']."\', \'".$o[\'ma\']."\', \'".$o[\'jun\']."\', \'".$o[\'jul\']."\', \'".$o[\'aug\']."\', \'".$o[\'sep\']."\', \'".$o[\'oct\']."\', \'".$o[\'nov\']."\', \'".$o[\'dec\']."\');
jQuery(\\".magi_calender\\").magiCalender(priority, customDays, customMonths, customMonthsShort);
</script>
";
}
else{
return $content;
}
}