联系我们表单
底部调用js
<script src="<?php bloginfo('template_url'); ?>/js/validate/jquery.validate.js"></script>
page-contact.php
<div class="bot">
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="title">GET IN TOUCH</div>
<div class="txt">
Your email address will not be published. Required fields are marked
<i class="iconfont icon-xinghao"></i>
</div>
<form action="#" method="post" name="contact_form" id="contact_form">
<div class="con">
<input type="text" id="firstname" name="firstname" placeholder="You Name">
<i class="iconfont icon-xinghao"></i>
</div>
<div class="con">
<input type="text" id="phone" name="phone" placeholder="You Phone">
<i class="iconfont icon-xinghao"></i>
</div>
<div class="con">
<input type="text" id="email" name="email" placeholder="You Email">
<i class="iconfont icon-xinghao"></i>
</div>
<div class="con">
<textarea name="message" id="message" cols="30" rows="6" placeholder="You Message"></textarea>
<i class="iconfont icon-xinghao"></i>
</div>
<button type="submit" name="contact_submit" id="contact_button" class="more">Post Mseeage</button>
</form>
</div>
<div class="col-md-6">
<img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title(); ?>" class="w100">
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
<script language="javascript">
$().ready(function() {
$("#contact_form").validate({
onsubmit: true,
//errorPlacement: function(error, element){
//error.appendTo(element.parent().prev().children('.errortip'));
//},
success: function(label) {
label.remove();
},
rules: {
firstname: {
required: true
},
phone: {
required: true,
},
email: {
required: true,
email: true,
},
},
messages: {},
submitHandler: function(form) {
var d = {};
var t = $('#contact_form').serializeArray();
$.each(t, function() {
d[this.name] = this.value;
});
d['action'] = 'add_post';
$.ajax({
url: '<?php echo admin_url('admin-ajax.php') ?>',
type: "post",
dataType: "json",
data: d,
success: function(msg) {
alert('Submitted successfully');
$('#contact_form')[0].reset();
}
});
},
invalidHandler: function(form, validator) {
return false;
}
});
return false;
});
</script>
SEO 标题等调用
title、keywords、description
header.php
<head>
<title><?php echo bzg_seo_title(); ?></title>
<?php
$bzg_keywords = bzg_seo_keywords();
if (!empty($bzg_keywords)) {
echo '<meta name="keywords" content="' . $bzg_keywords . '" />';
echo "\n";
}
$bzg_description = bzg_seo_description();
if (!empty($bzg_description)) {
echo '<meta name="description" content="' . $bzg_description . '" />';
echo "\n";
}
?>
<?php if (is_home()) : ?>
<?php endif; ?>
</head>
functions.php
//Title标题
function bzg_filter_title( $title ) {
$title['site'] = '';
$title['tagline'] = '';
$title['page'] = '';
return $title;
}
add_filter( 'document_title_parts', 'bzg_filter_title', 10, 1 );
function bzg_seo_title() {
global $cat, $tag_id, $page, $paged;
$page_num = '';
if ( $paged >= 2 || $page >= 2 )
$page_num = '_' . sprintf( '第%s页', max( $paged, $page ) );
$title = wp_get_document_title();
if( is_author() )
$title = '作者:' . $title;
if( is_category() && get_term_meta( $cat , 'seo_title', true ) )
$title = get_term_meta( $cat , 'seo_title', true );
if( is_tag() && get_term_meta( $tag_id , 'seo_title', true ) )
$title = get_term_meta( $tag_id , 'seo_title', true );
if ( ! is_home() ) {
$title .= $page_num . ' - ';
$title .= get_option('blogname');
} else {
$description = get_option( 'blogdescription' );
$home_title = get_option( 'home_title' );
if ( $home_title ) {
$title = $home_title;
} elseif($description) {
$title .= ' - ' . $description;
}
$title .= $page_num;
}
return $title;
}
function bzg_seo_keywords() {
global $post;
$keywords = '';
if ( is_home() )
$keywords = get_option( 'home_keywords' );
if ( ( is_category() || is_tag() ))
$keywords = single_cat_title('', false);
if ( is_single() || is_page() ) {
if ( $post->post_excerpt ) {
$keywords = $post->post_excerpt;
} else {
$keywords = $post->post_title;
}
}
return $keywords;
}
//Description标签
function bzg_seo_description() {
global $post;
$description = '';
if ( is_home() )
$description = get_option( 'home_description' );
if ( ( is_category() || is_tag() ) && category_description() )
$description = wp_strip_all_tags( category_description(), true );
if ( is_single() || is_page() ) {
if ( $post->post_excerpt ) {
$description = $post->post_excerpt;
} else {
$description = mb_strimwidth(esc_html(wp_strip_all_tags($post->post_content, true)), 0, 200);
}
}
return $description;
}