Alright so I'd like to thank everyone for
coming out today to WordCamp Baltimore
You obviously going to be learning
a very beginner's guide to PHP within
WordPress. This is generally going to be a crash course.
uhm, again my name is Zane Matthew. I've been doing
PHP for about 10 years now. I've been doing
WordPress about almost half of those 7 years now,
maybe a little more. I've been doing PHP
since I think around version 4.7 or 5.1
and WordPress since 2.9. I've done kinda
a little bit of everything within PHP.
uhm a lot of MVC work, along with a lot of framework
I'm sorry a lot of WordPress work, and
proprietary frameworks. uhm again this is very
geared towards beginners, gotta really get
their feet wet in PHP. So I apologize
upfront if it's not as intermediate or as advanced
as some might like. So with
that being said we'll get started about with PHP.
With PHP which version of PHP you need to
use and how to obtain it. So there's 3 ways
you can get PHP. You can obviously use
MAMP if you're on Apple or Mamp Pro.
So basically if you're an Apple person
you're gonna want to use MAMP or MAMP Pro.
There's other ways you can obtain PHP
but those are a little more advanced.
When you're using something like MAMP
there's gonna be a free or paid application
that you can download, install it, click a
couple of buttons and you'll be up
and running and ready to go with PHP.
If you're a Windows user you're gonna
want to use WAMP. The W
in WAMP obviously stands for Windows.
The M in MAMP obviously stands for Mac.
So with that being said you're gonna
want to know which version
of PHP are you going to use.
With both of those MAMP and WAMP, you
have 3 different options. All 3 of these
options are fairly updated considering
PHP is up to version 5.6 now.
But that's actually not that bad, because
WordPress is actually currently running
the majority of WordPress Users 75% or so
or more are on 5.2 and 5.3
So you don't really need to be
that concerned about running the
latest version of PHP.
If you're running version 5.3 that's ideal
The minimum version that WordPress
supports is 5.2. Actually I think it's 5.2.3
and specifically if you're going to be
doing PHP within WordPress, for any
kind of contribution uhh if you want
to contribute to core, you want to create
your own themes, you want to create
your own plugins and you want to
submit those to work on dot org
You're actually gonna want to stick with
version 5.3 which is the safest.
And this specifically is due to the ah
due to the majority of web hosts actually
do not support version 5.4, 5.5 or 5.6
yet. All of them kind of do a lot of
cool things. WordPress is a little bit
behind, but it's mainly behind because
of the uh hosting. So with that being said
specifically what code do you need to know
that's native to PHP in WordPress that's
going to help you become a better developer.
So we're gonna look at these specific
items here. Which are going to be
conditional statements, arrays, loops,
functions, and file includes.
So, just curious based off the previous
slide, show of hands how many people
have PHP installed? Ok great.
So this is going to seem like a review
for some people, but again this is geared
very much towards beginners.
So the first thing we're going to look
is a simple conditional statement.
if, else, elseif, switch
Now this is generally nothing complex
with this. Normally you're just going to
use this with comparison operators.
Your and, or's, equals, not equals,
exact equal and exact not equals
and greater than and less than,
The only things here that kind of catch
beginners are the exactly equals and
the exactly not equals.
Those are sometimes referred to as
triple e's and those specifically will
get you when you're testing something
like here I'm showing an example of
zero or zero. The first zero is a string
and the second is an integer.
So both of those would actually
be not equals. If you wanted to determine
exactly or exactly equals they would both
need to be strings or both
need to be integers. So aside from
your comparison operators, you also
have, I'm sorry aside from your
conditional statements your gonna have
your type comparisons. Your
type comparisons are going to be
things like your empty, is_null, isset();
And these generally you're going to use
when you want to check if a variable
has been defined, or if a variable
isn't used, or if a variable
actually exists. A couple things
that are going to help, are gonna
be this handy chart, which is on
PHP.net. I strongly recommend,
you go to PHP.net along with the
WordPress Codex. This is one of
the handy charts on PHP.net which will
actually help a lot of beginners, because
there are numerous times where
when you're dealing with a conditional
statement and you'll see a lot of things
like not empty, not isset, not is null
and things along that. This chart actually
will extend about maybe 3 times the length
of this page here, and as you can see
it's showing get_type empty, isset and is null
which is just a normal exclamation mark
And with this chart you can actually see
you know, true or false. It's very
very clear.
So, with that being said, we're gonna move
on to printing and displaying content.
Again, seems very simple.
echo, print, printf() sprintf()
And just curious, by a show,
by a show of hands, how many
people here actually know the general
difference between printf and echo?
ok, so we look up here echo vs print
They're generally both the same,
except that echo is a language construct.
Technically echo is supposedly a little
bit faster, no matter which one you use
you want to pick one and stick with it.
Where as printf() and sprintf()
these two are specifically used within
WordPress to ah they are native to
PHP but you normally use these within
WordPress to kind of help you code up
translations a little bit easier.
Because it's actually easier to view your
translation, which is actually something
I'm not actually going to talk about much
within this talk. It's easier to work with
your translations when you're doing
printf() and sprintf() statements.
So here I'm giving an example of a
printf() statement and a sprintf() statement
Now I'm going to point out that a
printf() statment is used to obviously sprint,
I'm sorry print. The sprintf() statement
it's not that, it's actually used to return content
So if you wanted to
assign content to a variable
you'd want to use sprintf()
So here what this is showing
is it's showing print with two
parameters. The first parameter is
a string, the second parameter
is a test. And when you translate
text this way, using printf() or
sprintf(), it's a little bit easier to wrap
markup around your translation.
Because now as a translator, if you
were to translate foo, I'm sorry
the name, all they're translating that
word name. If you do not do it this way
the translator would actually see the
strong tags wrapped around a name
when they were actually going to
translate this. Which sometimes
you may or may not want.
And then sprintf() here I'm showing a
little bit more flexibility. Because here
I've actually assigned one two to
name first. So what this is actually doing is
it's actually showing first as in %$1s.
So with that being said, we're going to
move on to arrays.
So within PHP, so generally have three
types of arrays. You have
an indexed array, associative array, and
multi-dimensional array. The
most important in my opinion and
I'd say the majority of PHP Developers
opinion, is going to be multi-dimensional
arrays. And those are the ones that
generally stump a lot of beginner users.
ahm, I'm not going to dive that deep
into them, but I do have examples
of multi-dimensional arrays.
First we're going to start with
an indexed array. So an indexed array,
this is very simple, the about, blog, and contact me.
Those are assigned, zero, one and two.
So if we were to traverse this, if we wanted
to actually display content or do
something with this. How would
we do that? We would use a simple loop.
We would use a foreach loop in this case.
So in this case we're gonna foreach
loop $pagesbyslug as $page
and then echo $page.
So I'm generally going to say by show
of hands, the majority of people here
will know what this will actually display
This will just display about, blog,
contact-me. So with that being said,
we're gonna look at our next example
of indexed, I'm sorry associative array.
And this one is showing that here
I've assigned a key value here.
So I've assigned (mumbles) to page_slug.
So this right here is generally a way that
a beginner would kind of generally go
about writing an array.
This would echo content in a very
similar fashion but there's a key
thing here and it should flag
those two if there's any intermediate or
advanced php developers. And that
specifically is the way the variable is
set, pageids and pageslug. When you
see yourself going through this naming
convention, you actually want to use a
multi-dimensional array, which we're going
to get to in one moment. So if you look
here again, how do we traverse that.
We're going to use a simple foreach loop
and we're going to say ok echo page and
we're going to use the key page_name.
And that would echo out, either about,
blog or content. So that's going to lead
out to a multi-dimensional array.
With this approach is a little more comlex
but this allows you to better organize
your arrays. Your arrays are kind of like
mini database containers and they can
be extremely powerful and they can be
extremely complex. But they're generally
the root of the majority of Programming
languages. So if we see here, this is a
nested array. Items is one array, Pages
is the second array, and then there's
another array of pages. So if we were
to traverse this, we would traverse it
this way. We would have a arg use as,
we would have our key and our value.
And from here, this right here would
actually echo the content a little bit
differently. And just curious would
anybody know what the output would be?
I assume the majority of people here would.
So anybody willing to blurt out the
answer of what the output would
be for that?
(from crowd)Would it be the post_id and
and the slug? Uh you're saying
it would be the post_id and the slug
Ah close, the output of that would
actually be, pages about because I'm using
K which is they key, which is here.
So you'd would be pages and then slug
uh, if slug was replaced with ID or name
it actually would have spit out the name
there. So, were gonna look at loops.
That was an example of arrays
within a foreach. So now we're gonna
start to look at your while loop.
Within WordPress, you have what's called
The Loop. It's generally based around
a while loop. (sneeze from crowd)
It's a little different in that a
WordPress loop does not contain,
counts, we're not actually counting
anything. It's actually much simpler
but there's more code so it will
look a little complex. So here this is
your standard WordPress loop.
You're going to have your if statement,
you're gonna have your while loop,
and then you're going to have something
in between there to needs to
get displayed. Anything that needs to
get displayed within this section of
the while is actually an instance of
the post. That's why you have that
function there at the end. And also this
is showing alternating syntax.
This is not using curly brackets
as you saw previously. This is using
colons, and endwhile statement, and endif
If this was to show the alternate syntax
for a foreach, this would have used
end foreach in replace of endwhile.
And foreach in place of while.
So with that being said, we're
going to move on to functions.
So functions are generally pretty simple.
Takes nothing more than a parameter
and you pass in your parameter.
What you'd want to know here is what
I'm doing, is I'm actually setting
both of those parameters to null.
This function takes two parameters.
Setting them to null, allows you to use
your function without throwing
any kind of warning or notices.
Now, aside from passing the parameters
in individually, you can pass them in
as an array. Once you pass in
your parameters as an array, you can
use what's called extract. Extract let's
you take your parameter and put those
into a variable for you.
So now rather than using. Rather than
having one function with a laundry list
of parameters, you can now have your
function with just one parameter and
then extract all those parameters as
an array. WordPress built into it
does have a couple of functions that can
help out with this, rather than use the
command extract. Has anyone here
written a shortcode for example?
ok. So if you've written a shortcode
you might have used something like,
shortcode args or parse args.
It's kind of along, along the same lines.
So now we're going to look at file includes.
So within PHP you have your general file
includes, which are going to be your
required and your include.
The difference between these is that
your require file obviously is required.
If the required file is not there, your
program is actually going to stop.
With include it'll through a warning or a notice.
Now WordPress does have it's own
set of includes which are going to be
right here. Theres also a couple more.
Now with these, specifically what
WordPress does is WordPress actually
makes sure that the WordPress required is
already loaded. You can safely include
certain files and rely on these functions.
It'll also help out the template
inheritance. So for example
header.php, sidebar, footer.
Rather than using a required once
to get those files, you can just use
get_header. And what that's going
to do is just (cough) one make
sure the WordPress environment is
fully loaded so you have access to all
the WordPress functions.
Two it's going to make sure that you
could, ah it's going to make sure that
you can retheme that particular file
either from a child theme if you want.
And then the other ones here
gettemplatepart, load_template,
locate_template, generally do the
same thing. They're all going to be
used within your theme.
And there is also a couple more
that are not listed here. There's
like your comment form, search form,
uh and a couple others that are
also listed on the Codex.
So, we're going to look at debugging.
And the whole concept with debugging
is that it's supposed to
make you more accurate at finding
problems when they arise.
Because you at the end of the day
you don't want to spend that much time
digging though your code trying
to fix a bug. So that's where debugging
comes into play. And we're going to have
three different types of debugging.
We're going to have your notices,
your warnings and your fatal errors.
Your fatal errors, it'll mean your
program will actually going to stop.
Your warnings on the other hand,
are going to tell you that hey,
something is possibly wrong but we're
going to keep going. And your notices
are generally going to say
Hey you probably shouldn't do it this way,
there's probably a better way to do it.
Now these errors, you're actually only
going to see them if you turn them on.
And there are three ways to enable
error reporting. If you're using something
like MAMP it's fairly simple, just go into
the software, find out where your error,
error is and enable it. If you're using
native php, you could add these two lines
to any php file and now you will actually
display all errors and errors will be
turned on and you will see everything.
If you do not want to add it to your
php file, you can also add it in
htaccess file. And you can see here
this is basically setting errors again.
Now these are native ways of handling
errors. Now I'm actually going to
show you specifically how you would
handle error within your WordPress
configuration file. So by a show of hands,
how many people here have actually enabled
error reporting within their
WP-Config file? OK so this will be
fairly new to a couple of people.
So, as you can see here, oops I'm sorry,
So you can see here what this does is
setting WP_Debug to true is actually
going to turn on errors, notices,
and warnings. And specifically what we
want to notice here that this is going
to turn on deprecated functions.
Deprecated functions are functions that
are no longer supported within WordPress.
They're still there, but they're no longer
supported and will be removed at some
point in time. Aside from that, you have
what's called ah WP_Log. Now this will
actually print your errors out to a
specific file that WordPress has
predetermined. So here as you can see
we're actually going to save the errors
into your content directory as debug.log.
So you can use that in, you can use that
in combination with a display errors off
or false. And this will set your errors,
to actually not be displayed to the
webpage. But error reporting will still
be turned on and they could be logged
out to your log file. Now this
specifically would help out if you're
doing something like making ajax requests.
Ajax requests is a little bit more of an
advanced topic, ah but they are very very
powerful can become troublesome.
So that's another instance where you'd
want to write up your log to a specific
file so you can see what's going on behind
the scenes. And whenever you're doing
this, you also want to be sure that
debugging within, within a development
environment or staging environment.
You're not going to actually want to turn
this on on a production environment
because they can release some sensitive
information along with slowing down your
server. So, the next level of debugging
that we could use is script debug.
What script debug is actually going to
allow you to do, is it's going to allow
you to see unminified javascript and css
files that WordPress natively loads.
So if you're using some of the WordPress
core javascript or css files, you can
use this particular debugging feature
to kind of help you troubleshoot
what's going on.
So along with those it, it will also have
an option where is can save queries.
So this does not actually save queries to
a specific file, rather it's saving
queries to a global variable that
you can access.
So, if we were to look at debugging,
and we were basically going
to say. I'm sorry, uhm yes again with
debugging you do not actually want to do
this in your production environment
or a live environment. You always want
to do this in a staging or
development environment.
So, generally that wraps up
a beginners guide to PHP in WordPress.
Uhm we've gone over comparisons,
arrays, conditional statements, and file
includes. And I've tried to keep it
very very basic and very very broad.
uhm this is a talk I've kind of given
in the past and it's it's kind of was a
little advanced believe it or not.
So I've kind of tried to really remove
a lot of extra bloat. And really make
this as beginner focused as possible.
So with that being said, does anybody
have any questions? Yes.
(audience member) So I'm
actually going to really use this,
but I'm curious about other development
technologies. I'm curious when you are
developing with something like
PHP or Javascript, when working with
WordPress, are you doing that natively
within WordPress or are you doing it
with like TFS with Microsoft's IDE
or some other development environment?
(Zane) Uhm that's a good question.
So were you specifically asking
if there some kind of development
environment or like an IDE that integrates
with WordPress. (audience member) Right.
(Zane) uhm there are a couple, ah I
personally use what's called
Sublime Text 2, and within Sublime
there is a WordPress uhm Sublime uses
what's called Packages. There is a
WordPress package which will actually
autocomplete a lot of your variables.
It will actually autocomplete uh your
variables to a point where you can either
autocomplete shorthand, I'm sorry
your function, it can autocomplete just
your function name or it can
autocomplete your entire function
the parameters, and comment block, and
a link to the codex actually detailing
what that particular function does
for every single parameter. So that's what
I would recommend. I'm not sure if
anybody here has other recommendations
or IDE's that integrate with WordPress.
(audience member) How do you spell
that name?
(Zane) uhm, Sublime Text 2,
S-u-b-l-i-m-e Text, T-e-x-t, actually I
think we're up to three now, SublimeText 3
And the package we want to search for
uhm I'm pretty sure is just
called WordPress. I think it's the only
one that comes up. Uhm,
it's actually really really useful
because again when you're doing
WordPress work all day, you know you
kind of once you're familiar
with the Codex, you really don't
want to retype all of this stuff,
so it kind of just spits out the code
for you you know? Any other questions?
(audience member) I got a question for you
So when doing front-end development,
like with Javascript and HTML, I'm a big
fan of using developer tools,
like in Chrome. (Zane) Ok yeah.
(audience member) Have you found
anything that works similar to like PHP
Development? (Zane) Uhm there's
FirePHP, which is written by for FireFox,
(audience member) ok.
(Zane) Uhm, it's outside of WordPress
I know a couple guys who have used it,
I haven't looked at it recently.
But that basically allows you
to write out what was going on with PHP
to the console. You know to ah Firebug,
which is very similar to Chrome.
uh also there are a couple of WordPress
plugins which leverage the Core,
not Core the WordPress debug which
is built by Automattic.
The Debug Bar extender which is also
I think contributed by Automattic
And the which leads me into answering
your question. There is another debug
logger, which I think is called Debug Log
which kind of mimics Chrome's console,
but specifically for WordPress.
And it will actually show indexing
like split pane. But for that you want to
use all three, the Debug, the Debug
Bar Extender, and uh Debug Log.
You can get them all in the WordPress
dot Org repository.
(audience member)Thanks.
(Zane) No problem. Uhm any
other questions? Yes.
(audience member) Do you know any
resources for somebody who is
just kind of getting started with
Development and PHP coming from C++
and HTML that are WordPress specific
rather than just the more full on approach?
(Zane) uhm. The one's I would say are more
WordPress specific uhm you might've heard
this before, but I think the best thing to
really do is look through the Codex.
And then look through an existing theme.
Uhm Underscores is generally a very very
good theme. It's a good starter theme.
uh Underscores, uh I think the site is
underscores.com. But is contributed to by
the team at Automattic contributes it,
it's on Github, it's a very powerful theme
and it will give you a good sense of how
to actually setup your theme files,
and then from there you can kind of start
to build into that particular theme and
kind of start removing what you don't want
uh because aside from just building out a
theme or just building out a plugin.
Like that's the only way to actually start
uhm and actually on the Codex, what
I would recommend uh, for themes
is there is a section on the Codex on
how to build a theme. And a theme
is literally nothing more than an
index.php and a style.css. And then
everything in between is just how
complex or simple you want to make
your specific theme.
So it is very case specific though.
Does that kind of answer your question?
(audience member) Sort of, I mean I had
gotten into child-themes first and have
kind of looked at what I want to change
on something pre-existing.
(Zane) Right.
(audience member) But maybe potentially
move into starting with a more blank
slate, I didn't know if there was any
other thing that you could suggest
to make that transition a little bit more
smooth other than just knock out as
many child themes and add plugins.
(Zane) Again I would just say,
just keep at that, and uh she's
mentioning child themes. That kind of
just reiterates the importance of making
the fucntions getheader(), loadtemplate(),
get_template args, and uh locate template
because all of those help leverage
uhm people that are using your
theme as a child theme. I think we
have another question.
(audience member) Taking it back to what
you said, it's actually underscores.me
is the website address. And then
two resources that I've found
treehouse and codecamdey have added
some WordPress tutorials where you
can walk through and they'll go through
a loop and various functions.
(Zane) Also too, PHPArch
I do a training session through PHPArch
which is strictly PHP. uh strictly PHP
and WordPress development. It's uhm not
really a quick crash course, it's a three
hour session three days a week
and it's very developer focussed.
(audience member) What that PHParc?
(Zane) Uh PHPArch, uh PHPArch.
PHP Arch, PHP Architect, PHPArch.com
(audience member)PHPArch.com
(Zane) Yes.
(audience member) Uh First off, this good
10:30?
(Zane) uh sorry it started
(audience member) because we're
approaching 10:30. (Zane) Yeah
(audience member) ok good.
because I'm maybe I'm in the minority
here, but I come from PHP with no
experience at all. I cut and pasted a
child theme and thing work and
sometimes they don't. And what I was
sort of hoping to get here was really just
take a sentence in PHP and break it down
for me so I can speak it. Because right
now, I don't really speak it. I can speak
CSS and HTML, but then so I can read
a line of it and know exactly what
it does. Because often I'm just guessing.
And I was sort of hoping since we had
about an hour here maybe some people
would be interested in learning. I'd love
for you to just take one of these
sentences and just break it down.
Say this do that, this do this, because
you ran a little fast with some of them.
because you're really really experienced
with this stuff and just take a look at
maybe more of your complicated
sentences and break them down?
before that, like more in the array area.
Yeah like there, right there.
Like the loops.
(Zane) ok yeah
(audience) noise (audience)
(Zane) Alright so, I'll break this down
a little bit more.
uh this is a good question, so
I should note, this particular block
of code within a template file.
So right off the top what that means
this can only be used within your
single.php or page.php or when you're
viewing a single item. Now what that means
is that you have to understand WordPress
is broken out into I'm gonna say, two
two kinds of ecosystems,
Either viewing a single item,
or a collection of items, such as a
category page or an archive page.
This will work when you're viewing
a single item. So if we see here,
again that first statement that first
if statement is using a native
WordPress function and it's checking
are there any posts available.
So in this instance you don't need
anything like an empty or isset or is_null
anything along those lines.
WordPress is already handling that,
handling that for you.
So then after that end. So the other thing
you'll have to know too is that,
this is using the alternating syntax,
again where it's not using semi-colons.
You generally use an alternating syntax
when you're specifically in your
template files, when you're not
in a function.php when you're not
writing out a large amount of
conditional logic. When you're in your
presentation area and you're actually
saying ok, I have my logic done, I want
to display my code, I want to wrap it
in some html and I want to style it,
you'd use your alternating syntax.
So the while loop right there,
goes in there and is checking
does this have posts.
And again have posts is a native WordPress
function. So to extend this,
with an else statement what you may have
is something like if have posts, whoops.
What you may have is an if have posts,
and then instead of the endif, you have
an else to display some kind of message.
Saying that there are no particular
posts to be displayed, then your endif.
So now that you're within your while
loop, you have the post.
What that's doing, is that's setting up
your specific WordPress. Your WordPress
function such as the title which
I have listed here and the content,
which I do not have listed.
The content will actually grab
all your content from the wysiwyg editor.
Uhm, other ones you could have would be
like categories, post thumbnail, and other
items specifically related to that one instance of your post.
So then from there, I'm wrapping that
particular function the title in H1 tags.
Now an interesting thing about this is
that function the title, actually takes
two parameters. Which are your
ending and closing markup. So I actually
could have taken the H1 tags and put
them inside of the title along with the
ending H1 and put it inside of the title
as well. And then I end my while, and
end my endif. And this will actually
be repeated for as many number of times
there are posts for the given ah, ah for
the given, I guess you would say either
paginated area that you're seeing.
Does that kind of help? I can break
down another one for you.
(audience member) What does the colon do?
(Zane) Oh uh the colon right there
(audience member) Well there's two of them
(Zane) Yeah the colon is actually part
of the alternating syntax. So normally
a while loop or if statements, or
for each's they use curly brackets.
So the colon right there, that's actually
your alternating syntax. That's actually
ending that particular, uh that
particular section. So it does look a
little long, but this is uh, what looks
a little long is the while section would
have post and the post, those could've
been broken up into two separate lines.
But generally uh, in the WordPress system
it's kind of written out this way
all as one line. So again the semi-colons
are just replacing curly brackets and
that's the alternating syntax.
Uh if you want, I can also look at
an array structure and break that down
more or if you have a specific line
in the code, I can also break that
down too. Does that kind of help or?
(audience member) The title and the post
are all built-in WordPress.
(Zane) Yes.
The title is part of a WordPress function
That is a core WordPress function.
Ah if you were to find some kind of
pattern between the functions here
uh whenever there is something like
the in front of it, it's actually going
to echo or print the content.
WordPress has a series of functions
that has get in front of it. Like
get the title, get permalink and
things like that, that don't actually
turn the item. Ah but there's also
a line in between there so.
Ah yes
(audience member) Is there Sublime Text
in a host environment or pc environment.
(Zane) ah what was that?
(audience member) So you were talking
about Sublime Text, does that run
on Host or PC?
(Zane) Ah Sublime is Cross Platform,
(audience member) So it runs on your
local computer just not on the server?
(Zane) Right, Right. If you did want to
use Sublime with the server, there is
another package for that.
Which is called Sublime SFTP, and that
basically would allow you to sync you know
uh I guess as you type or however
you want to do it, but that package is
SFTP package.
(audience member) Uhm, earlier you were
talking about echo and print. You were
saying that for your own to not confuse
yourself, there's nothing technical
about that?.
(Zane) Uhm I mean technically
echo is a language construct, so what that
means is it's part of the PHP language.
Where as print is, I don't want to say
just have to use echo,
I mean in my opinion echo
is just short for print.
Kind of silly, but yeah just pick one and
stick with it.
Any other questions?
(audience member) I would like to go over
array in more detail.
(Zane) Uhm, sure.
So you want to look at the
multi-dimensional one? Ok yeah
this would be a good one because I
can jump back and forth between
associative and multi-dimensional.
So if we look at the associative
uh there is three items in this
particular array, page name, page id,
and page slug. Now normally what
you would use this for is you want to
have a collection of related items.
And then within your collection
of related items, you may start doing
something like this where you're
prefixing everything with page underscore.
And then from there that will lead into
the multi-dimensional array, how you can
break down your content even more.
So what's going on here, is that you have
page name, points to contact,
page id points to 89
page slug and so on. So if we look at the
multi-dimensional array it's broken down
even further into specific buckets.
So this is an array within an array.
And one of the things you do to kind of
help you visually see how to traverse
the array and what's going on is use
what's called a printr() statement.
And that will actually print out all your
content for that particular array.
Uh specifically is there like a section
or kind of like something that you have
question about?
(audience member) So when you go over the
one where they were nested, that was when
I was kind of a little bit uhm...
(Zane) So from here to here,
you're saying?
(audience member) Yeah
(Zane) Yeah, so what this is doing
so now mind you, this is a
multi-dimensional array, so it's an array
within an array. So we have our array
of pages, and then a second array of
pages that are all part of this
parent array. And then what this allows
you to do, it now allows you to
traverse through pages and now traverse
into pages and then iterate over each
particular item there. So that's where
you would use this syntax. For each items
as the key, the $k in this case stands
for key. You can actually name it
anything you want. The $v in this case
stands for value, again you can name it
anything you want. And that key,
the $k points to the key, right here pages
and the value will point actually to the
array of pages. So that's why I'm using
the square bracket with the comma,
uh I'm sorry the square brackets with
the single quotes. Because it's actually
pointing into that particular index.
And then I can print out the slug,
you can do the id, you can do whatever
you want with it. So does that
kind of help. Ok. Any other questions
anybody else have a question.
(audience member) So if you're using a
tool like Sublime Text, and you're
a developer, which I'm not which I'm not
yet, uhm as you're debugging or whatnot
would you see your code as well as what's
being visualized on screen at the
same time or within the IDE.
(Zane) You wouldn't see it in the IDE,
you would see it within the web browser.
So that would determine whether or not
you have display errors turned on or
display errors turned off. And that's
also where if you wanted to keep it
within your IDE, uhm which
might be a pretty handy way to work,
with Sublime you can set panes.
So you can have like a pane up top,
and then a pane on the bottom.
So for example you can turn on debug log,
turn on debugging within WordPress,
and you can open up your debug.log
file on your bottom pane, and while you
code you have display errors turned off
and then while you code you'll see
sublime will update the file as you type
you'll see errors pop up in that log file.
You can use something like that instead
of FirePHP. And that will kind of
keep it all in the same window.
(audience member) So that part of PHP,
you either have to go through the log or
you have to kind of put errors on your
rendered page to see what's going on.
(Zane) Yeah, yeah that's definitely true.
uhm ok cool, is there any other questions?
I think we're going to wrap it up.
Oh uh Yes.
(audience member) I was just wondering
with the error log stuff, is there any way
you can wrap that in a div
so that could hide it from anybody
who's not logged in?
(Zane) Oh yeah, yeah you definitely can
uh So with the error, with errors what
you can do is. You could, you could do
something like a printr() statement
it's not really error logging, but you
can use a printr() statement or like a
vardump() and those two you can actually
return content and display it or
you can return content and display it
as you want. So you might be able to do
something like that, uh or you can
honestly with PHP for example you can just
write the error log out to the php file
and just wrap like a an html comment block
around it and that
will (indistinguishable audio).
(audience member) Can you do like if is,
alt in. Saying like if you are in a place
where you can't have a production link,
you know stuff happens, and you're in
development and something happens.
(indistinguishable audio)
(Andy Stratton) I, I can chime in here.
So I know what you're talking about doing,
and I would officially never support doing that.
I would never do it. Uhm, I've know of
people who have done something like that,
uhm where they'll check for a query string
parameter, uhm and just use like
you had up here, $i and $i set,
error report, display errors on display errors off,
in production you typically want them
off anyways. Right, in case something goes wrong,
you don't want someone to see
something that could lead them to a
vulnerability in your code.
uh, so if you know if get Andy = 1
display errors on, it's a way to do it,
So it's unrecommended, somebody
told me about it (audience laughter).