发新话题
打印

[分享] Z-blog编辑新文章时自动生成文章的URL(仅限英文站)

Z-blog编辑新文章时自动生成文章的URL(仅限英文站)

(发布完后看了一眼,不好排版,可能一些标签还被转义了,可以去博客原地址查看:http://www.ajaxstu.com/archives/Z-blog-alias.html

在Google的SEO优化过程中,文章的URL对关键字的排名起到了很大的作用,如果给每篇文章生成一个合适的url,那对你的关键字排名将会起到很大的作用,类似Wordpree的功能,本文针对Z-blog 用户的英文博客根据标题和分类自动生成文章的URL,或许对一些写英文文章的朋友们有一些帮助。
其实实现该功能也不是很麻烦,主要用javascript的方法,当标题输入框焦点转移后自动根据输入的标题生成一个以“—”分割的字符串,需要在/admin/edit_fckeditor.asp文件中做如下修改:

<p><%=ZC_MSG060%>:<input type="text" name="edtTitle" id="edtTitle" size="56" value="<%=EditArticle.Title%>" /></p>
改为:

<p><%=ZC_MSG060%>:<input type="text" name="edtTitle" id="edtTitle" size="56" value="<%=EditArticle.Title%>" /></p>

在最后的javascript代码段中增加:
function getStaticName(){
        var str;
        str = document.getElementById("edtTitle").value;
        str = str.replace(/(^\s*)|(\s*$)/g, "");
        str = str.replace(/\ /g,"-");
        str = str.replace(/\--/g,"-");   
        str = str.replace(/\---/g,"-");
        str = str.replace(/\----/g,"-");
        str = str.replace(/\--/g,"-");
        str = str.replace(/\./g,"-");
            
        document.getElementById("edtAlias").value=str;
        }
如果只需按标题自动生成URL,上面的修改已经可以实现了,如果还需要在选好分类后自动在URL前加上分类名,还需要做如下的修改:

<p><%=ZC_MSG012%>:<select class="edit" size="1" id="cmbCate" ><option value="0"></option>
修改为:

<p><%=ZC_MSG012%>:<select class="edit" size="1" id="cmbCate" ><option value="0"></option>


在"</select>"后增加下面的代码:
<%
Response.Write "<script>"
Response.Write "var cat = new Array();"
Response.Write "function GetAlias(indexid,catId)"
Response.Write "{"
Response.Write "document.getElementById(""edtCateID"").value = indexid;"
For Each Category in Categorys
  If IsObject(Category) Then
  
   if len(Category.Alias)>0 then
    Response.Write "cat[" & Category.ID & "] = """ & Category.Alias&""";"
   else
    Response.Write "cat[" & Category.ID & "] = """ & Category.Name&""";"
   End If
  End If
Next
Response.Write "document.getElementById(""edtAlias"").value = cat[catId] " & "+ ""-"" + document.getElementById(""edtAlias"").value;"
Response.Write "}"
Response.Write "</script>"
%>
现在,类似wordpress自动生成文章URL的功能已经实现了,由于我本是打算自己使用,所以修改了很多代码,经过使用没有什么问题,但是朋友们在修改代码之前一定要记得先做备份哦。还有一个不足之处就是每次焦点转移就会生成一次,如果焦点转移后又修改了标题或者分类,那么自动生成的URL就会有冗余,需要手动的删除一下。
本文来源于悠悠博客 http://www.ajaxstu.com/ , 原文地址:http://www.ajaxstu.com/archives/Z-blog-alias.html

[ 本帖最后由 tomorrow819 于 2007-12-30 09:23 编辑 ]

TOP

请问自动生成e文标题是通过翻译软件实现的,还是?
文章太长。没耐心看下去了。哪个直接告诉我!

TOP

回复 2# 的帖子

人家标题都已经说了,仅限英文站……也就是只能是英文标题。

TOP

哎~好东西!可惜用不上~
推荐博客:飞月博客

TOP

看不懂哦 我只想知道哪里有自动生成网页内标签的文章

TOP


<p><%=ZC_MSG060%>:<input type="text" name="edtTitle" id="edtTitle" size="56" value="<%=EditArticle.Title%>" /></p>
改为:

<p><%=ZC_MSG060%>:<input type="text" name="edtTitle" id="edtTitle" size="56" value="<%=EditArticle.Title%>" /></p>

这2段代码有区别吗?
看了N遍都没看出哪里不同!
SEO

TOP

引用:
原帖由 hayou 于 2008-3-27 02:45 发表

:
改为:

:

这2段代码有区别吗?
看了N遍都没看出哪里不同!
我去楼主博客看了.转过来哈



<p><%=ZC_MSG060%>:<input type="text" name="edtTitle" id="edtTitle" size="56" value="<%=EditArticle.Title%>" /></p>
改为:
<p><%=ZC_MSG060%>:<input type="text" name="edtTitle" id="edtTitle" size="56" value="<%=EditArticle.Title%>" onBlur="getStaticName()"/></p>
本文来源于悠悠博客 http://www.ajaxstu.com/ , 原文地址:http://www.ajaxstu.com/archives/Z-blog-alias.html

TOP

发新话题