How to add custom functions to a WordPress 1.5 theme? Come aggiungere funzioni personalizzate a un tema di WordPress 1,5?
Recently the question (How to add add custom functions to a theme) was posed in Recentemente la questione (Come aggiungere aggiungere funzioni personalizzate a un tema) è stata posta in WordPress Support Forum WordPress forum di supporto . Personally I faced the same question when re-designing Personalmente ho riscontrato la stessa domanda quando ri-progettazione this site questo sito . The following is a discussion of the option with the pros and cons. Il seguente è una discussione l'opzione con il pro e il contro.
There are two solutions. Ci sono due soluzioni.
The first is to create a plugin which goes with the theme. Il primo è quello di creare un plugin che va con il tema. However the theme, when invoking functions defined in the plugin should check first for the availability of the function. Tuttavia il tema, quando invocando funzioni definite nel plug-dovrebbe verificare prima per la disponibilità della funzione. It should also provide a fallback option if the plugin is not available or has not been activated. Essa dovrebbe inoltre fornire un ripiego opzione se il plugin non è disponibile o non è stato attivato.
if(function_exists('your_function_name')) { // Invoke your function: your_function_name()... if (function_exists ( 'your_function_name')) (/ / Richiama il tuo funzione: your_function_name ()... else { // Execute fallback option } else (/ / Esecuzione di ripiego opzione)
The advantages are: I vantaggi sono:
- The plugin can be independently managed. Il plugin può essere gestito indipendentemente.
- The plugin can be reused for other purposes. Il plugin possono essere riutilizzati per altri scopi.
The disadvantages are: Gli svantaggi sono:
- It requires another additional step for the theme user to remember. Essa richiede un altro ulteriore passo per il tema utente da ricordare.
- It slightly complicates development and testing. Si complica leggermente lo sviluppo e la sperimentazione.
The second solution to this problem would be to incorporate the functionaility in a php file (as usual) which resides in the theme directory. La seconda soluzione a questo problema sarebbe quello di integrare la functionaility php in un file (come al solito) che risiede in tema di directory. This file is included in header.php like: Questo file è incluso in header.php come:
include (’your_php_file.php’); include ( 'your_php_file.php');
Yes you may also require it for simplicity like: Sì si possono anche richiedere che per semplicità come:
require (’your_php_file.php’); richiedono ( 'your_php_file.php');
The advantage to this approach is simplicity of usage and deployment by end-users. Il vantaggio di questo approccio è la semplicità di utilizzo e di implementazione da parte degli utenti finali. It also simplifies development. Ha inoltre semplifica lo sviluppo.
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. Se l'utente decide più tardi a passare a un tema diverso e ancora vuole mantenere la funzionalità, che avrebbe dovuto ri-fine, il codice personalizzato in un plugin.
In essence the reusability of the custom functionality determines the ideal location of the custom code. In sostanza la riutilizzabilità dei personalizzato funzionalità determina la posizione ideale del codice personalizzato.
Filed under Elencato sotto CMS Software CMS Software , Headline News Headline News , How To Come , Pro Blogging Pro Blogging , Technology Tecnologia , Web , WordPress | |
| |
RSS 2.0 RSS 2,0 | |
Email this Article Invia questo articolo
You may also like to read Si può anche leggere come |





June 3rd, 2005 at 2:48 pm 3 giugno 2005 a 2:48 pm
Thanks for this. Grazie per questo. ~I am new to both WordPress and PHP but also wanted a few home cooked functions. ~ Io sono una novità per entrambi WordPress e PHP, ma anche voluto qualche casa cotti funzioni. 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. Nel mio caso ho voluto cambiare un paio di WP funzioni per tornare in modo diverso Ho copiato questi, rinominati e messi a loro i miei cambiamenti in modo da non disturbare i file distribuibili. Not knowing where to put them, I just created a my-hacks.php file and turned that one. Non sapendo dove metterli, ho appena creato un my-hacks.php file e trasformato quello. All works fine. Tutti i funziona bene. But is this NOT a good place to put my code? Ma questo non è un buon posto per mettere il mio codice?
Appreciate any advice. Apprezziamo qualsiasi consulenza. Thanks Grazie
June 3rd, 2005 at 7:54 pm 3 giugno 2005 a 7:54 pm
As I mentioned above, I think you should just create a plugin and put them there. Come ho già detto in precedenza, credo che si dovrebbe creare un plug-in e metterli là.
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. Idealmente nel tuo modello è possibile verificare se la funzione è disponibile (o se il plugin è attiva) e poi usarlo, se non utilizzare la funzione di default di 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). Anch'io uso più di tali funzioni personalizzate sul mio sito tutti i imballati via in una generica plug nome d'impatto (dal nome di mio tema personalizzato).
June 4th, 2005 at 5:45 pm 4 giugno 2005 a 5:45 pm
Thanks for the advice. Grazie per il consiglio. 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 I'll raccoglierli tutti insieme, se un mio file di hack-fino al I; m completo quindi impostare circa la conversione ad un plugin personalizzato come lei suggerisce, Grazie ancora