How to embed popular posts by php
-
Hi, I currently have php code for embedding new posts, but I want to show popular post. can anyone please help me out??
<?php $args = array( 'showposts' => 6, 'post_type' => 'post', 'post__not_in' => [$post->ID] ); $otherVoiceQuery = new WP_Query($args); ?> <?php if ($otherVoiceQuery->have_posts()) : ?> <div class="main007"> <div class="tittle001">New Posts</div> <div class="other-posts row mgt20"> <?php while ($otherVoiceQuery->have_posts()): ?> <?php $otherVoiceQuery->the_post(); $thumbnail_url = ""; if (has_post_thumbnail()): $image_id = get_post_thumbnail_id(); $thumbnail_url = wp_get_attachment_image_src($image_id, 'news-thumbnail_pc', true); $thumbnail_url = $thumbnail_url[0]; else: $thumbnail_url = "/assets/pc/images/common_project/noimage-news.jpg"; endif; ?> <a>" class="other-post__inner-wrapper"> <div class="listbox001 clearfix"> <!--<div class="pict001"><img />" alt = "" /></div>--> <div class="pict002"style="background-image:url(<?php echo $thumbnail_url; ?>);"></div> <div class="textbox001"> <?php $category = get_the_category()[0]->name; ?> <div class="category001"><?php echo $category; ?></div> <div class="text001"> <?php if (mb_strlen($post->post_title) > 50) { echo mb_substr(the_title($before = '', $after = '', FALSE), 0, 50) . '...'; } else { the_title(); }; ?> </div> <div class="date001"><?php the_time( 'Y.m.d' ); ?></div> </div> </div> </a> <?php endwhile; wp_reset_postdata(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to embed popular posts by php’ is closed to new replies.