在wordpress上的任何页面上显示博客帖子查询不起作用
在上面的代码在wordpress更新之前工作之前,我的问题是post显示的数量必须只有3个post,但它显示的数量超过3个。我上面的代码中是否有任何希望或混乱的地方嗯,在wordpress上的任何页面上显示博客帖子查询不起作用,wordpress,Wordpress,在上面的代码在wordpress更新之前工作之前,我的问题是post显示的数量必须只有3个post,但它显示的数量超过3个。我上面的代码中是否有任何希望或混乱的地方嗯,showposts参数被替换为posts\u per\u page。所以试试看 $wp\u query->query('posts\u per\u page=3'.&paged='。$paged) 您可以使用: <?php // $temp = $wp_query; $wp_query= null; $wp
showposts
参数被替换为posts\u per\u page
。所以试试看
$wp\u query->query('posts\u per\u page=3'.&paged='。$paged)代码>
您可以使用:
<?php //
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=3' . '&paged='.$paged);
?>
<ul class="column-three">
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>">
<?php if (has_post_thumbnail()){ the_post_thumbnail('post-thumbnails'); } else {echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/b.jpg'. '"/>'; }?>
<span class="title"><?php the_title(); ?></span>
<span class="incrypt"><?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,30); ?></span>
<span class="read-more">Read More</span>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php wp_reset_postdata(); ?>
那么,showposts
参数将替换为posts\u per\u page
。所以试试看
$wp\u query->query('posts\u per\u page=3'.&paged='。$paged)代码>
您可以使用:
<?php //
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=3' . '&paged='.$paged);
?>
<ul class="column-three">
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>">
<?php if (has_post_thumbnail()){ the_post_thumbnail('post-thumbnails'); } else {echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/b.jpg'. '"/>'; }?>
<span class="title"><?php the_title(); ?></span>
<span class="incrypt"><?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,30); ?></span>
<span class="read-more">Read More</span>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php wp_reset_postdata(); ?>
您的代码正在为我工作,我已经生成了page-test.php并在该页面中获取帖子,而为我工作的“showposts”仍然使用@jogesh\u pi comment提到的“每页帖子”,还可以尝试下面的代码,这些代码也将通过获取帖子功能获取帖子
$args = array(
'posts_per_page' => 3,
'paged' => $paged,
);
$query = new WP_Query( $args );
$post\u list=get\u posts(数组)(
“post_type”=>“post”,
“numberposts”=>3,
'orderby'=>'菜单\u顺序',
“排序顺序”=>“asc”
) );
?>
-
您的代码正在为我工作,我已经生成了page-test.php并在该页面中获取帖子,而为我工作的“showposts”仍然使用@jogesh\u pi comment提到的“每页帖子”,还可以尝试下面的代码,这些代码也将通过获取帖子功能获取帖子
$args = array(
'posts_per_page' => 3,
'paged' => $paged,
);
$query = new WP_Query( $args );
$post\u list=get\u posts(数组)(
“post_type”=>“post”,
“numberposts”=>3,
'orderby'=>'菜单\u顺序',
“排序顺序”=>“asc”
) );
?>
-
试试这个
$post_list = get_posts( array(
'post_type' => 'post',
'numberposts' => 3,
'orderby' => 'menu_order',
'sort_order' => 'asc'
) );
?>
<ul class="column-three">
<?php foreach ( $post_list as $post ) { ?>
<li>
<a href="<?php the_permalink(); ?>" id="post-<?php $post->ID; ?>">
<?php if (has_post_thumbnail($post->ID)){ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
?>
<img src="<?php echo $image[0]; ?>"/>
<?php
} else {echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/b.jpg'. '"/>'; }?>
<span class="title"><?php echo $post->post_title; ?></span>
<span class="incrypt"><?php $excerpt = $post->post_excerpt; echo substr( $excerpt , 0, 30);?></span>
<span class="read-more">Read More</span>
</a>
</li>
<?php } ?>
</ul>
<?php
wp_reset_postdata();
试试这个
$post_list = get_posts( array(
'post_type' => 'post',
'numberposts' => 3,
'orderby' => 'menu_order',
'sort_order' => 'asc'
) );
?>
<ul class="column-three">
<?php foreach ( $post_list as $post ) { ?>
<li>
<a href="<?php the_permalink(); ?>" id="post-<?php $post->ID; ?>">
<?php if (has_post_thumbnail($post->ID)){ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
?>
<img src="<?php echo $image[0]; ?>"/>
<?php
} else {echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/b.jpg'. '"/>'; }?>
<span class="title"><?php echo $post->post_title; ?></span>
<span class="incrypt"><?php $excerpt = $post->post_excerpt; echo substr( $excerpt , 0, 30);?></span>
<span class="read-more">Read More</span>
</a>
</li>
<?php } ?>
</ul>
<?php
wp_reset_postdata();
Yes不推荐使用showposts。现在是每页发布。是的,不推荐使用showposts。现在每页都是帖子。