• WP主题制作常用标签代码


    WordPress模板结构

    style.css : CSS文件
    index.php : 主页模板
    archive.php : Archive/Category模板
    404.php : Not Found 错误页模板
    comments.php : 留言/回复模板
    footer.php : Footer模板
    header.php : Header模板
    sidebar.php : 侧栏模板
    page.php : 内容页(Page)模板
    single.php : 内容页(Post)模板
    searchform.php : 搜索表单模板
    search.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页是否以多页显示
    -----------------------------------------------------------------------------------
    style.css头部主题注释文字

    1 /*
    2 Theme Name: 1990c
    3 Theme URI: http://www.1990c.com
    4 Author: Lin Yunpeng
    5 Author URI: http://www.1990c.com
    6 Description: Lin Yunpeng's theme
    7 Version: 1.0
    8 Tags: white,simple
    9 */

    -----------------------------------------------------------------------------------
    header.php常用标签

    1 <pre>style.css路径<?php bloginfo( 'stylesheet_url' ); ?>
    2 主题文件夹路径<?php bloginfo('template_directory'); ?>
    3 主页路径<?php echo get_option('home'); ?>
    4 wordpress编码<?php bloginfo( 'charset' ); ?>

     

    01 /*网站标题:
    02 文章页显示“文章标题 - 博客标题”
    03 分类页显示“分类标题 - 博客标题”
    04 其余全显示为“博客标题 - 副标题”*/
    05 <?php
    06 if (is_single())
    07 {the_title();print " - ";bloginfo('name'); }
    08 else if(is_category())
    09 {single_cat_title();print " - ";bloginfo('name'); }
    10 else
    11 { bloginfo('name');print " - ";bloginfo('description'); }
    12 ?>

     

    01 //自定义css的导航调用方法
    02 <?php
    03 $args=array(
    04 'orderby' => 'id',
    05 'order' => 'ASC'
    06 );
    07 $categories=get_categories($args);
    08 foreach($categories as $category) {
    09 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>';
    10 }
    11 ?>

    -----------------------------------------------------------------------------------

    sidebar.php常用标签

    1 //最新文章
    2 <?php $rand_posts = get_posts('numberposts=9&orderby=date');foreach($rand_posts as$post) : ?>
    3 <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    4 <?php endforeach;?>

     

    1 // 随机文章
    2 <?php $rand_posts = get_posts('numberposts=9&orderby=rand');foreach($rand_posts as$post) : ?>
    3 <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    4 <?php endforeach;?>

    -----------------------------------------------------------------------------------

    index.php常用标签

    1 调用head.php<?php get_header();?>
    2 调用footer.php<?php get_footer();?>
    3 调用sidebar.php<?php get_sidebar();?>
    4 调用其它文件<?php include(TEMPLATEPATH . '/文件名'); ?>
    5 显示注册链接<?php wp_register(); ?>
    6 显示登录/注销链接<?php wp_loginout(); ?>

     

    01 //首页文章调用
    02 <?php if(have_posts()) : ?>/*检查是否存在Post/Page*/
    03 <?php while(have_posts()) : the_post(); ?>/*如果存在Post/Page则予以显示 */
    04 <?php the_title(); ?>/*文章标题*/
    05 <?php the_time('Y.m.d h:i') ?>/*发表时间*/
    06 <?php the_category(' '); ?>/*文章分类*/
    07 <?php comments_popup_link('0', '1', '%', ”, 'CLOSE'); ?>/*评论数*/
    08 <?php edit_post_link('EDIT'); ?>/*显示编辑链接*/
    09 <?php the_content(''); ?>/*正文内容*/
    10 <?php endwhile; ?>/*While结束*/
    11 <?php endif; ?>/*If结束*/

    -----------------------------------------------------------------------------------

    single.php常用标签

    1 上一篇<?php previous_post_link('%link'); ?>
    2 下一篇<?php next_post_link('%link'); ?>
    3 评论调用<?php comments_template(); ?>
    4 日历调用<?php get_calendar(); ?>
  • 相关阅读:
    Qt画笔实现折线图
    Qt动态布局
    ffmpeg录制流媒体,正常方式停止录制
    解决libvlc_media_player_stop时死锁的方法
    Ubuntu 16 修改时区!
    qt窗口最小化之后无法打开
    Qt 之 去除窗口部件被选中后的焦点虚线框
    WINDOWS中, 如何查看一个运行中的程序是64位还是32位的
    DHTMLX学习总结
    mui plus.uploader.createUpload 上传文件服务端获取文件名中文乱码问题
  • 原文地址:https://www.cnblogs.com/wangblognet/p/3425959.html
Copyright © 2020-2023  润新知