Hier ist der Aktuell Stand:
Wenn ich auf das Submenü AddNew klicke, soll eine Unterseite mit dem Formular zum anlegen neuer Datensätze angezeigt werden.
Wie muss ich das submenü ändern, bzw. wie binde ich diese Seite aus dem Plug-in Ordner ein?
PHP
<?PHP
/*
Plugin Name: Wanderführer - Verwalten
Plugin URI:
Description: Dieses Plugin erstellt eine Übersicht der Wanderführer.
Author: Matthias Reichert
Version: 1.0
Author URI: http://www.wandernimsaaletal.de
*/
add_action('admin_menu', 'bookAddMenu');
function bookAddMenu() {
add_menu_page('Wanderführer Verwalten', 'Wanderführer', 10, __FILE__, 'start');
add_submenu_page(__FILE__, 'Add New', 'Add New', 10, 'addnew', 'addnew');
add_submenu_page(__FILE__, 'Help', 'Help', 10, 'help', 'help');
}
function addnew() {
echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>';
echo '<h2>Neuen Eintrag anlegen:</h2>';
echo '</div>';
// Formular zum anlegen
}
function create_mybooks()
{
// do NOT forget this global
global $wpdb;
$table_name = $wpdb->prefix . "mybooks";
// this if statement makes sure that the table doe not exist already
if($wpdb->get_var("show tables like ".$table_name."") != 'wp_mybooks')
{
// Alte Tabelle löschen
$sql1 = "DROP TABLE IF EXISTS ".$table_name."";
$wpdb->query($sql1);
// Tabelle installieren
$sql2 = "
CREATE TABLE $table_name(
book_id int auto_increment not null,
book_title varchar(175),
book_desc text,
book_ausgabe varchar(5),
book_jahr varchar(5),
book_post_url varchar(125),
book_anhang1 varchar(100),
book_anhang2 varchar(100),
book_images varchar(100),
PRIMARY KEY (`book_id`)
)";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql2);
// Beispieldaten installieren
$wpdb->insert($table_name , array(
'book_title' => "Von der Quelle nach Alsleben" ,
'book_desc' => "Lorem ipsum in nulla ligula donec mollis massa porttitor ullamcorper risus, eu platea fringilla habitasse suscipit pellentesque donec est habitant, vehicula tempor ultrices placerat sociosqu ultrices consectetur ullamcorper tincidunt. quisque tellus ante nostra euismod nec suspendisse sem, curabitur elit malesuada lacus viverra sagittis sit ornare, orci augue nullam adipiscing pulvinar libero.",
'book_post_url' => "14",
'book_ausgabe' => "1",
'book_jahr' => "2013",
'book_anhang1' => "../wp-content/uploads/flipbooks/Wandern_FSW_1",
'book_anhang2' => "../wp-content/uploads/pdf/FSW_Ausgabe_1",
'book_images' => "../wp-content/uploads/flipbooks/Wandern_FSW_1/files/shot.png"
));
$wpdb->insert($table_name , array(
'book_title' => "Test Ausgabe 2" ,
'book_desc' => "Lorem ipsum in nulla ligula donec mollis massa porttitor ullamcorper risus, eu platea fringilla habitasse suscipit pellentesque donec est habitant, vehicula tempor ultrices placerat sociosqu ultrices consectetur ullamcorper tincidunt. quisque tellus ante nostra euismod nec suspendisse sem, curabitur elit malesuada lacus viverra sagittis sit ornare, orci augue nullam adipiscing pulvinar libero.",
'book_post_url' => "14",
'book_ausgabe' => "2",
'book_jahr' => "2013",
'book_anhang1' => "../wp-content/uploads/flipbooks/Wandern_FSW_2",
'book_anhang2' => "../wp-content/uploads/pdf/FSW_Ausgabe_2",
'book_images' => "../wp-content/uploads/flipbooks/Wandern_FSW_2/files/shot.png"
));
}
}
// this hook will cause our creation function to run when the plugin is activated
register_activation_hook( __FILE__, 'create_mybooks' );
// Startseite anzeigen
function start() {
global $wpdb;
$table_name = $wpdb->prefix . "mybooks";
print "<div id=\"icon-themes\" class=\"icon32\"><br></div>";
print "<div class=\"wrap\">";
print "<h2>Wanderführer Verwalten:</h2> <br>";
if ( current_user_can( 'manage_options' ) ) {
/* A user with admin privileges */
print " <p> Hier finden Sie eine Übersicht der Wanderführer : </p> <br>";
print "<div class=\"tablenav top\">";
print "<form enctype=\"multipart/form-data\" method=\"POST\" style=\"float:left; margin:5px 20px 0 0\">";
print "<input type=\"submit\" name=\"addnew\" value=\"Add New\" />";
print "</form>";
print "</div> <br>";
print "<table cellspacing=\"0\" class=\"wp-list-table widefat plugins\">";
print "<thead>";
print "<tr>";
print "<th style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\">View:</th>";
print "<th style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\">Ausgabe:</th>";
print "<th style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\">Erstellt:</th>";
print "<th style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\">Beschreibung:</th>";
print "<th style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\">Aktionen:</th>";
print "</tr>";
print "</thead>";
print"<tfoot>";
print"<tr>";
print "<th style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\"> </th>";
print "<th style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\"> </th>";
print "<th style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\"> </th>";
print "<th style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\"> </th>";
print "<th style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\"> </th>";
print "</tr>";
print "</tfoot>";
// Daten ausgeben
$booksdata = $wpdb->get_results(
"
SELECT book_title,book_desc,book_ausgabe,book_jahr,book_ausgabe,book_images,book_anhang1
FROM $table_name
ORDER BY book_id ASC
"
);
foreach ( $booksdata as $books )
{
print"<tr>";
print "<td style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\"><a href=\"".$books->book_anhang1."/index.html\" target=\"_blank\"><img src=\"".$books->book_images."\"></a></td>";
print "<td style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\">Ausgabe ".$books->book_ausgabe."</td>";
print "<td style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\">".$books->book_jahr."</td>";
print "<td style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\"> ".$books->book_title." <br> ".$books->book_desc." </td>";
print "<td style=\"\" class=\"manage-column\" id=\"name\" scope=\"col\">Edit | Delete</td>";
print "</tr>";
}
print "<tbody id=\"the-list\">";
print "</tbody>";
print "</table>";
$book_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM ".$table_name.""));
echo '<p>Anzahl der Bücher: ' . $book_count . '</p>';
}
print "</div>";
}
// Startseite anzeigen
function help() {
print "<div id=\"icon-themes\" class=\"icon32\"><br></div>";
print "<h2>Wanderführer Verwalten</h2>";
if ( current_user_can( 'manage_options' ) ) {
/* A user with admin privileges */
print "<h3>Dokumentation:</h3>";
}
}
?>
Alles anzeigen