Build Your Own Business Website header image

How to Create File Constants in Thesis 2

Difficulty Level -

Filed Under Topics - , ,

Listed Under Lesson Subjects -

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

In this session we discuss how to create constants to reference skin, box and package files in Thesis 2. Thesis 2 constants can be found in thesis.php. We use WordPress and Thesis constants to create our own custom constants.

Video Transcript

Member:  How about now?

Rick:  That’s better. Yes, thank you.

Member:  Okay, sorry about that.

Rick:  No problem.

Member:  The question is regarding Thesis 2 and because Thesis now generates its own folder where we keep our boxes and skins, etc. which is in the… it’s actually the same level as themes in the WordPress file structure. Now how would I get the directory path on say, a box or a skin? Because if I was to do something like blog info template path then it will go to the themes folder, wouldn’t it? Which is actually a level above where I need to be.

Rick:  Yeah, you wouldn’t want to use the… right. You wouldn’t want to use the template. What you would use instead is… let’s see. I should open up one of my own. Well, you can start off by using a Thesis constant. So Thesis… the Thesis constants can be found in Thesis php. And so Thesis constant you know, starts off using template path as the beginning part.

Member:  Right.

Rick:  So there is a Thesis user, a Thesis user skins, a Thesis user boxes and a Thesis user packages. Now you don’t have to use these constants. You could create your own constant. And if you’re going to create your own constant, you would start off with a wp content directory constant so it’s wp_content_dir. So as a practical matter, I do this in all of my boxes or virtually all of my boxes.

So for example, in public function construct, I say define my unique preface path and you’re going to define both. You’re going to define a local path and you’re going to define the URL. So I define my local path by Thesis user boxes and then slash the name of the box or the name of the box folder. And then the URL is the same except I used Thesis user box’s URL and then the name of that. Now I could just as easily you know, say wp content dir and then here, thesis boxes. That’s the same thing.

Member:  Yeah.

Rick:  So as a practical matter, when I’m creating a box or a skin or a package, the first things I do in my public function construct is the define the pads to this because you know, I’m always going to want to add stuff to the… whether I want to you know, add a javascript file or I want to add an image or something like that. You know, in these latest responsive menus I created, I’m including some images. So in a similar responsive menu, I’m creating that menu icon. And so in order to make that menu icon accessible, I have you know, created the image URL and it’s that constant plus the name of the file. And then I can just insert that into my css.

And the same thing is true with the flex nav responsive menu. You know, in the flex nav responsive menu, I needed to include… well actually, I need to include a couple of things and I seem to be missing one of them. Well, I needed to include flex nav js in order for this thing to work and then there were a couple of other images too. Oh, I included the images in the package, that’s right. So included the javascript in the box and in that case you know, I need to register the script and enqueue the script so I’m using that constant byob from URL. Again, this thing that we defined up here as the thing to register the script. And then in the package, the flex nav responsive package, I’ve got my arrow down and my arrow down 2. And so I’ve just… I’ve defined the constant for the package so that when I get down here to css, I can you know, define the background image URL starting from that constant.

So now that was kind of a long-winded answer. Did that get to your question?

Member:  That nailed it. Thank you.

0 Comments… add one

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
THIS IS A LIMITED TIME OFFER!
Subscription Options
0 comments… add one

Leave a Comment