几年后,我又回到Wordpress和php中。在php语法方面,我非常无知,所以会犯很多错误。
我需要在一个页面上显示一个帖子,它的标题和内容,它需要特定于我创建的一个类别。
我抓起了这个网站,并试图改变它,但我无法让它发挥作用。
<?php query_posts('category_name=qaadrant&showposts=1');
while (have_posts()) : the_post();
// do whatever you want
?>
<h2><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<p><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_content(); ?>"><?php the_content(); ?></a></p>
任何帮助都很感激。尼尔
发布于 2015-09-17 08:37:55
请使用可怕的WP_QUERY类,参见这里的参考:使用下面的代码获得来自您所选类别的文章的引用:Query。不分页设置为使查询速度更快:
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 1,
'category_name' => 'qaadrant',
'no-paging' => true,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h3><?php echo get_the_title(); ?></h3>
<p><?php echo get_the_excerpt(); ?></p>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
https://stackoverflow.com/questions/32634610
复制相似问题