Generally speaking, yes – that’s exactly the best way to proceed. Is this theme your own custom theme or one you downloaded from elsewhere?
Always develop on your local server. If you’re just testing code this is the way to do it (develop / test (and learn)).
Maybe creating a child theme instead of editing your theme directly would be better.
If you are developing a plugin or theme (or something else) I would use some kind of version control:
http://betterexplained.com/articles/a-visual-guide-to-version-control/
A popular one is github:
http://en.wikipedia.org/wiki/GitHub
https://github.com/
Here is a good tutorial for setting up sublime 2 for php:
http://blog.stuartherbert.com/php/2012/02/28/setting-up-sublime-text-2-for-php-development/
Another tip is just to look into the code of WordPress and see how everything is working (never edit it).
Hello guys
Thanks for the feedback which I really appreciate.
The theme I am using for my learning experience is a premium theme (the same I am using on my live site)
I am mainly trying to learn how to display my content in different ways and so loop and functions are my current focus (rather than theme development itself)
One example of the stuff that confuses me is this. One book I am reading (Professional WP Plugin development by Brad Williams) says stuff like this:
Check out which custom plugins are registered in your WP site by running this: CODE SNIPPET
I understand the code snippet fine – but where do I run it in order to get the output? Should I be in some sort of console mode?
Thanks P
Can you post the code snippet?
Without having access to the book it’s difficult to know where the snippet should go. Probably somewhere in your plugin (as it’s about plugin development) or maybe in your theme’s functions.php file.
http://codex.wordpress.org/Functions_File_Explained
If you want to see what’s stored inside a variable you can just echo it:
<?php
$var = some_function();
echo $var;
?>
If $var is an array it will echo:
Array
To see what is in an array you can use:
<?php
$var = some_function();
echo '<pre>';
print_r($var);
echo '</pre>';
?>
Be aware that printing out a variable can sometimes break your site (but your developing on a local host so you’re okay).
Hi Keesiemeijer
Really appreciate your help and links so far.
Here is an example of the things that are confusing me. I can understand the code OK, but where to run it?
Heres the example from the book:
To return a list of all registered post types in WordPress, you’ll use the get_post_types() function. <? php get_post_types( $ args, $ output, $ operator ); ?>
Williams, Brad; Damstra, David; Stern, Hal (2012-12-17). Professional WordPress: Design and Development (Kindle Locations 3437-3439). Wrox. Kindle Edition.
Paul
Look at the codex page for that function:
http://codex.wordpress.org/Function_Reference/get_post_types
Look at the parameters section. It tells you what parameters are optional or required. None of the parameters are required for this function. This means you can use the function without any of the parameters (it will use the default values):
$var = get_post_types();
If you do provide parameters (other than the default) the returned results will change. Try and use the examples from the codex page (or from your book) in the copied theme template and see the difference.
Let’s take a look at another function:
http://codex.wordpress.org/Function_Reference/get_category
If you look at the parameters you see that that $category is a required parameter. This means it doesn’t return a value (or some functions throw an error) if you use it without the required parameter:
// without the ID parameter
$var = get_category();
By reading the codex you now now it needs a category ID:
$var = get_category(22);
Most codex functions pages in the codex also provide the return values of a function.
OK, but where to run it?
That depends on the function but generally you can use the functions on all your theme template files or plugin files. Be aware that returned results may differ on what template file you are using it. (e.g. is_category() will only return true on a category request (page))
Just try and test functions that return something with the examples to print out a variable above.
Keesiemeijer
Thanks for all your help. You have really tried to point me in the right direction which is appreciated
Thanks
Paul