jeudi 3 mars 2016

How to display custom post type category list using Advanced Custom Fields - wordpress

I have installed Advanced Custom Fields 4.4.5 wordpress plugin, and i have created a custom post type called "albums". Albums custom post type contains two parent categories (Birds and Animals) with featured image. Each parent category have minimum one child category(Birds->Cuckoo and Animals->Dog) with featured image. I'm using "Categories Images" Plugin to add featured image for categories.

I want to display the parent category with featured image in my one of the template page(twentysixteen theme). When I click the link or featured it should go to respective child category. The child category page also should display category name with featured image. if we click any one of the child category it should list the posts in that category with post featured image.

Advanced Custom Fields Field Group

Custom post(Birds->Cuckoo->Cuckoo-1)

Here is my Archive file(archive-albums.php)

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
    <?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>
        <?php   
        while ( have_posts() ) : the_post();
            get_template_part( 'template-parts/content', get_post_format() );       
        endwhile;
        the_posts_pagination( array(
            'prev_text'          => __( 'Previous page', 'twentysixteen' ),
            'next_text'          => __( 'Next page', 'twentysixteen' ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>',
        ) );
    else :
        get_template_part( 'template-parts/content', 'none' );

    endif;
    ?>
    </main>
  </div>

And this is my Post page(single-albums.php)

<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">

    <?php
    // Start the loop.
    while ( have_posts() ) : the_post();

        // Include the single post content template.
        get_template_part( 'template-parts/content', 'single' );

        // If comments are open or we have at least one comment, load up the comment template.
        if ( comments_open() || get_comments_number() ) {
            comments_template();
        }

        if ( is_singular( 'attachment' ) ) {
            // Parent post navigation.
            the_post_navigation( array(
                'prev_text' => _x( '<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'twentysixteen' ),
            ) );
        } elseif ( is_singular( 'post' ) ) {
            // Previous/next post navigation.
            the_post_navigation( array(
                'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentysixteen' ) . '</span> ' .
                    '<span class="screen-reader-text">' . __( 'Next post:', 'twentysixteen' ) . '</span> ' .
                    '<span class="post-title">%title</span>',
                'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentysixteen' ) . '</span> ' .
                    '<span class="screen-reader-text">' . __( 'Previous post:', 'twentysixteen' ) . '</span> ' .
                    '<span class="post-title">%title</span>',
            ) );
        }

        // End of the loop.
    endwhile;
    ?>

 </main><!-- .site-main -->

 <?php get_sidebar( 'content-bottom' ); ?>

</div>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire