我正在尝试创建一个约会插件,到目前为止,我可以创建约会并查看约会的详细信息视图。
问题是,在一个名为“约会”的页面上,我不想列出所有约会,但没有显示任何内容。我还想知道,如何修改所有约会的样式。我想把它放在4列中。
我知道这些列的标记,但我不知道在哪里需要修改插件。
以下是我的插件中的5个文件:
终点站。php
<?php
/**
* Plugin Name: Termine
* Description: Terminverwaltung für Wordpress
* Author: Me
* Version: 1.0
*/
setlocale(LC_ALL, \'de_DE.UTF-8\');
require_once(\'posttype.php\');
require_once(\'datumsbox.php\');
require_once(\'termineansicht.php\');
require_once(\'seite.php\');
?>
posttype。php
<?php
add_action(\'init\',\'post_type_termine\');
function post_type_termine(){
register_post_type(
\'termine\',
array(
\'labels\' => array(
\'name\' => \'Termine\',
\'singular_name\' => \'Termin\',
\'add_new_item\' => \'Neuen Termin anlegen\'
),
\'public\' => true,
\'show_ui\' => true,
\'supports\' => array(
\'title\',\'excerpt\',\'editor\',\'thumbnail\',\'custom-fields\'
)
)
);
}
?>
datumsbox。php(用于在后端放置包含约会详细信息的框)
<?php
add_action(\'add_meta_boxes\',\'nw_termine_addmetaboxes\');
add_action(\'save_post\',\'nw_termine_savedata\');
function nw_termine_addmetaboxes(){
add_meta_box(
\'termine_metabox\',
\'Datum und Ort\',
\'termine_datumsbox\',
\'termine\',
\'normal\',
\'high\'
);
}
function termine_datumsbox(){
wp_nonce_field(\'termine_action\', \'termine_name\');
echo \'<label for="myplugin_field1">Tag: </label>\';
$wert1=get_post_meta(get_the_ID(), \'_tag\',true);
echo \'<input type="number" step="1" min="1" max="31" id="myplugin_new_field" name="myplugin_field1" value="\'.$wert1.\'" style="width:4em"/>\';
echo \'<label for="myplugin_field2">Mon.: </label>\';
$wert2=get_post_meta(get_the_ID(), \'_monat\',true);
echo \'<input type="number" step="1" min="1" max="12" id="myplugin_new_field2" name="myplugin_field2" value="\'.$wert2.\'" style="width:4em" />\';
echo \'<label for="myplugin_field3">Jahr: </label>\';
$wert3=get_post_meta(get_the_ID(), \'_jahr\',true);
echo \'<input type="number" step="1" min="2011" max="2020" id="myplugin_new_field3" name="myplugin_field3" value="\'.$wert3.\'" style="width:5em"/>\';
echo \'<br/><label for="myplugin_field4">Stunde: </label>\';
$wert4=get_post_meta(get_the_ID(), \'_stunde\',true);
echo \'<input type="number" step="1" min="0" max="23" id="myplugin_new_field4" name="myplugin_field4" value="\'.$wert4.\'" style="width:4em"/>\';
echo \'<label for="myplugin_field5">Min.: </label>\';
$wert5=get_post_meta(get_the_ID(), \'_minute\',true);
echo \'<input type="number" step="1" min="00" max="59" id="myplugin_new_field5" name="myplugin_field5" value="\'.$wert5.\'" style="width:4em"/>\';
echo \'<br/><label for="myplugin_field7">Bis: </label>\';
$wert7=get_post_meta(get_the_ID(), \'_bis\',true);
echo \'<input type="text" id="myplugin_new_field7" name="myplugin_field7" value="\'.$wert7.\'" /> (beliebiger Text)\';
echo \'<br/><br/><label for="myplugin_field6">Adresse für Google Maps: </label><br/>\';
$wert6=get_post_meta(get_the_ID(), \'_geo\',true);
echo \'<input id="myplugin_new_field6" name="myplugin_field6" value="\'.$wert6.\'" style="width:90%" />\';
echo \'<br/><br/><label for="myplugin_field8">Angezeigte Adresse: </label><br/>\';
$wert8=get_post_meta(get_the_ID(), \'_geoanzeige\',true);
echo \'<input id="myplugin_new_field8" name="myplugin_field8" value="\'.$wert8.\'" style="width:90%" />\';
}
function nw_termine_savedata($post_id){
if( defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE ) return false;
if( !current_user_can(\'edit_post\', $post_id) ) return false;
if ( !wp_verify_nonce($_POST[\'termine_name\'],\'termine_action\') ) return false;
update_post_meta($_POST[\'post_ID\'], \'_tag\', $_POST[\'myplugin_field1\'], false);
update_post_meta($_POST[\'post_ID\'], \'_monat\', $_POST[\'myplugin_field2\'], false);
update_post_meta($_POST[\'post_ID\'], \'_jahr\', $_POST[\'myplugin_field3\'], false);
update_post_meta($_POST[\'post_ID\'], \'_stunde\', $_POST[\'myplugin_field4\'], false);
update_post_meta($_POST[\'post_ID\'], \'_minute\', $_POST[\'myplugin_field5\'], false);
update_post_meta($_POST[\'post_ID\'], \'_geo\', $_POST[\'myplugin_field6\'], false);
update_post_meta($_POST[\'post_ID\'], \'_bis\', $_POST[\'myplugin_field7\'], false);
update_post_meta($_POST[\'post_ID\'], \'_geoanzeige\', $_POST[\'myplugin_field8\'], false);
$zeitstempel=mktime((int) $_POST[\'myplugin_field4\'],(int) $_POST[\'myplugin_field5\'],0,(int) $_POST[\'myplugin_field2\'],(int) $_POST[\'myplugin_field1\'],(int) $_POST[\'myplugin_field3\']);
update_post_meta($_POST[\'post_ID\'], \'_zeitstempel\', $zeitstempel, false);
}
?>
终端安全。php(约会的详细视图)
<?php
add_action(\'the_content\',\'nw_termine_ansicht\');
function nw_termine_ansicht( $content ){
if ( get_post_type() != \'termine\') return $content;
$custom = get_post_custom (get_the_ID());
$datumsformat = "%A, den %e. %B %G";
$zeitanzeige = strftime($datumsformat,$custom[\'_zeitstempel\'][0]);
if(strftime(\'%R\',$custom[\'_zeitstempel\'][0])!=\'00:00\'){
$zeitanzeige.=strftime(\', um %H:%M Uhr\',$custom[\'_zeitstempel\'][0]);
}
if(isset($custom[\'_bis\'][0]) AND $custom[\'_bis\'][0]!=\'\'){
$zeitanzeige .= \' bis \'.$custom[\'_bis\'][0];
}
$datum=\'<div class="zeitanzeige" style="\'.$options[\'style\'].\'">\'.$zeitanzeige.\'</div>\';
$ort=\'\';
if(isset($custom[\'_geo\']) AND $custom[\'_geo\'][0]!=\'\'){
$geo=urlencode($custom[\'_geo\'][0]);
if(isset($custom[\'_geoanzeige\'][0]) AND $custom[\'_geoanzeige\'][0]!=\'\') $adresse=$custom[\'_geoanzeige\'][0];
else $adresse=$custom[\'_geo\'][0];
$ort=\'<div class="googlemaps"><strong>Ort:</strong> \'.$adresse;
$ort.=\'<a href="https://maps.google.de/maps?q=\'.$geo.\'" class="aufmapsanzeigen"><img src="http://maps.googleapis.com/maps/api/staticmap?center=\'.$geo.\'&zoom=14&size=600x180&sensor=false&markers=color:green|\'.$geo.\'"/></a>\';
$ort.=\'<a href="https://maps.google.de/maps?q=\'.$geo.\'" class="aufmapsanzeigen">Auf Google Maps anzeigen »</a>\';
$ort.=\'</div>\';
}
return $datum . $content . $ort;
}
?>
终点站。php(所有约会的列表)
<?php
class terminadd{
function rewrite_post($mypost){
$mypost = stripslashes($mypost);
if(preg_match("/\\[termine\\]/",$mypost)){
$termininfo = "Termin";
// Hole alle Termine
// die vergangen sind oder noch kommen
if(isset($_GET[\'archiv\'])){
$order=\'DESC\'; $compare=\'<\';
$title="Vergangene Termine";
}else{
$order=\'ASC\'; $compare=\'>=\';
$title="Kommende Termine";
}
$posts = get_posts(
array(\'post_type\'=>\'termine\',
\'orderby\' => \'meta_value\',
\'meta_key\' => \'_zeitstempel\',
\'order\' => $order,
\'meta_query\' => array(
array(
\'key\' => \'_zeitstempel\',
\'value\' => time(),
\'compare\' => $compare
)
)
)
);
$termininfo = "$title ";
ob_start();
global $post;
foreach ($posts AS $post){
setup_postdata($post);
get_template_part( \'content\', get_post_format() );
}
$mypost = preg_replace("/\\[termine\\]/",ob_get_contents(),$mypost);
ob_end_clean();
}
return $mypost;
}
}
add_action(\'the_content\', array(new terminadd(), \'rewrite_post\'));
我已将这些文件上载到此处:
appointment plugin download