Advertisement
Guest User

Untitled

a guest
Aug 12th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.03 KB | None | 0 0
  1. <?php
  2. function load_script(){
  3. wp_enqueue_script('jquery');
  4. }
  5. add_action('init', 'load_script');
  6.  
  7. //アイキャッチサムネイル
  8. add_theme_support('post-thumbnails');
  9. add_image_size('thumb100',100,100,true);
  10. add_image_size('thumb110',110,110,true);
  11. add_image_size('thumb170',170,170,true);
  12.  
  13. //WordPress の投稿スラッグを自動的に生成する
  14. function auto_post_slug( $slug, $post_ID, $post_status, $post_type ) {
  15. if ( preg_match( '/(%[0-9a-f]{2})+/', $slug ) ) {
  16. $slug = utf8_uri_encode( $post_type ) . '-' . $post_ID;
  17. }
  18. return $slug;
  19. }
  20. add_filter( 'wp_unique_post_slug', 'auto_post_slug', 10, 4 );
  21.  
  22. //カスタムメニュー
  23. register_nav_menus(array('navbar' => 'ナビゲーションバー'));
  24.  
  25. //カスタムヘッダー
  26. $args = array(
  27. 'width' => 1035,
  28. 'height' => 84,
  29. 'flex-height' => true,
  30. 'default-image' => get_template_directory_uri() . '/images/stinger3.png',
  31. );
  32. add_theme_support( 'custom-header', $args );
  33.  
  34. //RSS
  35. add_theme_support('automatic-feed-links');
  36.  
  37. //エディタスタイル
  38. add_theme_support('editor-style');
  39. add_editor_style('editor-style.css');
  40. function custom_editor_settings( $initArray ){
  41. $initArray['body_class'] = 'editor-area';
  42. return $initArray;
  43. }
  44. add_filter( 'tiny_mce_before_init', 'custom_editor_settings' );
  45.  
  46. //画像に重ねる文字の色
  47. define('HEADER_TEXTCOLOR', '');
  48.  
  49. //画像に重ねる文字を非表示にする
  50. define('NO_HEADER_TEXT',true);
  51.  
  52. //投稿用ファイルを読み込む
  53. get_template_part('functions/create-thread');
  54.  
  55. //カスタム背景
  56. add_theme_support( 'custom-background' );
  57.  
  58. //ページャー機能
  59. function pagination($pages = '', $range = 4)
  60. {
  61. $showitems = ($range * 2)+1;
  62.  
  63. global $paged;
  64. if(empty($paged)) $paged = 1;
  65.  
  66. if($pages == '')
  67. {
  68. global $wp_query;
  69. $pages = $wp_query->max_num_pages;
  70. if(!$pages)
  71. {
  72. $pages = 1;
  73. }
  74. }
  75.  
  76. if(1 != $pages)
  77. {
  78. echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
  79. if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link
  80.  
  81. (1)."'>&laquo; First</a>";
  82. if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;
  83.  
  84. Previous</a>";
  85.  
  86. for ($i=1; $i <= $pages; $i++)
  87. {
  88. if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems
  89.  
  90. ))
  91. {
  92. echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link
  93.  
  94. ($i)."' class=\"inactive\">".$i."</a>";
  95. }
  96. }
  97.  
  98. if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged +
  99.  
  100. 1)."\">Next &rsaquo;</a>";
  101. if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a
  102.  
  103. href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
  104. echo "</div>\n";
  105. }
  106. }
  107.  
  108. //ヘッダーを綺麗に
  109. remove_action( 'wp_head', 'feed_links_extra', 3 );
  110. remove_action( 'wp_head', 'feed_links', 2 );
  111. remove_action( 'wp_head', 'rsd_link' );
  112. remove_action( 'wp_head', 'wlwmanifest_link' );
  113. remove_action( 'wp_head', 'index_rel_link' );
  114. remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
  115. remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
  116. remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
  117. remove_action( 'wp_head', 'wp_generator' );
  118.  
  119. //moreリンク
  120. function custom_content_more_link( $output ) {
  121. $output = preg_replace('/#more-[\d]+/i', '', $output );
  122. return $output;
  123. }
  124. add_filter( 'the_content_more_link', 'custom_content_more_link' );
  125.  
  126. //セルフピンバック禁止
  127. function no_self_ping( &$links ) {
  128. $home = home_url();
  129. foreach ( $links as $l => $link )
  130. if ( 0 === strpos( $link, $home ) )
  131. unset($links[$l]);
  132. }
  133. add_action( 'pre_ping', 'no_self_ping' );
  134.  
  135.  
  136. //ウイジェット追加
  137. if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(4) )
  138. register_sidebars(1,
  139. array(
  140. 'name'=>'サイドバー1',
  141. 'before_widget' => '<ul><li>',
  142. 'after_widget' => '</li></ul>',
  143. 'before_title' => '<h4 class="menu_underh2">',
  144. 'after_title' => '</h4>',
  145. ));
  146. register_sidebars(1,
  147. array(
  148. 'name'=>'スクロール広告用',
  149. 'before_widget' => '<ul><li>',
  150. 'after_widget' => '</li></ul>',
  151. 'before_title' => '<h4 class="menu_underh2" style="text-align:left;">',
  152. 'after_title' => '</h4>',
  153. ));
  154. register_sidebars(1,
  155. array(
  156. 'name'=>'Googleアドセンス用',
  157. 'before_widget' => '',
  158. 'after_widget' => '',
  159. 'before_title' => '<h4 style="display:none">',
  160. 'after_title' => '</h4>',
  161. ));
  162.  
  163. register_sidebars(1,
  164. array(
  165. 'name'=>'Googleアドセンスのスマホ用width300',
  166. 'before_widget' => '',
  167. 'after_widget' => '',
  168. 'before_title' => '<h4 style="display:none">',
  169. 'after_title' => '</h4>',
  170. ));
  171.  
  172. //contents widthの指定
  173. if ( ! isset( $content_width ) ) $content_width = 620;
  174.  
  175. //更新日の追加
  176. function get_mtime($format) {
  177. $mtime = get_the_modified_time('Ymd');
  178. $ptime = get_the_time('Ymd');
  179. if ($ptime > $mtime) {
  180. return get_the_time($format);
  181. } elseif ($ptime === $mtime) {
  182. return null;
  183. } else {
  184. return get_the_modified_time($format);
  185. }
  186. }
  187.  
  188. //ショートコードを外す
  189. function stinger_noshotcode( $content ) {
  190. if ( ! preg_match( '/\[.+?\]/', $content, $matches ) ) {
  191. return $content;
  192. }
  193.  
  194. $content = str_replace( $matches[0], '', $content );
  195.  
  196. return $content;
  197. }
  198.  
  199. //スマホ表示分岐
  200. function is_mobile(){
  201. $useragents = array(
  202. 'iPhone', // iPhone
  203. 'iPod', // iPod touch
  204. 'Android.*Mobile', // 1.5+ Android *** Only mobile
  205. 'Windows.*Phone', // *** Windows Phone
  206. 'dream', // Pre 1.5 Android
  207. 'CUPCAKE', // 1.5+ Android
  208. 'blackberry9500', // Storm
  209. 'blackberry9530', // Storm
  210. 'blackberry9520', // Storm v2
  211. 'blackberry9550', // Storm v2
  212. 'blackberry9800', // Torch
  213. 'webOS', // Palm Pre Experimental
  214. 'incognito', // Other iPhone browser
  215. 'webmate' // Other iPhone browser
  216.  
  217. );
  218. $pattern = '/'.implode('|', $useragents).'/i';
  219. return preg_match($pattern, $_SERVER['HTTP_USER_AGENT']);
  220. }
  221.  
  222.  
  223. function add_ads_before_1st_h2($the_content) {
  224. if (is_single()) {
  225. if (wp_is_mobile()) {
  226. $ads = <<< EOF
  227. ★レクタングル中のコードを記述
  228. EOF;
  229. } else {
  230. $ads = <<< EOF
  231. ★レクタングル大のコードを記述
  232. EOF;
  233. }
  234. $h2 = '/<h2.*?>/i';//H2見出しのパターン
  235. if ( preg_match( $h2, $the_content, $h2s )) {//H2見出しが本文中にあるかどうか
  236. $the_content = preg_replace($h2, $ads.$h2s[0], $the_content, 1);//最初のH2を置換
  237. }
  238. }
  239. return $the_content;
  240. }
  241. add_filter('the_content','add_ads_before_1st_h2');
  242.  
  243. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement