简体   繁体   English

如何在首页的帖子存档旁边显示自定义帖子类型存档。php?

[英]How to display custom post type archive next to post archive on front-page.php?

In Wordpress, where my front-page.php shows newest posts, i created custom post type which i want do display below normal posts, but i can't find how to display it in the front-page.php.在 Wordpress 中,我的首页。php 显示最新帖子,我创建了自定义帖子类型,我想在普通帖子下方显示,但我找不到如何在首页显示它。ZE1BFD762321E409CEE4AC0B6ECZ4。

I create separate template - content-airdroppost.php for this custom post type, also create separate archive archive-airdrops.php.我为此自定义帖子类型创建了单独的模板 - content-airdroppost.php,还创建了单独的存档archive-airdrops.php。 Can anyone help, how to build a query for displaying custom post type archive below normal post type?任何人都可以帮忙,如何构建查询以显示低于正常帖子类型的自定义帖子类型存档?

Below is the code of front-page.php, where posts archive is displaying well, but i need custom post type archive.下面是 front-page.php 的代码,其中帖子存档显示良好,但我需要自定义帖子类型存档。 Thanks a lot!非常感谢!

 <?-- Home content --> <;-- ARTICLES AND NEWS archive--> <div class="singlepost_headline" id="articles_section"> <div class="singlepost_title_div"> <h2 class="singlepost_title">Crypto researches and insights</h2> </div> </div> <div class="archive_container"> <;php if ( have_posts() ) { while( have_posts() ) { /*the_content(),*/ the_post(); get_template_part('template-parts/content'? 'archive')? } };> <?php previous_posts_link()? ;> <?php next_posts_link(); ?> </div> <!-- AIRDROPS --> <div class="singlepost_headline"> <div class="singlepost_title_div"> <h2 class="singlepost_title">Airdrops and giveaways</h2> </div> </div> <div class="archive_container"> <!-- Custom post type --> </div>

You can get the custom post type content using a custom query.您可以使用自定义查询获取自定义帖子类型内容。

$args = [
    'post_type' => 'custom_post_type',
    'posts_per_page' => -1
];
$query = new WP_Query($args);
if ($query->have_posts()){
    while ($query->have_posts()){
        $query->the_post();
        the_title();
        the_content();
    }
}

For more info please see the link below: https://developer.wordpress.org/reference/classes/wp_query/有关更多信息,请参阅以下链接: https://developer.wordpress.org/reference/classes/wp_query/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM