Support » Fixing WordPress » Comment With Tag Based Permalink

  • amidknight

    (@amidknight)


    As of now I do not have an example link; however, I will try to be as descriptive as possible regarding the issue.

    Permalink Structure
    /%tag%/%year%/%monthnum%/%postname%/

    I would like to add commenting. I have added the form.

    Issue 1:
    When a comment is submitted – the redirect is (if posted today):
    http://wpurl.com/%tag%/2009/03/postname/

    Which should be something like:
    http://wpurl.com/news/2009/03/postname/

    Issue 2:
    Despite the redirect not being appropriate – the comment does get submitted & attached properly. However, have_comments(); returns false; therefore, will not display the comments using the default comments.php. Further, comments_number(); – does – find the proper number of associated comments. Lastly, so far, wp_list_comments(); does not find the associated posts either.

    Again, this is not something I will be running. Therefore, the solution cannot involve hacking individual WP files outside the content folder.

    Any assistance/guidance which can be offered would be appreciated. Thanks.

    AMK

Viewing 15 replies - 1 through 15 (of 19 total)
  • Doodlebee

    (@doodlebee)

    Out of curiosity – why are you using %tag% instead of %category%? Tags are a version of categories, so if you use %category% it would most likely work better.

    Thread Starter amidknight

    (@amidknight)

    I went with Tags to differentiate between two organizational methods (previous to this version of WordPress I would have used categories). And, because WordPress uses tags similar (at least for what I need) to categories – I figured it would work the same way.

    Tags = Post Type (blog, news, etc.)

    Categories = Content Focus (flowers, photography, etc.)

    This way instead of creating a parent category called Blog – with child categories (flowers, photography, etc.). Which would in-turn mean creating another parent category called News – with child categories (flowers, photography, etc.).

    I guess you could say I’m part of the “there’s a difference between a tag, and a category” movement. Good and completely valid question.

    Thread Starter amidknight

    (@amidknight)

    the_permalink(); function also doesn’t convert the %tag% to the proper tagname

    Workaround for permalink:
    <?php print(preg_replace('/%tag%/', 'blog', get_permalink())); ?>

    Doodlebee

    (@doodlebee)

    Yes, there is definitely a difference between the two 🙂 I was just curious as to what you were trying to do. because you *can* us the tagging system how you’d like to (I know I’d doing something a little bit similar on a client’s site), but setting up the *default* permalinks with %tag% just seems a little weird to me. You can “name” your default “tag” category in the settings (under where you’re talking about), but by default it just seems to make more sense to set it with %category%. You can *link* to the tags any way you like.

    Maybe it’s just personal preference, I guess – but I was just wondering. Looks like Knight there has your reason as to why it’s not working.

    Thread Starter amidknight

    (@amidknight)

    Basically, the idea is similar to what WordPress MU does – with multiple blogs/users. However, instead of multiple ‘Blogs’ – there are multiple ‘dynamic’ areas to post – while still having the normal category and pagination capabilities of WordPress Posts available (which aren’t really available for Pages – at least that I’m aware of).

    Tags:
    blog
    news
    podcasts
    …etc.

    URLs:
    wpurl.com/blog/
    wpurl.com/news/
    wpurl.com/poscasts/
    wpurl.com/etc/

    This way when an author creates a post – they can tag it as one of those. Then via query_posts(‘tag=tagname’); single out the posts for that URI – a page can be displayed and filtered.

    In theory, an author could tag something as a ‘blog’ then categorize it as ‘technology’. And, another post can be tagged as ‘news’ then categorized as ‘technology’. Finally, an end-user could go to wpurl.com/categories/technology/ and see both Blog and News posts dealing with technology.

    It just seems that the current release hasn’t been fully implemented to use %tag% as part of the Permalink structure – despite the option being available.

    Thread Starter amidknight

    (@amidknight)

    I don’t usually go for bumping. And, normally I would contact the vendor directly.

    Having said that: I need to know if this is a planned “fix” in a soon-to-be-released update? Or, if I should just abandon tags and convert back to the category method?

    have_comments(): returning false. Because the comment count (where there are comments) is greater than 0 in the DB. It would be my guess that the proper ID or GUID is not happening.

    wp_list_comments(): return empty. Same guess as for reason.

    Seems odd to me that comments can be posted. Further, comments are associated with the proper post (front and back end). Also, comments_number() finds the proper count.

    However, the proper default redirect_to part of the form does not work. Finally, the the_permalink() does not take out %tag% (I can work around this one but not very elegantly).

    Again, if someone could let me know – I would appreciate it greatly.

    Doodlebee

    (@doodlebee)

    An alternative idea to this, then, would be to assign users to a category, so they only post in the category they are allowed to. Sounds like you’re planning ot have multiple authors on your site, and you want to be sure they stay where they are supposed to stay.

    There’s no need for a “fix” for this – it has nothing to do with permalink structures. You might find this to be useful: Bind user to category. I’ve used it on a 2.6 site, but not 2.7 – so I don’t know if it’s compatible or not.

    Thread Starter amidknight

    (@amidknight)

    Thanks for the information doodlebee I didn’t know that was possible. But, regarding this project, I’m not looking to restrict someone to a category. I’m wanting to create a permalink structure based on tags, and allow commenting (any author can tag a post as “news” or “blog” or whatever). And, the URL a user puts in – will have a tag in it.

    Because this option is available as part of the permalink structure menu, and is treated similar to categories (without parents) – I would expect WordPress to decipher the URL in the same manner it would categories.

    If my permalink structure was something like:

    /%category%/%year%/%title%

    get_permalink() – should return the /category/2009/title URL, yeah?

    wp_list_comments() – should return the comments for /category/2009/title URL, yeah?

    Also, the comment form would redirect to /category/2009/title URL, yeah?

    If the above are true – it should work with tags as well (currently it does not). Otherwise, why have the option available as part of the permalink structure?

    Basically, when it comes to tags – I don’t think WordPress is properly converting the URL when there is a tag involved in the permalink structure – for these particular functions. Beyond that – it works as expected – and the client is pleased.

    Will try to setup a ‘dummy’ site to demonstrate better, because I must not be communicating this well.

    Doodlebee

    (@doodlebee)

    Well, if you set up the permalinks to /%category%/%postname% the tags WILL indeed show up in the permalink structure. I know this for a fact, because I’m doing it here:

    Simsbury Newcomer’s Club

    I’m still working out some issues – but the archived newsletter list in the sidebar? Those are tags. If you click one, you’ll see that the permalink shows “newsletter” – which is my default tag name. but my permalinks are set up only with /%category%/%postname%

    Is this what you’re after?

    i think what you’re missing is that tags are a sub-category of categories, SO if you use /%category% you’re still going to get the /%tag% in the permalink – there’s a spot in your permalink settings where you can give the “tag” a default name, so it doesn’t show up as simply “tag”. But use the /%category/%postname% permalink settings, and your url for the tag of “fish” will be “sitename.com/tag/fish” If you give your tag a default name of say, “animals” then the tag permalink will be “sitename.com/animals/fish”

    Does that help at all?

    Thread Starter amidknight

    (@amidknight)

    Try the example below.

    Examples:

    Permanent Link (permalink) structure = /%tag%/%year%/%monthnum%/%postname%

    http://joshbruce.com/tag_url/
    All the recent posts show up – no matter the tag/category – as expected. Clicking on the Permanent Link (permalink) – results in a 400 error (because “%tag%” is literally not replaced with the tag-slug of the lowest number – which is what should happen).

    http://joshbruce.com/tag_url/news
    http://joshbruce.com/tag_url/blog
    Example URL structure (which works) – to isolate posts between the two types based on tags. However, again, get_permalink() does not replace “%tag%” in the link. (It’s not that the post-slug is incorrect – it’s that the delimiter “%tag%” isn’t being replaced.)

    http://joshbruce.com/tag_url/category/photography/flowers
    Categories – being different than tags – works as expected. Only posts with the category photography->flowers show up – independent of tag.

    http://joshbruce.com/tag_url/blog/2009/04/blog-2
    This is an example of a single blog post permalink (the proper post does appear).

    http://joshbruce.com/tag_url/news/2009/04/news-1
    Example of single news post (which, again, proper post does appear).

    Submitting the comment form results in the following:
    http://joshbruce.com/tag_url/%tag%/2009/04/blog-2/comment-page-1#comment-2

    Because the “%tag%” delimiter is not changed.

    Note: With this fresh install – wp_list_comments() works. Not sure if there was a minor patch or anything.

    Therefore, given the way the other parts work as expected & desired – it seems WordPress wants it to be capable of doing something like this. It just doesn’t work with the get_permalink() and the_permalink() functions; or, the redirect for the default comment form (this I should be able to fix with a hidden form element $_POST[‘redirect_to’]).

    Does that demonstrate it a little better?

    ps. Thanks for continuing to look at this – I really do appreciate it.

    Okay, I’m a little confused, because there’s a lot of time between each post, and now I have to get my head wrapped around this again, so I’m reading through the thread one more time LOL

    So you’re wanting to write a post, and have people be able to comment on the post. This is working fine.

    The initial URL you *want* is:

    http://wpurl.com/news/2009/03/postname/&#8217;

    but you say that’s not working? it shoul be. As I mentioned before, if you set your permalinks to /%category%/%year%/%month%/%postname%, and scroll down a bit and set your Tag name to “news”, then the URL you want WILL happen.

    it seems you’re stuck on using %tag% in the permalink structure, instead of %category%, and I’m not quite sure why. Not all categories are tags, but all tags *are* categories, they are just a sort of more specific subset. So I’m still not quite clear on why you’re insisting on using %tag% instead.

    In the OP, you say ‘However, have_comments(); returns false’ – what are you using “have_comments()’ for? What defines ‘have_comments()’? That’s not a standard WP function – so how is that defined, and why do you need it? I also don’t know about “commments_number()” – again that’s not standard WP stuff. These sound like functions that are part of your theme – and I don’t know how they are defined.

    You ask:

    “If my permalink structure was something like:

    /%category%/%year%/%title%

    get_permalink() – should return the /category/2009/title URL, yeah?

    wp_list_comments() – should return the comments for /category/2009/title URL, yeah?

    Also, the comment form would redirect to /category/2009/title URL, yeah?”

    Again, categories and tags are pretty much the same thing – tags are just a subset/more defined and specific. But categories override tags because.. well it’s like a book with chapters. Think like a recipe book. It’s divided between breakfast, appetizers, desserts (these would be your categories). But if you’re looking for a specific recipe that uses apples – then you’d look in the index for that (that would be your tag). It would make no sense to have chapters for Apples in a recipes book – you’d have to redo recipes all the time because *many* recipes use apples, but they don’t all use tomatoes. So you’d have to re-insert them in he tomatoes section as well. that’s why they’re all in “Desserts” or “Sauces”.

    and by the way, wp_list_comments() isn’t a function that returns category stuff at all – it defines the layout of your comments. it has nothing to do with tags, categories, pages or anything – it just defines your comment layout, and provides the Loop for your comments. The comment form redirects to the *post* you’re commenting on – you can’t comment on a grouping. Well, I suppose you *could*…maybe – but that would be weird.

    Does that help?

    If you want to provide *links* to each section using tags, then you can. Just use the wp_tag_cloud(); instead of wp_list_categories. There’s further functions at the bottom of that page that lead you to more info on tag links.

    Thread Starter amidknight

    (@amidknight)

    No worries on the getting confused. It’s difficult to convey some things via text. 🙂

    I wanted to respond to your points – but, didn’t want to make the situation more confusing. So, the part in the blockquote is the important bit – and I could/should start a new thread using just that.

    http://joshbruce.com/tag_url/

    Changed Permalink structure as mentioned. And, unfortunately it doesn’t work the way it should/would (considering the other bits work). the_permalink(), as suspected, uses the root category “photography” – not the tags “blog/news” – which it would if “%tag%” were being sanitized properly. As I said before I’m trying to avoid having a complex category structure – the way I would have to set up the categories to get this permalink structure to create the URLs desired would be:

    • news
    • photography
    • weddings
    • flowers
    • blog
    • photography
    • wedddings
    • flowers

    That’s bad UX for the admins. Using this method the author will have to check the news/blog category, then check whatever is appropriate under that tree – not idiot proof. What I want are two separate lists (which, with the introduction of tags – I should be able to do):

    Tags:

    • news
    • blog

    Categories:

    • photography
    • weddings
    • flowers

    Which drastically reduces the complexity for the Admin/Author. They choose the type of post (news/blog) – then the content type (photography/wedding/flowers).

    I’m stuck on using tags partially because it makes for a much more elegant Authoring experience in this case. And, because WordPress says it can be used. But, WordPress is not sanitizing the “%tag%” in some cases.

    have_comments() – was introduced in 2.7 to begin the new comment display loop. It is a binary (true/false) function – which determines if the post has comments associated with it (this is now working properly).

    comments_number() – is a template tag – which is used in the default theme’s comments.php file (version 2.7+) – also works properly.

    wp_list_comments() – I don’t want it to return category stuff. I want it too read the URL – get the appropriate comments – and display them. And, as of now, it does that properly – but, it didn’t when I initially posted.

    The form doesn’t redirect to the proper post – because WordPress is creating a URL for the post based on incorrect sanitation of the permalink structure – hence %tag% not being removed. Which can be hacked by adding the following to the comment form:

    <input type="hidden" name="redirect_to" value="<?php print($_SERVER['SCRIPT_URI']); ?>" />

    However, if WordPress were sanitizing the %tag% properly – based on the personalized permalink structure – it wouldn’t be needed.

    Thinking of the recipe book analogy. Categories are hierarchical – macro to micro. Tags are independent of hierarchy. Therefore, let’s use an apple pie as an example. This method would Tag the pie as “dessert”. Category = pie. Pie could then have subcategories for type: Pie->apple. Another root category: Ingredients. With subcategories: Ingredients->apples, Ingredients->flour, Ingredients->eggs, etc. Therefore, when a user put in the URL:

    domain.com/dessert – this recipe would appear.

    Or:

    domain.com/category/pie – this recipe would, again, appear.

    Or:

    domain.com/category/ingredients/apples

    Regarding the tag cloud – I don’t want to list the tags. This issue is all about URLs – not data display.

    Having said all that.

    The problem still remains. If I, as the admin set the permalinks to use tags in the permalink structure. Then use get_permalink() or the_permalink() – %tag% is not sanitized, which according to the ducumentation, it should be.

    All other aspects pertaining to Friendly-URLs work fine and as expected.

    Thanks again, really appreciate it.

    Thread Starter amidknight

    (@amidknight)

    Addendum: Regarding Themes

    The links above are the default WordPress theme – no changes. If anyone would like to experiment (see for themselves):

    1. Install WordPress 2.7+
    2. Login & set the permalink structure to: /%tag%/%year%/%monthnum%/%postname% (or anything with %tag% in it)
    3. Create some tags
    4. Create some posts referencing the tags
    5. Then preview the site
    6. follow a title link

    No other changes are necessary to demonstrate the error.

    See: http://codex.wordpress.org/Using_Permalinks#Structure_Tags

    For performance reasons, it is not a good idea to start your permalink structure with the category, tag, author, or postname fields.

    Thread Starter amidknight

    (@amidknight)

    Understood. However, “not recommended” does not equal “impossible”. Right now it’s not possible to put %tag% in a custom permalink structure, and have get_permalink() and the_permalink() functions return the properly formatted URL – no matter where it appears in the structure. And, for logistics – I want to – the loss of performance is moot.

    Finally, the get_permalink() and the_permalink() functions should still return the URL without the %tag% delimiter – as it does with every other structure delimiter listed on the codex page referenced multiple times in the thread.

    Again, the bottom line is, if %tag% is used anywhere (beginning, middle, or end) in a custom permalink structure – get_permalink() and the_permalink() do not work.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Comment With Tag Based Permalink’ is closed to new replies.