How to Create Archive Template for Custom Post Type in Genesis

How to Create Archive Template for Custom Post Type in Genesis

wprocket

I have created an archive template for custom post type in Genesis. I want to show my custom post ‘code’ into an archive template. Here is the snippet of the template:

/**
 * Template Name: Code Snippets Archive
 * Description: Used as a page template to show custom-post-type 'code'
 */
 
// Add 'code_snippet' ID
function be_site_inner_attr( $attributes ) {
    
    // Add an id of 'code_snippet' for accessible skip links
    $attributes['id'] = 'code_snippet';
    
    // Add the attributes from .entry, since this replaces the main entry
    $attributes = wp_parse_args( $attributes, genesis_attributes_entry( array() ) );
    
    return $attributes;
}

add_filter( 'genesis_attr_body', 'be_site_inner_attr' );
 
// Remove standard post content output
remove_action( 'genesis_post_content', 'genesis_do_post_content' );
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
 
add_action( 'genesis_entry_content', 'code_archive_content' );
add_action( 'genesis_post_content', 'code_archive_content' );

/**
 * This function outputs sitemap-esque columns displaying all pages,
 * @author Anwer Ashif
 * @link   https://rainastudio.com/
 */
function code_archive_content() { ?>
 
    <h1><?php _e( 'All Code Snippets:', 'genesis' ); ?></h1>
    <ul>
        <?php wp_get_archives( 'type=postbypost&post_type=code' ); ?>
    </ul>
 
<?php
}
 
genesis();

 

GenesisPro728x90

Facebook
Twitter
LinkedIn
Pinterest
Tumblr
Anwer Ashif

Anwer Ashif

Founder of RainaStudio. Help businesses and individuals to create and outstand their online presence. Our success rate is measurable. Our blog served all around the world and counting.

Leave a Reply

Your email address will not be published. Required fields are marked *