wordpress怎么制作模板(wordpress企业站主题仿站函数和方法)

wordpress企业站主题仿站函数和方法

1、企业静态页面制作成wordpress主题
2、制作header.php,footer.php和sidebar
3、首页图片调用和文章列表显示和友情链接
4、新闻列表页面的制作和分页
5、产品展示页面的制作和分页
6、制作详细内容页面single.php
7、制作独立页面page.php

1、企业静态页面制作成wordpress主题

企业主题和博客主题的区别

1、首页显示内容不一样

2、产品为主,图片丰富,更加的细分

3、在制作上和博客主题的区别,category.php

制作一个最简单的主题,只需要两个文件,index.php和style.css

第一步,准备静态页面

第二步,制作index.php和style.css

第三步,给style.css添加版权信息

第四步:把主题上传到空间中wordpress安装路径,wp-content/themes/下面,这里主题的文件夹名字必须是英文

第五步,在wordpress后台启用主题

先给style.css添加版权信息

/*Theme Name: wordpress theme 01Theme URI: https://www.80snake.com/Description: a company themeAuthor: xixiAuthor URI: https://www.80snake.com/Version: 1.0Tags: white, company, liweihui, blue,products,news*/

Style.css路径调用:<?php bloginfo( ‘stylesheet_url’ ); ?>

主题所在路径调用:<?phpbloginfo(‘stylesheet_directory’); ?>

第六步,把index.php拆分成header.php,footer.php和sidebar.php

需要用到的调用标签:

<?phpget_header();?>

<?phpget_footer();?>

<?phpget_sidebar();?>

2、制作header.php,footer.php和sidebar

1、Header.php和footer.php用到代码:

<metahttp-equiv=”Content-Type” content=”text/html; charset=<?phpbloginfo( ‘charset’ ); ?>” />

<?phpwp_head(); ?>

<title><?phpif (is_home()||is_search()) { bloginfo(‘name’); } else { wp_title(”); print” – “; bloginfo(‘name’); } ?> </title>

Footer.php版权信息:

© Copyright (c)

获取博客名字:<?phpbloginfo(‘name’); ?>

获取博客描述:<?phpbloginfo(‘description’); ?>

获取主页路径:<?phpecho get_option(‘home’); ?>

页面调用:

<?phpwp_list_pages(‘sort_column=menu_order&title_li=&depth=2&include=’);?>

分类目录调用:

<?phpwp_list_categories(‘title_li=0&orderby=name&show_count=0&depth=2’);?>

含有css的调用方法:

分类调用:

<?php

$args=array(

‘orderby’ => ‘name’,

‘order’ => ‘ASC’,

‘include’ => ‘10,1,11,5,19,20’

);

$categories=get_categories($args);

foreach($categories as $category) {

echo ‘

<td width=”15%”align=”center” valign=”middle” fontcolor=”#FF0000″ ><a href=”‘ . get_category_link($category->term_id ) . ‘” title=”‘ . sprintf( __( “View allposts in %s” ), $category->name ) . ‘” ‘ . ‘>’ .$category->name.'</a></td> ‘;

}

?>

页面调用:

<?php

$args=array(

‘orderby’ => ‘name’,

‘order’ => ‘ASC’,

‘include’ => ‘231,237’

);

$pages = get_pages($args);

foreach ($pages as $pagg) {

echo ‘<li><a class=”nava” href=”‘ .get_page_link($pagg->ID). ‘” title=”‘ . sprintf( __( “Viewall posts in %s” ), $pagg->post_title ) . ‘” ‘ . ‘>’ .$pagg->post_title.'</a></li>’;

}

?>

2、sidebar.php用到代码:

产品分类调用代码:修改child_of=

<?phpwp_list_cats(‘sort_column=name&optioncount=1&hierarchical=1&hide_empty=0&child_of=10’);?>

新闻分类代码调用:修改child_of=

<?phpwp_list_cats(‘sort_column=name&optioncount=1&hierarchical=1&hide_empty=0&child_of=10’);?>

部分页面导航调用:修改include=中的id为你想要显示的id

<?phpwp_list_pages(‘sort_column=menu_order&title_li=&depth=2&include=’);?>

3、首页图片调用和文章列表显示和友情链接

这里需要用到缩略图插件wp-thumbnails

1、首页图片展示代码:

<?php if (have_posts()) : ?>

<?php query_posts(‘cat=3’ . $mcatID.‘&caller_get_posts=1&showposts=6’); ?>

<?php while (have_posts()) : the_post();?>

<li>

<?phpif(function_exists(‘wp_thumbnails_for_homepage’)) {wp_thumbnails_for_homepage(); } ?>

<br /><p><ahref=”<?php the_permalink() ?>”><?php the_title(); ?></a></p>

</li>

<?php endwhile;?>

<?php else : ?>

<?php endif; ?>

2、调用一个类别下面的文章:

<?php if (have_posts()) : ?>

<?phpquery_posts(‘cat=1&showposts=20’); ?>

<?php while (have_posts()) : the_post();?>

<ul>

<li><a href=”<?phpthe_permalink() ?>” rel=”bookmark” title=”Permanent Linkto <?php the_title_attribute(); ?>”><?php the_title();?></a></li>

</ul>

<?php endwhile; ?>

<?php else : ?>

<?php endif; ?>

首页友情链接:

<?phpwp_list_bookmarks(‘title_li=&categorize=0&orderby=rand&limit=24’);?>

4、新闻列表页面的制作和分页

新建页面category-*.php,*号为wordpress后台建立的相应的分类id号

1、显示列表:

<?php if ($posts_perpage) { ?>

<?php$postsperpage = $posts_perpage; ?>

<?php } else { ?>

<?php $postsperpage= 10; ?>

<?php } ?>

<?php

$categoryID=$cat;

$wp_query= new WP_Query(‘cat=’ . $categoryID.‘orderby=date&order=desc&posts_per_page=’.$postsperpage.’&paged=’.$paged);?>

<?phpwhile (have_posts()) : the_post(); ?>

<ul>

<li><span><?phpthe_date_xml(); ?></span><span></span><ahref=”<?php the_permalink() ?>” rel=”bookmark”title=”Permanent Link to <?php the_title_attribute();?>”><?php the_title(); ?></a></li>

</ul>

<?php endwhile; ?>

2、显示分页

调用方式: <?php pagenav($query_string); ?>

在functions.php中添加:

//pagenav

function pagenav($query_string){

global $posts_per_page, $paged;

$my_query = new WP_Query($query_string.”&posts_per_page=-1″);

$total_posts = $my_query->post_count;

if(empty($paged))$paged = 1;

$prev = $paged – 1;

$next = $paged + 1;

$range = 4; // only edit this if you wantto show more page-links

$showitems = ($range * 2)+1;

$pages =ceil($total_posts/$posts_per_page);

if(1 != $pages){

echo “<divclass=’pagination’>”;

echo ($paged > 2 &&$paged+$range+1 > $pages && $showitems < $pages)? “<a href='”.get_pagenum_link(1).”‘>最前</a>”:””;

echo ($paged > 1 && $showitems< $pages)? “<a href='”.get_pagenum_link($prev).”‘>上一页</a>”:””;

for ($i=1; $i <= $pages; $i++){

if (1 != $pages &&( !($i >=$paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){

echo ($paged == $i)? “<spanclass=’current’>”.$i.”</span>”:”<ahref='”.get_pagenum_link($i).”‘ class=’inactive’>”.$i.”</a>”;

}

}

echo ($paged < $pages &&$showitems < $pages) ? “<ahref='”.get_pagenum_link($next).”‘>下一页</a>” :””;

echo ($paged < $pages-1 &&$paged+$range-1 < $pages && $showitems < $pages) ? “<ahref='”.get_pagenum_link($pages).”‘>最后</a>”:””;

echo “</div>\n”;

}

}

在sytle.css下面添加

/*分页的样式 */

.pagination{ margin:0 10px 10px15px;line-height:23px;text-align:center;}

.pagination span, .paginationa{font-size:12px;margin: 2px 6px 2px 0;background:#fff;border:1px solid#ccc;color:#787878;padding:2px 5px 2px 5px;text-decoration:none;}

.pagination a:hover{background:#8cb900;border:1px solid #436206;color:#fff;font-size:12px;padding:2px 5px 2px5px;}

.pagination .current{background:#8cb900;border:1px solid #436206;color:#fff;font-size:12px;padding:2px 5px 2px5px;}

5、产品展示页面的制作和分页

新建页面category-*.php,*号为wordpress后台建立的相应的分类id号

图片调用:

<?php if ($posts_perpage) { ?>

<?php$postsperpage = $posts_perpage; ?>

<?php } else { ?>

<?php $postsperpage= 9; ?>

<?php } ?>

<?php

$categoryID=$cat;

$wp_query= new WP_Query(‘cat=’ . $categoryID. ‘orderby=date&order=desc&posts_per_page=’.$postsperpage.’&paged=’.$paged);?>

<ul>

<?php while (have_posts()) : the_post(); ?>

<li>

<?phpif(function_exists(‘wp_thumbnails_for_homepage’)) {wp_thumbnails_for_homepage(); } ?>

<br/><p><a href=”<?php the_permalink() ?>” ><?php the_title();?></a></p>

</li>

<?php endwhile;?>

</ul>

6、制作详细内容页面single.php

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post();?>

<?php endwhile; ?>

<?php else : ?>

<?php endif; ?>

标题调用:<ahref=”<?php the_permalink() ?>”><?phpthe_title_attribute(); ?></a>

时间调用:<?phpthe_time(‘F d, Y’) ?>

作者::<?php the_author_posts_link();?>

标签:<?phpthe_category(‘, ‘) ?>

内容:<?phpthe_content(“Read More…”); ?>

文章导航,上一篇,下一篇

<divstyle=”float:left”><?php previous_post_link(‘&laquo;%link’); ?></div>

<divstyle=”float:right”><?php next_post_link(‘%link &raquo;’);?></div>

7、制作独立页面page.php

复制single.php,删除文章导航,上一篇,下一篇代码。