douxi7219 2013-08-24 20:00
浏览 41

自定义帖子类型未显示

I am relatively new to WordPress development, and I am attempting to build a site-specific plugin that gives me the ability to have a photo album gallery.

A Little Background

Each image will be treated as an attachment (thus getting it’s own single page). I will use the built-in featured thumbnails for album cover photo (Source: http://www.wpbeginner.com/wp-tutorials/how-to-create-a-photo-album-gallery-in-wordpress-without-a-plugin/comment-page-1/#comment-182006)

I essentially have four new files, algallery.php, style.css in my plugin folder and two template folders under templates of a child theme of Roots, archive-albums.php, and single-albums.php.

My problem so far is that when I have implemented get_template_part('templates/archive', 'albums'), I have my "grid" and CSS rendered, but WordPress isn't finding my album posts I've created, and these posts were created with a custom post type. To give you an idea of the approach:

<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>';
        }

    }
}
?>

I have WP_DEBUG on as well, and I have yet to find the issue. What may be the problem?

  • 写回答

1条回答 默认 最新

  • doutongfu9484 2013-08-26 18:44
    关注

    What if you add a global $post; at the top of your code ?

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据