大闹前端Web前端之路程序员

WordPress快速建站

2017-01-23  本文已影响74人  Iris_mao
简单介绍:

WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。也可以把 WordPress当作一个内容管理系统(CMS)来使用。
WordPress是一款个人博客系统,并逐步演化成一款内容管理系统软件,它是使用PHP语言和MySQL数据库开发的。用户可以在支持 PHP 和 MySQL数据库的服务器上使用自己的博客。
WordPress有许多第三方开发的免费模板,安装方式简单易用。不过要做一个自己的模板,则需要你有一定的专业知识。比如你至少要懂的标准通用标记语言下的一个应用HTML代码、CSS、PHP等相关知识。

步骤:

/*
Theme Name: 自定义
Theme URI: http://www..com
Description: 自定义
Author: 自定义
Author URI: http://www.
.com
Version: 1.0
Tags: ***
*/
```
Style.css路径调用:<?php bloginfo( 'stylesheet_url' ); ?>
主题文件夹路径:<?php bloginfo('template_directory'); ?>

<?php get_header();?>
<?php get_footer();?>
<?php get_sidebar();?>

获取主页路径:<?php echo get_option('home'); ?>
Header.php中用到的标签:

<meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( 'charset' ); ?>" />
<title><?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' | '; } ?> <?php bloginfo('name'); ?></title>    
<?php wp_head(); ?>

自定义的导航调用方法:(分类栏目中的项目)

  <?php
$args=array(
  'orderby' => 'id',
  'order' => 'ASC'
  );
$categories=get_categories($args);
  foreach($categories as $category) { 
    echo '<li class="thisclass"><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></li>';
    } 
?>
<?php $display_categories = array(1,3,4,130,6,7,8,5); 
        foreach ($display_categories as $category) { ?>
<div class="P_category">
<?php query_posts("showposts=8&cat=$category")?>
<h2 class="P_c_one"><a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?></a></h2>
    <ul class="p_news">
<?php while (have_posts()) : the_post(); ?>
    <li>· <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo mb_strimwidth(get_the_title(), 0, 40, '…'); ?>
</a> </li>
<?php endwhile; ?>
    </ul>
    </div>
<?php } wp_reset_query();?>

}

在header定义菜单的部分加上即可

<?php
if (function_exists('wp_nav_menu')) {
wp_nav_menu(array(
'theme_location' => 'primary',
'menu_id' => 'nav',
'container' => 'ul',
));
}
?>

![菜单编辑界面.png](http:https://img.haomeiwen.com/i3810529/938b306e596f3620.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 经过以上步骤基本就能搭建一个简单的cms页面了,更多的可以到https://www.wpdaxue.com/进行学习
上一篇下一篇

猜你喜欢

热点阅读