Moin Moin!
Ich möchte gern über die Seite "Hörspiele" eine ein Template ausgeben. Das funktioniert allerdings nicht da ich über /hoerspiele. Hier wird eine Archiv ausgegeben
Über Custom Post Type habe ich den Bereich Hörspiele erstellt und über Seiten die gleichnamige Seite
Wenn ich das Template auf eine andere Seite anwende sieht das Ergebnis wie auf dem Bild aus.
Wo liegt der Fehler im Code?
Freue mich über Hilfe
functions.php
PHP
function hoerspiele_custom_post_type() { $labels = array('name' => 'Hörspiele Einträge','singular_name' => 'Hörspiele','menu_name' => 'Hörspiele','parent_item_colon' => '','all_items' => 'Alle Einträge','view_item' => 'Eintrag ansehen','add_new_item' => 'Neuer Eintrag','add_new' => 'Hinzufügen','edit_item' => 'Eintrag bearbeiten','update_item' => 'Update Eintrag','search_items' => '','not_found' => '','not_found_in_trash' => '',);$rewrite = array('slug' => 'hoerspiele','with_front' => true,'pages' => true,'feeds' => true,);$args = array('labels' => $labels,'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'trackbacks', ),'taxonomies' => array( 'category', 'post_tag' ),'hierarchical' => false,'public' => true,'show_ui' => true,'show_in_menu' => true,'show_in_nav_menus' => true,'show_in_admin_bar' => true,'menu_position' => 5,'can_export' => false,'has_archive' => true,'exclude_from_search' => false,'publicly_queryable' => true,'rewrite' => $rewrite,'capability_type' => 'page',);register_post_type( 'hoerspiele', $args );
$labels = array('name' => 'Hörspiele Einträge','singular_name' => 'Hörspiele','menu_name' => 'Hörspiele','parent_item_colon' => '','all_items' => 'Alle Einträge','view_item' => 'Eintrag ansehen','add_new_item' => 'Neuer Eintrag','add_new' => 'Hinzufügen','edit_item' => 'Eintrag bearbeiten','update_item' => 'Update Eintrag','search_items' => '','not_found' => '','not_found_in_trash' => '',);$rewrite = array('slug' => 'hoerspiele','with_front' => true,'pages' => true,'feeds' => true,);$args = array('labels' => $labels,'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'trackbacks', ),'taxonomies' => array( 'category', 'post_tag' ),'hierarchical' => false,'public' => true,'show_ui' => true,'show_in_menu' => true,'show_in_nav_menus' => true,'show_in_admin_bar' => true,'menu_position' => 5,'can_export' => false,'has_archive' => true,'exclude_from_search' => false,'publicly_queryable' => true,'rewrite' => $rewrite,'capability_type' => 'page',);register_post_type( 'hoerspiele', $args ); } // Hook into the 'init' actionadd_action( 'init', 'hoerspiele_custom_post_type', 0 );
Template
PHP
<div class="gridcontainer"> <?php// Grid Parameters$counter = 1; // Start the counter$grids = 5; // Grids per row$titlelength = 40; // Length of the post titles shown below the thumbnails// The Query$args=array ('post_type' => 'hoerspiele','posts_per_page' => -1);$the_query = new WP_Query($args);// The Loopwhile ( $the_query->have_posts() ) :$the_query->the_post();// Show all columns except the right hand side columnif($counter != $grids) :?><div class="griditemleft"><div class="postimage"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a></div><!-- .postimage --><h2 class="postimage-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php if (mb_strlen($post->post_title) > $titlelength){ echo mb_substr(the_title($before = '', $after = '', FALSE), 0, $titlelength) . ' ...'; }else { the_title(); } ?></a></h2></div><!-- .griditemleft --><?php// Show the right hand side columnelseif($counter == $grids) :?><div class="griditemright"><div class="postimage"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a></div><!-- .postimage --><h2 class="postimage-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php if (mb_strlen($post->post_title) > $titlelength){ echo mb_substr(the_title($before = '', $after = '', FALSE), 0, $titlelength) . ' ...'; }else { the_title(); } ?></a></h2></div><!-- .griditemright --> <div class="clear"></div><?php$counter = 0;endif;$counter++;endwhile;wp_reset_postdata();?> </div><!-- .gridcontainer --> <?php get_footer(); ?>