WordPress.org

Ready to get started?Download WordPress

Forums

Suggestions on how to handle navigation. (12 posts)

  1. McCordRM
    Member
    Posted 4 years ago #

    So here's my site:
    http://www.richardmccord.com

    The purpose is to put my writing online for personal use. IE: Not a "company" website. The problem is that I can't seem to figure out how to handle the navigation.

    A one-page section is easy, such as my About The Author page. You click it in the top menu and you go to the Page.

    However, I have a Poems "Category". I'd like the visitor to click that option in the top menu and then have the Sidebar show the title Poems with the poems listed below by their title. Since poems are only one-page, they'll be page links.

    Then, there's the Stories "Category". When the visitor clicks Stories the sidebar should show it's Sub-Categories of Horror, Sci-Fi, etc. Then when the visitor clicks Horror (for example) the sidebar would show the title Horror with the stories listed by title. From there it's a further issue since Stories are many pages long. Once the visitor clicks a story title... how best to handle that? Have the sidebar change to the Pages being listed for that story?

    Anyhow, I'd really appreciate any suggestions since this is my first time dealing with WordPress and I obviously have no concept.

  2. keesiemeijer
    moderator
    Posted 4 years ago #

    You can use conditional tags in your sidebar.
    something like this:

    <?php if(is_category('poems')) : ?>
    <!-- do stuff -->
    <?php endif; ?>
    <?php if(is_category('stories')) : ?>
    <!-- do stuff -->
    <?php endif; ?>
  3. McCordRM
    Member
    Posted 4 years ago #

    That's sudo-Greek to me.
    I downloaded a Plug-in that I thought would do that automatically, but it doesn't seem to fit the bill: http://wordpress.org/extend/plugins/extended-categories-widget/

    When you say "do stuff", I have no idea what to tell it to do. Like I said, I'm just starting out with WordPress. You're talking to a guy that used Frontpage for years. I'm trying to make the sidebar dynamic based on what Top-level Category is chosen. Like I said, when you hit About the author, it goes straight to that one page. Easy. No sidebar required. But making a dynamic sidebar is proving rather difficult for me. I can have it show all categories and sub-categories, but not JUST sub-categories based on the Top-Level Category.

  4. McCordRM
    Member
    Posted 4 years ago #

    Here's something someone had suggested for my Sidebar:

    <div id="sidebar">
    <?php
    if (is_category()) {
      $this_category = get_category($cat);
      if (get_category_children($this_category->cat_ID) != "") {
        echo "<h1>Subcategories</h1>";
        echo "<ul>";
        wp_list_categories('orderby=id&show_count=0&title_li=
    &use_desc_for_title=1&child_of='.$this_category->cat_ID);
        echo "</ul>";
      }
    }
    ?>
    </div>

    The problem with this code is that it can tell if a Category has sub-categories beneath it... great. I know this because if you click a Top-Level Category that doesn't have any children then no Sidebar appears at all. If a Category does have children, however, instead of listing them it puts No Categories. Which, of course, isn't the case as my Stories Category has Horror, Sci-Fi, Fantasy and Western under it and Reviews has Books, Movies and Tv Shows.

  5. keesiemeijer
    moderator
    Posted 4 years ago #

    try this:

    <?php
    if(is_category()) {
    // we are on a category page
    // get current category id
    $category = get_query_var('cat');
    // show child categories of the current category
    wp_list_categories('child_of='.$category);
    }
    ?>
  6. keesiemeijer
    moderator
    Posted 4 years ago #

    Aha I see you posted your code. If categories don't have posts yet they will not show up. You can put this in your wp_list_categories &hide_empty=0

  7. McCordRM
    Member
    Posted 4 years ago #

    The theme has a built-in sidebar that displays the way I have it right now by default. The sidebar.php file has this in it:

    <div id="sidebar">
    
    	<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?>
    	<?php endif; ?>
    
    </div> <!-- end sidebar -->

    I like the way it looks, but not the way it functions. All I have to do is put the default Category widget in the Sidebar and that's what I get. I'm leaving this setup on my site so you can see it in action.

  8. keesiemeijer
    moderator
    Posted 4 years ago #

    try this and see if it looks the same but only shows the child categories:

    <div id="sidebar">
    
    	<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?>
    	<?php endif; ?>
    
    <?php if(is_category()) : ?>
    <?php
    $this_category = get_category($cat);
    if (get_category_children($this_category->cat_ID) != "") : ?>
    <div id="categories-3" class="block widget_categories">
    <h2>Sub Categories</h2>
    <img width="200" height="16" alt="Sidebar Hr" src="http://richardmccord.com/wp-content/themes/Polished/images/sidebar_hr.png" class="divider"/>
    <ul>
    <?php
    wp_list_categories('orderby=id&show_count=0&hide_empty=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID);
    ?>
    </ul>
    </div> <!-- end categories-3 -->
    <?php endif; ?>
    <?php endif; ?>
    </div> <!-- end sidebar -->
  9. McCordRM
    Member
    Posted 4 years ago #

    Holy shit, you rock. I haven't found ANYONE that could pull that off.
    You're a god, man. Do you have a website or something I can link to?

    EDIT
    Oh, and instead of <h2>Sub Categories</h2>, can I use the Echo command to have it put the name of the sub category being used?

  10. keesiemeijer
    moderator
    Posted 4 years ago #

    Maybe this is what you want
    <h2><?php $this_category->cat_name; ?></h2>

    You should really only just show categories that have posts. So after testing you should delete the &hide_empty=0 bit.

  11. McCordRM
    Member
    Posted 4 years ago #

    I got it figured out.
    Now I'm just trying to decide how best to handle the layout for
    stories. Poems are easy since they just take up a single Post.
    Stories have multiple Pages so the navigation is going to be
    something to figure out.

  12. McCordRM
    Member
    Posted 4 years ago #

    Oh, you didn't let me know if you have a website or something for me
    to link to for credit.

Topic Closed

This topic has been closed to new replies.

About this Topic