Last active
August 29, 2015 14:23
-
-
Save debabratakarfa/f914757e5f5ad646c477 to your computer and use it in GitHub Desktop.
Display Data with ACF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Register Custom Post Teams | |
if ( ! function_exists('custom_post_team') ) { | |
function custom_post_team() { | |
$labels = array( | |
'name' => _x( 'Teams', 'Post Type General Name', 'text_domain' ), | |
'singular_name' => _x( 'Team', 'Post Type Singular Name', 'text_domain' ), | |
'menu_name' => __( 'Teams', 'text_domain' ), | |
'name_admin_bar' => __( 'Teams', 'text_domain' ), | |
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ), | |
'all_items' => __( 'All Teams', 'text_domain' ), | |
'add_new_item' => __( 'Add New Team Member', 'text_domain' ), | |
'add_new' => __( 'Add New', 'text_domain' ), | |
'new_item' => __( 'New Item', 'text_domain' ), | |
'edit_item' => __( 'Edit Item', 'text_domain' ), | |
'update_item' => __( 'Update Item', 'text_domain' ), | |
'view_item' => __( 'View Item', 'text_domain' ), | |
'search_items' => __( 'Search Item', 'text_domain' ), | |
'not_found' => __( 'Not found', 'text_domain' ), | |
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ), | |
); | |
$args = array( | |
'label' => __( 'teams', 'text_domain' ), | |
'description' => __( 'Team Description', 'text_domain' ), | |
'labels' => $labels, | |
'supports' => array( 'title', 'thumbnail', ), | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'menu_position' => 5, | |
'menu_icon' => 'dashicons-format-image', | |
'show_in_admin_bar' => true, | |
'show_in_nav_menus' => true, | |
'can_export' => true, | |
'has_archive' => true, | |
'exclude_from_search' => false, | |
'publicly_queryable' => true, | |
'capability_type' => 'page', | |
); | |
register_post_type( 'teams', $args ); | |
flush_rewrite_rules(); | |
} | |
// Hook into the 'init' action | |
add_action( 'init', 'custom_post_team', 0 ); | |
} | |
//Create Advance Custom Fields for Custom Post type Team | |
if(function_exists("register_field_group")) | |
{ | |
register_field_group(array ( | |
'id' => 'acf_team-details', | |
'title' => 'Team Details', | |
'fields' => array ( | |
array ( | |
'key' => 'field_557447c2dddf5', | |
'label' => 'Position', | |
'name' => 'team_position', | |
'type' => 'text', | |
'instructions' => 'Maximum 15 Characters, for Title and Position.', | |
'required' => 1, | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '', | |
'append' => '', | |
'formatting' => 'none', | |
'maxlength' => 15, | |
), | |
array ( | |
'key' => 'field_557447e9dddf6', | |
'label' => 'LindkedIn Url', | |
'name' => 'team_lindkedin_url', | |
'type' => 'text', | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '', | |
'append' => '', | |
'formatting' => 'html', | |
'maxlength' => '', | |
), | |
array ( | |
'key' => 'field_557448add22b2', | |
'label' => 'Facebook Url', | |
'name' => 'team_facebook_url', | |
'type' => 'text', | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '', | |
'append' => '', | |
'formatting' => 'html', | |
'maxlength' => '', | |
), | |
array ( | |
'key' => 'field_557448bcd22b3', | |
'label' => 'Twitter Url', | |
'name' => 'team_twitter_url', | |
'type' => 'text', | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '', | |
'append' => '', | |
'formatting' => 'html', | |
'maxlength' => '', | |
), | |
array ( | |
'key' => 'field_557448ccd22b4', | |
'label' => 'Bio Data', | |
'name' => 'team_bio_data', | |
'type' => 'wysiwyg', | |
'default_value' => '', | |
'toolbar' => 'full', | |
'media_upload' => 'yes', | |
), | |
), | |
'location' => array ( | |
array ( | |
array ( | |
'param' => 'post_type', | |
'operator' => '==', | |
'value' => 'teams', | |
'order_no' => 0, | |
'group_no' => 0, | |
), | |
), | |
), | |
'options' => array ( | |
'position' => 'normal', | |
'layout' => 'no_box', | |
'hide_on_screen' => array ( | |
), | |
), | |
'menu_order' => 0, | |
)); | |
} | |
//Display the Advance Custom Field i.e. single-team.php or index.php or home.php | |
$id = get_post($id); //Gets post ID | |
$team_title = $the_post->post_title; | |
$team_position = get_field( "team_position", $id); | |
$team_lindkedin_url = get_field( "team_lindkedin_url", $id); | |
$team_facebook_url = get_field( "team_facebook_url", $id); | |
$team_twitter_url = get_field( "team_twitter_url", $id); | |
$team_bio_data = get_field( "team_bio_data", $id); | |
//Display the Data with Featured Image | |
<div class="demo1"> | |
<?php echo get_the_post_thumbnail( $id, 'medium' ); ?> | |
<div class="clearfix"> | |
<ul class="demo_social clearfix"> | |
<li> | |
<a class="i-wrapper" href="<?php echo $team_lindkedin_url; ?>" target="_blank"> | |
<i class="social_linkedin"></i> | |
</a> | |
</li> | |
<li> | |
<a class="i-wrapper" href="<?php echo $team_twitter_url; ?>" target="_blank"> | |
<i class="social_twitter"></i> | |
</a> | |
</li> | |
<li> | |
<a class="i-wrapper" href="<?php echo $team_facebook_url; ?>" target="_blank"> | |
<i class="social_facebook"></i> | |
</a> | |
</li> | |
</ul> | |
<div class="info"> | |
<p class="name"><?php echo $team_title; ?></p> | |
<p class="pos"><?php echo $team_position; ?></p> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment