WEB AND IT

Generate Text dari Function utk source Comica

Share on FacebookTweet about this on TwitterPin on PinterestShare on LinkedInShare on Google+Share on TumblrEmail this to someone

Baru aja berhasil test untuk auto genere text list apabila ada action "publish post". text ini ini yang nantinya dipakai untuk modalnya comica. biar gak memberatkan kerja php, biar gak selalu request hal yang sama. maka text ini sangat efektif.

Sebelumnya aku langsungkan requesnya menggunakan PHP, tapi kok kepikiran juga kalo mungkin ini membebani server atau lebih lemot daripada langsung saja load file yang sama, apalagi kalau sudah ter-cache.

here goes the code:

[merch-ad-disabled][DISCOUNTAD-disable]
function generate_comica_post_list() {
   
    $posts = new WP_Query('category_name=design&post_type=post&posts_per_page=-1&post_status=publish&orderby=date');
    $posts = $posts->posts;
    $all_values = "";
    $counts = 0 ;
     
    header('Content-type:text/plain');
    foreach($posts as $post) {

        switch ($post->post_type) {

            default:
                $permalink = get_post_permalink($post->ID);
                $counts++;
                break;
        }
       
    $attach_id          = get_post_thumbnail_id( $post->ID );
    $attachment_title   = get_the_title($attach_id);
    $gambar_besar_url       = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    $post_title         = get_the_title($post->ID);
    $post_link              = get_permalink($post->ID);
    $thumb_url          = get_the_post_thumbnail_url($post->ID, array(220,220) );

    $all_values .= "<div class=\"comica-gal $post->ID\" data-sort=\"$counts\"><div class=\"img-data-carrier\" data-gbr=\"$gambar_besar_url\" data-judul=\"$attachment_title\" data-post=\"$post_link\"><img srcx=\"$thumb_url\"/></div><a class=\"post-uri\" href=\"$post_link\" title=\"$post_title\"></a><div class=\"title-nya\">$post_title</div></div>\n\n";
     
    }
    file_put_contents('../scripts/tonia-comica-gallery/tonia-comica-gallery.poshlist', $all_values);

}
add_action( 'publish_post', 'generate_comica_post_list' );

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *