wordpress不同分类设置不同模板
wordpress不同分类设置不同模板wordpress默认的通用模板是archive.php模板,那么如何根据不同分类设置不同模板呢?简单介绍一下实现代码! 具体实现代码如下:把原来的archive.php通用模板复制到category-other.php,把下面内容添加到archive.php模板中,再根据需求新建其它模板。 具体代码12345678910111213<?phpif (is_category(array(1,2,3))){ //分类id=1,2,3调用category-123模板 include(TEMPLATEPATH . '/category-123.php');}elseif (is_category(array(4,5,6))){ //分类id=4,5,6调用category-456模板 include(TEMPLATEPATH . '/category-456.php');}else{ //其它分类调用category-other inclu...
wordpress 获取上一篇下一篇文章的标题和链接
一般我们添加上一篇和下一篇文章时的代码是这样子的:123<?php previous_post_link('%link','%title',true) ?><?php next_post_link('%link','%title',true) ?> 该代码最终解析出来的代码大概如下:123<a href="……" rel="external nofollow" rel="external nofollow" > …… </a><a href="……" rel="external nofollow" rel="external nofollow" > …… </a> 这样子的结构是非常简单,如果我要增加 title、target 等属性值时,单靠上面两个函数是办不到的。 其实要解决这个问题很简单,不知道大家有没有...
WordPress调用按浏览量排序的热门文章,带排序,带class修饰
背景介绍123456789101112添加序号计数器为前三名添加特殊class移除浏览量显示添加target=”_blank”属性保持原有查询逻辑不变修改后的完整代码如下: 具体代码123456789101112131415161718192021222324<ul> <?php $args = array( 'meta_key' => 'views', 'orderby' => 'meta_value_num', 'posts_per_page' => 8, // 显示8篇文章 'order' => 'DESC' ); query_posts($args); $count = 0; // 初始化计数器 while (have_posts()) : the_post(); $count++;...
wordpress主题,文章模板调用当前文章页所属的分类名以及链接
方法1:调用第一个分类(常用)12345678910<?php $categories = get_the_category(); if ( ! empty( $categories ) ) { $first_category = $categories[0]; // 获取第一个分类 $category_name = esc_html( $first_category->name ); $category_link = esc_url( get_category_link( $first_category->term_id ) ); echo '<a href="' . $category_link . '">' . $category_name . '</a>';}?> 方法2:调用所有分类(逗号分隔)1234567891011<?php $categories = g...
wordpress和zblog搜索功能差异
这个是zblog的搜索功能代码1234<form name="search" method="get" action="<?php bloginfo('url'); ?>/"> <input class="br" type="text" name="q" placeholder="搜索..." /> </form> 这个是WordPress搜索功能代码1234<form name="search" method="get" action="<?php bloginfo('url'); ?>/"> <input class="br" type="text" name="s" placeholder=&...
wordpress主题首页index.php模板中,调用全站文章函数代码
具体代码函数12345678910111213141516171819<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="entry-content"> <?php the_excerpt(); ?> </div> </article> ...
wordpress使用the_tags()函数
具体代码函数12345678910111213141516171819202122232425262728<div class="post-meta"> <!-- 其他元信息 --> <div class="post-date">发布于: <?php the_date(); ?></div> <div class="post-categories">分类: <?php the_category(', '); ?></div> <!-- 标签区域 --> <div class="post-tags-wrapper"> <h4>相关标签</h4> <div class="tags-cloud"> <?php ...
自定义Wordpress分页导航-智能省略与active状态优化
具体代码函数123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990<?phpfunction custom_pagination() { global $wp_query; $total_pages = $wp_query->max_num_pages; if ($total_pages <= 1) return; $current_page = max(1, get_query_var('paged')); $pagination = '<div class="pagination">'; // 上一页链接 if ($current_pa...
wordpress调用文章内的三个tag标签
在WordPress中获取文章的前三个标签,你可以在循环中使用以下代码:方法一:使用 get_the_tags() 函数1234567891011121314151617181920212223242526272829<?php if (have_posts()) : while (have_posts()) : the_post(); ?> <article> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="post-content"> <?php the_excerpt(); ?> </div> <div class="post-tags"> ...
wordpress免插件显示文章浏览量次数,WordPress热门文章调用
首先在网站后台的wordpress模板函数functions.php文件中加入以下的代码:12345678910111213141516171819202122/*显示文章浏览次数*/function getPostViews($postID){$count = get_post_meta($postID,'views', true);if($count==''){delete_post_meta($postID,'views');add_post_meta($postID,'views', '0');return "0";}return $count.'';}function setPostViews($postID) {$count = get_post_meta($postID,'views', true);if($count==''){...