不同的URL地址结尾,用于将用户定向到同一页面但具有动态内容

不同的URL地址结尾,用于将用户定向到同一页面但具有动态内容

问题描述:

I have a WordPress based site with a custom social network functionality that I wrote using php and jQuery.

Right now when my users sign up for an account, WordPress automatically creates a page for them with the address www.mysite.com/members/username where 'username' is their unique URL address. This way each member has their own page that they can access with their unique URL address.

The problem is that as my members base is growing, I am realizing that I will have thousands of profile pages created for each user and this can become a big mess.

So I was thinking to simplify this process and instead of creating a WordPress Page for each user have one profile WordPress page that dynamically loads its contents based on which 'username' ending is found in the URL address.

Is this possible? and if so how can I get started?

Thanks for all your help in advance.

我有一个基于WordPress的网站,其中包含我使用php和jQuery编写的自定义社交网络功能。 p>

现在,当我的用户注册一个帐户时,WordPress会自动为他们创建一个页面,地址为www.mysite.com/members/username,其中“username”是他们唯一的URL地址。 这样,每个成员都有自己的页面,可以使用其唯一的URL地址进行访问。 p>

问题在于,随着我的会员基础的增长,我意识到我将为每个用户创建数以千计的个人资料页面,这可能会变得非常混乱。 p> \ n

所以我想简化这个过程,而不是为每个用户创建一个WordPress页面,而是有一个配置文件WordPress页面,根据在URL地址中找到的“用户名”结尾动态加载其内容。 p>

这可能吗? 如果是这样,我该如何开始? p>

提前感谢您的帮助。 p> div>

Using Wordpress:

Create a new rewrite rule for /members/username

function members_rewrite_rules()
{
  add_rewrite_rule('members/(.+)/?$', 'index.php?pagename=members&username=$matches[1]', 'top');
}
add_action( 'init', 'members_rewrite_rules' );

Add the username variable to $wp_query.

function members_query_vars($query_vars)
{
  $query_vars[] = 'username';
  return $query_vars;
}
add_filter('query_vars', 'members_query_vars');

Then in your 'members' template page you can grab the query var and use it to load the member profile:

<?php
get_header();
$username = get_query_var('username');
// load the user details using $username
get_footer();
?>

You want to look at URL rewriting.

# .htaccess
RewriteRule ^members/([0-9a-z]+)/?$ ?members&username=$1 [NC,L]

// members.php
$username = $_GET['username'];
$result = mysql_query("SELECT age, location FROM members WHERE username = '$username'");
$data = mysql_fetch_assoc($result);

echo "age: ".$data['age'];
echo "location: ".$data['location'];

well, something like that. and all users are using the same page(file) members.php. you just load data into it and then print out details.