Tag-posts usage

Hello,

I'm trying to implement the plugin Tag-Posts. It seems I don't understand something regarding its usage. Here is what I have.

- Post-Indexer and tag-posts are installed, I wrote a test post tagged 'test'
- On my WPMU install I have a template dedicated to displaying tags (tag.php).

- In tag.php template, I call the plugin like this :

At the very top of the template, I do this :

$gthe_tag = wp_title('', false);
echo $gthe_tag; // Just to check the variable contains something - and yes, that works because it displays 'test'

Then in the template, I have :

<?php tag_posts_display_recent($gthe_tag,10,40,150,'','<strong>','</strong>','
<ul>','</ul>
','
<li>','</li>
');?>

There is a problem : it should show results for tag 'test' but it doesn't show anything.

BUT : if I replace $gthe_tag by 'test', the plugin DOES show the results for the tag 'test'.

I don't understand... can you please tell me what is the right usage for your plugin ?

Last question : what if I want to show a global tag cloud in the sidebar of the pages ? Does the plugin can handle that ?

Thanks a lot for your support,

Gautier

  • Gautier_Girard

    Hi Ron_r,

    Thanks for your reply. Unfortunately it doesn't work. It still doesn't show anything.

    Here is the code of my tag.php template :


    <?php get_header();
    global $gthe_tag;
    $gthe_tag = wp_title('', false);
    echo $gthe_tag;
    ?>
    <div class="post">
    <h1 class="section-header"><?php single_tag_title(); ?></h1>
    <div class="entry">
    <?php _e('You are browsing the archives of','visionary'); ?> "<?php single_tag_title(); ?>".
    </div>
    </div>
    <div class="post">
    <div class="entry">
    <?php tag_posts_display_recent($gthe_tag,50,40,150,'
    ','','','

      ','
    ','
  • ','
  • ');?>
    </div>

    </div>
    <?php get_footer(); ?>

    I don't understand why it doesn't work. The echo $gthe_tag; displays test. But the tag_posts_display_recent function doesn't return anything while used with $gthe_tag. This function does return the result for test if I put 'test' instead of $gthetag.

    Thanks,

    Gautier

  • Gautier_Girard

    Hi Andrew,

    Thanks for your reply. So now I do a trim() to the variable before calling the plugin... and yes, now tag-posts does show results.

    I did a small patch to the plugin : currently it doesn't actually link to the posts returned.
    So if WPMU users want to add a link to each post, they can alter tag-posts.php at line 45 and replace your code with this one :

    echo '< a title="' . substr($tmp_post['post_title'],0,$tmp_title_characters) . '" href="' . $tmp_post['post_permalink'] . '">' . substr($tmp_post['post_title'],0,$tmp_title_characters) . '< /a>';

    (EDIT - delete two spaces : at the beginning of the line between the < and the a, and at the end between the < and the /a>

    With this code, Tag-Posts will also link to each post containing the tag. Feel free to update the plugin if you want to add this feature for others.

    # Tag Cloud

    Do you think it should be possible to take the code from the standard WP tag_cloud function. And modify it to use sitecategories and site_posts tables for building a global tag cloud ? I don't remember if the standard WP tag_cloud function uses term_relationships and term_taxonomy tables to do that ?

    Maybe there is a better or easier way to do that ?

    Thanks a lot,

    Gautier

  • Gautier_Girard

    Hello,

    I've made a very simple script that will later display a tag cloud. For now, it just display a flat list.

    I have a problem with sitecategories table : My plugin displays everything in it, including the default category and 'blogroll'.

    How can I differenciate whether a row is a category, a tag, or something else ?

    My SQL query is:

    $query = "SELECT cat_ID, cat_name, category_nicename FROM " . $wpdb->base_prefix . "sitecategories LIMIT $tmp_number;";

    If I check the table site_posts, the column post_terms contains the post category, and the post tags.
    Also, I don't know why but your plugin post-tags.php won't display a 'tag' if it is actually a category... it returns stuff only if it is actually a tag.

    Then I'm stuck...

    Can you please help me ?

    Thanks in advance,

    Gautier

  • Andrew

    Hi Gautier,

    How can I differenciate whether a row is a category, a tag, or something else ?

    There's really not a way to easily differentiate whether a row is a tag or category. We just consider them all tags.

    If I check the table site_posts, the column post_terms contains the post category, and the post tags.

    Yep. We just consider them all to be tags for simplicity.

    Also, I don't know why but your plugin post-tags.php won't display a 'tag' if it is actually a category... it returns stuff only if it is actually a tag.

    Are you sure? I've used this plugin and many sites and have never seen that behavior.

    Thanks,
    Andrew

  • Gautier_Girard

    Hi Andrew,

    Thanks for your reply.

    Actually my tag.php template returns a 404 error. It seems to be due to the fact that WPMU recognizes the category... as a category and not as a tag.

    "non-classe" is the slug of my category.

    If I go to mysite.com/category/non-classe it works because I do have a category "non-classe" on the main WPMU install. "non-classe" is the default WPMU category.

    If I go to mysite.com/tag/non-classe it doesn't work because I don't have any tag "non-classe" on the main WPMU install nor in other blogs.

    I don't have any clue on how to solve this.

  • Andrew

    Hiya,

    Have you tried creating pages for the the tags/categories giving you the problem? Basically if /tag/something is tossing a 404 due to it recognizing something then create a page with your template at /tag/something.

    That's one possible workaround. The other way is a touch more complex and I can't spend the time detailing it here. However what I can do is send you a plugin that uses it if you wish.

    Thanks,
    Andrew

  • Gautier_Girard

    Hi Andrew,

    I haven't tried. If I use this method, I'll have to create a page for each category created by bloggers ? I'm not sure to want that.

    What is the other method Andrew ?

    Alternatively, I haven't played much with URLS and URL rewriting... but it may work using them ?

    I could add the code to a new template 'global_tags.php', tell my .htaccess to call global_tags.php?tag=xxx if one goes to mysite.com/global_tags/xxx ?

    Your help is much appreciated.

    Thanks,

  • Luke

    Have you tried creating pages for the the tags/categories giving you the problem? Basically if /tag/something is tossing a 404 due to it recognizing something then create a page with your template at /tag/something.

    Unfortunately, I've seen WP do this as well and even when using the internal rewrite structure. Unfortunately, it wasn't something that had a predictable pattern either. I didn't spend much time trying to track it down, but the page option worked just fine.

    While this wasn't exactly based around tags, it's similar in the overall concept. What's really strange, is that it wouldn't necessarily affect just any particular slug which was also a category. It was pretty random. That being the case, for me it was just easier to add a page or two. If it's something where it's happening more frequently, you may have to massage the rewrite global with a filter, and check the request uri for /tags/, etc. and then unset part of the rewrite rules for those page loads.