php 相关帖子短代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 相关帖子短代码相关的知识,希望对你有一定的参考价值。
<?php
function ('pad_related_posts_shortcode') {
// get the custom post type's taxonomy terms
$custom_taxterms = wp_get_object_terms( $post->ID, 'TAXONOMY_SLUG', array('fields' => 'ids') );
// arguments
$args = array(
'post_type' => 'TAXONOMY_SLUG',
'post_status' => 'publish',
'posts_per_page' => 2,
'orderby' => 'rand',
'tax_query' => array(
array(
'taxonomy' => 'TAXONOMY_SLUG',
'field' => 'id',
'terms' => $custom_taxterms
)
),
'post__not_in' => array ($post->ID),
);
// Run the query
$related_items = new WP_Query( $args );
// loop through query
if ($related_items->have_posts()) :
// open wrappers
$output = '<div>';
while ( $related_items->have_posts() ) : $related_items->the_post();
$output .= '<div class="related-featured-image">';
$output .= get_the_post_thumbnail();
$output =. '</div>';
$output =. '<div class="related-title">';
$output =. '<a href="'.get_the_permalink().'">'.get_the_title("<h3>").'</a>';
$output =. '</div>';
endwhile;
// close wrappers
$output =. '</div>';
endif;
return $output;
// Reset Post Data
wp_reset_postdata();
}
add_shortcode('pad_related_posts', 'pad_related_posts_shortcode');
以上是关于php 相关帖子短代码的主要内容,如果未能解决你的问题,请参考以下文章
PHP 使用帖子附件的Wordpress图像库短代码
php Wordpress - 仅当帖子内容中存在短代码时才加载短代码插件(CF7)依赖项
php Wordpress - 使用WP All Import Pro将图像导入帖子时插入图库的短代码
php 联系表单7插件:在使用Contact Form 7短代码的页面,帖子和CPT上加载Javascript和CSS。
php 联系表单7插件:在使用Contact Form 7短代码的页面,帖子和CPT上加载Javascript和CSS。
从 AFC 自定义字段变量中获取 ID 的 foogallery php 短代码不显示