Should I make woocommerce template via action hooks or edit directly? - wordpress

I'm learning WooCommerce Theme development. I have a question about making template.
For example, I'm making "archive-product.php". Should I edit some HTML code to this file to design layout? Or should I use action hooks to design? Which is better?
I have copied this file to "mytheme/woocommerce" folder.

Working with custom template files was, in my experience, more typical years ago than today, the exception being when you're radically re-designing them. Working with hooks and filters instead will generally be more flexible and maintainable across WC, WC add-on, and theme changes and updates, and, if properly organized, the functions will be easier to switch on and off during debugging, or to remove at whatever point.

Related

WordPress Code Organization

I'm working on a premium theme for WordPress, it's my first. My question is how modular should/can I get my code before it gets to be a problem for the server or other developers who buy my theme?
For example I have 3 custom post types with taxonomies and custom column headings. Should they all be in one php file or can I break them up so that each post type is in its own file?
I'm thinking that for future projects more modular is the way to go so I can just drag and drop the pieces that I need for that project. I don't want to make my theme any slower though so I could use a little advise on how granular to make my files.
I've bought themes in the past that have both extremes but want to set myself up properly from the start.
Thanks.
This is an opinion request this one because either approach works and based on this information plus the fact you seem keen on individual files. I would encourage just that.
Modular approach works with themes if you plan to provide the same functionality per theme as you won't need to edit functions per theme. I would go with individual files and just put them in a folder. If one of those files has a bug you'll be quick on applying the changes to all the themes you create.
If you put all the functions in one file and each theme gets its own versions of those files due to requests etc. Then you create a little more work in that you copy and paste code. Not a lot of work but then that demands on just how much that single file changes over the years or even within some months.
There is nothing wrong with many folders and files. It won't have an effect on loading. It would take hundreds of include() or require() before it becomes an issue.

Changing the comment template in wordpress

So wordpress uses php wp_list_comments(); to go into the wordpress core and fetch comment-template.php to output comments.
As I understand it, editing the wordpress core is a no no, so how does one go about styling the actual comments themselves?
This is only possible so far with CSS, but I want to completely change how they look and for this I'll need to edit the php/html.
The comment-template.php itself is monolithic, writing any semblance of that is frankly, beyond my abilities.
So how can I edit that, or create my own without breaking the wp core?

Drupal 6: duplicate theme function in two themes

I have a regular and mobile theme for a site; there are currently a couple of duplicate functions in the template.php of each theme, which do some text munging on the same fields. That is, the markup is the same for these fields in both themes.
How can I impose DRY and only have the logic in one place?
I understand I could make the regular theme inherit the mobile theme, but this doesn't seem like a "proper" solution, since the themes are quite different at the end of the day. Even more so as this would require ex-post-facto manipulation of the preprocess functions, and overriding mobile CSS and JS files - seemingly creating as much work and future WTH as it solves.
Thanks!
I would love to see the proper answer for this.
All i can think of is making a module that holds the duplication of functionality. A library module if you will.
So I'm making this "answer" as a conversation starter.
in: (mobile)template.php
preprocess_page(&$vars){
mymodulename_pagepreprocess($vars,'mobile');
}
(desktop)template.php
preprocess_page(&$vars){
mymodulename_pagepreprocess($vars,'desktop');
}
You can have preprocess-functions in modules as well btw. But it might be nice to send witch template as an argument.(you could however extract this from the global $theme)
How about you make a base theme which holds the functions, and implement both as sub-themes of it.
Or just the mobile theme a sub-theme, and the PC theme is the base?
Creating a sub-theme

Wordpress creating custom theme-Reusability

first approach to CMS and wordpress I'm wondering if there's any predefined html structure and classes/IDs "must-be" reference that I can refer for making my own theme willing to change in the future for another wordpress theme
thanks
Luca
There are a few other 'template' themes that could get you started - if Starkers isn't quite your thing, you might find WP Framework a good alternative. Or - just start stripping down the Twenty Eleven theme to give you a base (which is just what the Starkers theme does, using the Twenty Ten theme as a base).
There's also quite a handy first-time guide on the WordPress Codex around theme development if you'd prefer to start from scratch.
Wordpress doesn't require you to have any specific classes or IDs in your theme in terms of the HTML and CSS, the only things WP needs are things like the wp_head function inside your element on every page. Having said that themes such as Starkers were created to enable developers to have a starting point instead of starting from scratch.
Now the above applies only to whatever code you write, there are however some functions in WP that will return standard code, for instance if you don't specifically create the comment thread code, WP will generate it for you, and that is really the only code that many themes will share.
I would say that if you are intending on making a number of blogging themes for instance, having a set of standard code might be a good idea, for the article pages for example, so that you don't have to re-write code over and over. Aside from that the only code I ever reuse when making themes is the CSS to style comments if I don't hand-code the comments section, this is a good idea as it will save you a lot of time.
Wordpress provide some functions which add CSS classes depending of page type, templete, conditional tags . . .etc.
These functions are body_class() and post_class().
For more info check:
http://codex.wordpress.org/Function_Reference/post_class
http://codex.wordpress.org/Function_Reference/body_class

What do you prefer ? Writing a Wordpress plugin or child theme?

What think to be consider when you prefer coding a solution in form of child theme rather then in form of a plugin ?
Themes and plugins solve different problems: plugins are for business logic, themes for presentation. They are not interchangeable. I prefer the right tool for the right job. :)
i prefer in child theme (or in function.php), rather then in form of plugin. It's more easy to reuse. You can just move it from one theme to another.
Any generic functions should be in a plugin. That way, they are available to all themes, and if you make changes in one place, you don't have to copy and paste to several files.
The benefit of a child theme is that you can make changes to an existing theme, such as twentyten, without directly modifying the source code, which is fragile -- it can cause errors and has to be repeated every time the theme is updated.
Depends on the situation. If it's something that could readily be used by any (or many) different sites regardless of the theme, I do a plugin.
If it's something specific to This Particular Site Only, I would probably put it in the child theme's functions.php. Even if specific to the one particular site only, I might make it a plugin if it's something I might want to turn on and off later.
Other than the fact that you can turn plugins on and off, there is little if any difference between code in a plugin and code in functions.php.
If it's something most easily coded straight into the theme (e.g. a particular permutation of the_loop) then of course just do it in the theme template and put supporting code in functions.php

Resources