Wordpress 如何获得分类法的最后5篇文章标题?
我有一个优惠券网站,我想在我的优惠券商店页面上添加模式。假设我有一个亚马逊商店,并在亚马逊上添加了5个优惠券帖子。现在,我想将这5个帖子标题和帖子链接添加到模式中。你能告诉我怎么做吗 下面是我的代码:Wordpress 如何获得分类法的最后5篇文章标题?,wordpress,schema,taxonomy,custom-taxonomy,taxonomy-terms,Wordpress,Schema,Taxonomy,Custom Taxonomy,Taxonomy Terms,我有一个优惠券网站,我想在我的优惠券商店页面上添加模式。假设我有一个亚马逊商店,并在亚马逊上添加了5个优惠券帖子。现在,我想将这5个帖子标题和帖子链接添加到模式中。你能告诉我怎么做吗 下面是我的代码: { “@context”:”http://schema.org", “@graph”:[ { “@type”:“网页”, “url”:“, “图像”:{ “@type”:“ImageObject”, “url”:“, “高度”:100, “宽度”:170 }, “出版商”:{ “@type”:“组
{
“@context”:”http://schema.org",
“@graph”:[
{
“@type”:“网页”,
“url”:“,
“图像”:{
“@type”:“ImageObject”,
“url”:“,
“高度”:100,
“宽度”:170
},
“出版商”:{
“@type”:“组织”,
“名称”:“Coupon.com”,
“徽标”:{
“@type”:“ImageObject”,
“url”:”https://cdn.coupontac.com/ovowhakr/2020/10/Logo.png.webp",
“宽度”:500,
“高度”:200
}
},
“dateModified”:“,
“说明”:“,
“名称”:“,
“标题”:“,
“主要实体”:{
“@context”:”http://schema.org",
“@type”:“Store”,
“名称”:“,
“图像”:“,
“sameAs”:“sameAs”,
“聚合”:{
“@type”:“聚合”,
“评级价值”:,
“评级计数”:,
“最佳评级”:5,
“Worsting”:0
},
“说明”:“,
“makesOffer”:[
{
“@type”:“Offer”,
“名称”:“,
“url”:“,
“说明”:“,
“有效日期”:“有效日期”,
“有效通过”:”
},
]
}
}
]
}
有人能帮我在下面的部分中获得5个帖子标题吗
“makesOffer”:[
{
“@type”:“Offer”,
“名称”:“,
“url”:“,
“说明”:“,
“有效日期”:“有效日期”,
“有效通过”:”
},
]
提前谢谢。您只需从
中查询所需的帖子,而不是使用html模板,而是使用模式模板
正如您在示例中已经展示的,PHP可以进入javascript内部,因为它是基于服务器的,首先呈现它
您不能多次使用“makesOffer”
或任何唯一键。你必须重复这个提议
您可以在线测试结构化数据
以下是基于
[
{
“@context”:”https://schema.org",
“@type”:“Person”,
“姓名”:“布伦特”,
“makesOffer”:{
“@type”:“Offer”,
“价格规格”:{
“@type”:“UnitPriceSpecification”,
“价格货币”:“美元”,
“价格”:“18000”},
“提供的项目”:{
“@type”:“Car”,
“名称”:“,
“说明”:“,
“图片”:“2009年大众·高尔夫·V·GTI·MY09.png”,
“颜色”:“黑色”,
“numberOfForwardGears”:“6”,
“汽车发动机”:{
“@type”:“EngineSpecification”,
“名称”:“4缸汽油涡轮增压中冷2.0升(1984 cc)”
}
}
}
},
]
到目前为止您尝试了什么?请提出疑问。我添加了这段代码,并且按照我的要求工作得很好,但是我有一个问题,我想显示特定的分类法文章,而不是最后的文章。那么这可能吗?@JackWhite您可以通过传递参数来构建自定义查询。谢谢你的帮助。
<script type="application/ld+json">
[
<?php
$args = array(
'post_type' => 'post',
//...
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while( $query->have_posts() ) :
$query->the_post(); ?>
{
"@context": "https://schema.org",
"@type": "Person",
"name" : "Brent",
"makesOffer" : {
"@type" :"Offer",
"priceSpecification" : {
"@type" : "UnitPriceSpecification",
"priceCurrency" : "USD",
"price" : "18000" },
"itemOffered" : {
"@type" : "Car",
"name" : "<?= wp_strip_all_tags( get_the_title(), true ); ?>",
"description" : "<?= wp_strip_all_tags( get_the_excerpt(), true ); ?>",
"image" : "2009_Volkswagen_Golf_V_GTI_MY09.png",
"color" : "Black",
"numberOfForwardGears" : "6",
"vehicleEngine" : {
"@type": "EngineSpecification",
"name" : "4 cylinder Petrol Turbo Intercooled 2.0 L (1984 cc)"
}
}
}
},
<?php endwhile;
endif;
wp_reset_postdata(); ?>
]
</script>