Jump to content

all items from member on member page


bwakad
 Share

Recommended Posts

I had trouble with this selector which

Even if not logged in - the current page (which is a user name), should give me info about that user and a list of items (pages) created by that user.

My selector was originally this for logged in users - works and handy on user profile template:

$selects = $pages->find("template=child-template,  created_users_id={$user}"); // find pages user created

But I was concerned about this part, because I want it also to be independent on a member page:

created_users_id={$user}

And needed to make it look like:

={$page->name}

I could not use :

$page->createdUser={$page->name} - since I am looking for other then current page.

createdUser={$page->name} - since the field does not excist.

$createdUser->name; - I would have to use $page in front which does not work for me, and $pages twice does not make sence.

$user or $users - will not work because I look for $pages

Then I browsed the API again... and used:

$member = $users->get($page->name) ;

which simply returns the ID of the user with that name

Now I can set the selector to:

created_users_id={member};

And, as always - if there are some things wrong I appreciate it if you let me know!

Link to comment
Share on other sites

Seems about right.

Nothing wrong with the way you've done it, but the short one-line version would be:

$userpages = $pages->find("template=child-template, created_users_id=" . $users->get($page->name));

Rather than using $selects all the time, I would name it something more meaningful like $userpages above, then iterate through them: foreach ($userpages as $userpage) { ...

It's more descriptive when you build your template file up and there's lots going on - helps you keep track of things a bit easier especially when you're using multiple PageArrays on a page, though it's not essential to do this and everyone has their own preference and naming style.

  • Like 1
Link to comment
Share on other sites

Thanks, I actually tried that before, but since I am moving all my selectors inside a function I tested the selector but eventually have to use the string: $selector= "string here". After that I use $selects = $pages->find($selector); If I use more common names for what I select I would end up with so much variables inside the function.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...