Title: User Widgets
Last modified: August 22, 2016

---

# User Widgets

 *  [greymatter](https://wordpress.org/support/users/greymatter/)
 * (@greymatter)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/user-widgets/)
 * Hi, wonder if anyone can advise?
 * I have a login working on the front end of WordPress, once the user logs in the
   site then loads a static template. In this template I would like a widget that
   knows which user has logged in to display certain content on that page.
 * Is this possible?
 * Thanks for any help in advance.

Viewing 10 replies - 1 through 10 (of 10 total)

 *  [RossMitchell](https://wordpress.org/support/users/rossmitchell/)
 * (@rossmitchell)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/user-widgets/#post-5212408)
 * Yes, this can be done.
 * Make sure you are using a [child theme](http://codex.wordpress.org/Child_Themes)
   first.
 * Then you will customise your page templates. First they will check if the user
   is logged in, if not then give them suitable content.
    If they are logged in,
   then depending upon their role or ID or whichever criteria you decide, you can
   serve up their specific content.
 *  Thread Starter [greymatter](https://wordpress.org/support/users/greymatter/)
 * (@greymatter)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/user-widgets/#post-5212412)
 * Great!
 * I would like it to get the user id. The thing I don’t get is how it will get 
   their content once logged in. I would like to use content area within the page
   I have set up.
 * I have something roughly working below. But I don’t want to put an id for every
   user in like I have used I need it to get it automatically 🙂
 * <?php
    $user_id = get_current_user_id(); if ($user_id == 2) { echo ‘<p>[User Area](https://wordpress.org/user-loggedin-page1/?output_format=md)
   </p>’; } elseif ($user_id == 1) { echo ‘<p>[My Area 1](https://wordpress.org/user-loggedin-page2/?output_format=md)
   </p>’; } else { echo “<p>Not logged in dude</p>”; } ?>
 * Thanks,
 *  [RossMitchell](https://wordpress.org/support/users/rossmitchell/)
 * (@rossmitchell)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/user-widgets/#post-5212421)
 * > I need it to get it automatically
 * In which case you need to use or create that automatic mechanism. You could use
   the user role (subscriber/author/editor …) This mechanism is already in place.
   OR you could create a supplementary database table, like which identified which
   team they played for or what grade of music exam they are sitting. You will query
   the database and then create their content.
 * You put it into the page content area of your page by placing your code into 
   the relevant part of your page template.
 *  Thread Starter [greymatter](https://wordpress.org/support/users/greymatter/)
 * (@greymatter)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/user-widgets/#post-5212427)
 * Thanks for the response!
    Could i just use username?
 *  [RossMitchell](https://wordpress.org/support/users/rossmitchell/)
 * (@rossmitchell)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/user-widgets/#post-5212457)
 * Yes, you could use username.
    But doesn’t this leave you in the same place ? 
   You now have to maintain a list of usernames in your code, only slightly easier
   than IDs I would think.
 *  Thread Starter [greymatter](https://wordpress.org/support/users/greymatter/)
 * (@greymatter)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/user-widgets/#post-5212459)
 * So use something unique in the user table?
 * Thanks!
 *  Thread Starter [greymatter](https://wordpress.org/support/users/greymatter/)
 * (@greymatter)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/user-widgets/#post-5212464)
 * Ross,
 * Do you have an example of code in the template I could use if querying a new 
   table in the db?
 * Thanks for your time.
 * Richard
 *  [RossMitchell](https://wordpress.org/support/users/rossmitchell/)
 * (@rossmitchell)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/user-widgets/#post-5212483)
 * Working in the template context is just like working in a plugin. So find a plugin
   that does database queries using $wpdb
 * I don’t have any examples that are compact enough to present here, but here is
   a snippet, not enough context, but it should give you some ideas:
 *     ```
       {
       	global $wpdb;
       	$this->set_self($pid);
       	if($this->user->ID > 0) {
       		$nfound = 0;
       		$query = 'SELECT mr_PID, mr_date FROM wpG_mru WHERE mr_id = '.$this->user->ID.' ORDER BY mr_date DESC';
       		$results = $wpdb->get_results($query, ARRAY_A);
       		foreach($results as $row) {
       			$this->MRU[] = ($last_id = $row['mr_PID']);
       			$this->add_PID($last_id);
       			if($last_id == $pid)
       				++$nfound;
       //D	echo 'PID:'.$id.' date:'.$row['fo_date'].' found:'.$nfound.'<br />';
       		}
       ```
   
 *  Thread Starter [greymatter](https://wordpress.org/support/users/greymatter/)
 * (@greymatter)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/user-widgets/#post-5212528)
 * Thanks Ross, looks like a plan…
 *  [akappaka](https://wordpress.org/support/users/akappaka/)
 * (@akappaka)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/user-widgets/#post-5212533)
 * Hi Ross
    I’m new here. My post is unrelated since I am yet to find where to post
   this. I am an administrator of my site ([) and cannot find where to administer
   users. It was there before under USERS, but this option is no longer visible/
   available. I hadn’t been on the site in quite a few months. Please help Thanks

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘User Widgets’ is closed to new replies.

## Tags

 * [login](https://wordpress.org/support/topic-tag/login/)
 * [widgets](https://wordpress.org/support/topic-tag/widgets/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 3 participants
 * Last reply from: [akappaka](https://wordpress.org/support/users/akappaka/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/user-widgets/#post-5212533)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
