Php Wordpress:在索引页上列出多个帖子类型
我正在处理一个2017年的儿童主题,因为我想改变一些事情。 但我在实现这一想法时遇到了一个问题: 我已经创建了一个名为“video”的自定义帖子类型,但在索引页面(index.php)上,我想显示两种类型的帖子,默认帖子类型和自定义“video”帖子类型,按发布日期排序 因为我非常喜欢index.php提供最新帖子的方式,所以我不想创建自定义归档(我想我必须保留get_template_part()函数)。我只想在索引页上显示这两种帖子类型Php Wordpress:在索引页上列出多个帖子类型,php,wordpress,wordpress-theming,custom-wordpress-pages,Php,Wordpress,Wordpress Theming,Custom Wordpress Pages,我正在处理一个2017年的儿童主题,因为我想改变一些事情。 但我在实现这一想法时遇到了一个问题: 我已经创建了一个名为“video”的自定义帖子类型,但在索引页面(index.php)上,我想显示两种类型的帖子,默认帖子类型和自定义“video”帖子类型,按发布日期排序 因为我非常喜欢index.php提供最新帖子的方式,所以我不想创建自定义归档(我想我必须保留get_template_part()函数)。我只想在索引页上显示这两种帖子类型 <?php if ( have_posts()
<?php if ( have_posts() ) : ?>
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
</header><!-- .page-header -->
<?php endif; ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
if ( have_posts() ) : ?>
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/post/content', get_post_format() );
endwhile;
the_posts_pagination( array(
'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
'next_text' => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
) );
else :
get_template_part( 'template-parts/post/content', 'none' );
endif; ?>
您可以在index.php中这样做
把下面的代码放在你想显示所有文章标题和内容的地方
<?php
$args = array(
'post_type' => array( 'post', 'video' ),
'orderby' => 'date',
);
$my_query = new WP_Query( $args );
if( $my_query->have_posts() ) :
while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<div class="smal-sec">
<h3><?php the_title();?></h3>
<?php the_content();?>
</div>
<?php
endwhile;
endif;
wp_reset_query(); // Restore global post data stomped by the_post().
?>
从这个循环中,我们将能够从默认帖子和“视频”自定义帖子类型中获取所有帖子。帖子将根据日期显示 您可以在index.php中这样做
把下面的代码放在你想显示所有文章标题和内容的地方
<?php
$args = array(
'post_type' => array( 'post', 'video' ),
'orderby' => 'date',
);
$my_query = new WP_Query( $args );
if( $my_query->have_posts() ) :
while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<div class="smal-sec">
<h3><?php the_title();?></h3>
<?php the_content();?>
</div>
<?php
endwhile;
endif;
wp_reset_query(); // Restore global post data stomped by the_post().
?>
从这个循环中,我们将能够从默认帖子和“视频”自定义帖子类型中获取所有帖子。帖子将根据日期显示 老兄,你帮了我这么多!谢谢这段代码非常完美。伙计,你帮了我这么多!谢谢这段代码非常完美。