自定义字段插件:Advanced CustomFields
自定义联系表单插件:Contact Form 7
自定义文章类型插件:Custom Post Type UI
发邮件插件:WP-MAIL-SMTP
自定义文章页面:single-fxd.php
内容模版: template-parts/content.php(content-fxd.php,content-zidingyi.php)
MobilePress 插件待测
MobilePress插件是一款自动识别访问设备的插件,它可以根据用户的设备来决定以什么样的主题来呈现内容,非常方便。
调用内容模版:
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content', 'single' ); ?>
//这里是指调用template-parts/content-single.php文件;
<?php endwhile; // End of the loop.
else: ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
自定义模块:module/fxd.php;
调用模块:include(locate_template('module/pagination.php'));
自定义页面page: page-fxd.php;
1、查看当前调用的文件
在wp-includes\template-loader.php文件中加入3行代码:
1 2 3 | if($_GET[tpl]=='die'){ die($template); } |

然后在地址中添加一个参数tpl=die就可以查看当前使用的文件;

wordpress模版结构图:

1.创建头文件header.php;
记得添加wp_head();
在</head>之前;
2.创建脚步文件footer.php;
记得添加wp_footer();
在</body>之前;
3.javascript文件的两种引入方式;
方式1:
<script src="<?php bloginfo('template_url');?>/js/jquery.js"></script>
(一般可行)
方式2:
wp_enqueue_script( 'init_js',get_bloginfo('template_url').'/js/init.js');
(更专业)
4.css文件的两种引入方式;
方式1:
<link rel="stylesheet" href="<?php bloginfo('template_url');?>/css/style-wide.css" />
(一般可行)
方式2:
wp_enqueue_style( 'init_style',get_bloginfo('template_url').'/css/mystyle.css');
(更专业)
5.通过get_header();和get_footer();包含头尾文件;
6.bloginfo('template_url');会输出模板地址的绝对路径
7.注意将所有的资源文件(图片,js文件,css文件)进行路径替换;(大家出现问题最多的就是这里!!!)
自定义循环查询
<?php
$args=array(
'post_type'=>'page',//查找出所有页面(多个结果集,复数)
'page_id'=>16//仅仅查询id号为16的页面,只有一个结果,单数
);
// 实例化wp_query
$the_query = new WP_Query( $args );
// 开始循环
if ( $the_query->have_posts() ) {//如果找到了结果,便输出以下内容
while ( $the_query->have_posts() ) {//再次判断是否有结果
$the_query->the_post();//不用问为什么,每次都要写这个;
//这里开始输出你想要的模板标签
?>
<div class="col col_1_3">
<div class="inner">
<h2><?php the_title();?></h2>
<p><?php the_content();?></p>
<a href="<?php the_permalink();?>" class="link-more">more details</a> </div>
</div>
<?php
}
} else {
// 如果没有找到任何结果,就输出这个
}
wp_reset_postdata();//不用问为什么,每次都记得写就好
?>
循环调用文章类型为post的文章,这里只输出了标题
<?php
$args = array('post_type'=>'post');
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
调用顺序:
定义查询范围(如post_type)再执行查询WP_Query($args); 再找到the_post(); 再调用它的 the_title(); the_content(); the_permalink(); 等等;
标签调用的格式为 the_tag()和 get_the_tag();
the_yourtag()会直接把标签内容输出到html上面;
get_the_yourtag()会把标签内容保存到一个变量中,以供稍后的使用;
常用的标签有:
<!--?php the_content(); ?--> 日志内容
<!--?php the_title(); ?--> 显示一篇日志或页面的标题
<!--?php the_permalink() ?--> 显示一篇日志或页面的永久链接/URL地址
<!--?php the_category(',') ?--> 显示一篇日志或页面的所属分类
<!--?php the_author(); ?--> 显示一篇日志或页面的作者
<!--?php the_ID(); ?--> 显示一篇日志或页面的ID
<!--?php edit_post_link(); ?--> 显示一篇日志或页面的编辑链接
<!--?php next_post_link('%link') ?--> 下一篇日志的URL地址
<!--?php previous_post_link('%link') ?--> 上一篇日志的URL地址
Wordpress 的默认循环
wordpress会根据【链接结构】来进行数据的查询,
和定自义循环不同,默认循环直接从while开始,不用定义查询参数
<?php
// single.php 一般文章页面
// Start the loop.
while ( have_posts() ) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
// Previous/next post navigation.
the_post_navigation( array(
'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentyfifteen' ) . '</span> ' .
'<span class="screen-reader-text">' . __( 'Next post:', 'twentyfifteen' ) . '</span> ' .
'<span class="post-title">%title</span>',
'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentyfifteen' ) . '</span> ' .
'<span class="screen-reader-text">' . __( 'Previous post:', 'twentyfifteen' ) . '</span> ' .
'<span class="post-title">%title</span>',
) );
// End the loop.
endwhile;
?>
<?php
// Start the loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
// End the loop.
endwhile;
?>
新建页面的2种方法:
自定义page文件命名的方式为:page-id.php page-feng.php
默认page文件为:page.php
方法1.创建一个新的模板文件
<?php
/*
*Template Name : New Template
*/
//And start to write your code here...
//然后这里写你的循环程序
....
...
.
?>
【方法2.创建page-$id.php文件】
这样的文件,因为是通过id直接定位对应的页面(page)模板,所以方法1中的代码可以省略不写。
这样的文件,因为是通过id直接定位对应的页面(page)模板,所以方法1中的代码可以省略不写。
没有评论:
发表评论