• I should preface this question with a statement: I don’t have “mad crazy skillz” with PHP so feel free to speak slowly and use exaggerated hand movements.

    I’m using WP for a client’s site to manage their news, events and press releases. Ideally, they’d like the homepage to display 3 tabs, 1 tab for each category. News is open by default, the other two tabs are inactive. You click and tab and presto! the posts related to that category appear.

    Is it as simple as assigning a tab to a category URL? In other words, <a href="#" rel="/wordpress/?cat=3">News</a>

Viewing 15 replies - 1 through 15 (of 34 total)
  • In header.php of the theme you are using, change <?php wp_list_pages; ?> with <?php wp_list_categories; ?>.

    That should do it.

    One more thing. If they are creating more than 3 categories, but they only want 3 tabs to show, then use template tags for wp_list_categories.

    If they will only create 3 total, than it’s fine as above.

    Thread Starter jhames

    (@jhames)

    Thank you for the tip on wp_list_categories, buddha trance. I’m using the following code to define the category tabs:

    <?php wp_list_categories('orderby=name&include=3,4,5' . 'exclude&title_li='); ?>

    The next step, after I apply CSS to each list item and create tabs, is to link each tab with its category. Is there a simple way to wrap an a tag around the categories?

    Thread Starter jhames

    (@jhames)

    The links should be automatically created, once the categories are listed with wp_list_categories.

    Assign a category to each relevant post, and when you click on the tab, it will take you to the list of posts of that category.

    It seems like you already have that working for you.

    So, all you have to do is to create new categories in admin –> Manage –> Categories –> Add New, and then assign them to each post.

    I am understanding the question correctly?

    Thread Starter jhames

    (@jhames)

    Totally follow you there. What I want to do is lead with “News” which has a white tab to indicate it’s selected. I thought I could somehow add an argument to <?php wp_list_categories('orderby=name&include=3,4,5' . 'exclude&title_li='); ?> but I’m not sure where to place current_category=1 in the tag. I tried include=3,4,5&current_category=1 but that didn’t seem to work.

    I see, you want to have active tabs.

    Do it in the style.css of your theme, with a ul class="menu" in your theme header.php

    ul.menu li a {
    color:#fff;
    }

    Let me know if this worked for you.

    Thread Starter jhames

    (@jhames)

    Part One:

    Each tab should have an off and on state. News, by default, will be on and therefore white. The other two tabs will be gray.

    If wp_list_categories can set the News tab to current, then I can use CSS to give it a white tab background.

    Part Two:

    Within <?php if (have_posts()) : ?>, do I need to add, delete or edit any of the default code to tell WP that I only want to see entries under category “News” because the tab “Latest News” is active?

    Part One:

    Sorry, I gave you the wrong part of the code…

    See, the funny part is that I do have active tabs, in my template. Looking there for reference.

    style.css

    ul.menu li.current_cat a, ul.menu li.current_cat a:hover {
    background:#fff;
    }

    In header.php, try this way

    <li class="current_cat=1<?php } else { ?>cat_item<?php } ?>"><a title="<?php bloginfo('name'); ?>" href="<?php bloginfo('url'); ?>">News</a></li>
    
    	<?php wp_list_categories('depth=1&title_li=&exclude='); ?>

    Part Two:

    I don’t think so, because the categories already pull the posts tagged with them.

    I found this reference about category lists.

    Thread Starter jhames

    (@jhames)

    I tried your code and the following list appeared:

    • News
    • Events
    • Latest News
    • Press Releases

    I removed the first list item tag and my result was the same as before but without “News”.

    *sigh*

    Let me download your theme…

    Looking at your page now, the tabs are gone. Just a list.
    Hold on…

    I looks like you customized the style from the Default theme, is that right?

    jhames,

    correction to Part Two, as I noticed the home page still pulls the main loop.

    Yes, edit using query posts

    <?php
    query_posts('cat=3');      //retrieves category 3 only
    ?>
    Thread Starter jhames

    (@jhames)

    I did customize the style from the Default theme. Is it possible to ignore header.php, sidebar.php and footer.php, and simply work with index.php?

Viewing 15 replies - 1 through 15 (of 34 total)
  • The topic ‘Work with index.php to display a tab for created categories’ is closed to new replies.