WordPress的:如何只显示在某一类别的职位?
-
19-09-2019 - |
题
我是很新,WordPress的,但花了大约50多个小时就可以学习了,想的东西出来,这样,并有我有一个不错的手柄上,现在的感觉..
然而,有一件事我根本无法工作是有一个页面吐出某一类别的职位名单。
这是我的例子: http://dev.jannisgundermann.com/ zoeikin /图形设计/排版-海报
我有一个职位,如果我去直接工作正常,但此页面上显示不出来。
在类别ID是 '3',而类别名称为 '印刷-海报'。
我对印刷,海报页,看起来像这样的自定义页面模板:
<?php
/*
Template Name: Typographic Posters
*/
?>
<?php get_header(); ?>
<?php get_sidebar(); ?>
<?php if (in_category('3')): ?>
<div class="post">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="post-description">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
<?=get_image('flutter-image');?>
</div>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
<?php endif; ?>
<?php get_footer(); ?>
然而使用该代码的页面只能说明得到头,侧边栏,并没有别的..
如果有人可以帮助我走出这将真正帮助我得到的wordpress类别的这种过滤的句柄。
感谢阅读,
Jannis
解决方案
in_category
将仅在环的外工作在单页上。我建议使用query_posts
功能来解决这个问题。您可以使用query_posts('cat=3')
或query_posts('category_name=typographic-posters')
得到你正在寻找的职位。
一旦获得,只是使用正常的WordPress循环来访问这些文章。
其他提示
在最简单的方式是创建一个名为category-3.php
文件,并从正常index.php
或category.php
文件中使用的标准代码。 WordPress会照顾获取职位只与ID = 3类和它的子类。
in_category将仅在环的外工作在单页上。一世 建议使用query_posts函数来解决这个问题。你可以 使用query_posts( '猫= 3')或 query_posts(“CATEGORY_NAME =印刷,海报”)来获得你的帖子 所期待的。
一旦获得,只是使用正常的WordPress循环来访问这些 讯息。
这工作出色的,但要确保你进入设置>阅读和页面设置的职位为 - 选择 - 选项,否则将有覆盖此查询和转储近期发表的所有帖子,无论类别
我已经通过类别ID使用后滤波下述方法:
query_posts('cat=1&showposts=3');
if (have_posts()) : while (have_posts()) :
// if(1) {
//echo the_category_ID();
the_post();
/**
* The default post formatting from the post.php template file will be used.
* If you want to customize the post formatting for your homepage:
*
* - Create a new file: post-homepage.php
* - Copy/Paste the content of post.php to post-homepage.php
* - Edit and customize the post-homepage.php file for your needs.
*
* Learn more about the get_template_part() function: http://codex.wordpress.org/Function_Reference/get_template_part
*/
$is_post_wrap++;
if($is_post_wrap == '1') {
?><div class="post-wrap clearfix"><?php
}
get_template_part('post', 'homepage');
if($is_post_wrap == '3') {
$is_post_wrap = 0;
?></div><?php
}
endwhile;
else :
get_template_part('post', 'noresults');
endif;
只需在循环之前添加:
<?php query_posts="cat=3&showposts=5">
这将强制循环来从3类显示5个(showposts = 5)(猫= 3)。
http://codex.wordpress.org/Template_Tags/query_posts
只要你知道这些问题的答案来了......从有很多更有趣的功能,你可以用query_posts做的一样好。
如果您希望能够改变显示的类别,而不通过代码去这个插件也帮助你: http://wordpress.org/extend/plugins/advanced-category-excluder/
感谢您分享您的想法的一个伟大的想法。通常你可以一个主题的index.php文件或category.php只是复制到品类3.php和调整需要
任何定制该模板