【发布时间】:2021-08-06 18:44:02
【问题描述】:
这段代码工作正常并拉动博客文章,但唯一的问题是我希望数据位于 json 数组中,以便我可以使用它创建一个 api 并在外部显示帖子......
<?php
require('/home/dealicopter/public_html/wp-load.php');
function wpdocs_custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );
$args = array(
'posts_per_page' => 10,
'cat' => 7,
);
query_posts($args); if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$permalink = the_permalink();
$title = the_title();
$age = array("id"=>$permalink, "title"=>$title);
?>
<?php echo json_encode($age); ?>
<?php endwhile; else: echo "[]"; endif; ?>
<?php wp_reset_query(); ?>
【问题讨论】:
标签: php android arrays wordpress jsonp