• Hey!
    I’m creating my first wordpress template and it fun.
    As I started to build the category.php page that suppose to show only the posts in the category that you browse ,I noticed that it shows all the posts in the site and not only the one that belong to the category you browse in.

    I tried to modify the LOOP but it didn’t worked out.
    This is the begging of the LOOP where I get to the post query

    <?php $current_category = single_cat_title(“”, false); ?>
    <?php query_posts(“category_name=$current_category”); $i = 1; ?>

    What am I doing wrong?

Viewing 7 replies - 1 through 7 (of 7 total)
  • A “common” archive file does not need to necessarily have its type identified prior to the loop.

    For instance, if you copy your index.php file and name it category.php, modifying the “new” file to taste. Now, when you click on a category on your blog it will show all posts that have that category attached to them (which may include posts from other categories as well).

    That being the case, without knowing more of your intent with the template file, you might try your category template without the lines of code you posted above … unless they are needed for other purposes.

    PS: Here is some additional reading that may help, too: https://codex.www.ads-software.com/Category_Templates

    Thread Starter diyphotographystuff

    (@diyphotographystuff)

    Hey,thanks for the reply.
    When you wrote:
    Now, when you click on a category on your blog it will show all posts that have that category attached to them (which may include posts from other categories as well).

    “(which may include posts from other categories as well)”
    You ment that there might be posts that are taged to many categories?

    Yes if they’re also in the category requested (that would happen even with your code).

    What cais is saying, is that you don’t need to do the query_posts line, just the while loop is fine, wordpress will handle the requested category for you automatically (it’s suppose to)..

    Thread Starter diyphotographystuff

    (@diyphotographystuff)

    Sorry guys but even as I deleted the query_posts stuff it still shows all the posts in the blog…
    I’m doing a regular LOOP
    What might be wrong?

    Might be easier if you just post up the complete code (use a pastebin – link below).

    So anyone looking can spot if there are errors that may cause a problem.

    https://wordpress.pastebin.ca/

    Also consider the template hierarchy.
    https://codex.www.ads-software.com/images/1/18/Template_Hierarchy.png

    You may have another template file taking priority, such as category-ID.php or category-SLUG.php , where ID and SLUG are a numeric id and an actual category slug respectively..

    Thread Starter diyphotographystuff

    (@diyphotographystuff)

    I’ll try the category-id.php
    as my category-name is in hebrew,and it might cause some problems

    Thread Starter diyphotographystuff

    (@diyphotographystuff)

    Here is the code I’m talking about:

    <?php $aa=0;?>
              <table ><tr>
              <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
              <?php if(!($aa%4)){ echo"</tr><tr>"; }?>
              <td>
              <div class="post_con">
              	 <?php $words = 30;
                  $content = get_the_excerpt();
    	          $excerpt = explode(' ',$content); ?>
                    <h4 ><a href="<?php echo the_permalink(); ?>"
                    				title="<?php echo('Permanent Link to') ?>
                    <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
                    <img class="centered" src="<?php $values = get_post_custom_values("thumb"); echo $values[0]; ?>"
                     class="thmb" />
                    <p><a href="<?php echo get_permalink($postid) ?>"><?php echo('??? ?? ????') ?> &raquo;</a></p>
                  <?php $aa++;?>
              <?php endwhile; ?>
    		  <?php else: ?>
                <h2 class="center"><?php echo('No Featured Articles') ?></h2>
                <p class="center"><?php echo('Create a category called &quot;Featured&quot;.
                							 Articles in that category will be shown here.') ?></p>
              <?php endif; ?>
    			</div>
             </td>
    
              </tr>
              </table>
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Help me solve creating a category.php “problems”’ is closed to new replies.