How to add custom functions to a WordPress 1.5 theme?カスタム機能を追加する方法をWordPress 1.5のテーマですか?
Recently the question (How to add add custom functions to a theme) was posed in最近では、質問(カスタム機能を追加する方法を追加してテーマ)が提起さ WordPress Support Forum WordPressのサポートフォーラム .です。 Personally I faced the same question when re-designing個人的に私と同じ問題に直面するときに再設計 this siteこのサイトについて .です。 The following is a discussion of the option with the pros and cons.は、次のオプションは、議論の長所と短所です。
There are two solutions.には2つのソリューションです。
The first is to create a plugin which goes with the theme.の最初のプラグインを作成するには、これが当てはまるのテーマです。 However the theme, when invoking functions defined in the plugin should check first for the availability of the function.しかし、テーマは、差込式で定義された関数を呼び出す際に最初は、空室状況を確認すると、関数です。 It should also provide a fallback option if the plugin is not available or has not been activated.フォールバックオプションを提供することも差込式ではないがご利用の場合、または活性化されていない。
if(function_exists('your_function_name')) { // Invoke your function: your_function_name()...もし( function_exists ( ' your_function_name ( ' ) ) ( / /起動して機能: your_function_name ( ()... else { // Execute fallback option }他( / /実行フォールバックオプション)
The advantages are:の利点は:
- The plugin can be independently managed.差込式に個別に管理することです。
- The plugin can be reused for other purposes.差込式は、他の目的のために再利用します。
The disadvantages are:の短所は:
- It requires another additional step for the theme user to remember.別の追加が必要な手順をテーマにユーザーを覚えています。
- It slightly complicates development and testing.やや複雑、開発およびテストのことです。
The second solution to this problem would be to incorporate the functionaility in a php file (as usual) which resides in the theme directory. 2番目のこの問題の解決策を組み込むことをfunctionailityをPHPファイルに保存(いつもどおり)に居住してテーマディレクトリにコピーします。 This file is included in header.php like:このファイルはheader.phpに含まれるように:
include (’your_php_file.php’); 含まれて( ' your_php_file.php ' ) ;
Yes you may also require it for simplicity like:はいすることも簡単にするために必要なことのよう:
require (’your_php_file.php’); 必要( ' your_php_file.php ' ) ;
The advantage to this approach is simplicity of usage and deployment by end-users.このアプローチの利点を利用方法は、シンプルなエンドユーザと展開されています。 It also simplifies development.また、開発を簡素化します。
If the user later decides to switch to a different theme and yet wants to retain the functionality, he would have to re-purpose the custom code into a plugin.ユーザーへの場合、決定に切り替えるには、別のテーマと機能を保持するにはまだありません望ん、彼は、目的のために、カスタムコードを再するプラグインです。
In essence the reusability of the custom functionality determines the ideal location of the custom code.本質的に、カスタム機能の再利用には理想の場所を決定しているカスタムコードです。
Filed under提出されて CMS Software CMSソフトウェア , 、 Headline Newsニュースの見出し , 、 How Toどのように , 、 Pro BloggingプロBlogging , 、 Technology技術 , 、 Webウェブ , 、 WordPress WordPressの | |
| |
RSS 2.0 RSS 2.0を | |
Email this Article電子メールこの記事
You may also like to readを読むようにすることも可能 |





June 3rd, 2005 at 2:48 pm 2005年6月3日は2:48 pmの
Thanks for this.のおかげです。 ~I am new to both WordPress and PHP but also wanted a few home cooked functions. 〜私は新しいWordPressのとPHPの両方に指名手配するだけでなく、いくつかのホーム調理機能です。 In my case I wanted to change a couple of WP functions to return differently so I copied these, renamed them and made my changes so as not to disturb distributable files.私の場合はしたかったWPの機能を変更するにいくつかのコピーを返すので、これらの異なる、名前を変更し、変更は私が不安にならないように配布ファイルです。 Not knowing where to put them, I just created a my-hacks.php file and turned that one.どこに置くかわからないし、私だけマイ- hacks.phpファイルを作成することとし、背き1つです。 All works fine.すべて正常に動作します。 But is this NOT a good place to put my code?良くないけど、これが私のコードを置く場所ですか?
Appreciate any advice.何かアドバイスに感謝します。 Thanksありがとう
June 3rd, 2005 at 7:54 pm 2005年6月3日7:54 pmの
As I mentioned above, I think you should just create a plugin and put them there.として私上述したように、と思うプラグインを作成するだけとする必要がかれらに置く。
Ideally in your template you can check if the function is available (or whether the plugin is active) and then use it, if not use the default WordPress function.理想的なテンプレートにしてチェックすることができますがご利用の場合、関数は、 (またはかどうかの差込式がアクティブに)と入力し、使用するには、そうでない場合は、デフォルトのWordPressの関数を使用します。
I too use several such customized functions on my site all packed away in a generic plugin named Impact (named after my custom theme).私もいくつかのようなカスタマイズ機能を使用するすべての満員離れた自分のサイトに、汎用的差込式の名前への影響(名前の後に私のカスタムテーマ) 。
June 4th, 2005 at 5:45 pm 2005年6月4日は午後5時45分
Thanks for the advice.アドバイスをありがとうございます。 I’ll collect them all together if a my-hacks file until I;m complete then set about converting to a custom plugin as you suggest,Thanks again私が一緒に収集してすべてのファイルの場合、マイ- hacksまで私、男性については完全に入力し、セットに変換するためのカスタムプラグインとしてお勧め、ありがとう再び