个人制作或修改wordpress程序模板常使用的标签

wordpress是一款非常好用的网站程序,很多博客都是使用的wordpress程序,包括追梦笔记也是一样的。我们在使用过程中往往会用到wordpress模板标签,像调用最新文章、随机文章、网站的标题、关键词等。如果每次都请人修改模板标签,那么建站的成本就会越来越高了,最重要的有时让别人修改还要等别人有时间的时候。我自己去网站找了一些个人制作或修改wordpress程序模板常使用的标签,操作起来非常简单,大家只要复制粘贴就可使用了。wordpress模板的基本结构

style.css 样式表文件index.php 主页文件single.php 日志单页文件page.php 页面文件archvie.php 分类和日期存档页文件searchform.php 搜索表单文件search.php 搜索页面文件comments.php 留言区域文件(包括留言列表和留言框)404.php 404错误页面header.php 网页头部文件sidebar.php 网页侧边栏文件footer.php 网页底部文件

WordPress Header头部 PHP代码

<?php bloginfo(‘name’); ?> 网站标题<?php wp_title(); ?> 日志或页面标题<?php bloginfo(‘stylesheet_url’); ?> WordPress主题样式表文件style.css的相对地址<?php bloginfo(‘pingback_url’); ?> WordPress博客的Pingback地址<?php bloginfo(‘template_url’); ?> WordPress主题文件的相对地址<?php bloginfo(‘version’); ?> 博客的Wordpress版本<?php bloginfo(‘atom_url’); ?> WordPress博客的Atom地址<?php bloginfo(‘rss2_url’); ?> WordPress博客的RSS2地址<?php bloginfo(‘url’); ?> WordPress博客的绝对地址<?php bloginfo(‘name’); ?> WordPress博客的名称<?php bloginfo(‘html_type’); ?> 网站的HTML版本<?php bloginfo(‘charset’); ?> 网站的字符编码格式

WordPress 主体模板 PHP代码

<?php the_content(); ?> 日志内容<?php if(have_posts()) : ?> 确认是否有日志<?php while(have_posts()) : the_post(); ?> 如果有,则显示全部日志<?php endwhile; ?> 结束PHP函数”while”<?php endif; ?> 结束PHP函数”if”<?php get_header(); ?> header.php文件的内容<?php get_sidebar(); ?> sidebar.php文件的内容<?php get_footer(); ?> footer.php文件的内容<?php the_time(‘m-d-y’) ?> 显示格式为”02-19-08″的日期<?php comments_popup_link(); ?> 显示一篇日志的留言链接<?php the_title(); ?> 显示一篇日志或页面的标题<?php the_permalink() ?> 显示一篇日志或页面的永久链接/URL地址<?php the_category(‘, ‘) ?> 显示一篇日志或页面的所属分类<?php the_author(); ?> 显示一篇日志或页面的作者<?php the_ID(); ?> 显示一篇日志或页面的ID<?php edit_post_link(); ?> 显示一篇日志或页面的链接<?php get_links_list(); ?> 显示Blogroll中的链接<?php comments_template(); ?> comments.php文件的内容<?php wp_list_pages(); ?> 显示一份博客的页面列表<?php wp_list_cats(); ?> 显示一份博客的分类列表<?php next_post_link(‘ %link ‘) ?> 下一篇日志的URL地址<?php previous_post_link(‘%link’) ?> 上一篇日志的URL地址<?php get_calendar(); ?> 调用日历<?php wp_get_archives() ?> 显示一份博客的日期存档列表<?php posts_nav_link(); ?> 显示较新日志链接(上一页)和较旧日志链接(下一页)<?php bloginfo(‘description’); ?> 显示博客的描述信息

其它的一些Wordpress模板代码

/%postname%/ 显示博客的自定义永久链接<?php the_search_query(); ?> 搜索表单的值<?php _e(‘Message’); ?> 打印输出信息<?php wp_register(); ?> 显示注册链接<?php wp_loginout(); ?> 显示登入/登出链接<!–next page–> 在日志或页面中插入分页<!–more–> 截断日志<?php wp_meta(); ?> 显示管理员的相关控制信息<?php timer_stop(1); ?> 显示载入页面的时间<?php echo get_num_queries(); ?> 显示载入页面查询

wordpress调用最新文章

<?php get_archives(‘postbypost’, 10); ?> (显示10篇最新更新文章)
或者<?php wp_get_archives(‘type=postbypost&limit=20&format=custom’); ?>

wordpress调用随机文章

<?php$rand_posts = get_posts(‘numberposts=10&orderby=rand’);foreach( $rand_posts as $post ) :?>

wordpress调用最新留言

<?phpglobal $wpdb;$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID,comment_post_ID, comment_author, comment_date_gmt, comment_approved,comment_type,comment_author_url,SUBSTRING(comment_content,1,30) AS com_excerptFROM $wpdb->commentsLEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =$wpdb->posts.ID)WHERE comment_approved = ’1′ AND comment_type = ” ANDpost_password = ”ORDER BY comment_date_gmt DESCLIMIT 10″;$comments = $wpdb->get_results($sql);$output = $pre_HTML; foreach ($comments as $comment) {$output .= “n<li>”.strip_tags($comment->comment_author).”:” . ” <a href=”” . get_permalink($comment->ID) .“#comment-” . $comment->comment_ID . “” title=”on ” .$comment->post_title . “”>” . strip_tags($comment->com_excerpt).”</a></li>”;} $output .= $post_HTML;echo $output;?>

wordpress调用相关文章

<?php$tags = wp_get_post_tags($post->ID);if ($tags) {$first_tag = $tags[0]->term_id;$args=array(‘tag__in’ => array($first_tag),‘post__not_in’ => array($post->ID),‘showposts’=>10,‘caller_get_posts’=>1);$my_query = new WP_Query($args);if( $my_query->have_posts() ) {while ($my_query->have_posts()) : $my_query->the_post(); ?><li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title();?> <?php comments_number(‘ ‘,’(1)’,’(%)’); ?></a></li><?phpendwhile;}}wp_reset_query();?>

wordpress调用指定分类的文章

<?php $posts = get_posts( “category=4&numberposts=10″ ); ?><?php if( $posts ) : ?><ul><?php foreach( $posts as $post ) : setup_postdata( $post ); ?><li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li><?php endforeach; ?></ul><?php endif; ?>

wordpress调用discuz论坛文章

<?php//截取utf8字符串function utf8Substring($str, $from, $len){return preg_replace(‘#^(?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,’.$from.’}’.'((?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,’.$len.’}).*#s’,’$1′,$str);}//建立数据库链接$conn = @mysql_connect(“这里修改成要调用的服务器地址默认为localhost”, “这里修改成数据库用户名”, “这里修改成数据库地址”) or die(“数据库链接错误”);//指定要链接的数据库@mysql_select_db(“这里修改成数据库名”, $conn);//使用UTF-8中文编码;@mysql_query(“set names ‘UTF8′”);//指定版块的所有文章中取10条最新帖子$SQL=”SELECT tid,subject FROM pre_forum_thread where fid in (2,42)ORDER BY tid DESC LIMIT 0,10″;$query=@mysql_query($SQL);//循环显示结果while($row=@mysql_fetch_array($query)){echo “<li><a class=title title=”.$row[subject].” href=’http://www.zhuimeng8.com/bbs/thread-“.$row[tid].”-1-1.html’ target=_blank>”.utf8Substring($row[subject], 0, 40).”</a></li>”;}//关闭链接@mysql_close($conn);?>

如果不是自己单独去制作wordpress模板,其实很多方面都是不用使用的。另外这里主要是纯代码形式的模版标签,大家也可以通过下载wordpress插件实现相应的功能。

(0)
摩榜哥摩榜哥

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注