wordpress调用指定类型post_type的文章
wordpress很强大,可以添加多种post_type文章类型,假如我们要调用product产品模型的文章要如何操作呢?随ytkah一起来看看吧。我们用'post_type' => 'product'进行指定,代码如下
<?php
$args = array(
'post_type' => 'product',//自定义文章类型名称
'showposts' => 5,//输出的文章数量,这个可以是缺省值,不用设置
'orderby' => 'rand',//按随机调用,如果不要随机可以把这行删除
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();?>
<div class="item col-xs-12 col-sm-4 col-md-3">
<div class="box">
<img src="<?php the_field('pimg01'); ?>" alt="<?php the_title(); ?>">
<div class="text">
<b><?php the_title(); ?></b>
<?php if (get_field('model')): ?>
<p><?php the_field('model'); ?></p>
<?php endif; ?>
<?php if (get_field('be_applicable')): ?>
<p><?php the_field('be_applicable'); ?></p>
<?php endif; ?>
<a href="<?php the_permalink(); ?>" class="common-btn">more</a>
</div>
</div>
</div>
<?php endwhile; wp_reset_query(); //重置query查询
} ?>
可以使用的排序方法有
'orderby' => 'date', //按发布日期排序
'orderby' => 'modified', //按修改时间排序
'orderby' => 'ID', //按文章ID排序
'orderby' => 'comment_count', //按评论最多排序
'orderby' => 'title', //按标题排序
'orderby' => 'rand', //随机排序
'order' => 'desc', // 降序(递减,由大到小)
有相同需求的朋友可以试一下
wordpress调用指定类型post_type的文章的更多相关文章
- wordpress调用指定分类除外的置顶文章
我们有时需要根据实际需要进行一些设置,比如wordpress调用指定分类除外的置顶文章,如何实现呢?随ytkah一起来看看吧,用如下代码插入到需要调取的位置 <div class="r ...
- wordpress调用指定tag的文章
前面的文章wordpress调用指定分类文章如何实现有网友回复要如何调用指定tag的文章,原理是类似的,有两种方法,随ytkah一起来看看 1.第一种 <?php $args=array( 't ...
- wordpress调用指定分类文章如何实现
wordpress是很强大的cms系统,你可以通过相关函数就能实现相关的功能.很多网友会问wordpress怎么调用指定分类文章的呢?其实很简单,随ythah一起来看看吧,几行代码就解决了,代码如下 ...
- 转载]PhpCms V9调用指定栏目子栏目文章的两种方法
PhpCms V9调用指定栏目子栏目文章的两种方法 第一种.直接写子栏目id ,用cat in {pc:get sql="SELECT * from v9_news where status ...
- PhpCms V9调用指定栏目子栏目文章的方法
PhpCms V9调用指定栏目子栏目文章的方法 第一种,直接写父类id {pc:content action="lists" catid="父类id" num= ...
- wordpress调用指定post type文章怎么操作
我们有时会用wordpress创建好几种post type文章,比如默认的post文章和product文章,如果我们要在每个页面的底部调用post type类型为post最新文章要如何操作呢?那我们就 ...
- wordpress调用指定id的page页面的方法,适用于多id调用
前面我们讲到wordpress如何调用指定page页面内容,现在再用另外的方法来调试一下,可以直接在single.php模板使用,同样可以调用多id,随ytkah一起来看看 <?php $arg ...
- dedecms如何随机调用指定分类下的文章到网站首页
dedecms是全静态的,有时会因为其他事情好几天没写文章推荐到首页,那样对se不是很友好.原本ytkah是想在网站首页上半部分调用几篇id从200到500的文章随机展示的,这样每次更新首页给se的赶 ...
- ecshop调用指定栏目下的文章的方法
打开 index.php 添加 fun函数一个,需放在<php与?>中间. /** * 获得指定栏目的文章列表. * @param int $cid 栏目ID * @param int $ ...
随机推荐
- [LeetCode] 337. House Robber III 打家劫舍之三
The thief has found himself a new place for his thievery again. There is only one entrance to this a ...
- Harbor 忘记密码
Harbor密码重置 01,登入到harbor容器里面的数据库上 docker exec -it harbor-db /bin/bash 02,登入数据库 psql -h postgresql -d ...
- GreenPlum 大数据平台--segment 失效问题排查
01,segment 检查一: 在master节点上检查失效的segment 正常情况下: :::: gpstate:greenplum01:gpadmin-[INFO]:-Starting gpst ...
- Scala 准引用 - Quasiquote介绍
Quasiquotes are a neat notation that lets you manipulate Scala syntax trees with ease: scala> val ...
- 微信企业号SDK
1. 微信企业号SDK class class_wxqiye { var $corpid = CorpID; var $corpsecret = CorpSecret; var $agentid = ...
- HUE-hive常用查询语句整理
通过hue进行数据导入: ,create table demo_id(`id` string) row format serde 'org.apache.hadoop.hive.serde2.Open ...
- 调试MATLAB代码
1.在子函数设置的断点,在运行时,不起作用: 因为在主函数开始时,使用了clear all,在运行时,会把断点给删除.
- 微服务浅谈&服务治理的演变过程
这两天对互联网的架构演变进行了简单了解,并对微服务的出现很感兴趣,所以对相关知识进行了简单的整理与总结. 本篇文章先简单介绍了互联网架构的演变,进而介绍了服务化,最后介绍了微服务及最新的服务网格(Se ...
- MySQL子查询结果集是否有记录
Mark SELECT tu.id userId, tu.avatar_url avatarUrl, tu.wx_nick_name wxNickName, tu.city city, (select ...
- VMWare 下安装 Windows XP
准备工作 安装VMware 我这里安装的是 VMware-workstation-full-12.1.1-3770994.exe 下载Windows XP with SP3 从网上下载的MSDN版本X ...