Build Your Own Business Website header image

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.

Lesson 11 – Part 4 – Add Member’s Forum Posts

Difficulty Level -

Filed Under Topics - ,

Listed Under Lesson Subjects - , ,

Applies to - ,

Video Transcript

Okay, so the next thing we’re going to do then is… we’re going to add personalized forum options here. In particular, what we’re going to do is display forum posts as they apply to a specific individual.

So for example, on the dashboard, I’m going to have it set to display all of my posts so I can see what my posts are. And we’re going to do that by installing a plugin called the enhanced text widget. So we’ll come back down here to plugins and add a new plugin. And it’s ‘enhanced text widget’.

Now the enhanced text widget allows you to add HTML, Javascript, Flash and/or PHP, so in order to do this we need to use PHP because we need to rely on template tags that we’re going to get from simple forum. So we’re going to go ahead and say install this now… Activate the plugin.

When we come back over to our widgets now and refresh our widgets, we now have this enhanced text widget that we can drag to the sidebar. We’re going to use this enhanced text widget for inserting Simple:Press template tags. And probably the easiest way to take a look at those Simple:Press template tags is to come over here to the forum and just click on the forum page and then come up to the Simple:Press wiki.

Now the Simple:Press wiki is actually an excellent source of documentation for the plugin, so if there are things you want to learn this is a great place to learn them. We’re going to come over here to the plugin API and we’re going to look at this category or this section called template tags. A template tag is essentially a function and it’s something in WordPress that allows you to call a specific PHP function and place it someplace.

You’re familiar probably with that, with the add action, remove action sort of thing where you can add a specific function to a specific place in thesis. And so you have functions like the thesis nav menu and the thesis default header and the thesis default footer and stuff like that. Thesis default header, thesis default footer, wp nav menu, those are all template tags. And in this case what we’re going to do is look at list template tags, cause the template tag we’re going to do is going to list the authors posts.

And there’s lots of different template tags that are available here but we’re going to scroll down here to the, not the lastest posts, but the authors posts. And this is the format of a template tag. It is a function, and then inside the brackets of that function are the arguments that the function takes. So I’ve actually written the code out here for you. Here’s the template tag, it is sf_author posts and then the brackets around that for the function, and then this function requires the author i.d., because it needs to know what author it’s going to display the posts for, and then it has this attribute, which is ‘Do you want to show which forum the post is in?’, and this is true, ‘Do you want to show the date that the post was posted’ and this says it’s true, and then ‘How many forum posts do you want to show?’ And this gives the limit of ten.  So that is the bare bones template tag.

Now we need to do a couple other things here though. The first thing is to get the author i.d. Now the author i.d. is stored in this global variable called current user. And so in order to get the author i.d. we need to invoke this global variable, current user. So that’s what we’re doing, we’re saying global current user. And then we’re creating a variable called author i.d. and we’re saying make that author i.d. equal to the current user’s i.d. And then, right here, this is the variable: author i.d., which now equals the current user’s i.d.

So the second thing we want to do is we want to make sure this doesn’t crash the site. And so the question we want to ask is ‘Does this function exist?’ So if this function exists, sf_author posts, then perform sf_author posts. If we didn’t do this, if we didn’t have ‘if function exists’, sf_author posts and simple forum was deactivated, our site would crash, because it would not be able to find this function.

So any time we call a plugin specific function, we want to make sure we ask the question ‘if the function exists’ before we call it. Even if you know for sure that you’re going to have this thing installed, you don’t know that you’re not going to deactivate it at some point, and when you deactivate it the site will crash if it tries to call this. So, ‘if the function exists.’

Now what I’m going to do is just copy this stuff and go over to my widget. So we have our enhanced text widget. We’re going to give this thing a title. We’re going to say ‘your forum posts’. Actually we’re going to say ‘my forum posts.’ And because this thing can read HTML, javascript, flash and PHP, we need to tell it that we’re looking at PHP here, so we need to do the opening PHP tag, which is the greater than sign, question mark, PHP. And then we can paste our PHP code in, and then we need the closing PHP tag which is question mark, greater than sign. Actually it was less than, question mark PHP and question mark greater than sign. And so we’ve posted this little function here, and if we hit save and come over to the….

Now we have this list, ‘How to install WordPress in thesis. Welcome to the course.’ This was the one post that I created. What I really want to do is create three posts. So under WordPress 201, I’m going to add a new topic and this is going to be called the ‘WordPress 201 first post by Rick’. And then ‘my first post in this course.’ We’re going to post that topic. Then we’re going to come back up to the forum, and we’re going to post another one in the membership one, and we’re going to add a new topic. And ‘Membership website first post by Rick.’ ‘Here is my first post.’ Post a new topic.

And so now I have three posts. Each one of them are in a different forum. So if I come back over to my dashboard, here are my three posts: My forum posts. ‘How to create a membership website’. That’s the forum it’s in. The ‘membership website first post by rick’, that’s the name of it, and here’s the date I published it. Here’s the next one, here’s the name, here’s the date, and here’s the third one. So those are all listing. And… We probably just want this to display, really only on the dashboard page. So we’re going to come back over here to widgets and we’re going to not let it be static but we’re going to make it dynamic.

And at the moment we can say ‘yeah it’s going to display to everybody’ because it doesn’t matter. It will display to everybody. But we only want it to display on a single page. So we don’t want to display on any pages except the dashboard page, which is my dashboard. And actually we may as well put it on the member support page also.

So now that we’ve got that we can hit save. It no longer shows up here on the home page, but if we go to the dashboard page it does show up. Okay? Now I think I’m going to take my account purchase stuff and instead of being on my dashboard, I’m going to move it over to member support. So just cut it out of there, go over to member support and paste it here. Now if we view this page, we’ve got our purchase history and we’ve got our forum posts showing up.

Okay so that is working the way it should. Well, now actually, we were really just getting started. Because now that we’ve done that we’re going to add a few more things to this. Not just my forum posts, but I think we’re also going to add a widget for latest posts, and a quick links widget and an unread posts widget. I guess it’s over here on the miscellaneous template tags. So we’re using the sf_new posts tag as our function. Just go ahead and grab this.

Now you can see that both the arguments are optional, so we’re going to skip both of them. We’re just going to grab that tag, go back over here, paste it there, new post tag and then we want to just say if that new post tag exists…. And actually we’re going to say ‘new unread forum posts.’ Say that. Come back over and refresh it.

Okay, now since I’m the author of all of them, it says that I don’t have any unread posts in the forum. However if I was logged in as the other guy, then each of these posts would show up as unread and we’ll take a look at that in a minute here. But that’s new unread forum posts.

And the next thing we’re going to do is look at the quick links. And so we’re going to come back over here to template tags… And, well actually before we do quick links let’s go ahead and do subscribed topics. And this is essentially the same thing. This will show you the topics that you are subscribed to so you can get to them quickly. And so we’ll just go ahead and grab this… Actually, let’s add a new widget, and we’re going to call it ‘my subscribed topics.’ And then we’ll go ahead and copy this PHP, paste it there, grab the tag, replace this tag with the other tag, replace this function name with a new function name, and save it… Refresh it. And it says ‘I have zero unread subscribed topics.’

And the next one we’ll add is the same thing for watched topics, because you may not subscribe it but you set it to watch.  So let’s go ahead and copy this, and drag the enhanced text over, paste it, and so, ‘my watched topics.’ And grab the watched topics. We’re going to add the ‘true’ to the argument. Come back over here and refresh this.

It says you have ‘zero unread watched topics’, and if you wanted to substitute these for the quick access bar then what we’ll do is go ahead and copy this one more time, and we’ll add the enhanced text widget. We’re not going to give it a name this time, but we will come over here and look for the quick links… Okay, quick links must be back over here under lists. Recent posts, latest posts, announce, authors posts, hot topics, highest rated, most rated, recent… There it is, quick links.

Okay so the quick links tag asks you to set a limit to how many are going to show, and then whether or not you want to show the name of the forum or whether or not you want to show… Pardon me, that’s not right. This will show two sets of quick links. It can show both the forum quick links and the recent quick links or it can show one of the two. We’re going to start off with it showing both.

Now we’ll copy the function name and make sure it exists first. Save it. Hmm, okay, same problem, didn’t get that greater than sign when I copied it. Refresh it. Okay and so this is the recent forum posts, and if you click on this it will take you over to the recent forum, right? Or it’ll take you to that specific forum.

So you can get fast access. Or this will take you to the latest post. And you can choose to do one or the other. And I’m going to say recent and we’re going to say false. Save. Refresh. Now we’ll only have the one choice. And in fact, it might make the most sense to take this and drag it all the way to the very top. So we now have a whole bank of forum selections that we can choose from.

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
0 comments… add one

Leave a Comment