• CodePoet

    (@design_dolphin)


    Here is what I want to do. ๐Ÿ™‚

    In single posts have tabs in the sidebar which:

    1. automatically create tabs with the names of the tags based on the tags for the current post as labels.
    2. In each tab window show the posts titles for the tag.
    3. Create a table of contents similar to the AZIndex plugin automatically in each tab.
    4. Only show posts for the categories that I want to show. This to seperate tags which run across multiple categories but are not related.
    5. Tabs switch on hover.
    6. W3C and Accessibility standards, javascript degrade gracefully. (I don’t think a pure css solution will be possible, but it might.)
    7. Keep size and load to a mininum and keep it loading quick.

    The reason I ran into this is that I started using related articles based on tags, which is simply awesome. Except as you can see in the following examples it looks great, I think, when you have a few posts, but when the post count runs higher it would be better, in my opinion, to orden the posts. One solution would be to show the tags and give visitors the ability to click on these, but then a new page has to be openened.

    Example 1 a few related posts:
    http://www.coolgrafimedia.com/chronisch-zieken-en-gehandicapten/beleid/moeten-chronisch-zieken-en-gehandicapten-kunnen-blijven-studeren-als-zij-een-uitkering-ontvangen.html

    Example 2 many related posts:
    http://www.coolgrafimedia.com/milieu/flow-plan-for-less-talk-and-more-action-as-climate-change-hits-rivers.html

    With example 2 I added an search function, but have been unable to duplicate this for other categories.

    Technically it should be possible to create the tabs automatically. I haven’t been able to find anything which does, yet. (The word “tags” is not the world’s easiest thing to search for. ๐Ÿ˜‰ ) However, I did find that it is possible to create dynamic tabs with javascript:
    http://dev.medryx.org/lib/js/dojo-extensions/dojox/widget/tests/test_DynamicStackContainer.html

    So it would be a matter of writing the php and giving it css.

    The exact specifications could differ for different websites (sections) For me the important part would be the automatically generation of tabs.

    So far I have the following, which is still buggy, because I haven’t been able to get it to respect the list only posts from the current related children categies and relevant tags. There have been different versions, but once the “cat=>” is sorted this will dynamically show related posts for the tags in the current post within the categories selected (in this case they are all children categories of parents with no relation, hence the “cat_name” for current category). Leave out the “cat=>” and preliminary testing shows that it will show related posts. Further testing is needed though.

    <ul>
     <?php
       global $post;
       foreach(get_the_tags($post->ID) as $tag) {
          $show_tags .= $tag->name . ',';
    $rel_art .= rtrim($show_tags , ',');
    }
     $args = array(
    	'numberposts' => -1,
    	'tag'=> $rel_art,
          'cat'=> cat_name,
           'exclude'=> $post->ID,
           'orderby'=> title,
            'order'=> ASC,
    	);
     $myposts = get_posts($args) ;
     foreach($myposts as $post) :
    
     ?>
        <li class="your_class_here"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
     </ul>

    Well that’s the theory, anyway. One thing that would have to be seen is would this still be practical if there are 3000 or 25,000 related posts.

    I will be working on this the next couple of weeks other people are welcome to join in. ๐Ÿ™‚

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter CodePoet

    (@design_dolphin)

    Solved the tab headings creating themselves for the most part.

    Still needed to solve a counting integer for “tab-id” this could make life a lot easier. The “tab-id” counter could be used for example with javascript. The location of tab-id in the code snippet below is illustrative.

    Code below subject to peer review

    <?php
       global $post;
       foreach(get_the_tags($post->ID) as $tag) {
          $show_tags .= $tag->name;
          $count_tags = count($show_tags);
          $show_url .= "<li><a href=\"tag_id-" . $tag->term_id . " and tab-id-$count_tags" . "\"" . "title=\"Open tab: " . $tag->name . "\"" . ">" . $tag->name . "</a></li>" ;
     }{
    echo "<ul>" . $show_url . "</ul>";
    }?>

    P.s:
    A suggestion if I may. Why not rename function “tags” to “wp_tags”? It could make life a lot easier with searching for the subject. ๐Ÿ™‚

    Thread Starter CodePoet

    (@design_dolphin)

    Getting there/ Code still needs to be reviewed:

    The following code creates the tabs and the content divs framework automatically based on the existing tags coupled to a post when viewed in single post view. The tabs and divs have automatically created matching numbering:

    <?php
       global $post;
       foreach(get_the_tags($post->ID) as $tag) {
       $x = $x + 1;
          $show_url .= "<li><a href=\"#tab" . $x . "\"" . "title=\"Open tab: " . $tag->name . "\"" . ">" . $tag->name . "</a></li>" ;
     }{
    echo "<ul>" . $show_url . "</ul>";
    
    }?>
    
    <?php
       global $post;
       foreach(get_the_tags($post->ID) as $tag) {
       $y = $y + 1;
          $show_div .= "<div id=\"#tab" . $y . "\"" .">" . $tag->name . "</div>" ;
     }{
    echo "<div class=\"main_content_pane" . "\"" .">" . $show_div . "</div>";
    
    }?>

    Still needed to figure out:

    How to place the dynamic content in the tab div based on a predefined variable (in this case a tag) + code checking, tweaking and/ or clean-up.

    Thread Starter CodePoet

    (@design_dolphin)

    Still needed to figure out:

    How to place the dynamic content in the tab div based on a predefined variable (in this case a tag)

    Solved this part, See here:
    http://wordpress.org/support/topic/264195?replies=6

    Still left to do:
    code rewrite to implement the new code that solves the posts being shown, code checking, tweaking, and/ or clean up. Implementing javascript for tabs, or optionally css (in some if not all cases, depending on (wanted) usage and placement) can be used.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Automatically created tag tabs which show relevant posts’ is closed to new replies.