gpt4 book ai didi

php - 自定义帖子类型未出现

转载 作者:搜寻专家 更新时间:2023-10-31 21:36:25 24 4
gpt4 key购买 nike

我是 WordPress 开发的新手,我正在尝试构建一个特定于站点的插件,使我能够拥有相册画廊。

一点背景

每张图片都将被视为附件(从而获得自己的单页)。我将使用内置的特色缩略图作为专辑封面照片(来源:http://www.wpbeginner.com/wp-tutorials/how-to-create-a-photo-album-gallery-in-wordpress-without-a-plugin/comment-page-1/#comment-182006)

我基本上有四个新文件,algallery.php、style.css 在我的插件文件夹中,还有两个模板文件夹在 Roots 的子主题模板下,archive-albums.php 和 single-albums.php。

到目前为止,我的问题是,当我实现 get_template_part('templates/archive', 'albums') 时,我呈现了“网格”和 CSS,但 WordPress 没有找到我的我创建的相册帖子,这些帖子是使用自定义帖子类型创建的。让您了解该方法:

<li class="album-grid">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail('album-grid'); ?>
</a>
</li>

<?php if ( $post->post_type == 'albums' && $post->post_status == 'publish' ) {
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id()
) );

if ( $attachments ) {
foreach ( $attachments as $attachment ) {
$class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type );
$title = wp_get_attachment_link( $attachment->ID, 'album-grid', true );
echo '<li class="' . $class . ' album-grid">' . $title . '</li>';
}

}
}
?>

我也有 WP_DEBUG,但我还没有找到问题所在。可能是什么问题?

最佳答案

如果您在代码顶部添加 global $post; 会怎样?

关于php - 自定义帖子类型未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18422602/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com