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. 두 번째 해결 방법이 문제가 될 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 직업적인 블로깅 , 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분
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. 나의 케이스에서 백린 싶었을 변경하는 기능을 두어 복사를 반환 다르게 그래서 이들이 제 이름을 변경하고 변경 내용 파일을 배포할 수 방해되지 않도록합니다. Not knowing where to put them, I just created a my-hacks.php file and turned that one. 어디에 담아도 모르고, 단지 내 - hacks.php 파일 및 설정을 만들어 한합니다. 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분
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 경우에는 파일을 때까지는, 남성 전체를 설정 사용자 정의 플러그 접속으로 변환하는 당신이 제안에 대해, 다시 한 번 감사드립니다