From ccbdd799bde53216b4b16b2616d15d7e860b4f2b Mon Sep 17 00:00:00 2001 From: KeyboardMan1996 <38783216+KeyboardMan1996@users.noreply.github.com> Date: Fri, 7 May 2021 21:54:22 +0800 Subject: [PATCH] feat: add contents picture (#369) --- inc/options-framework/js/options-custom.js | 2 ++ inc/theme-article.php | 8 +++++- inc/theme-options.php | 29 +++++++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/inc/options-framework/js/options-custom.js b/inc/options-framework/js/options-custom.js index 9f851d2..95d999e 100755 --- a/inc/options-framework/js/options-custom.js +++ b/inc/options-framework/js/options-custom.js @@ -92,10 +92,12 @@ jQuery(document).ready(function ($) { jQuery("#g_thumbnail").click(function () { jQuery("#section-g_postthumbnail").fadeToggle(400); + jQuery("#section-essay_feature_img_usable").fadeToggle(400); }); if (jQuery("#g_thumbnail:checked").val() !== undefined) { jQuery("#section-g_postthumbnail").show(); + jQuery("#section-essay_feature_img_usable").show(); } jQuery("#top_select").change(function () { diff --git a/inc/theme-article.php b/inc/theme-article.php index 8a5300d..ccdd68e 100644 --- a/inc/theme-article.php +++ b/inc/theme-article.php @@ -126,7 +126,13 @@ function post_thumbnail() if (!empty($img_val)) { echo ''; } else { - if (!kratos_option('g_postthumbnail')) { + $category=get_the_category($post->ID); + $catid=$category[0]->term_id; + if(kratos_option('essay_feature_img_'.$catid) + && kratos_option('essay_feature_img_usable',true)) + { + $img = kratos_option('essay_feature_img_'.$catid); + }elseif(!kratos_option('g_postthumbnail')) { $img = ASSET_PATH . '/assets/img/default.jpg'; } else { $img = kratos_option('g_postthumbnail', ASSET_PATH . '/assets/img/default.jpg'); diff --git a/inc/theme-options.php b/inc/theme-options.php index 43e9956..b427ec3 100644 --- a/inc/theme-options.php +++ b/inc/theme-options.php @@ -360,6 +360,15 @@ function kratos_options() 'type' => 'checkbox', ); + $options[] = array( + 'name' => __('开启目录默认特色图片', 'kratos'), + 'desc' => __('为每一个目录设置一个默认的特色图片', 'kratos'), + 'std' => '1', + 'class' => 'hidden', + 'id' => 'essay_feature_img_usable', + 'type' => 'checkbox', + ); + $options[] = array( 'name' => __('默认特色图', 'kratos'), 'desc' => __('当文章中没有图片并且没有设置特色图时在首页显示', 'kratos'), @@ -368,7 +377,25 @@ function kratos_options() 'std' => ASSET_PATH . '/assets/img/default.jpg', 'type' => 'upload', ); - + #在这里获取所有分类的名称和id 然后加入到设置中 + if(kratos_option('essay_feature_img_usable',true)){ + $args=array( + 'orderby' => 'name', + 'order' => 'ASC', + #设置获取没有文章的空类 + 'hide_empty' => false + ); + $categories=get_categories($args); + foreach($categories as $category) { + $options[] = array( + 'name' => __( $category->name.'分类默认特色图片', 'kratos'), + 'desc' => __('没有设置默认图片时,按照文章分类默认给出', 'kratos'), + 'id' => ('essay_feature_img_'.$category->term_id), + 'std' => ASSET_PATH . '/assets/img/default.jpg', + 'type' => 'upload', + ); + } + } $options[] = array( 'name' => __('无内容图片', 'kratos'), 'desc' => __('当搜索不到文章或文章分类中没有文章时显示', 'kratos'),