Shortcode mod request – Display Post by language on homepage
-
Hi Guys,
I’m still new with WordPress and I have the following issue. I bought a theme in which I had a shortcode to display blog post on the home page. Problem is, it uses IDs to identify Post and my site is bilingual (EN & FR), therefore I have all post in all language on each homepage.
Is there a way to identify the language within the shortcode so it displays EN post on EN homepage and FR post on FR homepage?
Here’s the code :
function trend_show_blog_post_shortcode( $params, $content ) { extract( shortcode_atts( array( 'number' => '', 'columns' => '' ), $params ) ); $args_posts = array( 'posts_per_page' => $number, 'post_type' => 'post', 'post_status' => 'publish' ); $posts = get_posts($args_posts); $shortcode_content = '<div class="trend_shortcode_blog vc_row sticky-posts">'; foreach ($posts as $post) { $excerpt = get_post_field('post_content', $post->ID); $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ),'portfolio_pic700x450' ); $author_id = $post->post_author; $url = get_permalink($post->ID); /* ISSUE HERE SINCE ID DIFFERENT EACH LANG */ $shortcode_content .= '<div class="'.$columns.' post">'; $shortcode_content .= '<a href="'.$url.'" class="relative">'; if($thumbnail_src) { $shortcode_content .= '<img src="'. $thumbnail_src[0] . '" alt="'. $post->post_title .'" />'; }else{ $shortcode_content .= '<img src="https://placehold.it/700x450" alt="'. $post->post_title .'" />'; } $shortcode_content .= '<div class="post-date absolute rotate45">'; $shortcode_content .= '<span class="rotate45_back">'.get_the_date( "j M" ).'</span>'; $shortcode_content .= '</div>'; $shortcode_content .= '<div class="thumbnail-overlay absolute">'; $shortcode_content .= '<i class="fa fa-plus absolute"></i>'; $shortcode_content .= '</div>'; $shortcode_content .= '</a>'; $shortcode_content .= '<h3 class="post-name"><a href="'.$url.'">'.$post->post_title.'</a></h3>'; $shortcode_content .= '<div class="post-author">by '.get_the_author_meta( 'display_name', $author_id ).'</div>'; $shortcode_content .= '<div class="post-excerpt">'.trend_excerpt_limit($excerpt,10).'</div>'; $shortcode_content .= '</div>'; } $shortcode_content .= '</div>'; return $shortcode_content; } add_shortcode('trend-blog-posts', 'trend_show_blog_post_shortcode');
Thanks in advance.
JP
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Shortcode mod request – Display Post by language on homepage’ is closed to new replies.