sevfurneaux Posted November 3, 2011 Share Posted November 3, 2011 Hey all, Is it possible to show the 'Author' of who created a particular page? For example, when creating a Blog article it would show the user who created this page (or most recently edited it) on the frontend. I've assumed it could work like this, but obviously the below code only shows the user who is currently logged in: foreach($children as $child) { echo "<h2><a href='{$child->url}'>{$child->title}</a></h2>"; echo "<p>{$child->summary}</p>"; echo "<p>Author {$user->name}</p>"; } Cheers, Sev Link to comment Share on other sites More sharing options...
Soma Posted November 3, 2011 Share Posted November 3, 2011 You can get user created and modified for a page with <?php $page->createdUser->name; $page->modifiedUser->name; $page would be $child in your code 4 Link to comment Share on other sites More sharing options...
sevfurneaux Posted November 3, 2011 Author Share Posted November 3, 2011 Brilliant! Thanks Soma. Link to comment Share on other sites More sharing options...
Juergen Posted June 12, 2016 Share Posted June 12, 2016 I have tried it with PW 3.21 and it seems not to work any longer. I always get Error 500. Link to comment Share on other sites More sharing options...
Robin S Posted June 12, 2016 Share Posted June 12, 2016 I have tried it with PW 3.21 and it seems not to work any longer. I always get Error 500. It works okay for me with PW 3.0.21. Not sure why it's not working for you but as an alternative you could use: $users->get($page->settings->created_users_id)->name $users->get($page->settings->modified_users_id)->name Link to comment Share on other sites More sharing options...
Juergen Posted June 12, 2016 Share Posted June 12, 2016 Doesnt work either for me. I have tested it with Tracy debugger tool and I always get an error message with pageimage after adding the line of code to the template? Exception: Method Pageimage::last does not exist or is not callable in this context (in ........web/wire/core/Wire.php line 409) I dont know why because this has nothing to do with the user name. Maybe I have to dive a little bit deeper into my template code. Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 12, 2016 Share Posted June 12, 2016 Do you do anything in hooks related to images (maybe on the user template)? Also Tracy will probably give you a stack trace, which might be helpful to debug this further. Link to comment Share on other sites More sharing options...
Juergen Posted June 12, 2016 Share Posted June 12, 2016 No I dont hook into image fields. I only have a textformatter running (without a hook) which manipulates the image class of images added with the CKEditor. The callstack shows me always an error on the index.php. Link to comment Share on other sites More sharing options...
Juergen Posted June 12, 2016 Share Posted June 12, 2016 Ok I have traced the problem down to my userimage. There must be the problem. The API of the userimage seems to be wrong. If I comment out the userimage, the name of the creator will be displayed properly. So the API call as described above works also in 3.0.21. Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 12, 2016 Share Posted June 12, 2016 That's expected to error there. The interesting part is where the exception did come from earlier in the call stack. And maybe look at that textformatter. There's some code calling last() on an image, while the object is probably supposed to be a list of images. Link to comment Share on other sites More sharing options...
Juergen Posted June 12, 2016 Share Posted June 12, 2016 $user->userimage->last() This line of code is responsible for the error. Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 12, 2016 Share Posted June 12, 2016 Just use $user->getUnformatted('userimage') and you'll get a Pageimages object no matter what. It's less error prone especially as the output-formatting on user objects is sometimes a bit iffy about when it's on or not. Link to comment Share on other sites More sharing options...
Juergen Posted June 13, 2016 Share Posted June 13, 2016 Oh it seems that the size attribute in the api call is responsible for the error. This works: $user->userimage but this works not: $user->userimage->size(75, 75, array('cropping' => 'outside'))->url Settings of my userimage field: Error message with Tracy: Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 13, 2016 Share Posted June 13, 2016 $user objects are not always (never??) in output formatting ON mode like all other pages are – even on the frontend. And as long as output formatting is off these field settings are ignored and you'll always get a list of images. So in the case of working with the user object it's wise to force a specific formatting: $user->getFormatted('image_field'); // Returns regarding to the fields setting $user->getUnformatted('image_field'); // Returns always a list (does not break when field settings would change) 2 Link to comment Share on other sites More sharing options...
Juergen Posted June 13, 2016 Share Posted June 13, 2016 You are absolutely right!! This code works: $user->getFormatted('userimage')->size(75, 75, array('cropping' => 'outside'))->url; I didnt know that user fields are specific on frontend, because I never had troubles before. Thank you so much! Now everything works as expected. Link to comment Share on other sites More sharing options...
sam13579 Posted May 19, 2022 Share Posted May 19, 2022 On 11/3/2011 at 5:04 PM, Soma said: You can get user created and modified for a page with <?php $page->createdUser->name; $page->modifiedUser->name; $page would be $child in your code Is there a documentations for all these things? Link to comment Share on other sites More sharing options...
3fingers Posted May 19, 2022 Share Posted May 19, 2022 43 minutes ago, Shohan Arafat said: Is there a documentations for all these things? Yes 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