在WordPress上,我在"Posts“下创建了”类别“。所以我要做的是在他们各自的分类下增加新的“帖子”。一些类别的例子是“图片库,新闻稿,视频画廊”。
现在,我正在尝试从类别中显示“新闻稿”。所以我的URL结构是www.example.com/press-releases/xyz
我已经阅读了有关这方面的文档和其他博客,但似乎并不能真正理解。说到做这件事,我有点困惑。有人能帮我吗。
发布于 2013-12-16 08:47:30
也许没有什么方法可以做到这一点--我想说的是,简单的方法是创建这样的模板页面:
PHP代码
<?php /* Template Name: Available Lots */?>
<?php get_header();?>
<?php // The Query
// Replace here-goes-the-slug with what you are trying to find
query_posts( array ( 'category_name' => 'here-goes-the-slug', 'posts_per_page' => -1 ) );?>
<?php if(have_posts()):?>
<?php // The Loop
while ( have_posts() ) : the_post();?>
// Here goes the code if there is posts found
<?php endwhile; ?>
<?php else: ?>
// Here goes the code if there is no posts in this category
// This code is very important it resets the query for new use
<?php // Reset Query
wp_reset_query(); ?>
<?php get_footer();?>这将为您创建一个模板页面,现在在您的WP中创建一个新页面。把它称为任何你喜欢在右边你会看到“模板”下拉菜单。从这个菜单中选择您刚刚创建的模板,您就可以继续了。
发布于 2013-12-16 09:23:14
试试下面的代码:
只要将"CATEGORYNAME“替换为您想要的类别名称:
<?php query_posts('category_name=CATEGORYNAME&showposts=5');
while (have_posts()) : the_post();
// do whatever you want
?>
<b><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
<?php
endwhile;
?>谢谢
https://stackoverflow.com/questions/20606518
复制相似问题