• Hi guys,

    I am trying to build a feature of my site where when a user logs in they will see a list of links. Each user will see a different set of links – specific to them.

    I can’t find a plugin that does this. My assumption is that the best way to do this would be to use a page template which checks the user ID and then serves up the appropriate links.

    Has anyone got any advice on achieving this?

    Thanks

    John

Viewing 4 replies - 1 through 4 (of 4 total)
  • I would start by creating a new page template.
    In your template, where you want the custom content to go, I would add something like the following:

    <?php
    if ( is_user_logged_in() ) {
      if ( $user_id = 1 ) {
        // display content for user_id #1
      } elseif ( $user_id = 2 ) {
        // display content for user_id #2
      } else {
        // display content for all other logged in users
      }
    } else {
      // display content for users that are not logged in
    }
    ?>

    You’ll have to know the user_id’s for each user you want specific content for. In the Dashboard, click on Users from the left menu. Hover your mouse over the username that you want custom content for, and in the URL that shows up at the bottom of your window you’ll see somewhere in there https://yoursite.com/wp-admin/user_edit.php?user_id=2 – this user’s ID would be 2 for instance.

    Thread Starter farser1

    (@farser1)

    Great, that is really helpful.

    Does that mean all the content (around 10 links per user) would have to be stored in the actual template file?

    I will need to do this for around 150 users and I don’t want it to get too confusing.

    Any pointers or thoughts would be massively appreciated.

    Since you have 150 users, a large template that lists every user in an if/else block is going to become unmanageable. Why not create a front end user profile page and then create custom user meta fields for the links specific to each user. Then simply display the meta fields on the user profile page.

    User Meta Manager might be of use to you.

    Thread Starter farser1

    (@farser1)

    Hi WPRanger,

    Thanks for the suggestion. I will experiment with that.

    The other thing i was considering is it possible to store all the links in a separate wp table and call that content into the page template?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to allow specific users to see different content on the same page?’ is closed to new replies.