Customizing Custom Post Type output


Hey Wyn,

Beans displays custom post type posts and taxonomies they same way it would display pages. Accessing your post type and tanoxomies would depend on how your permalinks are set, Beans will treat is like WP Core themes would do.

I am not sure I understand 100% what you are trying to do and what can't you get to work. Could you very simply explain what part isn't working and where you are stuck at.

Thanks 🙂


I found this post when I search solution for custom types for show testymonials... After more search in WP codex i found solution and I want to share with community.

For this i used approach describede here: https://www.smashingmagazine.com/2012/11/complete-guide-custom-post-types/

I split my code in three parts:

  1. Add Custom post type,
  2. Add custom taxonomy (for categories),
  3. Display all post type posts by name in a loop.

1. Add Custom post type

function custom_post_testymonial() {
  $labels = array(
    'name'               => _x( 'Testymonials', 'post type general name' ),
    'singular_name'      => _x( 'Testymonial', 'post type singular name' ),
    'add_new'            => _x( 'Add New', 'testymonial' ),
    'add_new_item'       => __( 'Add New Testymonial' ),
    'edit_item'          => __( 'Edit Testymonial' ),
    'new_item'           => __( 'New Testymonial' ),
    'all_items'          => __( 'All Testymonials' ),
    'view_item'          => __( 'View Testymonial' ),
    'search_items'       => __( 'Search Testymonial' ),
    'not_found'          => __( 'No Testymonial found' ),
    'not_found_in_trash' => __( 'No Testymonial found in trash' ), 
    'parent_item_colon'  => '',
    'menu_name'          => 'Testymonials'
  );
  $args = array(
    'labels'        => $labels,
    'description'   => 'Holds Testymonials data',
    'public'        => true,
    'menu_position' => 5,
    'supports'      => array( 'title', 'editor' ),
    'has_archive'   => true,
  );
  register_post_type( 'testymonial', $args ); 
}
add_action( 'init', 'custom_post_testymonial' );

2. Add custom taxonomy

function custom_taxonomies_testymonial() {
  $labels = array(
    'name'              => _x( 'Testymonial Categories', 'taxonomy general name' ),
    'singular_name'     => _x( 'Testymonial Category', 'taxonomy singular name' ),
    'search_items'      => __( 'Search Testymonial Categories' ),
    'all_items'         => __( 'All Testymonial Categories' ),
    'parent_item'       => __( 'Parent Testymonial Category' ),
    'parent_item_colon' => __( 'Parent Testymonial Category:' ),
    'edit_item'         => __( 'Edit Testymonial Category' ), 
    'update_item'       => __( 'Update Testymonial Category' ),
    'add_new_item'      => __( 'Add New Testymonial Category' ),
    'new_item_name'     => __( 'New Testymonial Category' ),
    'menu_name'         => __( 'Testymonial Categories' ),
  );
  $args = array(
    'labels' => $labels,
    'hierarchical' => true,
  );
  register_taxonomy( 'testymonial_category', 'testymonial', $args );
}
add_action( 'init', 'custom_taxonomies_testymonial', 0 );

3. Display posts in a loop

add_action( 'beans_main_after_markup', 'add_testymonials' );
function add_testymonials() {
    ?>

    <section class="uk-container uk-container-center uk-block tm-testymonials">
        <?php 

        //Define custom post type name in the arguments
        $args = array('post_type' => 'testymonial');

        // Define the loop based on arguments
        $loop = new WP_Query( $args );

        //Display the contents
        while ( $loop->have_posts() ) : $loop->the_post();
        ?>
        <h1><?php the_title(); ?></h1>
        <div>
        <?php the_content(); ?>
        </div>
        <?php endwhile;?>
    </section>

    <?php
}

Write a reply

Login or register to write a reply, it's free!