*

WordPressの小テーマでfunctions.phpを使うの巻

公開日: : WEB

screen20130501c

小テーマのfunctions.php利用は、あっさり出来ました

連休を利用してWordPressのテーマを変更中です
あっさり出来たのですが、1点、問題が発生
関数で利用している機能が上手く出来ていません

問題を起こしている機能は、こちら↓
繰り返し表示を大量生産! WordPressで差込表示するの巻 | No:822 | でんきもの カフェ

その機能は元々functions.phpに書かれているのですが、ネットで調べると、どうも厄介なものらしいのです
どのように厄介なのかというと、小テーマと親テーマのfunctions.phpにダブって書かれていると機能しないのでなく、白画面のエラー画面になるらしいのです

って、親テーマに書けば解決じゃん!と思うのですが、テーマのアップデートがあるとファイルが更新され書かれたものが消えてしまう
アップデートのたびに書き加えるのも面倒
ジレンマ
なら、小テーマのfunctions.phpに書いてしまえでやってみたところ、あっさり動作
関数がダブっていなかったから出来たようです

簡単でした

screen20130501a
最初はこんな感じ
[]で囲まれたショートカットが上手く変換されていません

screen20130501b
単純に親テーマから小テーマにfunctions.phpをコピーした場合
関数ダブりでエラー画面になります

で、今回、小テーマの内容は、このように、必要部分だけ、もって来ました

<?php
/**
 * Twenty Eleven functions and definitions
 *
 * Sets up the theme and provides some helper functions. Some helper functions
 * are used in the theme as custom template tags. Others are attached to action and
 * filter hooks in WordPress to change core functionality.
 *
 * The first function, twentyeleven_setup(), sets up the theme by registering support
 * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
 *
 * When using a child theme (see http://codex.wordpress.org/Theme_Development and
 * http://codex.wordpress.org/Child_Themes), you can override certain functions
 * (those wrapped in a function_exists() call) by defining them first in your child theme's
 * functions.php file. The child theme's functions.php file is included before the parent
 * theme's file, so the child theme functions would be used.
 *
 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
 * to a filter or action hook. The hook can be removed by using remove_action() or
 * remove_filter() and you can attach your own function to the hook.
 *
 * We can remove the parent theme's hook only after it is attached, which means we need to
 * wait until setting up the child theme:
 *
 * <code>
 * add_action( 'after_setup_theme', 'my_child_theme_setup' );
 * function my_child_theme_setup() {
 *     // We are providing our own filter for excerpt_length (or using the unfiltered value)
 *     remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
 *     ...
 * }
 * </code>
 *
 * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */

/*-------------------------------------------------------*/

function show_file_func( $atts ) {
	extract( shortcode_atts( array('file' => ''), $atts ) );

	if ($file!='') return @file_get_contents($file);
}

add_shortcode( 'show_file', 'show_file_func' );

screen20130501c
そうすると、このように無事、変換されました
よかった

簡単、かんたんでした

PC

関連記事

サイトのダウンが直ぐ判る!IS IT DOWN RIGHT NOW?

落ちているサイトを判別できるのは便利です 先日のこと、自分のサイトにアクセスで

記事を読む

改善しないなあ、どうしたもんでしょ! アクセス数低下

いろいろ手を打っているのですが、アクセス数の低下に歯止めがかかりません う~ん

記事を読む

ブログにWordPressのメンテナンス表示が出てしまったの巻

一瞬、焦りましたが無事に回復できてよかったです ちょっとした不注意で慌てましたので、ご

記事を読む

アクセス低迷中! 重複するメタデータやタイトルタグの重複の改善なし

アクセス低迷中w 先日から報告しているウェブマスターツールの重複するメタデータ

記事を読む

アフェリエイトを少し有利に!もしもアフェリエイトを申請、カエレバ、ヨメレバを設定してみたの巻

ちょっとアフェリエイトが有利になりそうです はじめ ブログのアクセス数もちょこっと伸びて

記事を読む

繰り返し表示を大量生産! WordPressで差込表示するの巻

WordPressの記事で特定のシリーズなどで同じ文章を繰り返し表示したいときってありますよね

記事を読む

WordPressのLightBoxが、おかしくなったので直してみたの巻

どうも一時期、プラグインのアップデートでプラグイン同士の齟齬が発生したようです ちょっ

記事を読む

12月だ! 大掃除の季節! WordPressのHeader内を掃除をしてみるの巻

12月です 大掃除の季節です WordpressのHeader内の余分なタグを削除してみ

記事を読む

Yahoo JapanディベロッパーネットワークのアプリケーションIDを簡単に取得してみる

プロジェクトJでYahoo JapanのディベロッパーネットワークのアプリケーションIDを取る必要が

記事を読む

「あっという間に月25万PVをかせぐ人気ブログのつくり方―これだけやれば成功する50の方法」を3つに分析!

「あっという間に月25万PVをかせぐ人気ブログのつくり方―これだけやれば成功する50の方法」を3つに

記事を読む

PC

PC

PAGE TOP ↑