1,输出图片
<?php
$s1_t_r = get_post_meta($post->ID, 's1_t_r', true);
if (is_array($s1_t_r) && $s1_t_r['url']) {
printf('<img src="%s" alt="%s">', $s1_t_r['url'], $s1_t_r['alt']);
} ?>
2,换行符转p标签
<?php
$s1_t_l = get_post_meta($post->ID, 's1_t_l', true);
foreach (explode("\n",$s1_t_l) as $value) {
printf('<p>%s</p>',$value);
}?>
3,图集输出图片组
<?php
$p_images = get_post_meta($post->ID, 'p_images', true);
$p_images_arr = [];
if ($p_images) {
$p_images_arr = explode(',', $p_images);
}
if (has_post_thumbnail()) {
array_unshift($p_images_arr, get_post_thumbnail_id());
$p_images_arr = array_unique($p_images_arr);
}
if ($p_images_arr) :
foreach ($p_images_arr as $img_id) {
$img_src = wp_get_attachment_image_url($img_id, 'full');
printf('<li><img src="%s"></li>', $img_src);
}
endif; ?>
4,循环1
5,分类页列出子分类(子导航)
<?php
global $taxonomy;
$cur_term_obj = get_queried_object();
// var_dump($cur_term_obj);
// exit;
$root_term_id = haozhuti_get_root_term_id($cur_term_obj->term_id, 'product_category');
$child_term_ids = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
'parent' => $root_term_id,
'fields' => 'ids',
)
);
foreach ($child_term_ids as $term_id) {
$cls = $cur_term_obj->term_id == $term_id ? 'common_tab_active' : '';
printf('<li class="%s"><a href="%s">%s</a></li>', $cls, get_term_link($term_id, $taxonomy), get_term($term_id, $taxonomy)->name);
}
?>
6,路径替换
<?php echo HAOZHUTI_ASSETS_URI ?>
7,文章内页
<?php echo get_the_terms($post->ID,'product_category')[0]->name ?>
8,文章循环体
<?php
while (have_posts()) {
the_post() ?>
<?php }?>
9,按钮1
<?php
if ($index_module_4['btn_tit']) { ?>
<a href="<?php echo $index_module_4['btn_link']; ?>"><?php echo $index_module_4['btn_tit']; ?></a>
<?php } ?>
10,轮播图
<?php
array(
'id' => 'index_module_1',
'type' => 'fieldset',
'title' => '模块1',
'fields' => array(
array(
'id' => 'banner',
'type' => 'group',
'title' => '',
'fields' => array(
array(
'id' => 'link',
'type' => 'text',
'title' => '链接',
),
array(
'id' => 'pc_img',
'type' => 'media',
'title' => '图片',
),
),
),
),
),
?>
<?php
$index_module_1 = hzt_admin_opt('index_module_1');
if (is_array($index_module_1) && is_array($index_module_1['banner'])) : ?>
<!--图片轮播切换1-背景-->
<section class="dt-lb1">
<div class="dt-lb1-div">
<div class="swiper-container">
<div class="swiper-wrapper">
<?php
foreach ($index_module_1['banner'] as $key => $value) {
if (is_array($value['pc_img']) && $value['pc_img']['url']) { ?>
<div class="swiper-slide">
<a href="<?php echo $value['link']; ?>" style="background-image:url('<?php echo $value['pc_img']['url'] ?>');"></a>
</div>
<?php }
} ?>
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev hide"></div>
<div class="swiper-button-next hide"></div>
</div>
</div>
</section>
<script>
var dt_lb1 = new Swiper('.dt-lb1 .swiper-container', {
loop: true, //开启循环
observer: true, //启动动态检查器,当改变swiper的样式(例如隐藏/显示)或者修改swiper的子元素时,自动初始化swiper
observeParents: true, //当Swiper的父元素变化时,swiper更新
observeSlideChildren: true, //子slide更新时,swiper是否更新
pagination: {
el: '.dt-lb1 .swiper-pagination', //开启分页器
clickable: true, //开启点击分页器控制swiper切换
},
navigation: {
prevEl: '.dt-lb1 .swiper-button-prev', //左箭头
nextEl: '.dt-lb1 .swiper-button-next', //右箭头
},
//开启自动切换
autoplay: {
delay: 3000, //三秒切换一次
stopOnLastSlide: false, //切换到最后一个时是否停止自动切换(loop模式下无效)
disableOnInteraction: false, //用户操作之后,是否继续自动切换。
},
});
//左右切换箭头-鼠标移入显示,移出隐藏
$(".dt-lb1 .swiper-container").mouseover(function() {
$(".dt-lb1 .swiper-button-prev, .dt-lb1 .swiper-button-next").removeClass('hide');
});
$(".dt-lb1 .swiper-container").mouseout(function() {
$(".dt-lb1 .swiper-button-prev, .dt-lb1 .swiper-button-next").addClass('hide');
})
//鼠标移入暂停自动切换
dt_lb1.el.onmouseover = function() {
dt_lb1.autoplay.stop();
}
//鼠标移出开始自动切换
dt_lb1.el.onmouseout = function() {
dt_lb1.autoplay.start();
}
</script>
<!--/图片轮播切换1-背景-->
<?php endif; ?>
11,导航菜单默认参数
<?php
$defaults = array(
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'container_aria_label' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'item_spacing' => 'preserve',
'depth' => 0,
'walker' => '',
'theme_location' => '',
);
?>
<?php
if (has_nav_menu('footer-menu')) {
wp_nav_menu($defaults = array(
'container' => '',
'menu_class' => 'clearfix',
'fallback_cb' => false,
'items_wrap' => '<ul class="%2$s">%3$s</ul>',
'depth' => 1,
'theme_location' => 'footer-menu',
));
}?>
11,限制安装插件
<?php
define('DISALLOW_FILE_MODS',true);
?>
12,输出背景图片样式
<?php
if (is_array($index_module_1['bg']) && $index_module_1['bg']['url']) {
$style = sprintf('style="background-image: url(%s);"', $index_module_1['bg']['url']);
} else {
$style = '';
}
?>
13,导航菜单
<?php
if (has_nav_menu('main-menu')) {
wp_nav_menu(
array(
'container' => '',
'menu' => '',
'menu_class' => '',
'menu_id' => '',
'fallback_cb' => false,
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul>%3$s</ul>',
'depth' => 1,
'theme_location' => 'main-menu',
)
);
} ?>
14,按钮
<?php
array(
'id' => 'btn_tit',
'type' => 'text',
'title' => '按钮文字',
),
array(
'id' => 'btn_link',
'type' => 'text',
'title' => '按钮链接',
),
if ($index_module_4['btn_tit']) {
printf(
'<a href="%s" class="btn idx_more">%s</a>',
$index_module_4['btn_link'],
$index_module_4['btn_tit']
);
}?>
nav walker
<?php
// 好主题
if (isset($args->walker->has_children) && $args->walker->has_children && 0 === $depth && $args->depth > 1) {
$output .= '<div class="sub_nav">';
}
// 好主题
// 好主题增加
if (0 === $depth) {
if (in_array('current-menu-item', $classes)) {
$classes[] = 'cur';
}
}
// 好主题增加
//a标签上加class
if (isset($atts['class'])) {
$atts['class'] .= ' a1';
} else {
$atts['class'] = 'a1';
}
文章分组循环
<?php
$args3 = array(
'post_type' => array('ba'),
'posts_per_page' => 2, //每组显示2个
'tax_query' => array(
array(
'taxonomy' => 'ba_cat',
'field' => 'term_id',
'terms' => [4],
'operator' => 'IN',
),
),
);
$i = 1;
$flag = false;
while (true) {
if ($flag || ($i > 10)) break;
$args3['paged'] = $i;
$query3 = new WP_Query($args3);
if ($query3->have_posts()) {
$i++; ?>
<div class="swiper-slide">
<div class="conW">
<?php
while ($query3->have_posts()) {
$query3->the_post(); ?>
<div class="con">
<a href="#" class="pic" style=" background-image:url(<?php echo haozhuti_get_post_thumbnail_img_url('680_680') ?>)">
<img src="<?php echo haozhuti_get_post_thumbnail_img_url('680_680') ?>" />
</a>
<div class="re">
<div class="reTxt">
<?php echo get_post_meta($post->ID, 'ba_content', true); ?>
</div>
<div class="reName"><?php the_title(); ?></div>
</div>
</div>
<?php }
wp_reset_postdata();
?>
</div>
</div>
<?php } else {
$flag = true;
} ?>
<?php
} ?>
简单导航菜单
<?php if (has_nav_menu('main-menu')) {
wp_nav_menu(
array(
'container' => '',
'fallback_cb' => false,
'items_wrap' => '<ul>%3$s</ul>',
'depth' => 1,
'theme_location' => 'main-menu',
)
);
} ?>
youtube
array(
'id' => 'youtube',
'type' => 'fieldset',
'title' => 'youtube 视频',
'fields' => array(
array(
'id' => 'url',
'type' => 'text',
'title' => '视频地址',
),
array(
'id' => 'w',
'type' => 'text',
'title' => '宽度',
'default' => '100%',
'desc' => '请填写具体宽度或者宽度比,如300或100%',
),
array(
'id' => 'h',
'type' => 'text',
'title' => '高度',
'default' => '600',
'desc' => '请填写具体高度值',
),
),
),
<?php
if (
is_array($five_step_2['youtube'])
&& $five_step_2['youtube']['url']
&& $five_step_2['youtube']['w']
&& $five_step_2['youtube']['h']
) {
$video_id = hzt_getYoutubeIdFromUrl($five_step_2['youtube']['url']);
if ($video_id) { ?>
<div id="ytplayer"></div>
<script>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
height: '<?php echo $five_step_2['youtube']['h'] ?>',
width: '<?php echo $five_step_2['youtube']['w'] ?>',
videoId: '<?php echo $video_id; ?>'
});
}
</script>
<?php }
} ?>
在激活/停用链接之前添加设置页面链接。
<?php
// Add plugin meta links
function WPTime_preloader_plugin_row_meta( $links, $file ) {
if ( strpos( $file, 'preloader.php' ) !== false ) {
$new_links = array(
'<a href="http://wp-plugins.in/the-preloader" target="_blank">Explanation of Use</a>',
'<a href="http://wp-plugins.in" target="_blank">More Plugins</a>'
);
$links = array_merge( $links, $new_links );
}
return $links;
}
add_filter( 'plugin_row_meta', 'WPTime_preloader_plugin_row_meta', 10, 2 );
?>
热门标签
<?php
$term_query = new WP_Term_Query(
array(
'taxonomy' => 'post_tag',
'orderby' => 'count',
'order' => 'DESC',
'number' => 30,
'hide_empty' => false,
)
);
if (!empty($term_query->terms)) {
foreach ($term_query->terms as $term) {
echo $term->name;
printf('<a class="tag" href="%s">%s</a>',get_term_link($term),$term->name);
}
} ?>
获取指定的分类
<?php
$term_query = new WP_Term_Query(
array(
'taxonomy' => 'category',
'include' => [14,15,16],
'hide_empty' => false,
)
);
if (!empty($term_query->terms)) {
foreach ($term_query->terms as $term) {
printf('<a class="tag" href="%s">%s</a>',get_term_link($term),$term->name);
}
} ?>
contact form7 表单
<?php
$form_id = get_post_meta($post->ID, 'contact2_form_id', true);
if ($form_id) {
$code = sprintf('[contact-form-7 id="%s"]', $form_id);
echo do_shortcode($code);
}
?>
内容页显示当前分类名称
<?php
global $post;
$taxonomies = get_the_taxonomies($post);
$term_name = '';
if ($taxonomies) {
$taxonomy = array_keys($taxonomies)[0];
$terms = get_the_terms($post->ID, $taxonomy);
if(is_array($terms)){
$term_name = $terms[0]->name;
}
}?>
图集 codestar
<?php
$gallery_opt = $index_module_4['imgs']; // for eg. 15,50,70,125
$gallery_ids = explode(',', $gallery_opt);
if (!empty($gallery_ids)) {
foreach ($gallery_ids as $gallery_item_id) {
$caption = wp_get_attachment_caption($gallery_item_id);
$img_src_small = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'photo')[0];
$img_src_big = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full')[0];
}
}
?>