WordPress Dynamic User pages
-
Is there a way to make a dynamic page that shows something different depending on which user is logged on? Lets say that I log on. Then the URL https://www.____.com/my-profile/ would show a page specifically designed for me. If someone else logs on, the same url would show different content. Is this possible with WordPress?
-
It is possible. I can think of two ways to do it:
First, it can be done using a custom page template that can be paplied to that page, and you can create any code that you want to to display what you want on the page.
Second, you can set up a shortcode to display the information and that can be added to any page on the site.
Thanks for replying! I’m fairly new to wordpress so I’m a total newbie. If I make a custom page template, would I be writing a conditional statement to change the page depending on the user? If I have that right, how would I do this? I don’t much coding experience, so it would be awesome if you could walk me through this.
Thanks in advance!
It would be the same both ways, so the only real difference is what it’s wrapped in to make it work.
For conditionals, you’d do something like this:
<?php $current_user = get_current_user_id (); ?> <?php if ($current_user == 1): ?> <p>First users content.</p> <?php elseif ($current_user == 2): ?> <p>Second users content.</p> <?php else: ?> <p>Default/not-logged-in content.</p> <?php endif; ?>
Instead of using php to do the content. Is it possible to create another WordPress page (that not visible to anyone) and then have that page show up for first users content.And also, how does my theme (angle) impact the custom page templates? Once again, thanks for helping me!
it is possible, but that’s a whole other level of coding. ?? You’d need to set up a choice for each user so that you can choose which page ot send them too. It’s possible but I’d think more work.
I don’t think that your theme should have much, if not nothing, ot do with this, but that’s a quiestion for the theme’s author.
I see… can I create a page using WordPress’s drag and drop function. Then find that page’s .php and copy paste and replace the <p>First users content.</p> you have above? The reason I’m asking is because i think coding an entire page in php is WAY too advance for me :P.
The page content isn’t stored in the PHP page, so there would be no files to cut-and-paste from. You might be able to cut-and-paste from the ditor window into a PHP file, but you’d still need all of the
if()
statements everywhere.After all of this, my biggest concern is just how many members you’re going to have. What happens when you get up to 10 users? 10? 50? 100? 1,000? You haven’t said what number of users you’re looking at, but from my past experience, anything over about 5 is going to become a nightmare to look after and you’d want to look for a different solution.
That leads me to my next big question… Exactly what do you want ot show each user that’s different? Do they all need some completely individual text, or are they shown their own details, or is there something else?
I’m doing a website for Earlybird youth services. Essentially each youth will be able to see their own progress and no one elses. As of now only around 60ish people are signed up, but anything could happen as we are just getting started.Some text might have to be different, but mostly numbers and such to keep them updated on progress.
Then the question beocmes how are those numbers recorded for each user? If you know how they are being stored, then you’ll be able to recall them for a user when they log in. That way there won’t be any changes like this, no need to use the
if()
statements anywhere, and no masses of content that you’d need to update for each user anyway.When you figure that out you’ll need one template, then get the value for the logged in user and display it. That’s all there is to it, and it’s a lot easier then the more complicated way that I was thinking of before.
If each number is entered in separately, how would I recall them for each individual user? Also, what do you mean by a template.Am I using a custom page template without the php code? Thanks for sticking with me! I’m pretty new to this stuff.
If each number is entered in separately, how would I recall them for each individual user?
That’s what you’d need to work out – how they are being stored at least.
How are the numbers being stored? You need to work that out before you think too far into displaying them as there’s no point working out how to display something when you don’t know what you’re going to be displaying in the first place.
For templates, you’d set up a file as a custom page template, and that is where you’d retrieve and display the information.
Could you give me an example of where I CAN store it and then how to call on the variable in the custom page template?
:/ There’s many different ways of doing this. How you do it is going ot depend on a lot of factors, like data strcuture, how many fields you need, is the number of fields going to increase over time, does the data need to be queried for trends between users, is it completely individual and private, etc, etc….
The two main ways that you could look are:
First, storing everything using update_user_meta() to stor all of the values. That will store everything against the users ID, and you’ll be able to retrieve it using get_user_meta(). This is good ofr individual information, but can be harder to do reports on if you ever need to aggregate any data.
Second, create a new database table/tables to match your own data structure and use the $wpdb class to store and retrieve everything. This will involve more work, but you’ll be able to manage the data better and put reports together a lot easier.
What you’re asking for is really far beyond the scope of these forums, and would need osmeone to sit down and spend a few hours to think about and come up with a final solution that would work for your individual case. Please b eassured that it is 100% possible, and most likely not as difficult as I’ve made it seem. But it’s a whole lot of work for the volunteers here to do.
Haha, I ended up downloading a plugin called Userpro. Thanks for your help though!
- The topic ‘WordPress Dynamic User pages’ is closed to new replies.