Wegen Weihnachten habe ich erst einmal nicht weiter gearbeitet. Hoffe Ihr hattet alle schöne Weihnachten :-)
Wie schon gesagt habe ich das ganze jetzt erneut ausprobiert. Mit ERFOLG :-)
Ich habe ein Child Theme erstellt und dort dann wie oben im Link beschrieben ein Custom Post Type erstellt. Nun geht das auch mit dem Permalink und die Archive Seite geht auch.
Was jetzt noch Fehlt ist das ich meine Datenbank in die Wordpress Datenbank übertrage und die Anpassung der php Daten jetzt damit auch meine Sportler geladen werden und bearbeitet werden können.
Doch eins nach dem anderen ;-)
Noch zu machen:
1. Datenbank einfügen
2. Datenbank Tabellen in Script anpassen
3. Die ArchiveSeiten etc. anpassen (sehe noch nicht schön aus!)
4. PopUp erstellen
Ich erkläre mal noch kurz was ich gemacht habe, vielleicht hat ja jemand die selben Probleme und würde dann hier fündig werden :) Hab ja auch lange auf dem Schlauch gestanden o_O
Als erstes habe ich ein Child Theme erstellt von hemingway Theme.
in meine functioins.php habe ich eingefügt:
require_once( 'post_types/product.php' );
Die product.php erstellt den CPT, die Metabox und das speichern des Wertes: (diese php Datei liegt im Child Theme im Ordner post_types)
<?php
/**
* Registriert den Post Type „product“
*/
function register_product_post_type() {
$labels = array(
'name' => __( 'Produkte', TRANSLATION_CONST ),
'singular_name' => __( 'Produkt', TRANSLATION_CONST ),
'add_new' => __( 'Hinzufügen', TRANSLATION_CONST ),
'add_new_item' => __( 'Produkt hinzufügen', TRANSLATION_CONST ),
'edit_item' => __( 'Produkt bearbeiten', TRANSLATION_CONST ),
'new_item' => __( 'Produkt hinzufügen', TRANSLATION_CONST ),
'view_item' => __( 'Produkt anzeigen', TRANSLATION_CONST ),
'view_items' => __( 'Produkte anzeigen', TRANSLATION_CONST ),
'search_items' => __( 'Produkt suchen', TRANSLATION_CONST ),
'not_found' => __( 'Keine Produkte gefunden', TRANSLATION_CONST ),
'not_found_in_trash' => __( 'Keine Produkte im Papierkorb gefunden', TRANSLATION_CONST ),
'parent_item_colon' => __( 'Übergeordnete Produkte:', TRANSLATION_CONST ),
'all_items' => __( 'Alle Produkte:', TRANSLATION_CONST ),
'archives' => __( 'Produkt Archiv:', TRANSLATION_CONST ),
'attributes' => __( 'Produkt Attribute:', TRANSLATION_CONST ),
'insert_into_item' => __( 'Zum Produkt hinzufügen', TRANSLATION_CONST ),
'uploaded_to_this_item' => __( 'Zum Produkt hinzugefügt', TRANSLATION_CONST ),
'featured_image' => __( 'Produktbild', TRANSLATION_CONST ),
'set_featured_image' => __( 'Produktbild setzen:', TRANSLATION_CONST ),
'remove_featured_image' => __( 'Produktbild entfernen:', TRANSLATION_CONST ),
'use_featured_image' => __( 'Als Produktbild verwenden:', TRANSLATION_CONST ),
'menu_name' => __( 'Produkte', TRANSLATION_CONST ),
);
$supports = array(
'title',
'editor', // Content Bereich
'excerpt', // Kurzer Auszug des Contents für Archivseiten
'author',
'thumbnail', // featured_image / Produktbild
//'trackbacks',
'custom-fields',
//'revisions',
'page-attributes',
'comments'
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => __( 'Produkte für mein eigenes E-Commerce Plugin', TRANSLATION_CONST ),
'supports' => $supports,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5, // Unterhalb der Posts
'menu_icon' => 'dashicons-card',
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'capability_type' => 'post'
);
register_post_type( 'product', $args );
}
add_action( 'init', 'register_product_post_type' );
function product_post_type_add_meta_boxes( $post ){
add_meta_box( 'price_meta_box',
'Price Detail',
'product_post_type_build_price_meta_box',
'product', 'normal', 'high'
);
}
add_action( 'add_meta_boxes_product', 'product_post_type_add_meta_boxes' );
function product_post_type_build_price_meta_box($post) {
wp_nonce_field( basename( __FILE__ ), 'product_post_type_price_meta_box_nonce' );
$current_price = get_post_meta( $post->ID, 'product_price', true );
?>
<div class="inside">
<section id="price-meta-box-container">
<p>
<input type="number" name="product_price" id="product-price"<?php echo ' value="'.$current_price.'"'; ?>>
</p>
</section>
</div>
<?php
}
function product_post_type_save_price_meta_boxes_data( $post_id ){
if ( !isset( $_POST['product_post_type_price_meta_box_nonce'] ) ||
!wp_verify_nonce(
$_POST['product_post_type_price_meta_box_nonce'],
basename( __FILE__ )
) ){
return;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
return;
if ( !current_user_can( 'edit_post', $post_id ) )
return;
if ( isset( $_REQUEST['product_price'] ) ) {
update_post_meta(
$post_id,
'product_price',
sanitize_text_field( $_POST['product_price'] )
);
}
}
add_action( 'save_post_product', 'product_post_type_save_price_meta_boxes_data', 10, 2 );
function the_product_price($post = 0, $echo = true) {
$post = get_post( $post );
$id = isset( $post->ID ) ? $post->ID : 0;
$value = get_post_meta( $id, 'product_price', true );
if($echo) {
echo sprintf(
'<span class="product-detail--price">%s %s</span>',
esc_html($value),
__('€', TRANSLATION_CONST)
);
}
else
return $value;
}
Alles anzeigen
Diese Dateien liegen im Child Theme Ordner:
archive-product.php
<?php
/**
* Template Name: Archive Product Template
*
* Description: Eine eigene Archivseite für meinen Post Type „product“
*/
get_header(); ?>
<div class="main-wrap" role="main">
<!-- Darstellung der Produkte -->
<section id="product-listing">
<?php if ( have_posts() ) : ?>
<div class="row">
<?php while ( have_posts() ) : the_post(); ?>
<div class="column"">
<?php get_template_part( 'product-content', get_post_format() ); ?>
</div>
<? endwhile; ?>
</div>
<?php endif; ?>
</section>
</div>
<?php get_footer();
Alles anzeigen
product-content.php
<?php
/**
* Das Standard-Template zum Anzeigen eines Produktes
*/
?>
<div class="product-container" id="product-<?php the_ID(); ?>">
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>">
<img src="<?php the_post_thumbnail_url( ); ?>">
</a>
<?php endif; ?>
<div class="product-content-section">
<header>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</header>
<div class="entry-content">
<?php
the_product_price(get_the_ID());
echo '<br />';
the_excerpt();
?>
</div>
</div>
</div>
Alles anzeigen
single-product.php
<?php get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<article <?php post_class() ?> id="product-<?php the_ID(); ?>">
<div class="row column" id="product-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</div>
<div class="main-wrap" role="main">
<div class="entry-content">
<div class="row">
<div class="medium-6 columns">
<?php if(has_post_thumbnail( )) : ?>
<a href="<?php the_post_thumbnail_url('large'); ?>">
<img src="<?php the_post_thumbnail_url('large'); ?>"/>
</a>
<?php endif; ?>
</div>
<div class="medium-6 columns">
<?php the_product_price(get_the_ID()); ?>
</div>
</div>
<div class="row columns">
<?php the_content(); ?>
</div>
</div>
<footer>
<?php
wp_link_pages(
array(
'before' => '<nav id="page-nav"><p>' . __( 'Produkte:', TRANSLATION_CONST ),
'after' => '</p></nav>',
)
);
?>
</footer>
<!-- Das ist das mit dem Kommentar kram -->
<?php comments_template(); ?>
</div>
</article>
<?php endwhile;?>
<?php get_footer();
Alles anzeigen
Ich werde wie gesagt das ganze jetzt weiter für mich versuchen anzupassen. Melde mich hier erneut wenn ich nicht weiter kommen bzw. wenn es klappt, wie ich es gemacht habe ;):)