WordPress.org

Ready to get started?Download WordPress

Forums

Hide category posts in archives? and Change category background? (10 posts)

  1. mayonaize
    Member
    Posted 8 years ago #

    Forgive me, am new to this - just ported over my Blogger blog to WordPress and have modded the default Kubrick theme (mainly through trail and error) to how I'd like it to look etc. but there's a couple of things I'd still like to know if they're possible;

    1. I followed a post here about hiding a certain categories posts from appearing on the main page - which works fine. However, is it also possible to hide them from the archives too? At present if you go to say; Feb 06 and that month did feature a post from Category 2 (along side the normal posts in Category 1) it will appear there. Is it possible to ONLY be able to view those specific category posts by clicking on that categories link in the sidebar?

    Not sure that made complete sense, but anyway..

    2. I'd also like that category page to load different background images. At present I have changed all the kubrick jpegs to a blue colour, and saved an identical set in the same folder (called 2kubrick...jpg etc.) as a yellow colour. So, is there a way for the category 2 page to load up and use the yellow images instead of the blue ones used everywhere else?

    Phew, you can view the blog here. The category I'd like to make the changes to is called 'Press'. Can anyone help??

  2. moshu
    Member
    Posted 8 years ago #

    1. That's a bit complicated. I don't have an out of the box solution for that.
    2. See Category_Templates; Template_Hierarchy and other useful articles in WP's online manual the Codex.

  3. mayonaize
    Member
    Posted 8 years ago #

    Ok. That template stuff confused me completely but I know that for my second query it is all associated with the header.php file (which refers to the kubrick images), so I'm guessing that if I created a duplicate header file (called header2.php for example) that pointed to the other, altered pictures, I'd then have to do something someplace else to tell that when viewing the 'Press' category to use the header2.php file instead of the normal one??? Or something. No?

  4. moshu
    Member
    Posted 8 years ago #

    You have to understand the "temnplate stuff" before you can achieve what you described earlier. There is no shortcut :)

    And for category templates, see this thread:
    http://wordpress.org/support/topic/30653?replies=16

  5. mayonaize
    Member
    Posted 8 years ago #

    Ok. Still somewhat confused, but following that page as best I can I have created a category.php file that, at present, contains duplicated code from the page.php file, as follows;

    <?php get_header(); ?>

    <div id="content" class="narrowcolumn">

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><?php the_title(); ?></h2>
    <div class="entrytext">
    <?php the_content('<p class="serif">Read the rest of this page »'); ?>

    <?php link_pages('Pages: ', '', 'number'); ?>

    </div>
    </div>
    <?php endwhile; endif; ?>
    <?php edit_post_link('Edit this entry.', '', ''); ?>
    </div>

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    I understand that this now has to be edited to include something like <?php if ( is_category() ) : ?> somewhere to make it only work on the category pages (Press is cat 3 on my site I believe). And also I want it to use the other header2.php file I made don't I? Or do I somehow include that code in the category.php file?

    In my head this seems pretty simple; when in this category, use these images instead of these ones. I am however quite quite tired and feeling pretty moronic at the mo. ;)

  6. mayonaize
    Member
    Posted 8 years ago #

    Woo! I figured it out don't worry! Thanks for all your help.

  7. moshu
    Member
    Posted 8 years ago #

    Just for those that will come to read it later:
    1. The best thing for creating a category.php template is to start with the archive.php
    2. You don't need any "if category"-stuff: WP is smarter than that and recognizes the template. see Template_Hierarchy.
    3. You can have as many category templates as many categories you have: category-1.php, category-2.php etc.

  8. pati
    Member
    Posted 8 years ago #

    Hiding Posts from a category in the archive view:

    1. create a file archive.php
    2. define the style of the archive page and put the loop also in the file. before the loop you need to write the following:
    if(is_archive()){$wp_query->set('cat','-ID'); query_posts(''); }
    3. When you use the code above, you still can use the prev/next function.
    4. Want to exclude more than one category from archive --> define a category in which you put all the categories, you don't want to be shown.

    greets,
    pati

    ps: works also with is_home() ;)

  9. Kraetos
    Member
    Posted 7 years ago #

    I can't seem to make this work. I want to omit one category from my archives - ID 19 - so I used the following code on a template page names archives.php:


    <?php if(is_archive()){$wp_query->set('cat','-19'); query_posts(''); } ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <ul><?php get_archives('postbypost','','custom','<li>','</li>'); ?></ul>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    What have I done wrong?

  10. moshu
    Member
    Posted 7 years ago #

    archive.php - no S at the end!

Topic Closed

This topic has been closed to new replies.

About this Topic