Skip to content

Instantly share code, notes, and snippets.

@nyankichi-n-n
Last active November 22, 2017 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nyankichi-n-n/0647e6f11dfb4c2c9adf5c5d7d5388a6 to your computer and use it in GitHub Desktop.
Save nyankichi-n-n/0647e6f11dfb4c2c9adf5c5d7d5388a6 to your computer and use it in GitHub Desktop.
にゃんきち日和のカスタマイズ
<?php get_header(); ?>
<div class="post">
<!--ループ開始-->
<?php
$lang = Mlp_Helpers::get_current_blog_language();
if ( $lang == 'ja_JP' ) : ?>
<h2 class="entry-title">ページが見つかりませんでした</h2>
<?php else : ?>
<h2 class="entry-title">The page could not be found</h2>
<?php endif; ?>
<?php if ( get_404_image() ): ?>
//
// 略
//
//
// 略
//
<?php get_template_part('datetime') //投稿日と更新日?>
<?php if ( is_category_visible() ): //カテゴリを表示する場合?>
<?php if ( get_the_category() ): //投稿ページの場合?>
<span class="category"><amp-img src="<?php echo get_template_directory_uri(); ?>/images/folder.svg" width="12" height="12" class="fa fa-svg fa-fw"></amp-img><?php the_category(', ') ?></span>
<?php else: //カスタム投稿の場合?>
<span class="category"><amp-img src="<?php echo get_template_directory_uri(); ?>/images/folder.svg" width="12" height="12" class="fa fa-svg fa-fw"></amp-img><?php echo get_the_term_list( get_the_ID(), 'm_category' ); ?></span>
<?php endif; ?>
<?php endif; //is_category_visible?>
//
// 略
//
<?php //固定ページ用のパンくずリスト ?>
<div class="breadcrumbs">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div>
<?php //カテゴリ用のパンくずリスト ?>
<div class="breadcrumbs">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div>
//
// 略
//
<?php
endif;
if ( is_comment_form_freeze() ) {//コメント凍結
echo get_theme_text_comment_freeze_label();
} else {//コメント表示
// ここからコメントフォーム
$lang = Mlp_Helpers::get_current_blog_language();
if ( $lang == 'ja_JP' ) {
$args = array(
'title_reply' => get_theme_text_comment_reply_title(),//コメントをどうぞ
'comment_notes_before' => '<p class="comment-notes">必須項目は設定していません。また、メールアドレスは公開されませんのでご安心ください。</p>',
'fields' => apply_filters( 'comment_form_default_fields', array(
'author' =>
'<p class="comment-form-author">' .
'<label for="author">'.'ニックネーム'.'</label> ' .
( $req ? '<span class="required">*</span>' : '' ) .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
'" size="30"' . $aria_req . ' /></p>',
'email' =>
'<p class="comment-form-email"><label for="email">'.'あなたのメールアドレス'.'</label> ' .
( $req ? '<span class="required">*</span>' : '' ) .
'<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) .
'" size="30"' . $aria_req . ' /></p>',
'url' =>
'<p class="comment-form-url"><label for="url">'.'あなたのウェブサイト'.'</label>' .
'<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
'" size="30" /></p>'
)
),
'label_submit' => get_theme_text_comment_submit_label(),//コメントを送信
);
} else {
$args = array(
'title_reply' => get_theme_text_comment_reply_title(),//コメントをどうぞ
'label_submit' => get_theme_text_comment_submit_label(),//コメントを送信
);
}
echo '<aside>';
comment_form($args);
echo '</aside>';
}
?>
</div>
<!-- /comment area -->
<?php
// 一行目はシンタックスハイライトするために追加しています。
///////////////////////////////////////////////////
// Maron用 新着エントリーウイジェットの追加
// /wp-content/themes/simplicity2/lib/widgets/new-entries.php をカスタマイズしてfunctons.phpに追加。
///////////////////////////////////////////////////
class MyMaronNewEntryWidgetItem extends WP_Widget {
function __construct() {
parent::__construct(
false,
'[S] Maron新着記事',
array('description' => 'Maron新着記事リストを表示するSimplicityウィジェット改です。')
);//ウイジェット名
}
//
// 略
//
//新着記事表示用の処理を書くところだけど
//コード量も多く、インデントが深くなり読みづらくなるので
//テンプレートファイル側に書く
if ( $entry_type == 'default' ) {
get_template_part('new-maron-entries');
}else{
get_template_part('new-entries-large');
}
//
// 略
//
add_action('widgets_init', create_function('', 'return register_widget("MyMaronNewEntryWidgetItem");'));
<?php //子テーマ用関数
//親skins の取得有無の設定
function include_parent_skins(){
return true; //親skinsを含める場合はtrue、含めない場合はfalse
}
//子テーマ用のビジュアルエディタースタイルを適用
add_editor_style();
//以下にSimplicity子テーマ用の関数を書く
//****** 自前のグローバル変数 ******
$my_maron_category_default = 'moan';
// カスタム投稿タイプとアイコン
$my_post_icon = array(
"maron" => "fa-paw",
);
//公開になっているカスタム投稿でMarkdownが使えるようにする
function my_custom_init() {
$args = array(
'public' => true,
'_builtin' => false
);
$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
$post_types = get_post_types( $args, $output, $operator );
foreach ( $post_types as $post_type ) {
add_post_type_support( $post_type, 'wpcom-markdown' );
}
}
add_action( 'init', 'my_custom_init' );
//rssにカスタム投稿も追加する
function mysite_feed_request($vars) {
if ( isset( $vars['feed'] ) && !isset( $vars['post_type'] ) ) {
$vars['post_type'] = array(
'post',
'maron'
);
}
return $vars;
}
add_filter( 'request', 'mysite_feed_request' );
//rssが抜粋でもサムネイルを追加する。
function rss_post_thumbnail( $content) {
global $post;
if (has_post_thumbnail( $post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) .'</p>' . $content;
}
return $content;
}
add_filter( 'the_excerpt_rss', 'rss_post_thumbnail');
add_filter( 'the_content_feed', 'rss_post_thumbnail');
// pri_get_postsを使って、ホームページにカスタム投稿を含める
// 投稿者一覧にカスタム投稿を含める
// 参考サイト http://qiita.com/_ruka_/items/e14280d34eddf49efad1
function change_posts_per_page($query) {
/* 管理画面,メインクエリに干渉しないために必須 */
if ( is_admin() || ! $query->is_main_query() ){
return;
}
/* ホームページの場合、ポストタイプにカスタム投稿を含める */
if ( $query->is_home() ) {
$query->set( 'post_type', array('post' ,'maron') );
return;
}
/* 投稿者の記事一覧の場合、ポストタイプにカスタム投稿を含める */
if (is_author() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post', 'maron' ) );
}
}
add_action( 'pre_get_posts', 'change_posts_per_page' );
// カスタム投稿タイプでカテゴリ未選択時にデフォルトで ぼやき を設定
function add_defaultcategory_automatically($post_ID) {
global $wpdb;
// 設定されているカスタム分類のタームを取得
$curTerm = wp_get_object_terms($post_ID, 'm_category');
// 既存のターム指定数が 0(つまり未設定)であれば)初期値のターム名を指定
if (0 == count($curTerm)) {
// 初期値のターム名からターム ID を取得して設定する
global $my_maron_category_default;
$term = get_term_by('slug',$my_maron_category_default , 'm_category');
if ( !empty( $term ) ) {
$defaultTerm = array( $term->term_id );
wp_set_object_terms($post_ID, $defaultTerm, 'm_category');
}
}
}
add_action('publish_maron', 'add_defaultcategory_automatically');
// トップページに文言表示 widget ここにテキストウィジットを置く
// 参考サイト http://ryus.co.jp/blog/toppage-widget-simplicity/
if (function_exists('register_sidebar')){
register_sidebar(array(
'before_widget' => '<div class="top_main_widget" id="%1$s">'."\n",
'after_widget' => '</div>'."\n",
'before_title' => '<h1 id="archive-title">',
'after_title' => '</h1>',
'name' => 'トップメイン',
'id' => 'top_main_widget'
));
}
// アーカイブのタイトル変更
function get_archive_chapter_text(){
$chapter_text = null; //アーカイブタイトル前
if( is_category() ) {
$chapter_text = 'Nyankichi:';
} elseif( is_tax() ) {
$chapter_text = 'Maron:';
} elseif (!is_author()) {
if( is_post_type_archive( 'maron' ) ) {
$chapter_text = 'Maron:';
} else {
$chapter_text = 'Nyankichi:';
}
}
$lang = Mlp_Helpers::get_current_blog_language();
if ( $lang == 'ja_JP' ) {
$chapter_text = '「' . $chapter_text; //アーカイブタイトルの取得
$chapter_text .= get_archive_chapter_title(); //アーカイブタイトル後
$chapter_text .= '」一覧'; //返り値として返す
} else {
$chapter_text = '[' . $chapter_text; //アーカイブタイトルの取得
$chapter_text .= get_archive_chapter_title(); //アーカイブタイトル後
$chapter_text .= '] Archive'; //返り値として返す
}
return $chapter_text;
}
// ************************************************************
// ****** ここから、prismのショートコード追加 *******
// 参考サイト https://tech.cmd08.com/wordpress-prism-js-shortcode
function set_prism_js()
{
if (is_single()) {
wp_enqueue_style('prism-style', get_stylesheet_directory_uri(). '/prism/prism.css', false, null);
wp_enqueue_script('prism-script', get_stylesheet_directory_uri(). '/prism/prism.js', false, null, true);
}
}
add_action('wp_enqueue_scripts', 'set_prism_js');
function shortcode_prism_js($atts, $content = null)
{
extract(shortcode_atts([
'language' => '',
'data_language' => '',
'data_line' => '',
'data_start' => ''
], $atts));
if ($data_language) {
$data_language = ' data-language="'. esc_attr($data_language). '"';
}
if ($data_line) {
$data_output = ' data-output="'. esc_attr($data_line). '"';
$data_line = ' data-line="'. esc_attr($data_line). '"';
}
if ($data_start) {
$data_start = ' data-start="'. esc_attr($data_start). '"';
}
if ($language == "command-line") {
$format = '<pre class="command-line" data-user="user" data-host="host"%s><code class="language-bash">%s</code></pre>';
return sprintf(
$format,
$data_output,
//htmlspecialchars(trim($content), ENT_QUOTES, 'UTF-8')
$content
);
} else {
$format = '<pre class="line-numbers"%s%s%s><code class="language-%s">%s</code></pre>';
return sprintf(
$format,
$data_language,
$data_line,
$data_start,
esc_attr($language),
//htmlspecialchars(trim($content), ENT_QUOTES, 'UTF-8')
$content
);
}
}
//add_shortcode('prism', 'shortcode_prism_js');
add_filter('the_content', function ($content) {
// 登録されている全ショートコード
global $shortcode_tags;
// 登録されているショートコードを退避してから消去
$orig_shortcode_tags = $shortcode_tags;
remove_all_shortcodes();
// wpautop関数実行前に処理したいショートコードをここで登録
add_shortcode('prism', 'shortcode_prism_js');
$content = preg_replace_callback(
'/\[prism(.+?)\](.+?)\[\/prism\]/su',
function ($matches) {
return '[prism'. $matches[1]. ']'. esc_html(trim($matches[2])). '[/prism]';
},
$content
);
// [prism]ショートコードを実行
$content = do_shortcode($content);
// 退避したショートコードを元に戻す
$shortcode_tags = $orig_shortcode_tags;
return $content;
}, 9, 1);
// ****** ここまで、prismのショートコード追加 *******
// ************************************************************
// コードの自動変換を停止
add_filter( 'run_wptexturize', '__return_false' );
// ************************************************************
// ****** ここから、Jetpackのパブリサイズのカスタマイズ *******
// 参考サイト https://blog.sus-happy.net/jetpack-publicize-custom/
//JetpackのOGPを止めて、simplicityのOGPを使う
remove_action('wp_head','jetpack_og_tags');
add_filter( 'jetpack_enable_opengraph', '__return_false' );
// パブリサイズ共有の文言を変更
function change_jetpack_publicize_content( $post_id, $post )
{
$POST_MESS = '_wpas_mess';
// 投稿,下書き,スケジュール待ちのみ
if ( !in_array( $post->post_status, array( 'publish', 'future' ) ) ) {
return;
}
// カスタムメッセージのPOSTがあったら無視
if ( !empty( $_POST['wpas_title'] ) ) {
return;
}
// カスタムメッセージがある場合は無視
if( get_post_meta( $post_id, $POST_MESS, TRUE ) ) {
return;
}
// 共有する文言の成形
if( $post->post_type == 'maron' ) {
$publicize_custom_message = sprintf( "まろん投稿:『%s』 見てにゃ\n %s", $post->post_title, wp_get_shortlink( $post->ID ) );
} else {
$publicize_custom_message = sprintf( "ブログ投稿:『%s』 \n %s", $post->post_title, wp_get_shortlink( $post->ID ) );
}
// カスタムメッセージとして登録
update_post_meta( $post_id, $POST_MESS, $publicize_custom_message );
// postmetaが削除されないように$_POSTにも代入
$_POST['wpas_title'] = $publicize_custom_message;
}
// JetPackのパブリサイズ共有のsave_postに対する処理の優先度は「20」
add_action( 'save_post', 'change_jetpack_publicize_content', 19, 2 );
// ****** ここまで、Jetpackのパブリサイズのカスタマイズ *******
// ************************************************************
<?php //トップページ用 ?>
<?php get_header(); ?>
<?get_template_part('breadcrumbs'); ?>
<? dynamic_sidebar('top_main_widget'); ?>
<?php get_template_part('list') ?>
<?php get_footer(); ?>
<?php
////////////////////////////
//パンくずリスト
////////////////////////////
if (is_archive() || is_post_type_archive() || is_author() || is_category()) {
get_template_part('breadcrumbs');
}
?>
<?php
////////////////////////////
//アーカイブのタイトル
////////////////////////////
//
// 略
//
<?php
//グローバル変数の呼び出し
global $g_widget_mode;//ウィジェットモード(全て表示するか、カテゴリ別に表示するか)
global $g_entry_count;
$args = array(
'posts_per_page' => $g_entry_count,
'orderby'=>'modified',
);
//
// 略
//
<?php
//グローバル変数の呼び出し
global $g_widget_mode;//ウィジェットモード(全て表示するか、カテゴリ別に表示するか)
global $g_entry_count;
$args = array(
'post_type' => array('maron'),
'posts_per_page' => $g_entry_count,
);
//
// 略
//
@charset "UTF-8";
/*!
Theme Name: Simplicity2 child
Template: simplicity2
Version: 20161002
*/
/* Simplicity子テーマ用のスタイルを書く */
@font-face {
font-family: 'mplus-1mn-regular';
font-style: normal;
font-weight: 400;
src: url('/font/mplus-1mn-regular.eot');
src: url('/font/mplus-1mn-regular.eot?#iefix') format('embedded-opentype'),
url('/font/mplus-1mn-regular.woff') format('woff'),
url('/font/mplus-1mn-regular.ttf') format('truetype');
}
body {
font-family: 'mplus-1mn-regular', sans-serif;
}
.top_main_widget {
background-color:#eee;
padding:10px;
margin-bottom:10px;
}
#sidebar h3{
text-align:center;
border: 2px solid #89BDDE;
border-radius: 10px;
}
a#footer-button-home{
display: block;
}
a#footer-button-prev,
a#footer-button-next{
display: none;
}
table.highlight tr:nth-child(2n+1) td {
background: #f5fffa;
}
table.highlight tr td,table.highlight tr td span {
font-weight:bold;
}
/* Breadcrumb NavXT パンくずリスト先頭にアイコンフォント表示と文字サイズを小さくする */
.breadcrumbs a.mainhome::before {
font-family: "FontAwesome";
content: "\f015 ";
}
.breadcrumbs a.home::before {
font-family: "FontAwesome";
content: "\f15c ";
}
.breadcrumbs a.post.post-page::before {
font-family: "FontAwesome";
content: "\f15c ";
}
.breadcrumbs a.taxonomy::before,
.breadcrumbs a.category::before {
font-family: "FontAwesome";
content: "\f07b ";
}
.breadcrumbs a.post.post-maron-archive::before {
font-family: "FontAwesome";
content: "\f1b0 ";
}
.breadcrumbs {
font-size: small;
margin-bottom: 14px;
}
/************************************
** サイドバー(Sidebar)・ウィジェットなど
************************************/
#sidebar h3{
margin-bottom: 10px;
font-size:20px;
}
#sidebar .widget{
margin-bottom: 45px;
}
.widget_search{
margin-bottom: 0;
}
#sidebar ul,
#sidebar ol,
.widget-over-article ul,
.widget-over-article ol,
.widget-under-article ul,
.widget-under-article ol,
.widget-over-sns-buttons ul,
.widget-over-sns-buttons ol,
.widget-under-sns-buttons ul,
.widget-under-sns-buttons ol{
padding-left: 1em;
list-style:none;
}
#sidebar ul.snsp,
#main ul.snsp,
#footer ul.snsp{
padding-left: 0;
}
.widget-over-article{
margin-top: 10px;
margin-bottom: 10px;
}
#sidebar-recent-posts li,
#sidebar-popular-posts li{
margin:20px 0;
}
#sidebar li{
margin-bottom: 8px;
}
.sidebar-thumbnail-box{
float: left;
width: 75px;
}
.sidebar-recent-posts-title{
float: right;
width: 165px;
}
#sidebar-recent-posts h3,
#sidebar-recent-posts p,
#sidebar-popular-posts h3,
#sidebar-popular-posts p{
margin: 0;
}
#main .widgets{
margin-top: 20px;
margin-bottom: 20px;
}
#sidebar .widget_category_sns_follow_buttons ul,
.widget_category_sns_follow_buttons ul{
padding-left: 0;
}
.widget_text ul {
list-style-type: disc;
}
.widget_text ol {
list-style-type: decimal;
}
/************************************
** 新着記事・人気記事(new, pupular)
************************************/
.widget_mymaronnewentrywidgetitem{
line-height:150%;
}
.widget_mymaronnewentrywidgetitem h4{
margin-bottom:15px;
}
#main .widget_mymaronnewentrywidgetitem ul,
#sidebar .widget_mymaronnewentrywidgetitem ul,
#footer .widget_mymaronnewentrywidgetitem ul {
padding-left:0;
list-style:none;
}
.widget_mymaronnewentrywidgetitem ul li {
clear: left;
float: none;
margin-bottom:10px;
/* overflow: auto;
zoom: 1;*/
}
.widget_mymaronnewentrywidgetitem ul li img {
border: medium none;
display: inline;
float: left;
margin-top: 3px;
margin-right: 5px;
width: 75px;
height: 75px;
margin-bottom: 10px;
border-radius: 10px;
}
span.wpp-views{
font-size:x-small;
font-style:italic;
}
/************************************
** 新着記事maron用
************************************/
.widget_mymaronnewentrywidgetitem .new-entrys-large .new-entry{
margin-bottom:15px;
line-height:120%;
position:relative;
display:block;
max-width: 440px;/*これを書いておかないと、タイトル部分がはみ出す*/
overflow: visible;
}
.widget_mymaronnewentrywidgetitem .new-entrys-large .new-entry img{
width:100%;
float:none;
margin:0;
display:block;
margin-bottom:5px;
min-height: 180px;
max-width: 440px;/*iPhone6は幅が414pxなのでそれより大きく*/
max-height: 240px;
height: auto;
}
.widget_mymaronnewentrywidgetitem .new-entrys-large-on .new-entry .new-entry-content{
position:absolute;
bottom:0;
left:0;
right:0;
/* 画像をBase64にするためコメントアウト
background: url("images/black-transparent.png") repeat scroll 0 0 transparent; */
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyAQMAAAAk8RryAAAAA1BMVEUAAACnej3aAAAAAXRSTlOZyTXzhgAAAA1JREFUGNNjGAWDCgAAAZAAAXtlmk8AAAAASUVORK5CYII=") repeat scroll 0 0 transparent;
/* opacity:0.7;
background-color:#333;*/
padding:10px;
max-height:28%;
overflow:hidden;
display:block;
}
.widget_mymaronnewentrywidgetitem .new-entrys-large-on .new-entry .new-entry-content a {
color:#fff;
/*opacity:0.8;*/
display:block;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment