• How do I present different images to different logged-in users?

    For example, I have a site with 20 different users, each of which has the author role assigned to them. When each user is logged in, how would I display a different set of images for each user – let’s say a set of 4 car images for one user, whilst another user would see a set of 4 flower images and so on?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Do you want the user themselves to be able to determine what images they get?
    Very rudimentary reply involves the following code:

    <?php
    global $current_user;
    if( user_is_logged_in() ) {
      get_currentuserinfo();
      // now $current_user->ID is the current user's id number
      // you could pass it to a function for conditionally retrieving images
      // or conditionally figure that out here (if/then; switch;)
    }
    ?>

    See:
    https://codex.www.ads-software.com/Function_Reference/get_currentuserinfo

    Thread Starter Tommy Walker

    (@acornflyer)

    Thanks for the reply – I want to serve the user images specific to them, not allow them to choose. The images would also be updated (changed) every week, so the user would see the updated images when yhey log in (provided it’s a new week).

    I also don’t know how to configure the request to the database to do this so any help there would also be much appreciated.

    Where will the images be stored?

    1. One idea is to have a post created for each of these users (noone has to see the posts…)
    2. Add the images you want that user to see — add them to the post that is specific for that user.
    3. Change the author of that post to be that particular user.
    4. Probably tag that post with something like “headerimg” to help with your later queries.
    5. Then all that is left is to write code that pulls all images from that particular post and displays them where you want.

    I could possibly help with #5 later, but am totally swamped right now. Search for how to:
    a. Query for a particular post (goal being to get the post authored by the current user with the tag “headerimg”)
    b. Then query for how to display all images attached to a post (which will of course use the post you found above in [a] )

    Good luck!
    Paul

    Thread Starter Tommy Walker

    (@acornflyer)

    Thanks Paul, that all certainly seems logical and perfectly do-able up until point no. 5, where I’m likely to be stuck ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to display different images for different logged-in users?’ is closed to new replies.