Patrik Posted May 21, 2013 Share Posted May 21, 2013 Hi, In short, what I'm looking for is profile pages for all registered users, that are visible to anyone visiting the site. Long version: I would like to link to the author's (user) page from a blog entry. I'm using the createdUser object to retrieve the user name, and then construct a link that looks something like this: /author/{$page->createdUser->name} Creating the link is obviously no problem, but how do I make that actual page exist without creating pages manually for all the users? Apologies if this topic has been up before. I have searched the forums, bit couldn't find an anwser. Regards, Patrik Link to comment Share on other sites More sharing options...
Wanze Posted May 21, 2013 Share Posted May 21, 2013 Hi patrik, You can use urlSegments for this case. In your template used by the /author/ page, enable urlSegments in the Template config. Then in the template file (example code): if ($input->urlSegment1) { $username = $sanitizer->selectorValue($input->urlSegment1); // Maybe you need to add 'check_access=0' to your selector if also guest users can see this page... $u = $users->get($username); if ($u->id) { // Display the information about user } else { throw new Wire404Exception(); } } // No urlSegment passed - throw a 404 or output some message 3 Link to comment Share on other sites More sharing options...
diogo Posted May 21, 2013 Share Posted May 21, 2013 With url segments (http://processwire.com/api/variables/input/ scroll to the middle of the page). Allow them on the authors page template, and on this template's file put something like this: if ($input->urlSegment1) { $username = sanitizer->name($input->urlSegment1); $userpage = $pages->get(name=$username, template=user, include=all); if ($userpage->id) { // echo the user info. these would be custom fields added to the "user" template echo "<h2>{$userpage->first_name} {$userpage->last_name}</h2>"; echo "<p>{$userpage->bio}</p>"; } } You can add any info you want to the users pages by adding fields to the "user" template (on the templates page, under "filters", enable "show system templates?") Edit: Wanze beat me again. He beats everyone lately Edit2: corrected my code to make the check for guest visitors that Wanze refered, except that I'm using $pages instead of $users to get the user page 3 Link to comment Share on other sites More sharing options...
onjegolders Posted May 21, 2013 Share Posted May 21, 2013 For the pages belonging to an author I think you can use the following selector created_users_id= (as per cheatsheet) so $auth_pages = $pages->find("created_users_id=$userpage->id"); Not tested. 2 Link to comment Share on other sites More sharing options...
Patrik Posted May 21, 2013 Author Share Posted May 21, 2013 Brilliant! Thanks a lot for the solution and super quick replies! As a newbie here, I'm blown away by both the capabilities of PW and the top-notch community! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now