wordpress调用指定分类文章如何实现
作者:admin 日期:2022-03-13
wordpress是很强大的cms系统,你可以通过相关函数就能实现相关的功能。很多网友会问wordpress怎么调用指定分类文章的呢?其实很简单,随ythah一起来看看吧,几行代码就解决了,代码如下
1
2
3
4
5
6
|
<ul>
<?php query_posts('cat=1&showposts=5'); //cat是要调用的分类ID,showposts是需要显示的文章数量 ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
|
是不是很方便?当然css样式可以自己定义
如果想从第二篇开始调用可以加一个参数&offset=1,第三篇开始调用就用&offset=2,以此类推
WordPress函数:wp_list_categories(分类列表)
作者:admin 日期:2022-03-13
wordpress调用当前分类的全部子分类
作者:admin 日期:2022-03-13
wordpress在制作企业主题的时候比较常遇到要调用当前分类下的全部子分类。要实现这个可以按照以下步骤操作。
首先在主题的“functions.php”里面写个函数,代码如下:
PHP代码
- // 获取子分类
- function get_category_root_id($cat){
- $this_category = get_category($cat);
- while($this_category->category_parent) {
- $this_category = get_category($this_category->category_parent);
- }
- return $this_category->term_id;
- }
然后在需要调用的页面里写以下代码:
PHP代码
- <?php
- if(is_category()) {
- $cat = get_query_var('cat');
- $categoryurl = get_category_link($cat);
- if(get_category_children(get_category_root_id(the_category_ID(false)))!= "" ) {
- echo wp_list_categories("child_of=".get_category_root_id(the_category_ID(false)). "&depth=0&hide_empty=0&title_li=&orderby=id&order=ASC");
- }
- }
- ?>
最后自己调整下css就ok了。
Wordpress数据恢复用到的一些代码
作者:admin 日期:2022-01-06
接前一篇文章:mysql根据.frm和.ibd文件恢复表结构和数据
数据库只要.ibd文件完整就可以恢复数据,.frm文件不需要。
数据库建表:
--
-- 表的结构 `wp_commentmeta`
--
Wordpress安装在windows下web.config伪静态规则
作者:admin 日期:2021-11-20
<rewrite>
<rules>
<rule name="WordPress: http://www.tyzqwl.com/blog" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule></rules>
</rewrite>
wordpress内容分页代码
作者:admin 日期:2021-09-27
Wordpress - IIS伪静态规则
作者:admin 日期:2017-03-10
这是适用于IIS7及以上的Wordpress的伪静态规则,保存成web.config文件,放到网站根目录即可。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
广告位