基于wordpress主题制作的具体实现步骤


当前第2页 返回上一页

制作index.php 文章列表
例子
*/
?>
<div class="grid_8">
    <!-- Blog Post -->
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post">
        <!-- Post Title -->
        <h3 class="title"><a rel="bookmark"><?php the_title(); ?></a></h3>
        <!-- Post Data -->
        <p class="sub"><?php the_tags('标签:', ', ', ''); ?> &bull; <?php the_time('Y年n月j日') ?> &bull; <?php comments_popup_link('0 条评论', '1 条评论', '% 条评论', '', '评论已关闭'); ?><?php edit_post_link('编辑', ' &bull; ', ''); ?></p>
        <div class="hr dotted clearfix">&nbsp;</div>
        <!-- Post Image -->
        <img class="thumb" alt="" src="<?php bloginfo('template_url'); ?>/images/610x150.gif" />
        <!-- Post Content -->
        <?php //the_excerpt(); ?>
        <?php the_content('阅读全文...'); ?>
        <!-- Read More Button -->
        <p class="clearfix"><a class="button right">阅读全文</a></p>
    </div>
    <div class="hr clearfix">&nbsp;</div>
    <?php endwhile; ?>

    <!-- Blog Navigation -->
    <p class="clearfix"><?php previous_posts_link('&lt;&lt; 查看新文章', 0); ?> <span class="float right"><?php next_posts_link('查看旧文章 &gt;&gt;', 0); ?></span></p>
    <?php else : ?>
    <h3 class="title"><a rel="bookmark">未找到</a></h3>
    <p>没有找到任何文章!</p>
    <?php endif; ?>
</div>
<?php
/*
have_posts();       判断是否有下一个文章
the_post();         改变当前文章指向到下一个文章

the_permalink();    当前指向文章的连接地址
the_title();        当前指向文章的标题
the_tags('标签:');  当前指向文章的标签
comments_popup_link('0 条评论', '1 条评论', '% 条评论', '', '评论已关闭');    显示打印当前指向文章的评论链接
edit_post_link('编辑', ' &bull; ', '');    当前指向文章,显示打印当前指向文章的编辑链接
the_excerpt();                 当前指向文章,只要在写文章的时候在"摘要"框内填写摘要,在首页显示的就是摘要,如果不填就输出全文!
the_content('阅读全文...');    用于输出当前指向文章全文,除非在文章中使用了<!-- more -->
the_permalink();              返回当前指向文章阅读全文的连接地址
previous_posts_link('&lt;&lt; 查看新文章', 0); 显示打印当前显示列表分页连接(每页文章数量取决于在后台设置每页可显示的文章数量)
next_posts_link('查看旧文章 &gt;&gt;', 0);      显示打印当前显示列表分页连接
the_time('Y年n月j日');显示日期如 1999年5月1日

另外,还有个存档页面的模板archive.php,跟index.php的制作过程完全一样,只不过需要在functions.php里添加一个函数

单文章页single.php,可以根据index.php页往这里添加自己想要显示的内容

page.php 也就是页面,博客上的所有网页都是页面,这里指的页面一个单独的页面,如"关于"、"联系方式"等,可以在WordPress后台 – 页面,进行页面的添加修改等。
可根据之前函数添加本页内容
*/
while (have_posts()) :
    the_post(); update_post_caches($posts);
endwhile;
/*
update_post_caches($posts);  该函数重置文章缓存且未被记录。仅在页面的第一次循环检索到文章子集时,第二次循环可执行基本循环。

常用函数
get_avatar($comment, 48);       获取评论者的gravatar头像,尺寸为48 * 48
comment_reply_link()                 回复留言的链接
get_comment_time('Y-m-d H:i');       获取评论发布时间
edit_comment_link('修改');           管理员修改评论的链接
comment_text()                       输出评论内容

is_user_logged_in()                  判断用户是否登录
wp_login_url( get_permalink() );     博客登录地址
get_comment_author_link()            用于获取评论者博客地址
$comment_author                      读取cookie,如果该用户之前已经发表过评论则自动帮助用户填写用户名
$comment_author_email                读取cookie,如果该用户之前已经发表过评论则自动帮助用户填写Email
$comment_author_url                  读取cookie,如果该用户之前已经发表过评论则自动帮助用户填写博客地址
do_action(‘comment_form', $post->ID) 该函数为某些插件预留
wp_logout_url(get_permalink())       退出登录的链接
*/

/*
创建模板文件
*/


/*
 Template Name: 自建模板
*/

/*
 模板文件中添加如上注释代码,模板文件名任意,在新建页面时模板选择即可显示 自建模板 来使用此模板
可添加想要的模板样式及页面内容,新建页面时只填标题不写内容,相当创建一个页面链接地址,新建页面存在 数据前缀_posts 表中
获取到页面地址后,在写地址时可在后添加参数,则转到该页时可通过$_GET,$_POST接收
可以单独建一个表存储地址,及所属页面类型,及各页面子父级关系,在插件中进行控制


wordpress固定链接
如果修改wordpress固定链接不好用,在apache配置文件 httpd.conf 中打开选项
#LoadModule rewrite_module modules/mod_rewrite.so
把前面 # 去掉,并把所有 AllowOverride None 改成 AllowOverride all
如果不是Apache服务器,而是用的IIS调试的话,那就得去安装一个“ISAPI_Rewrite3_0069_Lite.msi”筛选器,然后在站点设置里面将PHP置为优先级。

创建小工具
在主题目录下新建自定义文件 mytool.php 文件名任意,内容任意
然后在 functions.php 中添加如下代码
*/
register_sidebar_widget ( "我的小工具", "mytool_fun" ); // "我的小工具"为后台显示小工具名称,mytool_fun为引入自建小工具页面内容的方法名
function mytool_fun() {
    include (TEMPLATEPATH . "/mytool.php");
}
/*
在后台小工具中即可看到自定义的小工具,添加后,前台页面即可看到自建小工具页面的内容
*/
?>


标签:WordPress

返回前面的内容

相关阅读 >>

wordpress博客seo更加完美的6个技巧

用dreamweaver制作wordpress的留言本iii

wordpress 忘记密码的处理方法

wordpress选项标签功能

wysiwyg web builder 17激活教程 附汉化步骤

再谈php未来之路

禁用wordpress gravatar使用本地头像提高网页打开速度

linux docker安装wordpress的方法详解教程

详解wordpress中用于合成数组的wp_parse_args()函数

wordpress中使主题支持小工具以及添加插件启用函数

更多相关阅读请进入《wordpress》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...