WordPress.org

Ready to get started?Download WordPress

Forums

how to display post category not as a link (21 posts)

  1. shelleycat
    Member
    Posted 10 years ago #

    I recently upgraded from b2 to 1.0 so am redoing my index.php. I'm using 'php the_category' in my template to display the categories for each post, however it displays it as a link to all posts for that category. I don't want the link, just the category names as text. I know I had it set up like this in my b2 template but can't figure out how to do it again. Please help?

  2. notthatugly
    Member
    Posted 10 years ago #

    Hmm... there's a tag for the_category_ID so there ought to be one for the_category_name. Try that and let us know whether it works.

  3. shelleycat
    Member
    Posted 10 years ago #

    There's no tag the_category_name although it seems that something like that would be useful. Is there any way I can do this without hacking into my files? I'm about 98% sure I didn't do that last time and it's always such a pain keeping track of changes ifandwhen I upgrade.
    I'm not sure I understand your reply davidchait. Bits of it yes, but not all of it. I don't know how to code PHP beyond using these template tags :( Also, I'm planning on using multiple categories in the future so want it outputting bascially just like it is but without the ugly and unecessary links, so simply echoing the cat name might not work, depending on how multiple categories are handled.

  4. Alex King
    Member
    Posted 10 years ago #

    I don't understand what WordPress gains through removing functionality that was available with b2.

    Your argument would have been better received (by me at least) without this comment.

  5. Shreela
    Member
    Posted 10 years ago #

    I'm new to WordPress, so I don't know how the previous versions worked. But I do like having the category made into a link to show all posts posted to that category.
    But I also wish there was a way to have it with, and without, the list tags ‹li›,
    I am currently using it as it's written for one of my side sections; it's nice how it is, I'm thinking I'd eventually like to try the dropdown hack, and am wondering if the ‹li›'s will interfere with that.
    Additionally, I'd like to place a PLAIN , (no list tags) "Posted to XXX Category" on the same line as my author/date/comments line that's under the entry. Since it has the ‹li› tags autogenerated, its dropping down under that line.
    So I put it back under the title...but now it's picking up my ‹li› styles, and looks strange 8^)
    Is there some code I can add to the template-functions.php that I could have it both ways?
    Thanks,
    Sherri
    http://shreela.f2o.org
    (I'm still struggling with my styles, but only a few things are off at this time)

  6. Shreela
    Member
    Posted 10 years ago #

    woops the (li) tags didnt' come out right, I'm not used to this forum software, sorry

  7. notthatugly
    Member
    Posted 10 years ago #

    Sorry, but in b2 (and in 0.72, for that matter) it was possible to show category names that were neither a link nor a list, so that people had the ability to choose how they wanted the category displayed. That functionality now appears to have been removed, so that it's now necessary to edit the php files or tinker with the CSS. You might not like me pointing that out (I know the developers are trying to move away from the perception of WordPress as a b2 fork) but I wouldn't bother giving you feedback if I didn't care about the success of the project.
    If I get stroppy sometimes (ok, a lot of the time ;) ) it's because I see a potentially great project being undermined by an occasional disregard of the needs/wants of the average, non-PHP-or-CSS-expert end user, and that frustrates me because I'd like to see WordPress get bigger, not smaller.

  8. Alex King
    Member
    Posted 10 years ago #

    This wasn't changed because we are trying to move away from b2. As far as I know, we are very proud of our b2 heritage. This was changed because we introduced support for multiple categories.
    Now that we have multiple categories, how would you expect a function like the_category_name() to work if it doesn't return a list?

  9. Alex King
    Member
    Posted 10 years ago #

    I'm not saying it can't be done, I am asking you how you'd want it to work. I want you to go through some of the thought process. It's easy to sit back and criticise, but sometimes the problems are a little more complicated than they appear on first glance.
    We can (and I expect we will) easily add a parameter to the existing function to not have it output the link. The existing function will return an unordered list or a comma separated list.
    Is there another way you want it to work? You want it to output an unordered list if there are muliple categories and just text if there is only one category? Can you see any potential problems with this?
    Here is your chance to design a feature - how should it work?

  10. Shreela
    Member
    Posted 10 years ago #

    Ok, got mine fixed up the way I want it. I copied the_category function, pasted it after itself, named it the_category2, and took out the echo ul stuff, and the li stuff. Then I made the changes to the index, Category: <?php the_category2() ?>
    This unlisted one is still linked, that's how I wanted it. I'm still using the listed one in my sidebar.
    Thanks

  11. davidchait
    Member
    Posted 10 years ago #

    @shelleycat:
    No problem. If you can add a template-tag, you are writing php code. ;)
    (This is OBV a temp solution...) I've created a file on my site my-hacks.phps. If you have a my-hacks.php file already, copy the function in my file into yours. Otherwise, copy the file to the root of your blog and rename it to my-hacks.php. Either way, make sure you enable the hacks file in the admin interface.
    This will enable a new 'tag': get_category_names(" : "). Its only parameter is the separator between the category names (and it is optional, defaults to comma+space). No ul, just returns a concatenated string of the category names.
    Use it like: <?php echo get_category_names(" * "); ?>
    -------------------------------
    @alex - how it might want to work:
    Since I proposed one solution, and I regularly update my functions with extra params/defaults, I'll take a shot at a possible 'answer'.
    - a param for links/no-links
    - a param for list/no-list
    >> note that I disagree with making it a list if >1 but not if ==1 -- a user should decide if they want it list-styled or not, period.
    - a param for between-multiple-categories separator, used in the no-list case
    defaults might be links=true, list=true, separator=', '
    I wouldn't mind becoming a 'cvs-blessed' contributor at some point, if you all need another set of hands at times. At the same time, I can keep posting away herein... ;)
    =d

  12. Alex King
    Member
    Posted 10 years ago #

    David, there is already a param for list/no list and the between multiple category separator. So the only thing you are asking for is what I already proposed - adding a param to turn off the links.

  13. Alex King
    Member
    Posted 10 years ago #

    If it's already possible to turn off the list using parameters, why hasn't that been mentioned before?

    That isn't "turning off the list", it is showing a list in a different way. I imagine it wasn't mentioned because the primary request was to "turn off links".

  14. notthatugly
    Member
    Posted 10 years ago #

    That isn't "turning off the list", it is showing a list in a different way. I imagine it wasn't mentioned because the primary request was to "turn off links".

    My mistake. When you said there was 'a parameter for list/no list' that confused me. I assumed that 'no list' meant not displaying the links as a list. (I tend to use 'list' in its narrowly technical HTML sense; as far as HTML is concerned, if it's not

      ,

        or <dl> it's not a list). And there have been more posts about the

          issue than the links, so I was surprised it hadn't popped up on any of those threads. But then, only a handful of people have access to this kind of information, so maybe I shouldn't be.

  15. shelleycat
    Member
    Posted 10 years ago #

    Sorry I was gone so long, real life gets in the way sometimes.
    Thanks for the my-hacks solution davidchait, I'm going to try that as soon as I upgrade to 1.0.1 (which I'm about to do). To me this seems like the obvious way to solve problems such as this, put it in a standalone hack file rather than go into the actual php files and mess with those. This way when I upgrade again (which I'm sure I will) it's not lost, plus I should be less likely to break other stuff along the way.
    Personally I'd like to see this as an option in the official wordpress relsease. All it needs to do is display all the categories without making them link to anything, I'm happy with the toptions already given for listvs comma deliminated output. However it's not essential and I'm just as happy adding it into a hack file which can then be included (since I know functionality has been built into wordpress to allow this).
    I'll report back on how it goes.

  16. davidchait
    Member
    Posted 10 years ago #

    Yeah, definitely drop a line if there's any problems with it -- I can always give you some tweaked code..
    =d

  17. shelleycat
    Member
    Posted 10 years ago #

    It worked perfectly, just as soon as I remembered to go enable it in the admin interface. Thanks :D
    The upgrade was wonderfully smooth and easy too in case anyone wonders :D

  18. shelleycat
    Member
    Posted 10 years ago #

    Ack, Ok it's not working as well as I thought. When I've finished writing an entry and press post it posts but then I get a page with the following error:

    Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/my-hacks.php:19) in /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/wp-admin/post.php on line 368

    The same thing happens when I try to go to the advanced entry page to open commenting and pings.
    Then when someone leaves me a comment they get the following errors (although the actual comment does show up):

    Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/my-hacks.php:19) in /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/wp-comments-post.php on line 114
    Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/my-hacks.php:19) in /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/wp-comments-post.php on line 115
    Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/my-hacks.php:19) in /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/wp-comments-post.php on line 116
    Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/my-hacks.php:19) in /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/wp-comments-post.php on line 118
    Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/my-hacks.php:19) in /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/wp-comments-post.php on line 119
    Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/my-hacks.php:19) in /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/wp-comments-post.php on line 120
    Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/my-hacks.php:19) in /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/wp-comments-post.php on line 121
    Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/my-hacks.php:19) in /home/httpd/vhosts/procrastinate.co.nz/httpdocs/blog/wp-comments-post.php on line 126

    I'm not sure if there are errors anywhere else.
    I don't have anything else in the my-hacks file by the way. For now I'll delete it and live with the category links until I know what's going wrong.

  19. Alex King
    Member
    Posted 10 years ago #

    Make sure you don't have any extra line breaks in your my-hacks file.

  20. Matt Mullenweg
    Troublemaker
    Posted 10 years ago #

    This page might help you out with my-hacks.php
    http://wiki.wordpress.org/index.php/my-hacks.php

  21. shelleycat
    Member
    Posted 10 years ago #

    Aha! How did those extra line breaks get in there? That fixed the problem, thanks :D

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.