zoukankan      html  css  js  c++  java
  • 如何调用出 wordpress文章列表

    在 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; ?>

    以上就是文章列表的调用方法,可以将例子中的代码结合起来达到你需要的效果。

  • 相关阅读:
    c# 泛型(知识整理)
    [VC++]C\C++中结构体知识点强化
    [VC++]CString转化成char
    [VC++]C++中类的多态与虚函数的使用
    [C#]关于自己编写MesasgeBox
    [C#]给DataGridView里的ComboBoxCol添加SelectIndexChange事件
    [C#]用代码触发一个事件
    [C#]序列化例子
    [VC++]怎么使对话框中的按钮DISABLE和ENABLE
    [VC++]控制台程序窗口隐藏
  • 原文地址:https://www.cnblogs.com/surplus/p/15463735.html
Copyright © 2011-2022 走看看