今天抽空分享一篇wordpress仿站的實戰教程,起因是一個朋友感覺自己的網站速度慢,希望能耕換成wordress系統,經過一番交流,確定了要更改的網站欄目和主題風格中需要保留的東西,然后便開始正式仿站操作,因為是仿制自己的網站,所以也不需要擔心版權什么的,要考慮的就是主題仿制好后,把關鍵詞的布局和原來做好對比,保障網站排名不會有大的波動就好。
wordpress的主題訂制,一般是對前端要求比較高,wordpress學會了,建站還是非常的快的。下面進行教程,沒有基礎知識的請先看基礎知識。
仿站的目標網站:hy1234.com。
1.目標網站的抓取,使用仿站小工具8.0.2挺好用的,能夠盡可能多的將整個網站抓取下來。
將文件保存到wp-content/tust。保存的首頁default.html和其他的文件目錄如下:
然后建立標準的wp文件。如下圖所示:
將default.html分割到header.php, index.php, footer.php
header.php 包含body再內的導航欄,等下還會貼出修改后的代碼。
index.php 包含主體部分,要引用header.php 和 footer.php。
footer.php 包含最后的版權等信息。
2.修改header.php中的鏈接使首頁正常。其中常用的模板函數:
基本條件判斷函數:
is_home():是否為主頁
is_single():是否為內容頁 (Post)
is_page():是否為內容頁 (Page)
is_category():是否為 Category/Archive 頁
is_tag():是否為標簽 (Tag) 存檔頁
is_date():是否為指定日期存檔頁
is_year():是否為指定年份存檔頁
is_month():是否為指定月份存檔頁
is_day():是否為指定日存檔頁
is_time():是否為指定時間存檔頁
is_archive():是否為存檔頁
is_search():是否為搜索結果頁
is_404():是否為 "HTTP 404: Not Found" 錯誤頁
is_paged():主頁 /Category/Archive 頁是否以多頁顯示
Header 部分常用到的 PHP 函數:
<?php bloginfo('name'); ?>:博客名稱 (Title)
<?php bloginfo('stylesheet_url'); ?>:CSS 文件路徑
<?php bloginfo('pingback_url'); ?>:PingBack URL
<?php bloginfo('template_url'); ?>:模板文件路徑
<?php bloginfo('version'); ?>:WordPress 版本
<?php bloginfo('atom_url'); ?>:Atom URL
<?php bloginfo('rss2_url'); ?>:RSS 2.o URL
<?php bloginfo('url'); ?>:博客 URL
<?php bloginfo('html_type'); ?>:博客網頁 HTML 類型
<?php bloginfo('charset'); ?>:博客網頁編碼
<?php bloginfo('description'); ?>:博客描述
<?php wp_title(); ?>:特定內容頁 (Post/Page) 的標題
模板常用的 PHP 函數及命令:
<?php get_header(); ?>:調用 Header 模板
<?php get_sidebar(); ?>:調用 Sidebar 模板
<?php get_footer(); ?>:調用 Footer 模板
<?php the_content(); ?>:顯示內容 (Post/Page)
<?php if(have_posts()):?>:檢查是否存在 Post/Page
<?php while(have_posts()):the_post(); ?>:如果存在Post/Page則予以顯示
<?php endwhile; ?>:While 結束
<?php endif; ?>:If 結束
<?php the_time('字符串') ?>:顯示時間,時間格式由"字符串"參數決定,具體參考 PHP 手冊
<?php comments_popup_link(); ?>:正文中的留言鏈接,如果使用 comments_popup_script(); 則新窗口打開鏈接
<?php the_title(); ?>:內容頁 (Post/Page) 標題
<?php the_permalink() ?>:內容頁 (Post/Page) URL
<?php the_category(',') ?>:特定內容頁 (Post/Page) 所屬 Category
<?php the_author(); ?>:作者
<?php the_ID(); ?>:特定內容頁 (Post/Page) ID
<?php edit_post_link(); ?>:如果用戶已登錄并具有權限,顯示編輯鏈接
<?php get_links_list(); ?>:顯示 Blogroll 中的鏈接
<?php comments_template(); ?>:調用留言/回復模板
<?php wp_list_pages(); ?>:顯示 Page 列表
<?php wp_list_categories(); ?>:顯示 Categories 列表
<?php next_post_link('%link '); ?>:下一篇文章鏈接
<?php previous_post_link('%link'); ?>:上一篇文章鏈接
<?php get_calendar(); ?>:日歷
<?php wp_get_archives() ?>:顯示內容存檔
<?php posts_nav_link(); ?>:導航,顯示上一篇/下一篇文章鏈接
<?php include(TEMPLATEPATH . '/文件名'); ?>:嵌入其他文件,可為定制的模板或其他類型文件
與模板相關的其他函數:
<?php _e('Message'); ?>:輸出相應信息
<?php wp_register(); ?>:顯示注冊鏈接
<?php wp_loginout(); ?>:顯示登錄/注銷鏈接
<!–next page–>:將當前內容分頁
<!–more–>:將當前內容截斷,以不在主頁/目錄頁顯示全部內容
<?php timer_stop(1); ?>:網頁加載時間(秒)
<?php echo get_num_queries(); ?>:網頁加載查詢量
將模板中的css,js,圖片的鏈接都換成上面的函數
3.頁面顯示正常時,進行導航欄的修改。
其中導航欄設置時,修改原始代碼:
<?php wp_nav_menu(
array(
'theme_location' => '' //指定顯示的導航名,如果沒有設置,則顯示第一個
'menu' => 'header-menu',
'container' => 'nav', //最外層容器標簽名
'container_class' => 'primary', //最外層容器class名
'container_id' => '',//最外層容器id值
'menu_class' => 'sf-menu', //ul標簽class
'menu_id' => 'topnav',//ul標簽id
'echo' => true,//是否打印,默認是true,如果想將導航的代碼作為賦值使用,可設置為false
'fallback_cb' => 'wp_page_menu',//備用的導航菜單函數,用于沒有在后臺設置導航時調用
'before' => '',//顯示在導航a標簽之前
'after' => '',//顯示在導航a標簽之后
'link_before' => '',//顯示在導航鏈接名之后
'link_after' => '',//顯示在導航鏈接名之前
'items_wrap' => '<ul id="%1$s">%3$s</ul>',
'depth' => 0,////顯示的菜單層數,默認0,0是顯示所有層
'walker' => ''// //調用一個對象定義顯示導航菜單 ));
?>
其中首頁header.php修改完成后,大致如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo('charset'); ?>" />
<title>天津科技大學海洋與環境學院</title>
<meta name="keywords" content="天津科技大學海洋與環境學院" />
<meta name="description" content="<?php bloginfo('description'); ?>" />
<link rel="shortcut icon" type="image/ico" href="<?php echo get_option(' wpd_logo '); ?>" />
<link href="<?php bloginfo('template_url'); ?>/css/reset-min.css" rel="stylesheet" type="text/css" />
<link href="<?php bloginfo('template_url'); ?>/css/fonts-min.css" rel="stylesheet" type="text/css" />
<link href="<?php bloginfo('template_url'); ?>/css/grids-min.css" rel="stylesheet" type="text/css" />
<link href="<?php bloginfo('template_url'); ?>/css/common.css" rel="stylesheet" type="text/css" />
<script src="<?php bloginfo('template_url'); ?>/js/jquery-1.7.2.min.js" type="text/javascript"></script>
<!--[if lt IE 7]>
<script src="js/ie7.js"></script>
<![endif]-->
<script type="text/javascript" src="js/iepngfix_tilebg.js"></script>
<link href="<?php bloginfo('template_url'); ?>/css/index.css" rel="stylesheet" type="text/css" />
<link href="<?php bloginfo('template_url'); ?>/css/frame-top-link.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/mainmenu.css" />
<link href="<?php bloginfo('template_url'); ?>/css/jqueryslidemenu.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/bigpic.css" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/modulelist.css" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/pager.css" />
<script src="<?php bloginfo('template_url'); ?>/js/jquery.slidemenu.js" type="text/javascript"></script>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/xmosaic.js"></script>
<script src="<?php bloginfo('template_url'); ?>/js/jquery.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_url'); ?>/js/kandytabs.pack.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_url'); ?>/js/custom.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/footer.css" />
<style>
.tag_description
{
float: left;
margin-top:7px;
padding-bottom:5px;
list-style:none;
}
.tag_description a
{
font-size: 12px;
text-indent: 24px;
}
.tag_description p
{
font-family:"宋體",Verdana, Lucida, Arial, Helvetica;
color: #666666;
float:right;
width:220px;
line-height:24px;
font-size: 12px;
text-indent: 24px;
text-align:justify;
margin-top:0px;
text-justify:inter-ideograph;
}
#AcadeInfoList
{
position:relative;
top:-20px;
}
#AcadeInfo_spliter
{
position:relative;
top:10px;
}
#AcadeInfoList:nth-of-type(n)
{
position:relative;
top:0px;
}
#AcadeInfo_spliter:nth-of-type(n)
{
position:relative;
top:30px;
}
.tag_title{
line-height:24px;
background-position-x: 0%;
background-position-y: -540px;
background-repeat: no-repeat;
overflow-x: hidden;
width:370px;
}
.tag_title a{color: #666666; font-size:12px; margin-left:0px; padding-left:5px; }
</style>
</head>
<body>
<div id="frame-top">
<div id="frame-top-warpper">
<div class="frame-top-link">
<ul>
<li class="first"><a target="" href="/">學院首頁</a></li><li class=""><a target="" href="/7db3dc.html">聯系我們</a></li><li class=""><a target="_blank" href="/admin.html">管理員入口</a></li> </ul>
</div>
<div id="frame-top-logo">
<table>
<tr>
<td style="vertical-align:top">
<a href="/" title="天津科技大學海洋與環境學院">
<img src="<?php bloginfo('template_url'); ?>/picture/2015-09-16-19-7642419411.png" />
</a>
</td>
</tr>
</table>
</div>
<div id="frame-top-navbar">
<script type="text/javascript">
$(document).ready(function () {
mlddminit(375);
});
</script>
<div id="navbar-left"></div>
<?php wp_nav_menu( array( 'container' => 'div','container_id' => 'navbar-middle','menu_class' => 'mlddm') ); ?>
<!--<ul class="mlddm" params="1,-1,500,slide,200,h">
<li class="">
<a href="#" target="">學院概況</a>
<ul>
<li><a href='/01589e.html' target="">學院簡介</a>
</li><li><a href='/cbc95b.html' target="">歷史沿革</a>
</li><li><a href='/1ab539.html' target="">學院領導</a>
</li><li><a href='/ad9daf.html' target="">學院黨委</a>
</li><li><a href='/0c2b70.html' target="">職能部門</a>
</li><li><a href='#' target="">學術機構</a>
</li> 替換這里第一條的東西。
-->
<div id="navbar-right"></div>
</div>
<?php wp_head(); ?>
4.修改index.php中的
這里先進行輪播圖的修改,后臺進行自我訂制了一份代碼,如果有想要的化,可以聯系我,其中輪播圖修改后的代碼如下:
<?php get_header(); ?>
<div id="frame-top-slider-detail"> </div>
<div id="frame-top-slider" class="smallslider">
<!-- 大圖輪播-->
<script type="text/javascript">
$(document).ready(function () {
var l=$('#bigpic').children().length;
var str='';
for(var i=0; i < l;i++)
{
if(i==0)
str += '<li class="on" ></li>';
else
str += '<li class=" "></li>';
}
$('#pager').html(str);
var mosaic = XMosaic('bigpic', { pager: 'pager', delay: 10000, countX: 10, countY: 5, how: 9, order: 0 });
});
</script>
<div id ="bigpic">
<a style="left: 0px; top: 0px; position: absolute;" target="_blank" href="/13v0to-1.html">
<img src='<?php echo get_option(' wpd_banner1 '); ?>' alt='1' />
</a><a style="left: 0px; top: 0px; position: absolute;" target="_blank" href="">
<img src='<?php echo get_option(' wpd_banner2 '); ?>' alt='2' />
</a> </div>
</div>
</div>
然后修改文章的列表部分:
<div id="frame-top-slider-mask">
<ul class="ctrls" id="pager">
</ul>
</div>
</div>
<div id="frame-main-body">
<div id="frame-main-wrapper" class="yui3-g">
<div id="frame-main" class="yui3-u">
<div id="frame-main-left" class="yui3-u-1-2">
<div class="module module_left">
<div class="module-name">
<a href="/75d14e-1.html" target="_blank">學院新聞</a>
<a style="font-size:13px; margin-left:250px; color:blue;" target="_blank" href="/75d14e-1.html">更多</a>
</div>
<div class="module-spliter">
<div> </div>
</div>
<div class="module-warpper">
<div>
<div class="row pd5 fb">
<a target="_blank" title="海洋與環境學院孫軍院長一行走訪國家海洋信息中心" href="/lqpmfv.html">海洋與環境學院孫軍院長一行走訪國家海洋信息中心</a>
</div>
<li class="row spic tag_description">
<a target="_blank" href="/lqpmfv.html" title="海洋與環境學院孫軍院長一行走訪國家海洋信息中心">
<img width=360 height="150" align="left" alt="海洋與環境學院孫軍院長一行走訪國家海洋信息中心" src="<?php bloginfo('template_url'); ?>/picture/540_225.jpg">
</a>
</li>
<div style="clear:both;"></div>
</div> <table cellspacing="0" cellpadding="0" class="tag_table">
<tbody>
<?php
query_posts(
//'query_type = post&posts_per_page=8'
array ( 'category_name' => 'business', 'posts_per_page' => 8 )
);
$i=0; while(have_posts()) : the_post(); $i++; ?>
<tr>
<td width="100%">
<ul>
<li class="tag_title">
<a target="_blank" title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
</ul>
</td>
</tr>
<?php endwhile; wp_reset_query(); ?>
</tbody>
</table> </div>
</div>
</div>
<div id="frame-main-right" class="yui3-u-1-2">
<div class="module">
<div class="module-name"> <a href="/c6c7e7-1.html" target="_blank">通知公告</a>
<a style="font-size:13px; margin-left:250px; color:blue;" target="_blank" href="/c6c7e7-1.html">更多</a>
</div>
<div class="module-spliter">
<div> </div>
</div>
<div class="module-warpper">
<table cellspacing="0" cellpadding="0" class="tag_table">
<tbody>
<?php
query_posts(
//'query_type = post&posts_per_page=8'
array ( 'category_name' => 'technolo', 'posts_per_page' => 8 )
);
$i=0; while(have_posts()) : the_post(); $i++; ?>
<tr>
<td width="100%">
<ul>
<li class="tag_title">
<a target="_blank" title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_time('Y年n月j日'); ?> <?php the_title(); ?></a>
</li>
</ul>
</td>
</tr>
<?php endwhile; wp_reset_query(); ?>
</tbody>
</table> </div>
</div>
</div>
</div>
<div id="frame-side" class="yui3-u">
<div id="placehoder"></div>
<ul>
<li><a target="" href="/906368.html">研究成果</a></li><li><a target="" href="/faef50-1.html">學術交流</a></li><li><a target="_blank" href="http://hyxy.tust.edu.cn/shiyanshifan/1shoye.html">實踐教學</a></li><li><a target="" href="/ccac59.html">教學成果</a></li><li><a target="" href="/4d3baa-1.html">學生資助</a></li><li><a target="" href="/801d37-1.html">校友相聚</a></li><li><a target="" href="#">學術報告</a></li> </ul>
</div>
</div>
<div id="frame-main-link" class="yui3-g">
<div>
<div id="demo" style="overflow:hidden;height:110px;margin:0 auto;">
<table align="left" cellpadding="0" cellspace="0" border="0">
<tr>
<td id="demo1" valign="top">
<div>
<a style="width:0px;" href="/0c8a9f.html#ppzy" target="_blank"><img src="<?php bloginfo('template_url'); ?>/picture/57243dbb36ec49fe8ea8839a947fe310.jpg" /></a><img src="<?php bloginfo('template_url'); ?>/picture/869b86dfeae34a31b851fb01cec2b074.jpg" /><a style="width:0px;" href="http://hyhjbhjs.cl1.soochong.com" target="_blank"><img src="<?php bloginfo('template_url'); ?>/picture/2015-08-27-20-0606158108.jpg" /></a><img src="<?php bloginfo('template_url'); ?>/picture/39bfa2a5c9be4d87bb8c50a886d3f3c0.jpg" /></div>
</td>
<td id="demo2" valign="top"> </td>
</tr>
</table>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
修改后顯示成下圖所示,文章換成了 后臺上傳的文章。
新聞熱點
疑難解答
圖片精選