Hi Forum,
auf meiner Seite habe ich einen Custom Post Type "wir" (mit 2 Custom Taxonomies) erstellt, der die Mitarbeiter anzeigen soll.
functions.php
Code
//custom post type wir erzeugen
add_action( 'init', 'register_cpt_wir' );
function register_cpt_wir() {
$labels = array(
'name' => _x( 'Wir', 'wir' ),
'add_new' => _x( 'Hinzufügen', 'wir' ),
'add_new_item' => _x( 'Wir hinzufügen', 'wir' ),
'edit_item' => _x( 'Wir bearbeiten', 'wir' ),
'new_item' => _x( 'Neuer Wir', 'wir' ),
'view_item' => _x( 'Wir ansehen', 'wir' ),
'search_items' => _x( 'Wir suchen', 'wir' ),
'not_found' => _x( 'Wir nicht gefunden', 'wir' ),
'not_found_in_trash' => _x( 'Kein Wir im Papierkorb gefunden', 'wir' ),
'parent_item_colon' => _x( 'Vorgesetzter', 'wir' ),
'menu_name' => _x( 'Wir', 'wir' ),
'all_items' => _x( 'Alle Wir', 'wir' )
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Wir von Npire',
'supports' => array( 'page-attributes', 'title', 'editor', 'custom-fields', 'thumbnail' ),
'taxonomies' => array( 'category', 'post_tag', 'page-category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type( 'wir', $args );
register_taxonomy( 'fertigkeiten', 'wir',
array(
'hierarchical' => false,
'label' => __('Fertigkeiten'),
'query_var' => 'fertigkeiten',
'rewrite' => array('slug' => 'fertigkeiten' )
)
);
register_taxonomy( 'interessen', 'wir',
array(
'hierarchical' => false,
'label' => __('Interessen'),
'query_var' => 'interessen',
'rewrite' => array('slug' => 'fertigkeiten' )
)
);
}
Alles anzeigen
Das Template dazu sieht folgendermaßen aus:
wir.php
PHP
<?php
/*
Template Name: Wir
*/
get_header();
$zaehler = 0;
?>
<?php query_posts('post_type=mitarbeiter&showposts=-1'); ?>
<link rel="stylesheet" href="http://www.nthusiasmus.de/wp-content/themes/npire-blog/css/wir.css">
<div id="post-container">
<div class="category-wrapper">
<h2>Mitarbeiter</h2>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $zaehler += 1; ?>
<div class="category <?php if($zaehler % 3 == 0) { echo 'no-space'; } ?>">
<div id="post-<?php the_ID(); ?>">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<div class="category-singlepic"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('custom-thumbnail-size', array(300, 210), array('class' => 'recent-thumbs')); ?></a></div>
<div class="taxonomies">
<?php echo get_the_term_list($post->ID, 'interessen', 'Interessen: ', ', ', ''); ?><br />
<?php echo get_the_term_list($post->ID, 'fertigkeiten', 'Fertigkeiten: ', ', ', ''); ?>
</div>
<div class="text"><?php the_content(); ?></div>
<hr />
<div class="link-icons">
<?php
echo '<ul>';
$key_1_value = get_post_meta($post->ID, 'url', true);
// check if the custom field has a value
if ($key_1_value != '') {
echo '<li class="homepage"><a href="' . $key_1_value . '" target="_blank"><span class="icon"> </span></a></li>';
}
?>
<?php
$key_2_value = get_post_meta($post->ID, 'twitter_url', true);
// check if the custom field has a value
if ($key_2_value != '') {
echo '<li class="twitter"><a href="' . $key_2_value . '" target="_blank"><span class="icon"> </span></a></li>';
}
?>
<?php
$key_3_value = get_post_meta($post->ID, 'facebook_url', true);
// check if the custom field has a value
if ($key_3_value != '') {
echo '<li class="facebook"><a href="' . $key_3_value . '" target="_blank"><span class="icon"> </span></a></li>';
}
?>
<?php
$key_4_value = get_post_meta($post->ID, 'pinterest_url', true);
// check if the custom field has a value
if ($key_4_value != '') {
echo '<li class="pinterest"><a href="' . $key_4_value . '" target="_blank"><span class="icon"> </span></a></li>';
}
echo '</ul>';
?>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
Alles anzeigen
Nun habe ich eine single-wir.php angelegt:
single-wir.php
PHP
<?php get_header(); ?>
<div class="category">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="nav-below">
<div class="nav-previous"><?php next_post_link('%link', '<span class="bg-element"><span class="title">%title</span></span>'); ?></div>
<div class="nav-next"><?php previous_post_link('%link', '<span class="bg-element"><span class="title">%title</span></span>'); ?></div>
</div><!-- #nav-below -->
<h2><?php the_title(); ?></h2>
<div class="category-singlepic"><?php the_post_thumbnail('custom-thumbnail-size', array(300, 210), array('class' => 'recent-thumbs')); ?></div>
<div class="taxonomies">
<?php echo get_the_term_list($post->ID, 'interessen', 'Interessen: ', ', ', ''); ?><br />
<?php echo get_the_term_list($post->ID, 'fertigkeiten', 'Fertigkeiten: ', ', ', ''); ?>
</div>
<div id="post-<?php the_ID(); ?>">
<?php the_content(); ?>
</div>
<hr />
<div class="link-icons">
<?php
echo '<ul>';
$key_1_value = get_post_meta($post->ID, 'url', true);
// check if the custom field has a value
if ($key_1_value != '') {
echo '<li class="homepage"><a href="' . $key_1_value . '" target="_blank"><span class="icon"> </span></a></li>';
}
?>
<?php
$key_2_value = get_post_meta($post->ID, 'twitter_url', true);
// check if the custom field has a value
if ($key_2_value != '') {
echo '<li class="twitter"><a href="' . $key_2_value . '" target="_blank"><span class="icon"> </span></a></li>';
}
?>
<?php
$key_3_value = get_post_meta($post->ID, 'facebook_url', true);
// check if the custom field has a value
if ($key_3_value != '') {
echo '<li class="facebook"><a href="' . $key_3_value . '" target="_blank"><span class="icon"> </span></a></li>';
}
?>
<?php
$key_4_value = get_post_meta($post->ID, 'pinterest_url', true);
// check if the custom field has a value
if ($key_4_value != '') {
echo '<li class="pinterest"><a href="' . $key_4_value . '" target="_blank"><span class="icon"> </span></a></li>';
}
echo '</ul>';
?>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php get_footer(); ?>
Alles anzeigen
Wenn man auf der Seite aber auf einen einzelnen Mitarbeiter klickt, findet WP keinen content, daraus schließe ich, dass er die single-wir.php nicht richtig verarbeitet. Hoffentlich kann mir jemand sagen, woran das liegen mag und was ich ändern muss, damit es funktioniert.
Gruß
Karsten