Viewing 10 replies - 1 through 10 (of 10 total)
  • Yes, this can be done.

    Make sure you are using a child theme 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

    (@greymatter)

    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</p>’; }
    elseif ($user_id == 1) {
    echo ‘<p>My Area 1</p>’;
    } else {
    echo “<p>Not logged in dude</p>”;
    }
    ?>

    Thanks,

    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

    (@greymatter)

    Thanks for the response!
    Could i just use username?

    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

    (@greymatter)

    So use something unique in the user table?

    Thanks!

    Thread Starter greymatter

    (@greymatter)

    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

    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

    (@greymatter)

    Thanks Ross, looks like a plan…

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘User Widgets’ is closed to new replies.