Skip to content

Commit

Permalink
タグメタ情報の仕様変更
Browse files Browse the repository at this point in the history
  • Loading branch information
yhira committed Aug 10, 2019
1 parent f1788bb commit a18b4a3
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 91 deletions.
4 changes: 2 additions & 2 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ function get_archive_chapter_title(){
} elseif( is_tag() ) {//タグページの場合
$tag_id = get_query_var('tag_id');
$icon_font = '<span class="fa fa-tags"></span>';
if ($tag_id && get_tag_title($tag_id)) {
$chapter_title .= $icon_font.get_tag_title($tag_id);
if ($tag_id && get_the_tag_title($tag_id)) {
$chapter_title .= $icon_font.get_the_tag_title($tag_id);
} else {
$chapter_title .= single_tag_title( $icon_font, false );
}
Expand Down
6 changes: 3 additions & 3 deletions lib/blogcard-in.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ function url_to_internal_blogcard_tag($url){
}
} elseif ($tag = url_to_tag_object($url)) {
$tag_id = $tag->term_id;
$title = get_tag_title($tag_id);
$snippet = get_tag_snippet($tag_id);
$image = get_tag_eye_catch_url($tag_id);
$title = get_the_tag_title($tag_id);
$snippet = get_the_tag_snippet($tag_id);
$image = get_the_tag_eye_catch_url($tag_id);

if ($image) {
$thumbnail = get_blogcard_thumbnail_image_tag($image);
Expand Down
8 changes: 4 additions & 4 deletions lib/content-category.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function get_the_category_eye_catch_url($cat_id = null){
}
endif;

//カテゴリ色の取得
//カテゴリのメタディスクリプション
if ( !function_exists( 'get_the_category_meta_description' ) ):
function get_the_category_meta_description($cat_id = null){
$res = get_term_meta( $cat_id, 'the_category_meta_description', true );
Expand Down Expand Up @@ -184,9 +184,9 @@ function get_the_category_keywords($cat_id = null){
//拡張カテゴリ編集フォーム
add_action ( 'edit_category_form_fields', 'extra_category_fields');
if ( !function_exists( 'extra_category_fields' ) ):
function extra_category_fields( $tag ) {
$cat_id = $tag->term_id;
$cat_meta = get_the_category_meta($cat_id);
function extra_category_fields( $cat ) {
$cat_id = $cat->term_id;
//$cat_meta = get_the_category_meta($cat_id);
//_v($cat_meta);
?>
<tr class="form-field term-color-wrap">
Expand Down
195 changes: 124 additions & 71 deletions lib/content-tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@
///////////////////////////////////////
// 拡張タグ設定
///////////////////////////////////////
if ( !function_exists( 'get_tag_meta_key' ) ):
function get_tag_meta_key($tag_id){

if ( !function_exists( 'get_the_tag_meta_key' ) ):
function get_the_tag_meta_key($tag_id){
return 'tag_meta_'.$tag_id;
}
endif;

//タグメタ情報の取得
if ( !function_exists( 'get_tag_meta' ) ):
function get_tag_meta($tag_id = null){
if ( !function_exists( 'get_the_tag_meta' ) ):
function get_the_tag_meta($tag_id = null){
if (empty($tag_id) && is_tag()) {
//タグないときIDを取得
//タグがないときはタグIDを取得
$tag_id = get_query_var('tag_id');
}
//IDが正常な場合
//タグIDが正常な場合
if ($tag_id) {
$res = get_term_meta( $tag_id, get_tag_meta_key($tag_id), true );
$res = get_term_meta( $tag_id, get_the_tag_meta_key($tag_id), true );
if (is_array($res)) {
return $res;
} else {
Expand All @@ -35,124 +36,152 @@ function get_tag_meta($tag_id = null){
}
endif;

//タイトルの取得
if ( !function_exists( 'get_tag_title' ) ):
function get_tag_title($tag_id = null){
$meta = get_tag_meta($tag_id);
if (!empty($meta['title']))
return $meta['title'];
else
return get_tag($tag_id)->name;
//タグタイトルの取得
if ( !function_exists( 'get_the_tag_title' ) ):
function get_the_tag_title($tag_id = null){
$res = get_term_meta( $tag_id, 'the_tag_title', true );
if ($res) {
return $res;
} else {//旧バージョン対応
$meta = get_the_tag_meta($tag_id);
if (!empty($meta['title']))
return $meta['title'];
else
return get_tag($tag_id)->name;
}
}
endif;

//本文の取得
if ( !function_exists( 'get_tag_content' ) ):
function get_tag_content($tag_id = null){
if (!$tag_id) {
$tag_id = get_query_var('tag_id');
//タグ本文の取得
if ( !function_exists( 'get_the_tag_content' ) ):
function get_the_tag_content($tag_id = null){
$res = get_term_meta( $tag_id, 'the_tag_content', true );
if ($res) {
return $res;
} else {//旧バージョン対応
if (!$tag_id) {
$tag_id = get_query_var('tag_id');;
}
$meta = get_the_tag_meta($tag_id);
if (!empty($meta['content']))
$content = $meta['content'];
else
$content = tag_description($tag_id);
}
$meta = get_tag_meta($tag_id);
if (!empty($meta['content']))
$content = $meta['content'];
else
$content = tag_description($tag_id);

$content = wpautop($content);
$content = apply_filters( 'the_category_tag_content', $content );//カテゴリー・タグ本文共通
$content = apply_filters( 'the_category_tag_content', $content );//カテゴリ・タグ本文共通
$content = apply_filters( 'the_tag_content', $content );
return $content;
}
endif;

//画像の取得
if ( !function_exists( 'get_tag_eye_catch_url' ) ):
function get_tag_eye_catch_url($tag_id = null){
$meta = get_tag_meta($tag_id);
if (!empty($meta['eye_catch'])){
$eye_catch_url = $meta['eye_catch'];
//画像が存在しているか
if (file_exists(url_to_local($eye_catch_url))) {
return $eye_catch_url;
//アイキャッチの取得
if ( !function_exists( 'get_the_tag_eye_catch_url' ) ):
function get_the_tag_eye_catch_url($tag_id = null){
$res = get_term_meta( $tag_id, 'the_tag_eye_catch_url', true );
if ($res) {
$eye_catch_url = $res;
} else {//旧バージョン対応
$meta = get_the_tag_meta($tag_id);
if (!empty($meta['eye_catch'])){
$eye_catch_url = $meta['eye_catch'];
} else {
return '';
$eye_catch_url = '';
}
}

//画像が存在しているか
if (file_exists(url_to_local($eye_catch_url))) {
return $eye_catch_url;
} else {
return '';
}
}
endif;

//説明文の取得
if ( !function_exists( 'get_tag_description' ) ):
function get_tag_description($tag_id = null){
$meta = get_tag_meta($tag_id);
if (!empty($meta['description']))
return $meta['description'];
//タグのメタディスクリプション
if ( !function_exists( 'get_the_tag_meta_description' ) ):
function get_the_tag_meta_description($tag_id = null){
$res = get_term_meta( $tag_id, 'the_tag_meta_description', true );
if ($res) {
return $res;
} else {//旧バージョン対応
$meta = get_the_tag_meta($tag_id);
if (!empty($meta['description']))
return $meta['description'];
}
}
endif;

//スニペット文を取得
if ( !function_exists( 'get_tag_snippet' ) ):
function get_tag_snippet($tag_id){
$snippet = get_tag_description($tag_id);
//タグのスニペット文を取得
if ( !function_exists( 'get_the_tag_snippet' ) ):
function get_the_tag_snippet($tag_id){
$snippet = get_the_tag_meta_description($tag_id);
if (!$snippet) {
//説明を取得
//タグ説明を取得
$snippet = tag_description($tag_id);
}
if (!$snippet) {
//内容の抜粋
$snippet = get_content_excerpt(get_tag_content($tag_id), get_entry_card_excerpt_max_length());
//タグ内容の抜粋
$snippet = get_content_excerpt(get_the_tag_content($tag_id), get_entry_card_excerpt_max_length());
}
if (!$snippet) {
//説明を取得
//タグ説明を取得
$tag = get_tag($tag_id);
if ($tag) {
$snippet = sprintf( __( '「%s」の記事一覧です。', THEME_NAME ), $tag->name );
}

}
return $snippet;
}
endif;

//キーワードの取得
if ( !function_exists( 'get_tag_keywords' ) ):
function get_tag_keywords($tag_id = null){
$meta = get_tag_meta($tag_id);
if (!empty($meta['keywords']))
return $meta['keywords'];
if ( !function_exists( 'get_the_tag_keywords' ) ):
function get_the_tag_keywords($tag_id = null){
$res = get_term_meta( $tag_id, 'the_tag_keywords', true );
if ($res) {
return $res;
} else {//旧バージョン対応
$meta = get_the_tag_meta($tag_id);
if (!empty($meta['keywords']))
return $meta['keywords'];
}
}
endif;

//編集フォーム
//拡張タグ編集フォーム
add_action ( 'edit_tag_form_fields', 'extra_tag_fields');
if ( !function_exists( 'extra_tag_fields' ) ):
function extra_tag_fields( $tag ) {
$tag_id = $tag->term_id;
$tag_meta = get_tag_meta($tag_id);
//$tag_meta = get_the_tag_meta($tag_id);
?>
<tr class="form-field term-title-wrap">
<th><label for="title"><?php _e( 'タグタイトル', THEME_NAME ) ?></label></th>
<td>
<input type="text" name="tag_meta[title]" id="title" size="25" value="<?php if(isset ( $tag_meta['title'])) echo esc_html($tag_meta['title']) ?>" placeholder="<?php _e( 'タグページのタイトル', THEME_NAME ) ?>" />
<?php
$the_tag_title = get_the_tag_title($tag_id);
?>
<input type="text" name="the_tag_title" id="title" size="25" value="<?php echo esc_attr($the_tag_title) ?>" placeholder="<?php _e( 'タグページのタイトル', THEME_NAME ) ?>" />
<p class="description"><?php _e( 'タグページのタイトルを指定します。タグページのタイトルタグにここで入力したテキストが適用されます。', THEME_NAME ) ?></p>
</td>
</tr>
<tr class="form-field term-content-wrap">
<th><label for="content"><?php _e( 'タグ本文', THEME_NAME ) ?></label></th>
<td><?php
$content = isset($tag_meta['content']) ? $tag_meta['content'] : '';
generate_visuel_editor_tag('tag_meta[content]', $content, 'content');
$the_tag_content = get_the_tag_content($tag_id);
generate_visuel_editor_tag('the_tag_content', $the_tag_content, 'content');
?>
<p class="description"><?php _e( 'タグページで表示されるメインコンテンツを入力してください。', THEME_NAME ) ?></p>
</td>
</tr>
<tr class="form-field term-eye-catch-wrap">
<th><label for="eye_catch"><?php _e( 'アイキャッチ', THEME_NAME ) ?></label></th>
<td><?php
$eye_catch = isset($tag_meta['eye_catch']) ? $tag_meta['eye_catch'] : '';
generate_upload_image_tag('tag_meta[eye_catch]', $eye_catch, 'eye_catch');
$the_tag_eye_catch_url = get_the_tag_eye_catch_url($tag_id);
generate_upload_image_tag('the_tag_eye_catch_url', $the_tag_eye_catch_url, 'eye_catch');
?>
<p class="description"><?php _e( 'タイトル下に表示されるアイキャッチ画像を選択してください。', THEME_NAME ) ?></p>
</td>
Expand All @@ -161,31 +190,55 @@ function extra_tag_fields( $tag ) {
<th><label for="description"><?php _e( 'メタディスクリプション', THEME_NAME ) ?></label></th>
<td>
<?php
$description = isset($tag_meta['description']) ? $tag_meta['description'] : '';
generate_textarea_tag('tag_meta[description]', $description, __( 'タグページの説明文を入力してください', THEME_NAME ), 3) ;
$the_tag_meta_description = get_the_tag_meta_description($tag_id);
generate_textarea_tag('the_tag_meta_description', $the_tag_meta_description, __( 'タグページの説明文を入力してください', THEME_NAME ), 3) ;
?>
<p class="description"><?php _e( 'タグページの説明を入力します。ここに入力したテキストはメタディスクリプションタグとして利用されます。', THEME_NAME ) ?></p>
</td>
</tr>
<tr class="form-field term-meta-keywords-wrap">
<th><label for="keywords"><?php _e( 'メタキーワード', THEME_NAME ) ?></label></th>
<td>
<input type="text" name="tag_meta[keywords]" id="keywords" size="25" value="<?php if(isset ( $tag_meta['keywords'])) echo esc_html($tag_meta['keywords']) ?>" placeholder="<?php _e( 'キーワード1,キーワード2,キーワード3', THEME_NAME ) ?>" />
<?php
$the_tag_keywords = get_the_tag_keywords($tag_id);
?>
<input type="text" name="the_tag_keywords" id="keywords" size="25" value="<?php echo esc_attr($the_tag_keywords) ?>" placeholder="<?php _e( 'キーワード1,キーワード2,キーワード3', THEME_NAME ) ?>" />
<p class="description"><?php _e( 'タグページのメタキーワードをカンマ区切りで入力してください。※現在はあまり意味のない設定となっています。', THEME_NAME ) ?></p>
</td>
</tr>
<?php
}
endif;

//情報の保存
//拡張タグ情報の保存
add_action ( 'edited_term', 'save_extra_tag_fileds');
if ( !function_exists( 'save_extra_tag_fileds' ) ):
function save_extra_tag_fileds( $term_id ) {
if ( isset( $_POST['tag_meta'] ) ) {
$tag_id = $term_id;
$tag_meta = $_POST['tag_meta'];
update_term_meta( $tag_id, get_tag_meta_key($tag_id), $tag_meta );
$tag_id = $term_id;

if ( isset( $_POST['the_tag_title'] ) ) {
$the_tag_title = $_POST['the_tag_title'];
update_term_meta( $tag_id, 'the_tag_title', $the_tag_title );
}

if ( isset( $_POST['the_tag_content'] ) ) {
$the_tag_content = $_POST['the_tag_content'];
update_term_meta( $tag_id, 'the_tag_content', $the_tag_content );
}

if ( isset( $_POST['the_tag_eye_catch_url'] ) ) {
$the_tag_eye_catch_url = $_POST['the_tag_eye_catch_url'];
update_term_meta( $tag_id, 'the_tag_eye_catch_url', $the_tag_eye_catch_url );
}

if ( isset( $_POST['the_tag_meta_description'] ) ) {
$the_tag_meta_description = $_POST['the_tag_meta_description'];
update_term_meta( $tag_id, 'the_tag_meta_description', $the_tag_meta_description );
}

if ( isset( $_POST['the_tag_keywords'] ) ) {
$the_tag_keywords = $_POST['the_tag_keywords'];
update_term_meta( $tag_id, 'the_tag_keywords', $the_tag_keywords );
}
}
endif;
2 changes: 1 addition & 1 deletion lib/html-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ function get_navi_card_image_attributes($menu, $type = ET_DEFAULT){
//タグページのアイキャッチを取得
$tag_obj = url_to_tag_object($url);
if ($tag_obj && isset($tag_obj->term_id)) {
$image_url = get_tag_eye_catch_url($tag_obj->term_id);
$image_url = get_the_tag_eye_catch_url($tag_obj->term_id);
$image_attributes = get_navi_card_image_url_attributes($image_url, $type);
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ function title_parts_custom( $title ){
} elseif (is_tag()) {
$tag_id = get_query_var('tag_id');
$tag_name = $title['title'];
if ($tag_id && get_tag_title($tag_id)) {
$tag_name = get_tag_title($tag_id);
if ($tag_id && get_the_tag_title($tag_id)) {
$tag_name = get_the_tag_title($tag_id);
}
$title['title'] = $tag_name;
$title['site'] = '';
Expand Down Expand Up @@ -508,7 +508,7 @@ function generate_meta_keywords_tag() {
if ( !function_exists( 'get_tag_meta_description' ) ):
function get_tag_meta_description($tag = null){
//タグ設定ページのディスクリプションを取得
$tag_desc = trim( strip_tags( get_tag_description() ) );
$tag_desc = trim( strip_tags( get_the_tag_meta_description() ) );
if ( $tag_desc ) {//ディスクリプションが設定されている場合
return htmlspecialchars($tag_desc);
}
Expand All @@ -518,7 +518,7 @@ function get_tag_meta_description($tag = null){
return htmlspecialchars($tag_desc);
}
//タグ本文から抜粋文を作成
$tag_desc = trim( strip_tags( get_content_excerpt(get_tag_content(), 160) ) );
$tag_desc = trim( strip_tags( get_content_excerpt(get_the_tag_content(), 160) ) );
if ( $tag_desc ) {//タグ設定に説明がある場合はそれを返す
return htmlspecialchars($tag_desc);
}
Expand All @@ -537,7 +537,7 @@ function get_tag_meta_description($tag = null){
//タグキーワード用のワードを取得
if ( !function_exists( 'get_tag_meta_keywords' ) ):
function get_tag_meta_keywords(){
if ($keywords = get_tag_keywords()) {
if ($keywords = get_the_tag_keywords()) {
$res = $keywords;
} else {
$res = single_tag_title('', false);
Expand Down
Loading

0 comments on commit a18b4a3

Please sign in to comment.