How to add custom functions to a WordPress 1.5 theme? عرف كيفية اضافة وظائف الى 1،5 WordPress الموضوع؟
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. هناك حلين.
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 في ملف بي. اتش. بى (كالعاده) الذي يقيم في موضوع الدليل. 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 برمجيه , ، Headline News أهم الانباء , ، How To كيف , ، Pro Blogging الموالية بلوغغينغ , ، Technology التقنيه , ، Web شبكة , ، WordPress | |
| |
RSS 2.0 ار اس اس 2،0 | |
Email this Article ارسل هذه المادة
You may also like to read ويمكنك ايضا ان تقرأ |




June 3rd, 2005 at 2:48 pm يونيو 3rd ، 2005 في الساعة 2:48
Thanks for this. شكرا لهذا. ~I am new to both WordPress and PHP but also wanted a few home cooked functions. ~ انا جديدة على كل من بي. اتش. بى WordPress ولكن يريد ايضا عدد قليل من المهام الرئيسية طهي. 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 يونيو 3rd ، 2005 في الساعة 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 يونيو 4th ، 2005 في 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 انا جمع لهم جميعا معا وإذا بي - المأجورون الملف حتى الاول ؛ م عن مجموعة كاملة ثم مخصص لتحويل البرنامج المساعد كما اقترحتم ، الشكر مرة اخرى