What to keep in mind when making Wordpress themes - php

I have been making Wordpress themes for a year or two and keep running into things I need to keep in mind when trying to make my themes as compatible and flexible as possible with their settings, plugins, etc.
Is there a resource that keeps a checklist of all the "don't forgets" of Wordpress theming? What things do you try to keep in mind when building your Wordpress themes?
Examples:
Checking if the author/admin has disabled comments for a particular post.
Remembering to call wp_head() at the end of the <head> tag.
Remembering to call wp_footer() at the end of the <body> tag.
Using bloginfo() variables instead of setting static values for charset, html type, description, etc. so admins can modify such things in the site settings.
Using function_exists() before calling a function from a plugin so it fails gracefully if that plugin isn't installed.

Wordpress documentation has an interesting topic addressing exactly what you're asking: it's called Designing Themes For Public Release. There's also Theme Development General Guidelines. The Templates article is wonderful too.
I don't know other official resources, but it would be interesting to add more info into those three guides. I'm interested in some other answers we may have in your question to complement them.
I'm so used to Wordpress that the examples you wrote just flows automatically when I'm developing, since using a function that outputs domain information such asbloginfo() instead of static values is a good practice in any web development.

A theme development checklist depends more on the intended audience for your theme. If it's beyond the basic blog and moving towards WordPress-as-CMS territory, you'd want to look into:
custom widgets and dynamic sidebars to make features more portable and flexible
support for custom fields, or plugins like MagicFields that implement the former in a whole new way
routing and creating custom templates for different levels of the site (ex: sub-categories get handled by category-x.php)
using a css framework so whoever gets to modify the styles has a higher chance of understanding it better; make sure to include ie support
custom wp-admin section with its own menus, pages, etc.; this is especially necessary if your theme has custom functionality that can be further customized by the user
use the wp_scripts and wp_styles classes and functions to add styles and scripts; this is especially important for javascript, as it prevents duplicate includes and works with dependency scripts (loads jQuery before your jQ script)
make sure the design of the theme doesn't look boring like everything else out there for WordPress
write a theme class; unless you're planning to support PHP4, use PHP5 classes and objects to make your life easier, in terms of feature inheritance and no naming conflicts. look at CodeIgniter and their singleton pattern; it makes custom globals inside template files a lot easier to manage
if you are (and you should be) making your theme a lot more advanced and more like a plugin, then know how to use the WP_Cache and WP_Rewrite objects so your custom queries with $wpdb (yes, you'll need to do these once in a while to get certain custom functionality) are less expensive, and your new pages (if you're rewriting urls) route correctly and your links are correctly dynamically generated, respectively.
last and most importantly, try your hardest to separate presentation (html) from logic (php); this gets hard as you start running custom WP loops and a good solution is the aforementioned theme class.

Our firm also develops a lot of various WordPress & WordPress MU themes & we haven't found any "Official" resources, but one thing we've done is create a basic set of template files can can be used as a "standard" setup in order to speed up our development process.
Then, whenever a new theme needs to be developed, we basically copy / paste this default set of template files into a new theme folder on the WordPress install. For us, items we've included in this default setup are pre-populated header.php, footer.php, index.php, home.php, single.php, functions.php, comments.php, /images (dir), /functions (dir), style.css, /css (dir), /scripts (dir), and a handfull of other items.
Then we've also used Yahoo Grids or Google Blueprint css frames works to also speed up the css work. There's a few other items / files I'm leaving out, but should give you a general idea of what works best for us in our shop.

Related

Converting PHP site to Joomla

I have a large complex web site currently implemented using PHP and MySQL.
Some of the pages (about, contact us, etc) are largely static, but need to be updated from time to time. I'd like these updates to be able to be done by non technical admins, so I'm migrating the site to Joomla CMS. I've created a Joomla template to reproduce the banners, styling etc of my existing web site and have successfully reproduced the static pages by cutting and pasting into Joomla articles.
I'm now trying to embed my existing dyanamic php pages into the Joomla framework. I assume that I need to convert them into one or more Joomla components? I realize that I'll need to strip out the php code that currently generates banners, menus, etc, but I don't want to make major changes to these php pages, i.e. I don't want to re-implement them to follow an MVC pattern. I'm looking for a simple Joomla 3.2 hello world component tutorial. The tutorials that I've found are either too complex (i.e. MVC) or they're "too simple". By too simple I mean the component is not listed when I select Menu Item Type within the Menu Manager. Can anyone point me to any documentation that explains the minimal config that I need to include in a custom Joomla 3.2 component in order for the component to be listed when selecting Menu Item Type?
Also, should I create one big custom component to wrap my existing PHP application containing multiple pages("views"?)? Conceptually there the system could be considered as about 3 sub-systems, but there is some overlap between the MySQL tables used in these different sub-systems.
I don't need the implementation to be portable, i.e. I'm not trying to create a reusable component that others could use, I just need it to work on my site, using the least amount of work possible.
Thanks, Wayne.
I hope to clarify a bit and give you way out.
In response to your comment on #user3057084, the power of Joomla and its flexibility comes from it being MVC! If you want to wrap your existing code with little modifications, Wordpress will let you do all kind of nasty things! Nasty in the sense of mixing logic with data, i.e. copying and pasting your code and getting it to work quickly.
Joomla coding standards require that you separate models from views. And that you understand how the Joomla MVC implementation works. It will take longer, but you'll learn a useful skill that can and should be applied if you want to write portable maintainable code following Design Patterns.
Now about the way out.
Nothing keeps you from putting your raw php code in a Joomla view, including the database access. It's really ugly and I feel bad even suggesting this, but if it can be a small step towards using a great framework, then the end justifies the means.
The absolute easiest way for you in Joomla would be to create a template override (which you'll do from the admin with a few clicks in the template manager), then throw your code in, and it will run. Then, a little bit at a time, you might learn to separate the parsing of the input in the controller, store / retrieve the data in a model, and leave just the markup in the view.
But are you absolutely sure you need to code for this? There are thousands of (free) extensions out there that might do the job for you with no coding and little configuration, leaving you just a data migration to handle.
Have you had a look at Wordpress yet? In my experience, non-technical people find it easier to administer a wordpress website in comparison to a Joomla website.
When it comes to the menu structures,themes and contact forms and blogs - Wordpress takes the cake.
It would be worth your while to check it out? It might save you hours of frustration?

Where to put custom function in Joomla

I want to create some function for rendering images from within Joomla v1.5.23. That function should be visible through all joomla application.
Where I have to put that function? Should I create plug in, modul or something else?
Best regards
Version info would be helpful, but I believe your answer is to create a plugin. Components are very broad "mini applications" installed and executed within Joomla. Modules are typically pieces of code that display information from a component, or an outside source. Plugins have various places within Joomla, depending on what they do - like authentication, or admin, etc. You'll have to define what role the plugin will play to determine where it fits into that hierarchy. Once done though, the plugin will be loaded, and you'll be able to access it's functions from within Joomla.
This link will show you how to begin by writing a content plugin. Note the events that are available. This isn't too difficult to do, so don't overcomplicate it, and you should be fine. An example of a System Plugin (which sounds like what you're looking for) can be seen at http://docs.joomla.org/Plugin/Events/System.

Creating multilingual wordpress site with shared structure and php functions

I know there are many multilingual wp plugins but I'm not sure which method should I use for this purpose;
I'd like to create a wp site with advanced features, partly coded by myself in php. Then I generally want to create duplicates of this site's structure, design and behavior in other languages, for example, es.blog.com would be a duplicate of en.blog.com. The content, however, shouldn't be shared.
I'd also like to keep changing the code only at one place and make those changes affect all the other languages duplicates, so I assume that means the code itself, or parts of it, would be shared.
Is there a way to have a shared structure, design and functions for several blogs, while the content of each blog is different?
I believe this is a perfect case for WordPress Multisite.
Multilingual Network (forum thread)
I would like for users to choose their language when they first get to the site - so they can choose to read, register, administer the entire site (front end and back) in either English, Kurdish (and perhaps others).
How to set a bilingual or multilingual WordPress multisite blog (blog post)
I need two independent sites to facilitate the plugins and theme localization with an easy way to switch between languages if a translation is available. Another reason is to optimize the search engine indexing. With this solution I can have some language specific posts without translation.
[ update ]
Multilingual Press (plugin)
Each site/blog can then be attributed to a different language. Simply write a post or page in one language and Multilingual-Press will automatically create a duplication of it in the other sites/blogs. These new posts and pages are interlinked and are easily accessible via the post/page editor screen - you can switch back and forth to translate them! Multilingual-Press is WordPress conform, easy to install and doesn't make any changes to the WordPress core. It doesn't harm your website's performance.
You could use any MVC framework to achieve this, and simply store the data in a database with a 'language' field and call only rows from that language.
Google 'MVC Framework'.
A good and free example would be CodeIgniter.
In CodeIgniter, you can include the Wordpress files in your 'libraries' folder then create a model with the specific functions you need to use.
Finally, you would have to create an .HTACCESS file to get the sub-domain section from the URL if you were to use this approach, however, again, there are many tutorials on achieving this, google 'htaccess URL rewrite'
I wouldn't recommend WP for any true multilingual site, searches get messed up, plugin-incompability etc.
Install parallell WP-instances in subdirs and make one the "master" for dev/bugfixes. Content is isolated and you can use standard WP-features without metadata or plugin-hacks.
By "changing the code", I presume you mean the template? It's a simple drag'n'drop in a decent ftp-client.

Why does magento use xml files for themeing? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am new to Magento and studying its documentation. Excuse me if I sound a bit to much against it but I am open minded. I don't understand why Magento uses XML for theming. What's the reason behind it?
I am running the newest version 1.6 from the SVN repo and following this site.
I read that I need to create local.xml declaring what gets in and out of the theme. After I did the basic structure then added my theme directory through the backend. I removed a elements on the front end using a few xml elements
Example:
<remove name="right.poll"/>
<remove name="right.permanent.callout"/>
<remove name="left.permanent.callout"/>
<remove name="paypal.partner.right.logo"/>
The homepage doesn't change... why is this? Is there another location that would need modification? I found out that i needed to disable all caching for dev only.
(for those that dont know its (admin page) -> system -> cache management -> select all and disable)
I also don't understand why the CSS/JS/media directory is completely separate from the template directory. It makes no sense why they would do this. Another thing I don't understand is why there are a million directories (sarcasm) that I need to get into to make a modification. I assume they are using some kind of MVC model but it is by far nothing I have ever seen. If they are attempting to make pretty URLs with all these directories I'm pretty sure they have heard of htaccess. (again excuse me if I sound ignorant but I am new).
PS., I looked into the phtml files and most of them look like their just calling these XML elements, is it possible to use plain old HTML and PHP to create a theme? Or am I forced to use their XML methods?
edit: the theme folder at app/design/frontend has two folders base and default which im thinking each of these are interfaces for example a group of themes i would like to use. i modified the design_change db table from default/default to base/default (also done on the admin page but i like the db better). i saw that a different page was rendered. so i figured i can just take out the base folder because its extra confusion. when i did that the site broke. so it looks like magento has tied two theme directories into this application. its as if they are just as confused as we are. am i right?
Please let me know your input.
Thanks.
ps: i found out magento is from the zend framework.
Your answers, in turn:
"I don't understand why Magento uses XML for theming."
In many MVC systems, determining what content and data are available in the view means dealing with (creating & customizing) controller actions. Layout XML gives even frontend developers the ability to add and remove view elements and their data ("Blocks" in Magento) to different routes without having to rewrite action controller classes.
"I read that I need to create local.xml declaring what gets in and out of the theme."
Not necessarily. If you have no customizations of layout XML, you won't need a local.xml file. Moreover, if you have layout XML customizations for ONLY the homepage, you can add your layout update XML to the page data via the CMS admin.
"[W]hy [is] the CSS/JS/media directory is completely separate from the template directory[?]"
This is simply a security feature. All files under ./skin can be directly accessed via the browser, and all files under ./app cannot be accessed via the browser, including theme-related files under ./app/design. Is this a logical, developer-friendly strategy? Not at all, and Magento is addressing this in Magento 2, which is available on github.
"[Why are there] a million directories (sarcasm) that I need to get into to make a modification[?] I assume they are using some kind of MVC model but it is by far nothing I have ever seen."
Magento is indeed an MVC framework, and a robust one at that. It is, as you've noticed, quite distinct, especially in the PHP frameworks realm.
Models are PHP classes under app/code/[codePool]/Namespace/ModuleName/. By convention, they are under the Model directory. They come in three general flavors: data models, which conventionally reside directly under the Model/ directory, and resource models & resource collections which conventionally reside under Model/Resource as of Magento 1.6.
Views are PHP classes which conventionally reside under app/code/[codePool]/Namespace/ModuleName/Block/. They may or may not be rendered along with template files (.phtml). Unlike many MVC frameworks, Views in Magento often load their own data independent of route / action.
Controllers are PHP classes which are found under app/code/[codePool]/Namespace/ModuleName/controllers/`.
"If they are attempting to make pretty URLs with all these directories I'm pretty sure they have heard of htaccess."
Not at all. The only thing which connects URLs to action controllers is configuration (this is true of all MVC classes outside of the Mage namespace). SEF URLs are achievable via configuration in multiple ways as well as via database rewrites which may be found in core_url_rewrite table. Magento does use an .htaccess file only as a means of routing appropriate requests to the system entry point, index.php.
"I looked into the phtml files and most of them look like their just calling these XML elements, is it possible to use plain old HTML and PHP to create a theme? Or am I forced to use their XML methods?"
Templates are dumb. They are pointless without the View class in which they are rendered - literally included()ed. The methods and data available to them come from their (often) layout-configured View class. For an example of view configuration, see app/design/frontend/base/default/layout/cms.xml: the <block type="core/template" name="page_content_heading" template="cms/content_heading.phtml"/> line declares an instance of Mage_Core_Block_Template with the cms/content_heading.phtml template from the frontend theme.
"[T]he theme folder at app/design/frontend has two folders base and default which im thinking each of these are interfaces for example a group of themes i would like to use. i modified the design_change db"
It's good that you are investigating these things; an explorer's approach will be helpful as you learn the framework. Themes in Magento are defined by three components: an area (frontend or adminhtml), a package name, and an actual theme name. In the filesystem, these settings map out to two places, as you've noticed. They are ./app/design/AREA/PACKAGE/THEME/ and ./skin/AREA/PACKAGE/THEME/. There are two more aspects to theming in Magento: theme asset type and fallback.
There are four theme asset types: layout, template, translation, and skin. The path that the system uses to find a given theme asset is based on configuration as well as some hardcoded paths. The absolute fallback point for theme assets is the base package's default theme. Appropriate Magento configuration has you first declaring a package (e.g. 'my_package' under System > Configuration > Design. With no theme settings declared, the system will simply look for assets under the default theme; this would map to app/design/frontend/my_package/default/template/. If you were to declare a "Templates" theme in Design configuration (e.g. "my_templates", the system would first look there and then look under the default theme. There is also a "Default" configuration setting which, if set, will be used for all theme asset types (e.g. "my_default"). This is all happening in Mage_Core_Model_Design_Package and it looks like the following; we'll use our example settings and the "cms/content_heading.phtml" param from above:
app/design/frontend/my_package/my_templates/template/cms/content_heading.phtml (if found, use this one, don't look anywhere else)
app/design/frontend/my_package/my_default/template/cms/content_heading.phtml (if found, use this one, don't look anywhere else)
app/design/frontend/my_package/default/template/cms/content_heading.phtml (if found, use this one, don't look anywhere else)
app/design/frontend/base/default/template/cms/content_heading.phtml (if not found here, someone screwed up, and an exception will be logged to the system log at ./var/log/system.log)
This design fallback is used for two reasons: allows failsafe places for developers to store theme assets (base/default) and allows for multistore reuse and DRY overriding of theme assets.
That said, this is not an ideal architecture, and as mentioned, this is going away in Magento 2 - all theme assets will be stored inside their respective module's directory.
Only reading will be able to help you much here. Once you get the hang of it, the xml layouts are pretty handy, it's just a pain learning how they work.
You can indeed ignore a lot of the xml stuff if and just put stuff inside the template files, but as you will read from other sources, it's not always best practice to work this way (though I'm sure every Magento developer does it on occasion).
Your best reference is often the Magento code itself. So long as you never touch anything inside base/default, you will always have a reference of how it's "supposed" to work.
Magento is definitely a Swiss Army Tool. You can get things done in many ways, each of which has it's pros and cons. Sometimes hardcoding stuff into templates/layouts is the way to go... sometimes you need to use static blocks and CMS (if a client wants to be able to edit something, for example).
Again, keep at it.. it is certainly frustrating to learn, but you will eventually pick up on the nuances and will start to feel more comfortable.

CMS like Drupal CCK

Is there anything for PHP that isn't Drupal but essentially has CCK-like features?
So far the only things I've found is SymphonyCMS and Drupal.
Personnaly not checked yet but Pimcore seems to be a PHP CMS that can provide such functionnality :
http://www.pimcore.org/wiki/display/PIMCORE/Document-Types
http://www.pimcore.org/wiki/display/PIMCORE/Editables
It's an Open Source CMS based on Zend Framework and extjs,[troll mode] 2 things that contains some smart elements that you won't find soon in Drupal[/troll mode].
There is also the WordPress powerfull Custom Types functionality, which with the help of plugins can act very likely Drupal CCK.
They are:
Types - most recent approach and a good step in the right way
Custom Post Type UI - Also very strong, should be used in conjunction with Custom Field Template Plugin which adds the the ability to add the fields themselves.
There are many out there, but I can only assure you'll have an good experience with this ones.
I'm a big fan of Drupal CCK concept but I cannot like Drupal itself. To me it always maked things much worse then it was. Maybe is just a case of learning curve...
Would love to see this concepts as much implemented as possible (great references here), but maybe the concept should get out of PHP to become full-powered (I do not know every one here, should give modx a try).
This is a pet project. I have been doing Drupal development for 12 years. Most of my work is with modules development using CCK and Views. So I created a php framework that works similarly. It's in beta stage but you are welcome to check out the demo http://cck.fhqk.com. The parts that will interest you most are in http://cck.fhqk.com/?admin/main under content types.
Somethings are different from Drupal because I do not like the limitations of the Drupal system. Content types, fields and containers are independant of each other so deleting one does not effect the others. When a field or container is deleted the user has the choice to keep or delete the data also. You can also change form field types at anytime, change a text field to a textarea or hidden without deleting the field and the data first. The form fields available are all HTML5. Development is done in PHP 5.+ and will move to PHP7 after the first public beta.
Content Connection Kit is not a CMS or Micro framework but something in between. There is not and will not be a list of user features like blogs, forum blah. Although I will use a microblog and portfolio as examples of how and what can be built the system. The concentration is on building of the website via content types menus, hooks and modules (Namespaced OOP class files). There is absolutly no javascript being used nor will there ever be. There is no nor will there evr be PSR compliance because it places restrictions on flexibility. To get all the fiffy stuff from js you have to do it yourself. The starter theme is responsive made from skeleton.css
This Website development kit is for developers and site builders that want to have the heavy lifting done and get on to customization from minute one.

Categories