很抱歉打扰你们,但这让我发疯了,我知道我错过了一些明显的东西。
我想在循环中以不同的方式显示不同的帖子类型。我正在尝试使用get\\u post\\u type()和if获取post类型。问题是,我得到的只是邮寄。每个帖子都返回为帖子。我并没有在自定义帖子类型方面做任何特别的事情,只是视频和标准。
这是我的循环:
<?php
get_header();
if ( have_posts() ) : while ( have_posts() ) : the_post();
printf( __( \'The post type is: %s\', \'textdomain\' ), get_post_type($post->ID) );
if ( \'Video\' == get_post_type() ) { ?>
<div id="the_post">
<div id="post_stuff">
<div id="the_category"><?php the_category(); ?></div>
<div id="the_title"><?php the_title(); ?></div>
<div id="the_excerpt"><?php the_excerpt(); ?></div>
<div id="the_links">
<?php $youtubelink = get_post_meta( $post->ID, \'youtube_link\', true ); ?>
<?php $youtubeembed = get_post_meta( $post->ID, \'youtube_embed\', true ); ?>
<?php
if ($youtubeembed) { ?>
<div id="front_youtube_embed"><?php $post_meta_value = get_post_meta( $post->ID, \'youtube_embed\', true ); print ($post_meta_value); ?></div>
<?php } ?>
<?php
if ($youtubelink) { ?>
<div id="front_youtube_button"><a href=" <?php print ($youtubelink); ?> ">YouTube</a></div>
<?php } ?>
</div>
</div>
</div>
<?php } else { ?>
<div id="the_post">
<div id="the_thumbnail"><?php the_post_thumbnail(); ?></div>
<div id="post_stuff">
<div id="the_category"><?php the_category(); ?></div>
<div id="the_title"><?php the_title(); ?></div>
<div id="the_excerpt"><?php the_excerpt();?></div>
<div id="the_links">
<?php $spreakerlink = get_post_meta( $post->ID, \'spreaker_link\', true ); ?>
<?php $soundcloudlink = get_post_meta( $post->ID, \'soundcloud_link\', true ); ?>
<?php $youtubelink = get_post_meta( $post->ID, \'youtube_link\', true ); ?>
<?php
if ($spreakerlink) { ?>
<div id="front_spreaker_button"><a href=" <?php print ($spreakerlink); ?> ">Spreaker</a></div>
<?php } ?>
<?php
if ($soundcloudlink) { ?>
<div id="front_soundcloud_button"><a href=" <?php print ($soundcloudlink); ?> ">Soundcloud</a></div>
<?php } ?>
<?php
if ($youtubelink) { ?>
<div id="front_youtube_button"><a href=" <?php print ($youtubelink); ?> ">YouTube</a></div>
<?php } ?>
</div>
</div>
</div>
<?php
}
endwhile; else : ?>
<p><?php esc_html_e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php endif; ?>
<?php get_footer(); ?>
这是我的函数。php以防万一:
<?php
if ( ! function_exists( \'theme_setup\' ) ) :
function theme_setup() {
add_theme_support( \'automatic-feed-links\' );
add_theme_support( \'post-thumbnails\' );
register_nav_menus( array(
\'primary\' => __( \'Primary Menu\', \'myfirsttheme\' )
) );
add_theme_support( \'post-formats\', array ( \'aside\', \'gallery\', \'quote\', \'image\', \'video\' ) );
}
endif;
add_action( \'after_setup_theme\', \'theme_setup\' );
function my_style() {
wp_enqueue_style( \'style\', get_stylesheet_uri());
}
add_action( \'wp_enqueue_scripts\', \'my_style\' );
?>