php 使用短代码/插件列出帖子或页面

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 使用短代码/插件列出帖子或页面相关的知识,希望对你有一定的参考价值。

<?php

// Post List Addons


	vc_map(array(
		"name" => esc_html__("Post List", "stock-toolkit") ,
		"base" => "post_list",
		"category" => esc_html__("Stock", "stock-toolkit") ,
		"params" => array(
			array(
				"type" => "textfield",
				"heading" => esc_html__("Post type", "stock-toolkit") ,
				"param_name" => "type",
				"value" => esc_html__("post", "stock-toolkit") ,
				"description" => esc_html__("Type post type here.", "stock-toolkit")
			) ,
			array(
				"type" => "textfield",
				"heading" => esc_html__("Post Count", "stock-toolkit") ,
				"param_name" => "count",
				"value" => esc_html__("-1", "stock-toolkit") ,
				"description" => esc_html__("Type how many items you want to show, Type -1 for unlimited item", "stock-toolkit")
			) ,
			array(
				"type" => "colorpicker",
				"heading" => esc_html__("Link color", "stock-toolkit") ,
				"param_name" => "color",
				"value" => esc_html__("#000", "stock-toolkit") ,
				"description" => esc_html__("Select link color.", "stock-toolkit")
			) ,
			array(
				"type" => "iconpicker",
				"heading" => esc_html__("Icon", "stock-toolkit") ,
				"param_name" => "icon",
				"value" => esc_html__("fa fa-link", "stock-toolkit") ,
				"description" => esc_html__("Select link icon.", "stock-toolkit")
			)
		)
	));
<?php

// Post List Shortcode

function post_list_shortcode($atts){

	extract(shortcode_atts(array(
		'count' => '-1',
		'type' => 'post',
		'color' => '#000',
		'icon' => ''
	) , $atts));
	$q = new WP_Query(array(
		'posts_per_page' => $count,
		'post_type' => $type
	));

	$list = '<ul>';

		while ($q->have_posts()):
			$q->the_post();
			$idd = get_the_ID();
			$post_content = get_the_content();

			$list.= '
		    	<li><a style="color:' . $color . '" href="' . get_permalink() . '">';
				if (!empty($icon)){
						$list.= '<i class="' . esc_attr($icon) . '"></i>';
					}
				$list.= '' . get_the_title() . '</a></li>';

		endwhile;

	$list.= '</ul>';
	wp_reset_query();
	return $list;

	}

add_shortcode('post_list', 'post_list_shortcode');

以上是关于php 使用短代码/插件列出帖子或页面的主要内容,如果未能解决你的问题,请参考以下文章

php 联系表单7插件:在使用Contact Form 7短代码的页面,帖子和CPT上加载Javascript和CSS。

php Wordpress - 仅当帖子内容中存在短代码时才加载短代码插件(CF7)依赖项

如何在URL中带有特定字符串的页面/帖子中执行短代码?

如何使用短代码找到“页面ID”?

从 AFC 自定义字段变量中获取 ID 的 foogallery php 短代码不显示

PHP 使用帖子附件的Wordpress图像库短代码