0

我有 2 种帖子类型,一种是游戏,另一种是我试图包含在此循环中的电影,我得到了帮助,所以我不确定要更改什么:

<?php if ( have_posts() ) : ?>


    <?php /* Start the Loop */ ?>

    <?php
    $query = new WP_Query( array( 'tag__not_in' => array( 20 ) ) );/* Exclude Tag 20 (reviews)*/
    while( $query->have_posts() ):
    $query->the_post();

    get_template_part( 'content', get_post_format() );

    endwhile;

    ?>

<?php else : ?>

    <?php get_template_part( 'no-results', 'index' ); ?>

<?php endif; ?>

我会在哪里包含这些帖子类型?


编辑:我更新了循环,但页面只是空白/白色。这是我所拥有的:

<?php if ( have_posts() ) : ?>


<?php /* Start the Loop */ ?>

<?php
$query = new WP_Query( array( 'post_type' => array( 'movies_cp','gaming_cp'), 'tag__not_in' => array( 20 )) )
while( $query->have_posts() ):
$query->the_post();

get_template_part( 'content', get_post_format() );

endwhile;

?>

<?php else : ?>

<?php get_template_part( 'no-results', 'index' ); ?>

<?php endif; ?>

电影自定义帖子类型(使用自定义帖子类型 UI 插件):

register_post_type('movies_cp', array(  'label' => 'Movie Posts','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,'rewrite' => array('slug' => 'movies'),'query_var' => true,'exclude_from_search' => false,'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes',),'taxonomies' => array('category','post_tag',),'labels' => array (
  'name' => 'Movie Posts',
  'singular_name' => 'Movie Post',
  'menu_name' => 'Movie Posts',
  'add_new' => 'Add Movie Post',
  'add_new_item' => 'Add New Movie Post',
  'edit' => 'Edit',
  'edit_item' => 'Edit Movie Post',
  'new_item' => 'New Movie Post',
  'view' => 'View Movie Post',
  'view_item' => 'View Movie Post',
  'search_items' => 'Search Movie Posts',
  'not_found' => 'No Movie Posts Found',
  'not_found_in_trash' => 'No Movie Posts Found in Trash',
  'parent' => 'Parent Movie Post',
),) );
4

1 回答 1

3

您想获取多于一种帖子类型的帖子吗?如果是,下面是可以帮助您的代码。

$query = new WP_Query( array( 'post_type' => array( 'gaming','movie'), 'tag__not_in' => array( 20 )) )

http://codex.wordpress.org/Class_Reference/WP_Query

于 2012-11-11T11:20:21.340 回答