我正在尝试修改我的存档。我可以在php中选择类别并过滤它们的记录。
我可以显示类别,检测是否是分类页面,但通过选择它们,它们不会过滤。我做错了什么?
当我选择一个类别时,它会显示所有记录,但不会过滤。
archive.php
<?php }elseif(is_tax(\'downloads-category\')){ ?>
<section id="conteudo">
<div class="title">
<div class="container">
<h1>Category Name</h1>
<?php if (function_exists(\'yoast_breadcrumb\')){ yoast_breadcrumb(\'<p id="breadcrumbs">\',\'</p>\'); }?>
</div>
</div>
<div class="content-master">
<div class="container">
<div class="row more-gutter">
<aside class="col-sm-3">
</aside>
<div class="col-sm-9">
<?php
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$infoDownload = array(
\'post_type\' => \'downloads\',
\'taxonomy\'=>\'downloads-category\',
\'paged\' => $paged
);
$resultadoDownload = new WP_Query($infoDownload);
if ($resultadoDownload->have_posts()) :
while ($resultadoDownload->have_posts()) : $resultadoDownload->the_post();
$postThumb = (has_post_thumbnail()) ? get_the_post_thumbnail_url() : get_stylesheet_directory_uri()."/img/layout/sem-imagem.jpg";
$postThumb = "<img src=\\"".$postThumb."\\" class=\\"img-fluid\\">";
?>
<div class="row lista-download">
<div class="col-sm-4">
<?php echo $postThumb; ?>
</div>
<div class="col-sm-8">
<h3><?php the_title() ?></h3>
<?php the_content(); ?>
</div>
</div>
<?php
wp_reset_postdata();
endwhile;
wpbs_pagination();
endif;
?>
</div>
</div>
</div>
</div>
</section>
functions.php
function create_posttype() {
register_post_type(\'downloads\',
array(
\'labels\' => array(
\'name\' => __(\'Downloads\'),
\'featured_image\' => __(\'Imagem Capa\'),
\'singular_name\' => __(\'Download\'),
),
\'taxonomies\' => array(\'downloads-category\'),
\'supports\' => array(
\'title\',
\'editor\',
\'custom-fields\',
\'thumbnail\'
),
\'menu_icon\' => \'dashicons-category\',
\'with_front\' => true,
\'public\' => true,
\'has_archive\' => true,
\'rewrite\' => array(\'slug\' => \'downloads\'),
)
);
$labels = array(
\'name\' => _x(\'Categorias\', \'taxonomy general name\'),
\'singular_name\' => _x(\'Categoria\', \'taxonomy singular name\'),
\'search_items\' => __(\'Procurar categoria\'),
\'all_items\' => __(\'Todos\'),
\'edit_item\' => __(\'Editar categoria\'),
\'update_item\' => __(\'Editar categoria\'),
\'add_new_item\' => __(\'Adicionar categoria\'),
\'new_item_name\' => __(\'Nova categoria\')
);
register_taxonomy(\'downloads-category\',array(\'downloads\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'show_in_nav_menus\' => true,
\'rewrite\' => array(\'slug\' => \'categoria-de-downloads\', \'with_front\' => false),
));
}
add_action(\'init\', \'create_posttype\');
哦,当我使用tax\\u查询时,不会显示任何内容。。。$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$infoDownload = array(
\'post_type\' => \'downloads\',
\'tax_query\' => array(
array(
\'taxonomy\'=>\'downloads-category\',
\'field\' => \'slug\'
)
),
\'paged\' => $paged
);
$resultadoDownload = new WP_Query($infoDownload);
if ($resultadoDownload->have_posts()) :