Created
June 24, 2015 02:18
-
-
Save pebriana/737988c650bc8991fa84 to your computer and use it in GitHub Desktop.
mengambil 5 post terakir. dalam format json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php header('Access-Control-Allow-Origin: *'); ?> | |
{"berita":[ | |
<?php | |
$args = array( 'posts_per_page' => 5, 'offset'=> 0 ); | |
$myposts = get_posts( $args ); | |
$no=1; | |
foreach ( $myposts as $post ) : setup_postdata( $post ); ?> | |
{ | |
"judul": "<?php the_title(); ?>", | |
"gambar": "<?php if ( has_post_thumbnail() ) { | |
$x=wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 100,100 ), false, '' ); | |
echo $x[0]; | |
}else{ echo "img-none.jpg"; } ?>", | |
"deskripsi": "<?php echo str_replace(array("'", "\"", ""","“","”"),"", substr(get_the_content(), 0, 200));?>", | |
"tautan": "<?php the_permalink(); ?>" | |
}<?php echo ($no != 5) ? ",":""; $no++; ?> | |
<?php endforeach; | |
wp_reset_postdata();?> | |
]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment