/*-------------------------------------------*/
/* Category list 'count insert to inner
/*-------------------------------------------*/
/* Block to delete iframe tag from TinyMCE
/*-------------------------------------------*/
/* Comment
/*-------------------------------------------*/
/* Archive page link ( don't erase )
/*-------------------------------------------*/
/* Paging
/*-------------------------------------------*/
/* Comment out short code
/*-------------------------------------------*/
/* ChildPageList widget
/*-------------------------------------------*/
/* posts pagenation setting in front-page
/*-------------------------------------------*/
function biz_vektor_theme_setup(){
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'custom-header' );
add_theme_support( 'custom-background', array(
'default-color' => 'fcfcfc',
) );
/*-------------------------------------------*/
/* Admin page _ Eye catch
/*-------------------------------------------*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 200, 200, true );
/*-------------------------------------------*/
/* Custom menu
/*-------------------------------------------*/
register_nav_menus( array( 'Header' => 'Header Navigation', ) );
register_nav_menus( array( 'FooterNavi' => 'Footer Navigation', ) );
register_nav_menus( array( 'FooterSiteMap' => 'Footer SiteMap', ) );
load_theme_textdomain('biz-vektor', false, dirname( __FILE__ ) . '/languages');
}
add_action( 'after_setup_theme', 'biz_vektor_theme_setup');
function biz_vektor_body_next(){
$body_next = '';
$body_next = apply_filters( 'biz_vektor_body_next', $body_next );
echo $body_next;
}
/*-------------------------------------------*/
/* Set content width
/* (Auto set up to media max with.)
/*-------------------------------------------*/
if ( ! isset( $content_width ) )
$content_width = 640;
/*-------------------------------------------*/
/* Widget
/*-------------------------------------------*/
function biz_vektor_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar(Front page only)', 'biz-vektor' ),
'id' => 'top-side-widget-area',
'description' => __( 'This widget area appears on the front page only.', 'biz-vektor' ),
'before_widget' => '
'.__('To distinguish between individual keywords, please enter a , delimiter (optional).', 'biz-vektor').'
';
$theme_option_seo_link = ''._x('','link to seo setting', 'biz-vektor').'';
sprintf(__('* keywords common to the entire site can be set from %s.', 'biz-vektor'),$theme_option_seo_link);
echo '
';
}
function biz_vektor_save_custom_field_metaKeyword($post_id){
$metaKeyword = isset($_POST['noncename_custom_field_metaKeyword']) ? htmlspecialchars($_POST['noncename_custom_field_metaKeyword']) : null;
if(!wp_verify_nonce($metaKeyword, plugin_basename(__FILE__))){
return $post_id;
}
if('page' == $_POST['post_type']){
if(!current_user_can('edit_page', $post_id)) return $post_id;
}else{
if(!current_user_can('edit_post', $post_id)) return $post_id;
}
$data = $_POST['metaKeyword'];
if(get_post_meta($post_id, 'metaKeyword') == ""){
add_post_meta($post_id, 'metaKeyword', $data, true);
}elseif($data != get_post_meta($post_id, 'metaKeyword', true)){
update_post_meta($post_id, 'metaKeyword', $data);
}elseif($data == ""){
delete_post_meta($post_id, 'metaKeyword', get_post_meta($post_id, 'metaKeyword', true));
}
}
/*-------------------------------------------*/
/* Admin page _ page _ customize
/*-------------------------------------------*/
add_post_type_support( 'page', 'excerpt' ); // add excerpt
/*-------------------------------------------*/
/* head_description
/*-------------------------------------------*/
function biz_vektor_getHeadDescription() {
global $wp_query;
$post = $wp_query->get_queried_object();
if (is_home() || is_page('home') || is_front_page()) {
if ( isset($post->post_excerpt) && $post->post_excerpt ) {
$metadescription = $post->post_excerpt;
} else {
$metadescription = get_bloginfo( 'description' );
}
} else if (is_category() || is_tax()) {
$metadescription = $post->category_description;
if ( ! $metadescription ) {
$metadescription = sprintf(__('About %s', 'biz-vektor'),single_cat_title()).get_bloginfo('name').' '.get_bloginfo('description');
}
} else if (is_tag()) {
$metadescription = strip_tags(tag_description());
$metadescription = str_replace(array("\r\n","\r","\n"), '', $metadescription); // delete br
if ( ! $metadescription ) {
$metadescription = sprintf(__('About %s', 'biz-vektor'),single_tag_title()).get_bloginfo('name').' '.get_bloginfo('description');
}
} else if (is_archive()) {
if (is_year()){
$description_date = get_the_date( _x( 'Y', 'yearly archives date format', 'biz-vektor' ) );
$metadescription = sprintf(_x('Article of %s.','Yearly archive description', 'biz-vektor'), $description_date );
$metadescription .= ' '.get_bloginfo('name').' '.get_bloginfo('description');
} else if (is_month()){
$description_date = get_the_date( _x( 'F Y', 'monthly archives date format', 'biz-vektor' ) );
$metadescription = sprintf(_x('Article of %s.','Archive description', 'biz-vektor'),$description_date );
$metadescription .= ' '.get_bloginfo('name').' '.get_bloginfo('description');
} else if (is_author()) {
$userObj = get_queried_object();
$metadescription = sprintf(_x('Article of %s.','Archive description', 'biz-vektor'),esc_html($userObj->display_name) );
$metadescription .= ' '.get_bloginfo('name').' '.get_bloginfo('description');
} else {
$postType = get_post_type();
$metadescription = sprintf(_x('Article of %s.','Archive description', 'biz-vektor'),esc_html(get_post_type_object($postType)->labels->name) );
$metadescription .= ' '.get_bloginfo('name').' '.get_bloginfo('description');
}
} else if (is_page() || is_single()) {
$metaExcerpt = $post->post_excerpt;
if ($metaExcerpt) {
// $metadescription = strip_tags($post->post_excerpt);
$metadescription = strip_tags($post->post_excerpt);
} else {
$metadescription = mb_substr( strip_tags($post->post_content), 0, 240 ); // kill tags and trim 240 chara
$metadescription = str_replace(array("\r\n","\r","\n"), ' ', $metadescription); // delete br
}
} else {
$metadescription = get_bloginfo('description');
}
global $paged;
if ( $paged != '0'){
$metadescription = '['.sprintf(__('Page of %s', 'biz-vektor' ),$paged).'] '.$metadescription;
}
$metadescription = apply_filters( 'metadescriptionCustom', $metadescription );
echo $metadescription;
}
/*-------------------------------------------*/
/* head_wp_head clean and add items
/*-------------------------------------------*/
// Add Google Web Fonts
add_action('wp_enqueue_scripts','biz_vektor_addWebFonts');
function biz_vektor_addWebFonts(){
wp_enqueue_style( 'bizvektoraddwebfonts', "http://fonts.googleapis.com/css?family=Droid+Sans:700|Lato:900|Anton");
}
// Add BizVektor option css
add_action('wp_enqueue_scripts','biz_vektor_addCommonStyle');
function biz_vektor_addCommonStyle(){
wp_enqueue_style( 'bizVektorAddCommonStyle', get_template_directory_uri()."/css/bizvektor_common_min.css", array(), '1.0.0');
}
// add pingback
add_action('wp_enqueue_scripts','biz_vektor_addPingback');
function biz_vektor_addPingback(){
wp_enqueue_style( 'bizVektorAddPingback', get_bloginfo( 'pingback_url' ), array(), '1.0.0');
}
/*-------------------------------------------*/
/* footer_wp_footer clean and add items
/*-------------------------------------------*/
add_action('wp_head','biz_vektor_addJScripts');
function biz_vektor_addJScripts(){
wp_register_script( 'biz-vektor-min-js' , get_template_directory_uri().'/js/biz-vektor-min.js', array('jquery'), '20140519' );
wp_enqueue_script( 'biz-vektor-min-js' );
}
function add_defer_to_bizVektor_js( $url )
{
if ( FALSE === strpos( $url, 'biz-vektor/js' ) or FALSE === strpos( $url, '.js' ) )
{ // not our file
return $url;
}
// Must be a ', not "!
return "$url' defer='defer";
}
add_filter( 'clean_url', 'add_defer_to_bizVektor_js', 11, 1 );
/*-------------------------------------------*/
/* Term list no link
/*-------------------------------------------*/
function biz_vektor_get_the_term_list_nolink( $id = 0, $taxonomy, $before = '', $sep = '', $after = '' ) {
$terms = get_the_terms( $id, $taxonomy );
if ( is_wp_error( $terms ) )
return $terms;
if ( empty( $terms ) )
return false;
foreach ( $terms as $term ) {
$term_names[] = $term->name ;
}
return $before . join( $sep, $term_names ) . $after;
}
/*-------------------------------------------*/
/* Global navigation add cptions
/*-------------------------------------------*/
class description_walker extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth=0, $args=array(),$id = 0) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '@', '\1', $html);
}
add_filter('get_archives_link', 'biz_vektor_my_archives_link');
/*-------------------------------------------*/
/* Category list 'count insert to inner
/*-------------------------------------------*/
function biz_vektor_add_my_list_categories( $output, $args ) {
$output = preg_replace('/<\/a>\s*\((\d+)\)/',' ($1)',$output);
return $output;
}
add_filter( 'wp_list_categories', 'biz_vektor_add_my_list_categories', 10, 2 );
/*-------------------------------------------*/
/* Block to delete iframe tag from TinyMCE
/*-------------------------------------------*/
function biz_vektor_add_iframe($initArray) {
$initArray['extended_valid_elements'] = "iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]";
return $initArray;
}
add_filter('tiny_mce_before_init', 'biz_vektor_add_iframe');
/*-------------------------------------------*/
/* Comment
/*-------------------------------------------*/
if ( ! function_exists( 'biz_vektor_comment' ) ) :
function biz_vektor_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
?>
Pingback: (', ')' ); ?>
max_num_pages > 1 ) : ?>
← Older post', 'biz-vektor')); ?>
→', 'biz-vektor')); ?>
max_num_pages;
if(!$max_num_pages) {
$max_num_pages = 1;
}
}
if(1 != $max_num_pages) {
echo ''."\n";
// Prevリンク
// 現在のページが2ページ目以降の場合
if ($paged > 1) echo '
«'."\n";
// 今のページからレンジを引いて2以上ある場合 && 最大表示アイテム数より最第ページ数が大きい場合
// (レンジ数のすぐ次の場合は表示する)
// 1...345
if ( $paged-$range >= 2 && $max_num_pages > $showitems ) echo '
1'."\n";
// 今のページからレンジを引いて3以上ある場合 && 最大表示アイテム数より最第ページ数が大きい場合
if ( $paged-$range >= 3 && $max_num_pages > $showitems ) echo '
…'."\n";
// レンジより前に追加する数
$addPrevCount = $paged+$range-$max_num_pages;
// レンジより後に追加する数
$addNextCount = -($paged-1-$range); // 今のページ数を遡ってカウントするために-1
// アイテムループ
for ($i=1; $i <= $max_num_pages; $i++) {
// 表示するアイテム
if ($paged == $i) {
$pageItem = '
'.$i.''."\n";
} else {
$pageItem = '
'.$i.''."\n";
}
// 今のページからレンジを引いた数~今のページからレンジを足した数まで || 最大ページ数が最大表示アイテム数以下の場合
if ( ( $paged-$range <= $i && $i<= $paged+$range ) || $max_num_pages <= $showitems ) {
echo $pageItem;
// 今のページからレンジを引くと負数になる場合 && 今のページ+レンジ+負数をレンジに加算した数まで
} else if ( $paged-1-$range < 0 && $paged+$range+$addNextCount >= $i ) {
echo $pageItem;
// 今のページからレンジを足すと 最後のページよりも大きくなる場合 && 今のページ+レンジ+負数をレンジに加算した数まで
} else if ( $paged+$range > $max_num_pages && $paged-$range-$addPrevCount <= $i ) {
echo $pageItem;
}
}
// 現在のページにレンジを足しても最後のページ数より2以上小さい時 && 最大表示アイテム数より最第ページ数が大きい場合
if ( $paged+$range <= $max_num_pages-2 && $max_num_pages > $showitems ) echo '
…'."\n";
if ( $paged+$range <= $max_num_pages-1 && $max_num_pages > $showitems ) echo '
'.$max_num_pages.''."\n";
// Nextリンク
if ($paged < $max_num_pages) echo '
»'."\n";
echo "
\n";
}
}
/*-------------------------------------------*/
/* ChildPageList widget
/*-------------------------------------------*/
function biz_vektor_childPageList(){
global $post;
if (is_page()) {
if($post->ancestors){
foreach($post->ancestors as $post_anc_id){
$post_id = $post_anc_id;
}
} else {
$post_id = $post->ID;
}
if ($post_id) {
$children = wp_list_pages("title_li=&child_of=".$post_id."&echo=0");
if ($children) { ?>
is_main_query() ){
return;
}
if ( !is_page() && is_front_page()) {
$query->set( 'posts_per_page', $options['postTopCount'] );
return;
}
}