duanbo2048 2014-06-30 07:57
浏览 57

最近的帖子显示使用短代码

I am trying to display recent post in staic page home-content.php so i have added this code in function.php

here it is a code

 function my_recent_posts_shortcode($atts){
 $q = new WP_Query(
   array( 'orderby' => 'date')
 );
$list ="";

while($q->have_posts()) : $q->the_post();

 echo '<div class="item">';

$title=get_the_title();

if ( has_post_thumbnail() ) {
 echo '<a class="single-image link-icon" href="' . get_permalink() . '">';
  $list .=the_post_thumbnail(array(300,200),array('alt' =>$title)); 
  echo '</a>';
}

echo '<h6 class="title"><a href="' . get_permalink() . '"><span>'.$title.'</span></a></h6>';

echo '<div class="entry-body">';
$list .= wpe_excerpt('wpe_excerptlength_index', '');
echo '<a class="button default color" href="' . get_permalink() . '">Read More</a>';
echo '</div>';

 echo '</div>';

endwhile;

wp_reset_postdata();

return $list ;

}
add_shortcode('recent-posts', 'my_recent_posts_shortcode');

[recent-posts] this is a shortcode for display recent post

and home-content.php for showing post

<?php 
$post_id = 7;
$queried_post = get_post($post_id);
?>
<p><?php  $check=$queried_post->post_content; ?></p>
<?php  echo do_shortcode('["'.$check.'"]');?>

All the recent post display on home page of my custom theme http://templategraphy.com/wp-demo/businessguru/

but the problem is theme structure is not properly shown i

want this type of structure is shown http://templategraphy.com/demo/businessguru/

suggest some solution where i am doing wrong.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题