wordpress主题
1.創(chuàng)建wordpress主題:在themes文件下建立新主題black文件夾
2.在black文件夾中放入index.php和style.css文件,
其中index對(duì)style.css文件的引用
?<link rel="stylesheet"? href="<?php bloginfo('stylesheet_url');?>"? type="text/css" media="screen" >
?
<!-- 博客地址 -->
<?php bloginfo('url'); ?>
<!-- 博客名字 -->
<?php bloginfo('name'); ?>
<!-- css地址 -->
<?php bloginfo('stylesheet_url');?> 網(wǎng)站描述?<?php bloginfo('description');?>
網(wǎng)站關(guān)鍵字?<?php bloginfo('keywords');?>
網(wǎng)站標(biāo)題在頭<?php wp_header();?>中已經(jīng)包含,其實(shí)不用單獨(dú)提出
網(wǎng)站各類文件地址的引用,如js文件的引用,不過一般通過在functions.php中添加后,再通過<?php wp_footer();?>調(diào)用
- home_url() 首頁(yè)URL http://www.example.com
- site_url() 網(wǎng)站目錄URL http://www.example.com? 或 http://www.example.com/wordpress
- admin_url() 管理目錄URL http://www.example.com/wp-admin
- includes_url() 包含目錄URL http://www.example.com/wp-includes
- content_url()? 文章目錄URL http://www.example.com/wp-content
- plugins_url() 插件目錄URL http://www.example.com/wp-content/plugins
- theme_url() 主題目錄URL http://www.example.com/wp-content/themes
- wp_upload_dir() 上傳目錄URL (返回一個(gè)數(shù)組) http://www.example.com/wp-content/uploads
?<?php bloginfo('template_url');?> 獲取主體文件位置
<?php bloginfo('stylesheet_url');?>獲取樣式表位置
以上兩條也可以通過function.php添加到header和footer中
?
?
?
主題必需頁(yè)面
- 404 error page,
- archive page (our hero today),
- image attachments page,
- index page (the main page),
- default?page template (for pages),
- search results page,
- single post and attachment pages.
?
sidebar
1)在functions.php中
// 顯示后臺(tái)菜單-小工具,并注冊(cè)sidebar if ( function_exists('register_sidebar') ) {register_sidebar(array('name' => 'rightBar','before_widget' => '<aside class="widget clearfix">','after_widget' => '</aside>','before_title' => '<h2>','after_title' => '</h2>',)); }
2)建立sidebar.php文件
<div><?php if ( ! dynamic_sidebar( 'rightBar' ) ) : ?><?php endif; ?> </div>
3)引用sidebar文件
//獲取sidebar文件內(nèi)容 <?php get_sidebar(); ?>//獲取sidebar-news文件內(nèi)容 <?php get_sidebar(‘news’); ?>
?
single.php
對(duì)于文章單頁(yè),文章框架代碼仍然需要放在一個(gè)循環(huán)中,只不過到了單頁(yè)面,只循環(huán)一次,所以while可以去掉。
<?php if ( have_posts() ) : the_post(); ?><?php the_title(); ?><?php the_excerpt(); ?><?php the_content(); ?> <?php endif; ?>
?
上一篇、下一篇
<?php $next_post=get_previous_post();$prev_post=get_next_post();?> //鏈接地址 <a href='<?php echo get_permalink( $prev_post );?>'> //鏈接標(biāo)題 <?php echo $prev_post->post_title;?></a>
?
Archive.php
文檔歸檔頁(yè)面的格式,archive.php位置:wp-content/themes/themename/archive.php;
后臺(tái)對(duì)應(yīng)欄目如下:
前端:archive.php文件即對(duì)應(yīng)每月內(nèi)容布局
?
Search.php
位置:wp-content/themes/themename/archive.php;
wordpress自帶的搜索包含文章和page,一般需要重新限制
/** *[只對(duì)指定的類型進(jìn)行搜索] *@param[type] $query [搜索的參數(shù)] */ function SearchFilter($query){ //僅搜索時(shí) if($query->is_search){ //設(shè)定指定的文章類型,這里僅搜索文章 $query->set('post_type','post'); //指定文章和自定義類型 $query->set('post_type', array('post','custom-post-type')); //排除指定的文章ID號(hào) $query-->set('post__not_in', array(10,11,20,105)); //搜索指定的類型 $query->set('cat','8,15'); //搜索條件.... } return $query; } add_filter('pre_get_posts','SearchFilter');
?
默認(rèn)每頁(yè)文章數(shù)
在后臺(tái)的"設(shè)置"->"閱讀"中設(shè)置
翻頁(yè)
?
圖片無法上傳
在.htaccess文件中添加以下代碼
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
轉(zhuǎn)載于:https://www.cnblogs.com/catcher625/p/wordpress.html
總結(jié)
以上是生活随笔為你收集整理的wordpress主题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 钢板多少钱啊?
- 下一篇: (1)Adapter适配器(ArrayA