【发布时间】:2021-10-13 14:03:32
【问题描述】:
卡住了! 我为我的 WP 后台制作了一个自定义帖子类型:
register_post_type('realisations',[
'label' => 'Réalisations',
'public' => true,
'menu_position' => 3,
'menu_icon' => 'dashicons-format-gallery',
'supports' => ['title', 'editor', 'thumbnail'],
]);
我希望所有文章都显示在我的自定义模板中:
<?php/* Template Name: Réalisations */?>
<?php materialis_get_header();?>
<div class="top-page">
<div class="title">
<i class="fas fa-camera"></i>
<h2>Réalisations</h2>
</div>
<div class="description-page">
<p>Le Lorem Ipsum est le faux texte standard de l'imprimerie depuis les années 1500, quand un imprimeur anonyme assembla ensemble des morceaux de texte pour réaliser un livre spécimen</p>
</div>
<div>
</div>
</div>
<?php get_footer(); ?>
所以我尝试了我找到的这个旧代码,它只显示帖子的标题,而不是里面的文章:
<?php/* Template Name: Réalisations */?>
<?php materialis_get_header();?>
<div class="top-page">
<div class="title">
<i class="fas fa-camera"></i>
<h2>Réalisations</h2>
</div>
<div class="description-page">
<p>Le Lorem Ipsum est le faux texte standard de l'imprimerie depuis les années 1500, quand un imprimeur anonyme assembla ensemble des morceaux de texte pour réaliser un livre spécimen</p>
</div>
<div>
<?php
$custom_post_types = get_post_types(
array(
// Set to FALSE to return only custom post types
'_builtin' => false,
// Set to TRUE to return only public post types
'public' => true
),
// Set to "objects", so we have the full CPT object
'objects'
);
// Add CPT permalinks to CPT objects
foreach ( $custom_post_types as $custom_post_type ) {
$custom_post_type->permalink = get_post_type_archive_link( $custom_post_type->name );
}
// Output CPT archive index permalinks list
echo '<ul>';
foreach ( $custom_post_types as $custom_post_type ) {
echo '<li>';
echo '<a href="' . $custom_post_type->permalink . '">' . $custom_post_type->name . '</a>';
echo '</li>';
}
echo '</ul>';
?>
</div>
</div>
<?php get_footer(); ?>
很抱歉成为 wordpress 中的菜鸟!并感谢您即将提供的答案!
【问题讨论】: