Wordpress 从特定类别中提取最新帖子
我试图从一个特定的类别中获取最新的帖子 我目前能够拉所有最新的职位,并显示他们的方式,我想使用下面的代码,但我不能做同样的事情,从一个特定的类别Wordpress 从特定类别中提取最新帖子,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我试图从一个特定的类别中获取最新的帖子 我目前能够拉所有最新的职位,并显示他们的方式,我想使用下面的代码,但我不能做同样的事情,从一个特定的类别 <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div id="content"><div id="circle"><div id="circle_text1"><p><?php the_time('M')
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="content"><div id="circle"><div id="circle_text1"><p><?php the_time('M') ?></p></div>
<div id="circle_text2"><p><?php the_time('dS') ?></p></div></div>
<div id="text"><div id="title"><p><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></p></div>
<div id="name"><p>By <?php the_author(); ?></p></div>
<div id="blurb"><p><?php the_content('<br />Read More'); ?></p></div></div>
<div id="line_rule"><p> </p><hr /></div></div>
<?php endwhile; ?><?php else : ?><h2>Not Found</h2><?php endif; ?>
借
找不到
提前感谢如果您从数据库中获取帖子,请使用order by ID desc,它将在顶部显示最新帖子。如果ID是自动递增的。像
select * from posts order by ID desc
如果您是从数据库获取文章,那么使用order by ID desc,它将在顶部显示最新的文章。如果ID是自动递增的。像
select * from posts order by ID desc
这是一个基本的可湿性粉剂查询,可自行重置,并可在模板中多次使用。您可以将html添加到其中。showposts是要显示的帖子数-1显示所有帖子
<?php $my_query = new WP_Query('category_name=mycategoryname&showposts=10'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
<?php endwhile; ?>
这是一个基本的WP查询,可自行重置,并可在模板中多次使用。您可以将html添加到其中。showposts是要显示的帖子数-1显示所有帖子
<?php $my_query = new WP_Query('category_name=mycategoryname&showposts=10'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
<?php endwhile; ?>
我一直都这样做。这将有助于: 将cat=编号更改为您想要使用的任何类别ID。 根据需要添加html标记和任何其他要提取的内容
<?php query_posts('cat=4&order=ASC');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
在这个例子中,我只抓取了帖子的内容,但是你可以把标题、元数据等放进去。重要的部分都在这里。
试试看。我一直都这么做。这将有助于: 将cat=编号更改为您想要使用的任何类别ID。 根据需要添加html标记和任何其他要提取的内容
<?php query_posts('cat=4&order=ASC');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
在这个例子中,我只抓取了帖子的内容,但是你可以把标题、元数据等放进去。重要的部分都在这里。
试试看。在开始的IF语句上方添加这行代码
<?php query_posts( 'cat=1' ); ?>
然后更改1以匹配您试图显示的类别的ID
:)在开始的IF语句上方添加这行代码
<?php query_posts( 'cat=1' ); ?>
然后更改1以匹配您试图显示的类别的ID
:)只需将第一行添加到代码中即可:
<?php query_posts( 'category_name=slug_of_your_category&posts_per_page=10' ); ?>
将“slug\u of\u your\u category”替换为类别的slug\u,将“10”替换为所需的帖子数量。只需将第一行添加到代码中即可:
<?php query_posts( 'category_name=slug_of_your_category&posts_per_page=10' ); ?>
将“你的类别中的slug\u”替换为你的类别中的slug\u,将“10”替换为你需要的帖子数量