子テーマディレクトリ作成
$ mkdir 親テーマ名 親テーマ名_child
もくじ
フォントを綺麗にしたい、表示の修正
$ vi style.css /* Theme Name: ajaira Child Template: ajaira */ @import url("../ajaira/style.css"); .entry-content { word-wrap: break-word; } .entry-content a{ text-decoration:underline; } .entry-title { word-wrap: break-word; } .nav-menu { background: #19317C; } ul, menu, dir{ -webkit-padding-start: 0px; } ol { -webkit-padding-start: 0px; } .menu-wrapper { background: #19317C; } ul, ol { margin-left : 5px !important; padding-left: 5px !important; } @media (max-width: 767px){ .slicknav_menu { background: #19317C !important; } .site-description { font-size: 15px; } .pagination-lg>li>a, .pagination-lg>li>span { padding: 10px 16px; font-size: 14px; line-height: 1.3333333; } } h1, h2, h3, h4, h5, h6 { font-family: sans-serif; line-height: 1.25; color: #2d2e33; } body, button, input, select, textarea { color: #333; font-family: Merriweather, Georgia, serif; font-size: 16px; line-height: 1.75; } a { color: black; text-decoration: none; -webkit-transition: .2s; transition: .2s; } #content img { display:block; margin: 0 auto; text-align: center; margin-bottom:0 !important; }
functions.php
- 管理画面にてタグ選択
- 管理画面URL変更
- 抜粋文字数変更
$ vi functions.php <?php // タグをカテゴリーのような仕様に変更 function re_register_post_tag_taxonomy() { global $wp_rewrite; $rewrite = array( 'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag', 'with_front' => ! get_option('tag_base') || $wp_rewrite->using_index_permalinks(), 'ep_mask' => EP_TAGS, ); $labels = array( 'name' => _x( 'Tags', 'taxonomy general name' ), 'singular_name' => _x( 'Tag', 'taxonomy singular name' ), 'search_items' => __( 'Search Tags' ), 'popular_items' => __( 'Popular Tags' ), 'all_items' => __( 'All Tags' ), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __( 'Edit Tag' ), 'view_item' => __( 'View Tag' ), 'update_item' => __( 'Update Tag' ), 'add_new_item' => __( 'Add New Tag' ), 'new_item_name' => __( 'New Tag Name' ), 'separate_items_with_commas' => __( 'Separate tags with commas' ), 'add_or_remove_items' => __( 'Add or remove tags' ), 'choose_from_most_used' => __( 'Choose from the most used tags' ), 'not_found' => __( 'No tags found.' ) ); register_taxonomy( 'post_tag', 'post', array( 'hierarchical' => true, 'query_var' => 'tag', 'rewrite' => $rewrite, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, '_builtin' => true, 'labels' => $labels ) ); } add_action( 'init', 're_register_post_tag_taxonomy', 1 ); // タグをカテゴリーのような仕様に変更 ここまで // 管理画面URL切り替え define( 'LOGIN_CHANGE_PAGE', 'himitsudayo.php' ); add_action( 'login_init', 'login_change_init' ); add_filter( 'site_url', 'login_change_site_url', 10, 4 ); add_filter( 'wp_redirect', 'login_change_wp_redirect', 10, 2 ); // 指定以外のログインURLは403エラーにする if ( ! function_exists( 'login_change_init' ) ) { function login_change_init() { if ( !defined( 'LOGIN_CHANGE' ) || sha1( 'keyword' ) != LOGIN_CHANGE ) { status_header( 403 ); exit; } } } // ログイン済みか新設のログインURLの場合はwp-login.phpを置き換える if ( ! function_exists( 'login_change_site_url' ) ) { function login_change_site_url( $url, $path, $orig_scheme, $blog_id ) { if ( $path == 'wp-login.php' && ( is_user_logged_in() || strpos( $_SERVER['REQUEST_URI'], LOGIN_CHANGE_PAGE ) !== false ) ) $url = str_replace( 'wp-login.php', LOGIN_CHANGE_PAGE, $url ); return $url; } } // ログアウト時のリダイレクト先の設定 if ( ! function_exists( 'login_change_wp_redirect' ) ) { function login_change_wp_redirect( $location, $status ) { if ( strpos( $_SERVER['REQUEST_URI'], LOGIN_CHANGE_PAGE ) !== false ) $location = str_replace( 'wp-login.php', LOGIN_CHANGE_PAGE, $location ); return $location; } } // 管理画面URL切り替え ここまで // 抜粋文字数変更 function custom_excerpt_mblength() { return 160; } add_filter( 'excerpt_mblength', 'custom_excerpt_mblength' ); // 最初の画像をアイキャッチ替わりにする function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ // 記事内で画像がなかったときのためのデフォルト画像を指定 //$first_img = "/images/default.jpg"; } return $first_img; }
スマホページのナビゲーションを変更する
複製
$ cp /var/www/vhosts/www.yuulinux.tokyo/httpdocs/contents/wp-content/themes/ajaira/archive.php /var/www/vhosts/www.yuulinux.tokyo/httpdocs/contents/wp-content/themes/ajaira_child/archive.php
the_posts_navigation()がスマホで上手く動作しないので、ナビゲーション関数を差し替える。
vi /var/www/vhosts/www.yuulinux.tokyo/httpdocs/contents/wp-content/themes/ajaira_child/archive.php (略) <?php /* Start the Loop */ while ( have_posts() ) : the_post(); /* * Include the Post-Format-specific template for the content. * If you want to override this in a child theme, then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'template-parts/content', get_post_format() ); endwhile; //the_posts_navigation(); ←●無効化 ajaira_paging_nav(); // ←●追加 else : get_template_part( 'template-parts/content', 'none' ); endif; ?> (略)
サムネイルがなければ最初の画像を抜粋する
$ mkdir /var/www/vhosts/www.yuulinux.tokyo/httpdocs/contents/wp-content/themes/ajaira_child/template-parts $ cp /var/www/vhosts/www.yuulinux.tokyo/httpdocs/contents/wp-content/themes/ajaira/template-parts/content.php /var/www/vhosts/www.yuulinux.tokyo/httpdocs/contents/wp-content/themes/ajaira_child/template-parts/content.php $ vi /var/www/vhosts/www.yuulinux.tokyo/httpdocs/contents/wp-content/themes/ajaira_child/template-parts/content.php </header><!-- .entry-header --> <?php if( has_post_thumbnail() ) { ?> <div class="post-image"> <a href="<?php echo esc_url( get_permalink() ); ?>" rel="bookmark" > <?php the_post_thumbnail( ); ?> </a> </div> <!-- .post-image --> <?php } ※下記を追加 else{ echo '<img src="'.catch_that_image().'" />'; } ?> ※ここまで