Uma armadilha comum é o fato de que:
category_name aceita a categoria SLUG NÃO o nome como atributo
Isso é freqüentemente errado.
Por que diabos esse trecho de código não está funcionando?
$my_query = new WP_Query('category_name=feature');
while ($my_query->have_posts()) : $my_query->the_post();
echo 'test';
endwhile;
Eu tentei com Feature
e feature
, sem diferença.
Preciso postar por nome de categoria.
Qualquer ajuda apreciada.
atualização
Isso não está funcionando: $my_query = new WP_Query('cat=3');
código
// index.php
<?php
include_once('header.php');
?>
<div id="fp-slider-container" class="blue-gradient">
<div class="main-content-container">
<?php
query_posts( 'cat=3&posts_per_page=5' );
while ( have_posts() ) : the_post();
echo 'test';
endwhile;
?>
</div>
</div>
<?php
include_once('footer.php');
?>
Uma armadilha comum é o fato de que:
category_name aceita a categoria SLUG NÃO o nome como atributo
Isso é freqüentemente errado.
em vez de hackear index.php por que não usar o filtro pre_get_posts?
add_filter('pre_get_posts', 'filter_homepage_posts');
function filter_homepage_posts($query) {
$limit_number_of_posts = 5;
$featured_category_id = get_cat_id('Reviews'); // by cat name...
if ($query->is_home) {
$query->set('cat', $featured_category_id);
$query->set('showposts', $limit_number_of_posts);
}
return $query;
}
copiado de: enlace
também deve funcionar assim, pois tecnicamente a consulta passa por referência
add_action('pre_get_posts', 'filter_homepage_posts');
function filter_homepage_posts( $query) {
$limit_number_of_posts = 5;
$featured_category = 'bacon-category'; // by cat slug...
if ($query->is_home) {
$query->set('category_name', $featured_category);
$query->set('showposts', $limit_number_of_posts);
}
return $query;
}
Tags wp-query