Forums

customizing the appearance of category links (3 posts)

  1. rstritmatter
    Member
    Posted 2 years ago #

    Greetings, folks. I have what should be a simple question for some of you theme experts out there. As you can see from the link to my site, I have set up a series of pages using the tab function.

    http://shake-speares-bible.com/

    However, I want these Pages to behave like Categories, so that I can add multiple posts within each one. So I set up one of them (dissertation) as a way to enable that functionality. You can see it in my Category list on the left side column.

    I could migrate all the Page content to Categories and then delete the Pages, but I would like the Category topics to show up in the tabs, rather than on the side column, as they do in the default.

    How do I do that neat trick?

    Thanks in advance to whoever can solve this riddle for me. :)

  2. spstieng
    Member
    Posted 2 years ago #

    Do as what I have done for my website http://www.norwegianfashion.no.

    This is what I have done:
    Created page A, B, C
    Created category A, B, C (same name as pages for simplicity)
    Created a template that lists posts by category.
    Set the pages to use this template
    Create a metatag called categories
    Enter which cateory / categories you would like to list on this page

    And voila, tehre you go.

    Here is some code to get you starting. It's untested - just snipetsfrom what I use:

    <?php
    /*
    Template Name: List Posts by category
    */
    
    get_header();
    
    echo '<div id="mainArea">'; 
    
    /*
      Get 'show_categories' page attribute to see
      which categories the posts are to be listed from.
      If no value, no posts will be listed.
      The values must be entered like this: 3,5,13 etc.
    */
    
      unset($categories);
      // Get the data from meta tag category_id
      $categories = get_post_meta($post->ID, 'category_id', true);
    
      // If no value is entered, the page will display information text
      if(empty($categories)) :
      	echo '<div id="articleListTextBox">';
    			echo 'Kategoriverdi ikke angitt for siden <br />';
    		echo '</div>';
      else:
    
        // Get current page. Is used for pagination.
        $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
        //Run the query and get the posts for selecteed categories
        query_posts("cat=$categories&paged=$page&order=DESC");
    
        //Display page navigation if enough posts and in use.
       	if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
    
        // List all posts
        	if (have_posts()) : while (have_posts()) : the_post(); ?>
            <div class="post">
              <a href="<?php the_permalink(); ?>"> <?php the_title('<h3>', '</h3>'); ?> </a>
            <?php  the_content('[Read more]'); ?>
            </div>
          <?php
          endwhile;
          endif;
          ?>
    <?php
      endif;
    
      get_sidebar();
      get_footer();
    ?>
  3. rstritmatter
    Member
    Posted 2 years ago #

    Hi spstieng,

    Many thanks for the prompt and lucid suggestion. It will take me a bit of time to absorb and understand what you are saying (just because I'm still a newbie), but I will report back on my progress in another day or two.

    Actually, I do have one follow up question. When you say, "create a template," based on the code you provide, can you elaborate just a bit? Where does this template go in the file structure of the site, and how do I make sure that the pages refer to it? Maybe you could point me to a resource on this topic, if answering in detail is too time consuming or redundant.

    Ok, I have the answer to the second part of my question, about setting the page the follow the template. For others for whom this might be useful, its here: http://codex.wordpress.org/Pages#Page_Templates

    But that's the part of your post that is most technical and obscure to me.

    thanks

    cheers,

    RS

Topic Closed

This topic has been closed to new replies.

About this Topic