| 本帖最后由 200711226 于 2011-1-13 11:55 编辑 
 【URL标准化】让最后发表用户以UID方式访问!!
 
 因为我的是万网G1空间,也不知道怎么的,用户名访问空间会出现错误,看到很多人都出现这种情况,也不知道怎么会事,干脆我就把用户名访问空间方式给改为UID访问了,一举两得,又解决了SEO优化问题,还让不支持中文URL的空间支持UID方式访问。
 
 例子网址:http://www.cdren.com.cn
 
 体现图片:
   
 可以看到图片上面标了的地方,默认的是以用户名方式访问,如:http://www.cdren.com.cn/space-username-%CA%B1%D6%AE%C9%B3.html
 
 而我的网站则是以UID方式访问:http://www.cdren.com.cn/space-uid-40.html
 
 网站绝大多数地方都是使用UID方式访问,不知道为什么DZ在这里偏偏要使用用户名方式来访问。
 
 好了,话不多说,开始吧!!!
 
 需要更改三个文件:
 
 source\function\function_forum.php 这个是函数存放的地方
 在文件最下面加入以下代码:
 template\default\forum\forumdisplay_list.htm  这个是列表页复制代码//自定义函数
function GetLastPosterId($UserName)//最后回复UID
{
        $sql = DB::query("SELECT uid FROM " . DB::table('common_member') . " WHERE username = '$UserName'");
        $row = DB::fetch($sql);
        return $row['uid'];
}
 查找:
 替换为:复制代码<a href="{if $thread[digest] != -2}home.php?mod=space&username=$thread[lastposterenc]{else}forum.php?mod=viewthread&tid=$thread[tid]&page={echo max(1, $thread[pages]);}{/if}" c="1">$thread[lastposter]</a>
template\default\group\group_index.htm 这个是群组首页复制代码<a href="{if $thread[digest] != -2}home.php?mod=space&uid={echo GetLastPosterId($thread[lastposter]);}{else}forum.php?mod=viewthread&tid=$thread[tid]&page={echo max(1, $thread[pages]);}{/if}" c="1">$thread[lastposter]</a>
 查找:
 替换为:复制代码<a href="{if $thread[digest] != -2}home.php?mod=space&username=$thread[lastposterenc]{else}forum.php?mod=viewthread&tid=$tid&page={echo max(1, $thread[pages]);}{/if}">$thread[lastposter]</a>
template\default\group\group_list.htm 这个是群组列表页复制代码<a href="{if $thread[digest] != -2}home.php?mod=space&username={echo GetLastPosterId($thread[lastposter]);}{else}forum.php?mod=viewthread&tid=$tid&page={echo max(1, $thread[pages]);}{/if}">$thread[lastposter]</a>
 查找:
 替换为:复制代码<cite><!--{if $thread['lastposter']}--><a href="{if $thread[digest] != -2}home.php?mod=space&username=$thread[lastposterenc]{else}forum.php?mod=viewthread&tid=$thread[tid]&page={echo max(1, $thread[pages]);}{/if}">$thread[lastposter]</a>
突然发现,原来论坛首页我还没有更改。悲剧中~~~复制代码<cite><!--{if $thread['lastposter']}--><a href="{if $thread[digest] != -2}home.php?mod=space&uid={echo GetLastPosterId($thread[lastposter]);}{else}forum.php?mod=viewthread&tid=$thread[tid]&page={echo max(1, $thread[pages]);}{/if}">$thread[lastposter]</a>
 source\function\function_forumlist.php 这个是论坛首页
 
 查找:
 替换为:复制代码$lastpost['author'] = '<a href="home.php?mod=space&username='.rawurlencode($lastpost['author']).'">'.$lastpost['author'].'</a>';
复制代码$lastpost['author'] = '<a href="home.php?mod=space&uid='.GetLastPosterId($lastpost['author']).'">'.$lastpost['author'].'</a>';
 |