Suporte » Desenvolvendo com WordPress » categoria exibe posts de outra categoria

  • Resolvido daniel cambui

    (@daniel-cambui)


    olá pessoal,
    o problema é o seguinte:
    tenho duas categorias: DICAS e FOTOS.
    Na pagina inicial, são exibidos resumos de 3 post de cada.
    http://viviamlafeta.com.br/1/

    Ao clicar em algum artigo ele exibe o artigo em sua categoria, tudo certinho.
    Ex:
    http://viviamlafeta.com.br/1/dicas/leo-semper-tellus-vitae-cursus-turpis/ (POST DE DICAS)
    http://viviamlafeta.com.br/1/fotos/mariana-santana-16-dias/ (POST DE FOTOS)

    Até ai tudo bem, o problema é que quando clico no ítem DICAS do menu, que leva até a categoria DICAS, ele exibe os posts da categoria FOTOS.
    http://viviamlafeta.com.br/1/dicas/

    Quando testo o link da categoria FOTOS tá tudo certinho. Mas em dicas dá esse erro.
    Já conferi na postagem se marquei a categoria certa e está tudo ok.

    Segue código da index, category e single:

    INDEX.PHP

    <?php get_header(); ?>
    <div id="content">
    
    <div class="fotos-index-out">
    <div class="titulo">FOTOS</div>
    <?php query_posts('cat=fotos&posts_per_page=3'); ?>
    <?php while ( have_posts() ) : the_post() ?>
    <div class="fotos-index">
    <a href="<?php the_Permalink()?> "><?php the_post_thumbnail();	 ?></a>
    <a href="<?php the_Permalink()?> "><?php the_title(); ?></a>
    </div>
    <?php endwhile; ?>
    </div>
    <div class="clear"></div>
    
    <div class="index-dicas">
    <div class="index-dicas-in">
    <div class="titulo">DICAS</div>
    <div class="dicas-um">
    <?php get_template_part( 'nav', 'above' ); ?>
    <?php query_posts('showposts=3&cat=1'); ?>
    <?php while ( have_posts() ) : the_post() ?>
    <div class="tipo-post">
    <?php the_post_thumbnail();	?>
    <?php get_template_part( 'entry' ); ?>
    <p class="leia-mais"><a href="<?php the_Permalink()?> ">Leia mais >> </a></p>
    </div>
    <?php endwhile; ?>
    </div>
    </div>
    </div>
    </div>
    <?php get_footer(); ?>

    CATEGORY.PHP

    <?php get_header(); ?>
    <div id="content">
    <div class="dicas2">
    <div class="titulo"><?php
    global $post;
    $categoria = get_the_category($post->id);
    $nomeCategoria = $categoria[0]->cat_name;
    echo $nomeCategoria;
    ?></div>
    <div class="dicas2-in">
    
    <?php $query = new WP_Query('posts_per_page=1' . '&paged=' . $paged); ?>
    
    <?php if ($query->have_posts()): while ($query->have_posts()) : $query->the_post();?> <!-- Início Loop do wodpress -->
    
    <h1><?php the_title();?></h1><!-- Permalink chama o link do post completo e The_title pega o titulo -->
    <p><?php the_content(__('Leia mais'));?></p>
    <div id="comments">
    <h3><a href="http://twitter.com/home?status=<?php the_title(); ?> -> <?php the_permalink() ?> RT @XXXXXXXX">Compartilhe no Twitter</a><a class="fb-comment" href="http://www.facebook.com/share.php?u=<?php the_permalink() ?>&t=<?php the_title(); ?>">Curta no Facebook</a><?php comments_number(__(''), __('1 Comment'), __('% Comments')); ?> &raquo; <a href="<?php the_permalink(); ?>#postcomment" title="<?php _e("Leave a comment"); ?>">Ver/Comentar</a></h3></div>
    
    <?php endwhile; else:?>
    
    <?php endif;?>

    SINGLE.PHP

    <?php get_header(); ?>
    <article id="content">
    <div class="dicas2">
    <div class="titulo"><?php
    global $post;
    $categoria = get_the_category($post->id);
    $nomeCategoria = $categoria[0]->cat_name;
    echo $nomeCategoria;
    ?></div>
    <div class="dicas2-in">
    <?php get_template_part( 'nav', 'above-single' ); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h1><?php the_title();?></h1>
    
    <?php the_content(); ?>
    <?php comments_template('', true); ?>
    <?php endwhile; endif; ?>
    <?php get_template_part( 'nav', 'below-single' ); ?>
    
    </div>
    </div>
    </div>
    <?php get_footer(); ?>

    Alguém pode me ajudar neste problema?

    Abraço

Visualizando 3 respostas - 1 até 3 (de um total de 3)
  • Isaac Borges

    (@isaac-borges)

    seguinte, o erro pode estar em duas opções ou na chamada da query ou na chamada do link, me passa o o link do menu ou a maneira que vc está fazendo ele para ter uma ideia, e poder te ajudar

    Criador do tópico daniel cambui

    (@daniel-cambui)

    cara, agora que vi que o erro é outro. na verdade ele não está categorizando os posts. ele está exibindo todos da lista de publicação. como eu coloquei pra exibir apenas 1 por página, eu nem percebi este erro.
    aí ferrou tudo.

    Eduardo

    (@eduardozulian)

    Daniel, o que acontece é que você está criando uma nova query dentro do seu category.php. Dessa forma, o loop principal não tá sendo realizado e a sua categoria pouco importa dentro dele.

    <?php
    // A global $query_string preserva a query
    // anterior e te permite adicionar os parâmetros desejados
    global $query_string;
    query_posts( $query_string . '&posts_per_page=1' );
    ?>

    Dá uma olhada na documentação do query_posts também que há várias coisas legais pra melhorar seu código.

    Ah, mais uma dica: você pode, em seu category.php, usar a função single_cat_title() em vez de ficar dando voltar pra receber o nome das categorias!

Visualizando 3 respostas - 1 até 3 (de um total de 3)
  • O tópico ‘categoria exibe posts de outra categoria’ está fechado para novas respostas.