• jberglund

    (@jberglund)


    Morning everyone!
    I’m using the Kubrick/Default template in my blog and want to be able to make my different categories have different ‘styles’ – ie, a different header, color scheme, etc.

    From what I can figure out (from previous posts), I think I first need to have a category page. So, my first question: How do I use the default ‘index.php’, save it as a ‘category.php’ file, and change the php in it to be a ‘category’ page?

    Here is the code from that part of the index.php file:
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class=”post”>
    <div class=”small”>Posted in <?php the_category(‘&’);?> <?php the_time(‘d M Y h:i a’); ?> <!– by <?php the_author() ?> –></div>
    <h2 id=”post-<?php the_ID(); ?>”>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></h2>

    <div class=”entrytext”>
    <?php the_content(‘Read the rest of this entry »’); ?>
    </div>

    <p class=”postmetadata”><?php edit_post_link(‘Edit’,”,’|‘); ?> <?php comments_popup_link(‘No Comments »’, ‘1 Comment »’, ‘% Comments »’); ?>

    <!– <?php trackback_rdf(); ?> –>
    </div>

    <?php endwhile; ?>

    I’m VERY new to php. Can someone tell me what I need to change here to create a category page?

    Any and all help greatly appreciated.
    Thanks!

Viewing 15 replies - 16 through 30 (of 30 total)
  • Thread Starter jberglund

    (@jberglund)

    I’m not sure what template pages Neptune uses. I used Kubrick (default). It’s built with sections – header.php, footer.php, sidebar.php… etc.

    I placed the above code in the ‘header.php’ file above ‘The Loop’.

    (The header.php file – in Kubrick – contains all call for the style sheets, like a typical index.php page normally would. By doing this, you can make a change to that file only, and it will make changes across ALL pages it is embedded inside – index.php, page.php, category.php, single.php… etc.

    Does that make sense?

    hayscg

    (@hayscg)

    Yes Thanks.

    We can use the is_category( ) tag instead of if else. Cuts the php by 80%.

    JBerglund:

    Can you please give me a hand with this. I’m using the Landzilla theme and all the calls for the CSS is located in the index.php. In fact, everything is in there. My blog is http://www.yunglee.com

    Please have a look if you can and let me know where I need to insert the code and if I need to make any alterations to the code you have provided. Thank you.

    We can use the is_category( ) tag

    Does anybody know what that would look like instead?

    Also, I’m confused about the header image call part that I’m supposed to put in the header. Why can’t I call my header image in each css like this:

    #header {
    background: url(‘category4.jpg’) no-repeat bottom;
    height: 185px;
    margin: 0 auto;
    width:700px;
    padding:0;

    That’s how I call my header image now…
    Thanks!

    Anybody?

    1. About the is_category see the Conditional tags in Codex http://codex.wordpress.org/Conditional_Tags
    2. Depending on your theme you can have the call for the header image either in the header (see the examples above in this thread) or in your css files for the given category.

    Wow, this thread is fantastic. Thank you for the info. My header file is a little different — it doesn’t extend below </head> so that I can really change the entire template when the category changes. Anyway, I built my css switcher a little differently and thought I should share:

    <style type="text/css" media="screen, projection">
    @import url(<?php bloginfo('template_directory'); ?>/global.css);
    @import url(<?php
    if ( is_category('3') ) { //FPO
    bloginfo('template_directory');
    echo "/support.css";
    } elseif ( is_category('4') ) { //Support Category
    bloginfo('template_directory');
    echo "/support.css";
    } else { //Home Page
    bloginfo('stylesheet_url');
    }
    ?>);
    </style>

    This allows me to use a global stylesheet that carries styles used throughout the site and then add in additional, category specific styles as necessary.

    My category.php file looks like this:

    <?php
    /*
    Template Name: Category
    */
    ?>

    <?php get_header(); ?>

    <?php
    if ( is_category('3') ) {
    include(TEMPLATEPATH . '/category3.php');
    } elseif ( is_category('4') ) {
    include(TEMPLATEPATH . '/support.php');
    } elseif ( is_category('5') ) {
    include(TEMPLATEPATH . '/category5.php');
    } elseif ( is_category('8') ) {
    include(TEMPLATEPATH . '/category8.php');
    } elseif ( is_category('13') ) {
    include(TEMPLATEPATH . '/category13.php');
    } elseif ( is_category('15') ) {
    include(TEMPLATEPATH . '/category15.php');
    }
    ?>

    <?php get_footer(); ?>

    Hope this helps someone. πŸ™‚

    Here’s a question: How do I write is_category() to include more than one? This doesn’t work:

    if ( is_category('3', '5', '6') ) {

    It was just a guess. πŸ™‚ I’m sure if I keep digging, I’ll find the answer…

    Answering myself. You write it like this:

    elseif ( is_category('3') || is_category('5') || is_category('6') ) {

    I happened to be in the same business πŸ™‚

    I applied nateomedia’s solution (the style part only) to change the background picture for a specific post and it worked.
    I would have liked to change the condition based on post id to narrow down on one single post because I plan to have similar posts with different background pictures and styling.
    However the respective conditional tag is_single() did not work for some reason.
    Could anybody advice me how to achieve this ?

    @kassad,
    it should work like is_single(23) – where 23 is the post ID#.
    At least according to Codex…
    http://codex.wordpress.org/Conditional_Tags

    Edit. You can also take a look at this thread:
    http://wordpress.org/support/topic/35053

    Thanks, Moshu !
    That, I did, exactly. Unfortunately, for some reason, it did not work.
    Browsing through the information you mentioned, it seems to me that everything is chained to the categories. It works, but when I choose the post from the Archive, it loses the preferences.
    It should have been the more elegant solution to tie the post to the id. So, it looks I shall have to take the other way, using several single files.

    Though, it is not urgent as the category chaining works beautifully even if with limitations. If you care to look at:

    Unique background

    If I have a working solution, I will post it.
    Thanks, again πŸ™‚

    Well, Moshu πŸ™‚

    Your were right. Nateomedia’s code works.
    Certainly, my level of erring hit the top.
    All in all, it was quite an exhausting but nevertheless interesting experience.
    I crunched myself through all the possible variants, all worked within their limitations.
    In the end, I just sticked to my origial concept as I sure will make every post individual in appearence.
    The point I missed due to my wooden mind was, that this works only if the call is for post id. Calls for categry, archives will result in loosing the preferred style. As a temporary solutions, I use the Recent Posts plugin and annotate the specific posts with asteriks. This is viable for a “two-person” blog like mine is. Certainly, I will search some other method, there are promising scripts here and there, mostly AJAX.
    I understand that this approach is very much different than the traditional one where people stick to one template generally.
    I do not want to switch theme, rather I would switch style for every or a lot of posts to make the user exprerience more rich, making the blog more lively.

    I wonder, if anybody would pick up this idea and could make a viable plugin for the purpose.

    Eh… sorry, in my previous post the link was screwed.

    My Presentation

Viewing 15 replies - 16 through 30 (of 30 total)
  • The topic ‘Creating a Category page in Kubrick’ is closed to new replies.