Getting category name/id from a post title
I was wondering if there is a way through which I could get the category’s name or id of a post by supplying post’s title.
The thing is that I have a bilingual blog, with some posts in English and others in Urdu. In my current theme, I also display the title of the next and previous posts when a single post is viewed. Since I use a different font for displaying Urdu characters correctly, I have a class (.urdu) in the CSS and I use something like
<span class="urdu">Urdu post title here</span>as the title of Urdu posts while saving them. This allowed the
next_post_link()functions to correctly display the post title in my desired font on a single entry page. (An example is this post).
Now in my opinion, stuffing tags in post title is not a nice approach. It also required some irritating changes here and there. If I don’t use tags in post title, the only problem I would encounter would be that if, while displaying the next/previous post title, there comes one with its title in Urdu, then it won’t be displayed correctly, since I would have no idea that the upcoming post is in Urdu and thus I won’t be able to use the suitable font.
The solution which came in my mind was that if I just get the next/previous post title, and then check whether it belongs to the category ‘Urdu’, then I can modify the PHP easily to apply the .urdu class and display the title correctly.
Any help or ideas about this (or a better solution) would be greatly appreciated. Thanks!
P.S. Sorry for the awfully long post 🙂
- The topic ‘Getting category name/id from a post title’ is closed to new replies.