• Resolved grezliq

    (@grezliq)


    Hello

    I have a problem.

    I have one, basic category – it’s blog.
    I added the second one – news.

    And.. on my site, when I’m opening category “news” it shows posts from blog.
    I don’t know what is wrong.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Michael

    (@alchymyth)

    what theme are you using?

    does the theme have a category.php or, if not, an archive.php?

    what is the code in those templates?

    Thread Starter grezliq

    (@grezliq)

    category :

    <?php
    /**
     * The template for displaying Category Archive pages.
     *
     * @package WordPress
     * @subpackage Twenty_Ten
     * @since Twenty Ten 1.0
     */
    
    get_header(); ?>
    <div class="page_img">
    	<?php
    
    	 if ( has_post_thumbnail(6))
    	 {
    		$image = get_the_post_thumbnail( 6 , 'page_photo' );
    	 	echo $image;
    	 }
    	 ?>
    
    </div>
    		<div class="page_content">
    
    				<h1 class="page-title"><?php
    					printf( __( '%s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' );
    				?></h1>
    				<?php
    					$category_description = category_description();
    					if ( ! empty( $category_description ) )
    						echo '<div class="archive-meta">' . $category_description . '</div>';
    
    				/* Run the loop for the category page to output the posts.
    				 * If you want to overload this in a child theme then include a file
    				 * called loop-category.php and that will be used instead.
    				 */
    				get_template_part( 'loop', 'category' );
    				?>
    
    			</div><!-- #content -->
    
    <?php get_footer(); ?>

    Archive:

    <?php
    /**
     * The template for displaying Archive pages.
     *
     * Used to display archive-type pages if nothing more specific matches a query.
     * For example, puts together date-based pages if no date.php file exists.
     *
     * Learn more: https://codex.www.ads-software.com/Template_Hierarchy
     *
     * @package WordPress
     * @subpackage Twenty_Ten
     * @since Twenty Ten 1.0
     */
    
    get_header(); ?>
    
    		<div id="container">
    			<div id="content" role="main">
    
    <?php
    	/* Queue the first post, that way we know
    	 * what date we're dealing with (if that is the case).
    	 *
    	 * We reset this later so we can run the loop
    	 * properly with a call to rewind_posts().
    	 */
    	if ( have_posts() )
    		the_post();
    ?>
    
    			<h1 class="page-title">
    <?php if ( is_day() ) : ?>
    				<?php printf( __( 'Daily Archives: <span>%s</span>', 'twentyten' ), get_the_date() ); ?>
    <?php elseif ( is_month() ) : ?>
    				<?php printf( __( 'Monthly Archives: <span>%s</span>', 'twentyten' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'twentyten' ) ) ); ?>
    <?php elseif ( is_year() ) : ?>
    				<?php printf( __( 'Yearly Archives: <span>%s</span>', 'twentyten' ), get_the_date( _x( 'Y', 'yearly archives date format', 'twentyten' ) ) ); ?>
    <?php else : ?>
    				<?php _e( 'Blog Archives', 'twentyten' ); ?>
    <?php endif; ?>
    			</h1>
    
    <?php
    	/* Since we called the_post() above, we need to
    	 * rewind the loop back to the beginning that way
    	 * we can run the loop properly, in full.
    	 */
    	rewind_posts();
    
    	/* Run the loop for the archives page to output the posts.
    	 * If you want to overload this in a child theme then include a file
    	 * called loop-archive.php and that will be used instead.
    	 */
    	 get_template_part( 'loop', 'archive' );
    ?>
    
    			</div><!-- #content -->
    		</div><!-- #container -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    Michael

    (@alchymyth)

    nothing suspicious in category.php;

    when I’m opening category “news” it shows posts from blog.

    what is the relation ship between those two cats?
    are both top level categories?

    are you using any plugins?
    – is so, try to temporarily deactivate all plugins, to see if that helps.

    you can then reactivate one plugin at atime to locate the interfering one.

    does your problem change if you temporarily switch to the unedited default theme Twenty Twelve or Twenty Eleven?

    Thread Starter grezliq

    (@grezliq)

    Ok I think I know what’s wrong, but don’t know how to fix it:

    As we can see, there’s a code in category template:

    /* Run the loop for the category page to output the posts.
    				 * If you want to overload this in a child theme then include a file
    				 * called loop-category.php and that will be used instead.
    				 */
    				get_template_part( 'loop', 'category' );
    				?>

    And we look into loop.php:

    <?php
    	/* Start the Loop.
    	 *
    	 * In Twenty Ten we use the same loop in multiple contexts.
    	 * It is broken into three main parts: when we're displaying
    	 * posts that are in the gallery category, when we're displaying
    	 * posts in the asides category, and finally all other posts.
    	 *
    	 * Additionally, we sometimes check for whether we are on an
    	 * archive page, a search page, etc., allowing for small differences
    	 * in the loop on each template without actually duplicating
    	 * the rest of the loop that is shared.
    	 *
    	 * Without further ado, the loop:
    	 */ ?>
    
    <?php
                $i = 0;
    		?>
     <?php query_posts($query_string . '&cat=1'); ?>
     <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
     <div class="blog-left">
    <?php if($i%2!=0) {  ?>
    
     <div class="post">
     <?php $photo = array(get_the_post_thumbnail( $post->ID, 'blog_photo')) ;?>
    ...

    So we can see that if I open any category, it shows posts from category id=1.

    How to change it? I have two categories in menu, both of them shows posts from category id=1… I would like to fix it.

    Michael

    (@alchymyth)

    So we can see that if I open any category, it shows posts from category id=1.

    remove the line

    <?php query_posts($query_string . '&cat=1'); ?>

    the line should not be there – unless you want to restrict the posts of the start page to a certain category;

    please give more details about the planned organisation of your site …

    Thread Starter grezliq

    (@grezliq)

    I deleted it. It’s ok now.

    Thank you so much.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Category shows wrong posts’ is closed to new replies.