php 培训笔记
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 培训笔记相关的知识,希望对你有一定的参考价值。
<?php
$manufacturer = get_terms(array(
'taxonomy' => 'bundle-manufacturer',
'hide_empty' => true
));
foreach ($manufacturers as $manufacturer) {
?>
<li>
<input type="radio" id="category-<?= $manufacturer->term_id; ?>" name="category[]" value="<?= get_term_link($manufacturer); ?>"<?= $manufacturer_id == $manufacturer->term_id?' checked':''; ?>>
<label for="category-<?= $manufacturer->term_id; ?>"><?= $manufacturer->name; ?></label>
</input>
</li>
<?php } ?>
<?php
// Training Courses
function create_post_type_name() {
register_post_type( 'training-course',
array(
'supports' => array( 'page-attributes' ),
'labels' => array(
'name' => __( 'Training Courses' ),
'singular_name' => __( 'Training Course' ),
'add_new' => __( 'Add New Course' ),
'add_new_item' => __( 'Add New Course' )
),
'menu_icon' => 'dashicons-admin-home',
'public' => true,
'has_archive' => 'training-course',
'menu_position' => 5,
'hierarchical' => true
)
);
}
add_action( 'init', 'create_post_type_name' );
function training_course_name() { //Add Taxonomy Name
register_taxonomy(
'course', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
'training-course', //post type name
array(
'hierarchical' => false,
'labels' => array(
'name' => __( 'Training Courses' ),
'singular_name' => __( 'Training Course' ),
'menu_name' => __( 'Create / Edit Training Courses' ),
'add_new' => __ ( 'Add New Training Course' ),
'add_new_item' => __( 'Add New Training Course', 'textdomain' ),
'edit_item' => __( 'Edit Training Course' )
),
'query_var' => true,
'rewrite' => array(
'slug' => 'course', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
)
)
);
}
add_action( 'init', 'training_course_taxonomy'); //Register the taxonomy
function training_location_taxonomy() {
register_taxonomy(
'location', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
'training-course', //post type name
array(
'hierarchical' => false,
'labels' => array(
'name' => __( 'Training Locations' ),
'singular_name' => __( 'Training Location' ),
'menu_name' => __( 'Create / Edit Training Locations' ),
'add_new' => __ ( 'Add New Training Location' ),
'add_new_item' => __( 'Add New Training Location', 'textdomain' ),
'edit_item' => __( 'Edit Training Location' )
),
'label' => 'Training Locations', //Display name
'query_var' => true,
'rewrite' => array(
'slug' => 'location', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
)
)
);
}
add_action( 'init', 'training_location_taxonomy');
?>
<?php
/*
sets a variable to the get the fields from the taxonomys and the sets it to the term id of the variable
*/
$course_location = get_field('location')->term_id;
$course_details = get_field('training_course')->term_id;
$course_dates = get_field('dates');
?>
/*
Create a new ACF Field Group
Assign the field group to;
Taxonomy - is equal to - training location (training location is the taxonomys singular name)
*/
// Getting the acf field information from the taxonomy location
<?= get_field('course_start_time');
$course_location = get_field('location')->term_id; //Gets the term id for the location taxonomy and sets it to a variable titled course_location
echo(get_field('course_start_time', 'location_' . $course_location)); // prints out the cours_start_time field that is stored within the locations taxonomy
?>
// When getting information from a repeater first
<?php
$i = 1;
?>
<?php
if( have_rows('course_information', 'course_' . $course_details) ): //'course_information' => repeater field name, 'course__' => taxonomy name . (php concatination) $course_details => the name of the variable to get the taxonomys term id
while ( have_rows('course_information', 'course_' . $course_details) ) : the_row();
?>
<div class="tab-title <?= $i == 1?' active':''; ?>" data-tab="<?= $i; ?>">
<?= get_sub_field('tab_title'); ?>
</div>
<div class="tab-content <?= $i == 1?' active':''; ?>" id="tab-<?= $i++; ?>">
<!--Content And Image -->
<?php if(get_sub_field('content_type') == 'Content and Image'){ ?>
<?= get_sub_field('tab_content'); ?>
<?php $content_image = get_sub_field('tab__image');
if( $content_image ) { ?>
<a href="">
<img class="img-responsive" src="<?php echo $content_image['sizes']['large']; ?>" />
</a>
<?php } ?>
<a href="<?php echo get_sub_field('tab__image')['sizes']['flex_medium']; ?>"></a>
<?php } else if(get_sub_field('content_type') == 'Data Sheet'){ ?>
<?php
$file = get_sub_field('course_data_sheet_pdf') ;
if( $file ): ?>
<a href="<?php echo $file['url']; ?>" target="_blank">
<a class="down-load-course-pdf" href="<?php echo $file['url']; ?>" target="_blank">Training Data Sheet</a>
</a>
<?php endif; ?>
<?php } ?>
</div>
<?php endwhile;
endif;
?>
以上是关于php 培训笔记的主要内容,如果未能解决你的问题,请参考以下文章