Products
GG网络技术分享 2025-03-18 16:13 0
这篇将比较简单,讲解如何调用存档链接列表和友情链接(blogroll)列表。
在侧边栏区域的 Categories 列表下面输入以下代码:
<li><h2><?php _e(’Archives’); ?></h2>
<ul>
<?php wp_get_archives(’type=monthly’); ?>
</ul>
</li>
复制之后检查下代码是否和下面一样:
保存并刷新浏览器。结果如下所示:
发生什么了?
我们使用了 wp_get_arhives() 这个 PHP 函数,并用了 type 这个参数以及 monthly作为它的值,这样就按月调用存档链接列表。
在存档链接列表下输入以下代码:
<?php get_links_list(); ?>
保存并刷新,结果如下:
默认情况下,我的 blogroll 和你想的是没有什么不同,这里是它在源代码中的样子:
上面的代码完全没有正确地被缩进,因为它们是由函数组成 get_links_list() 产生的,就像上一篇所学的函数一样 wp_list_pages() 产生的代码一样,但是它遵循规则 #1,按正确顺序关闭所有的东西。我已经圈出了元素和无序列表的标签让你看得更明显。
在 wordpress主题制作开发 中经常会需要在特定的页面中调用出指定的文章或文章列表,接下来教大家如何调用出 wordpress文章列表 。
调用网站最新文章:
代码如下:
<?php query_posts(\'showposts=10&orderby=new\'); //showposts=10表示10篇 while(have_posts()): the_post(); ?> <li><a href=\"<?php the_permalink(); ?>\"target=\"_blank\"><?php the_title() ?></a></li> //这里可以写成你自己需要的样式 <?php endwhile; ?> |
调用随机文章:
复制代码代码如下:
<?php query_posts(\'showposts=10&orderby=rand\'); //showposts=10表示10篇 while(have_posts()): the_post(); ?> <li><a href=\"<?php the_permalink(); ?>\"target=\"_blank\"><?php the_title() ?></a></li> //这里可以写成你自己需要的样式 <?php endwhile; ?> |
调用某个分类下的最新文章:
代码如下:
<?php query_posts(\'showposts=10&cat=1\'); //cat=1为调用ID为1的分类下文章 while(have_posts()) : the_post(); ?> <li><a href=\"<?php the_permalink() ?>\"title=\"<?php the_title(); ?>\"><?php the_title(); ?></a></li> <?php endwhile; ?> |
排除某个分类下的文章:
代码如下:
<?php query_posts(\'showposts=10&cat=-1\'); //cat=-1为排除ID为1的分类下文章 while(have_posts()) : the_post(); ?> <li><a href=\"<?php the_permalink() ?>\"title=\"<?php the_title(); ?>\"><?php the_title(); ?></a></li> <?php endwhile; ?> |
以上就是文章列表的调用方法,可以将例子中的代码结合起来达到你需要的效果。
以上就是wordpress怎么调用特定文章列表的详细内容,更多请关注网站的其它相关文章!
Demand feedback