我试图在静态页面主页内容中显示最近的帖子。php。我在函数中添加了此代码。php
function my_recent_posts_shortcode($atts){
$q = new WP_Query(
array( \'orderby\' => \'date\', \'posts_per_page\' => \'4\')
);
$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_query();
return $list ;
}
add_shortcode(\'recent-posts\', \'my_recent_posts_shortcode\');
[recent-posts]
这是显示最近帖子的快捷码
和主页内容。用于显示帖子的php
<?php
$post_id = 7;
$queried_post = get_post($post_id);
?>
<p><?php $check=$queried_post->post_content; ?></p>
<?php echo do_shortcode(\'["\'.$check.\'"]\');?>
所有最近的帖子都显示在我的自定义主题主页上
http://templategraphy.com/wp-demo/businessguru/但问题主题结构没有正确显示。我想要这种结构http://templategraphy.com/demo/businessguru/
就我做错的地方提出一些解决方案。
最合适的回答,由SO网友:Jansha Mohammed 整理而成
您错过了\\u permalink()中的引号。使用以下代码
function my_recent_posts_shortcode($atts){
$q = new WP_Query(
array( \'orderby\' => \'date\', \'posts_per_page\' => \'4\')
);
$list ="";
while($q->have_posts()) : $q->the_post();
echo \'<div class="item">\';
$title=get_the_title();
if ( has_post_thumbnail() ) {
$list .= \'<a class="single-image link-icon" href="\'. get_permalink().\'">\'.the_post_thumbnail(array(300,200),array(\'alt\' =>$title)).\'</a>\';
}
$list .= \'<h6 class="title"><a href=\'.the_permalink().\'><span>"\'.the_title().\'"</span></a></h6>\';
echo \'<div class="entry-body">\';
$list .= wpe_excerpt(\'wpe_excerptlength_index\', \'\').\'<a class="button default color" href="\'.the_permalink().\'">Read More</a>\';
echo \'</div>\';
echo \'</div>\';
endwhile;
wp_reset_postdata();
return $list ;
}