2016-07-22 11 views
2

ich diesen Brauch Post Typbenutzerdefinierte Post-Typ leitet zur Startseite in Wordpress

function my_custom_post_game() { 
$labels = array(
'name'    => _x('Game', 'post type general name'), 
'singular_name'  => _x('Games', 'post type singular name'), 
'add_new'   => _x('Add New', 'Game'), 
'add_new_item'  => __('Add New Game'), 
'rewrite'   =>array('slug' => 'game'), 
'edit_item'   => __('Edit Game'), 
'new_item'   => __('New Game'), 
'all_items'   => __('All Games'), 
'view_item'   => __('View Game'), 
'search_items'  => __('Search Game'), 
'not_found'   => __('No Games found'), 
'not_found_in_trash' => __('No Games found in the Trash'), 
'parent_item_colon' => '', 
'menu_name'   => 'Games' 
); 
$args = array(
'labels'  => $labels, 
'description' => 'Holds our Games and Game specific data', 
'public'  => true, 
'menu_position' => 5, 
'supports'  => array('title', 'editor', 'thumbnail','custom-fields',    'comments'), 
'has_archive' => true, 
); 
register_post_type('games', $args); 
} 
add_action('init', 'my_custom_post_game'); 
erstellt

Dies ist die Schleife auf der Homepage

$counter = 0; 
     $args = array('post_type' => 'Game', 'posts_per_page' => 10); 
     $loop = new WP_Query($args); 
    while ($loop->have_posts()) : $loop->the_post(); 
    echo $post_id[rand(0,sizeof($post_id))]; 
    if($counter < 2){ 
     ?> 
     <a href=<?php get_post_permalink()?>> 
     <div id="mypost" class="col-md-5" style="min-height:400px;"> 
     <?php the_post_thumbnail('large'); 
     ?> 
     </div> 
     </a> 
     <div class="col-md-1"></div> 
    <?php 
    $counter++; 
    } 
    else {?> 
    <a href=<?php get_post_permalink()?>> 
    <div id="mypost" class="col-md-3" href=<?php get_permalink()?>> 
     <!-- post display --> <?php echo get_post_permalink()?> 
     <?php the_post_thumbnail('medium'); ?> 
     </div> 
    </a> 
     <div class="col-md-1"></div> 
     <?php 
     } 
    endwhile; ?> 

permalink gibt http://localhost/indigamer/?post_type=game&p=63

aber wenn ich mit der rechten Maustaste auf den Div-Block klicke und den Link kopiere Lage, es einen Link gibt

Ich habe erstellt Single-game.php in meinem Thema Stammordner

Hier ist der Code

<?php get_header(); ?> 

<div id="primary" class="content-area"> 

    <main id="main" class="site-main site-main--single" role="main"> 

    test 

    </main><!-- #main --> 

</div><!-- #primary --> 
+0

funktioniert immer noch nicht. Selbes Problem –

+0

Hast du jeden Post auf deiner Homepage bekommen? Könnten Sie mir bitte mitteilen, ob Sie die Seitenvorlage für die Startseite verwendet haben? – purvik7373

Antwort

1

Ich glaube, Sie ein paar Probleme haben zur Startseite in deinem Code.

Versuchen Sie:

$args = array(
'labels'  => $labels, 
'description' => 'Holds our Games and Game specific data', 
'public'  => true, 
'menu_position' => 5, 
'supports'  => array('title', 'editor', 'thumbnail','custom-fields',    'comments'), 
'rewrite' => array('slug' => 'games'), 
'has_archive' => true, 
); 
register_post_type('games', $args); 

in der WP-Abfrage verwenden, um die Schnecke:

$args = array('post_type' => 'game', 'posts_per_page' => 10); 

nicht vergessen

wp_reset_postdata(); 

EDIT hinzuzufügen: ein paar mehr Fehler Saw: Sie müssen

0 tun
+0

funktioniert immer noch nicht –

+0

Können Sie den eigentlichen Beitrag besuchen? – brianxautumn

+0

Kannst du mir auch zeigen, was deine Ausgabe ist? – brianxautumn