tag and manage portions of a post (10 posts)

  1. elpen
    Posted 8 years ago #

    I'm looking for a freeform way to add traceable and manipulable semantic data to portions of a post. Take an entry that includes a quotation. This quotation might appear as a blockquote or it might appear inline. What I'd like is a way to mark these quotations, and anything else, so that at a later time I could generate a page containing nothing but quotations. I know I can add each post that has a quotation in it to a quotations category but that's not what I'm after.

    I've begun using a local installation of WP as notebook/diary/scrapbook. For the last several years I used a plain text file. There are portions of daily entries in the older file that I'd like to be able t manipulate as I would entire categorized posts. Again, if I have a quotation I'd like to be able to tag it in such a way that I could later generate a page with every quotation I'd ever entered and a link to the post it occurs in. Similarly, I could tag story ideas or definitions of words and later get a page that contains nothing but those ideas or those definitions and the date I entered them.

    Another way to think of this would be that I'm trying to add specific portions of a post to categories so I can later see those portions in isolation with links to the post in which they occurred and some meta data such as when they were entered.

    Is this something that I can do with WP? Thanks!

  2. Kafkaesqui

    Posted 8 years ago #

    Keeping in mind this a slightly complicated request you're making (WordPress is designed to handle content of a post as a single object and does not normally manage it in compartmentalized ways), I can thumbnail a couple ways you could go about it:

    1. Add quotations (or whatever) as custom fields to a post, using a predefined key (let's say 'quote') to mark a quotation (or whatever), and the text of the quotation (or whatever) for the value.

    You would then require a bit of custom code -- in a page template or script file you plan to use to display them -- which would collect the meta text of your custom fields and lay it out accordingly.

    2. Make use of some 'benign' HTML markup, like say the <span> tag, to designate your desired text:

    This sentence <span class="quotation">has some bang to it</span>, though it ends with a whimper.

    For the display part, the code would need to query the posts table in the database for these lines, then parse them out so they can be shown unencumbered by the rest of each post's content.

  3. elpen
    Posted 8 years ago #

    Hm. Let me see if I understand. These are both, in broad, mirroring the concepts I came up with when I initially tried to ask myself how I would do this. The idea of using a class as a selector makes sense. The idea that there is one post to a cell in the database makes sense. So in the second solution generating a page of quotations would mean greping the content of each post cell with a regex to match forward from class="quotation"> to '<' and there my understanding breaks down. How does that make it into a new page?

    If I understand what you are saying in 1 then something like the following should be possible.

    a post is written and a portion of that post is encapsulated in a custom quotation tag (I don't know what this would look like). In the database there'd be a column for that custom field and the relationship between individual posts and the content of that field would be preserved. Some php magic that I don't know how to do could be used to grab everything in that custom field and, thanks to the relationship, the standard the_permalink and the_time (variables? functions?) could also be used to provide a link back to the parent post in the first instance and to show the date of the parent post (and thus of the quotation) in the second instance.

    Or am I even more confused than I think I am? If I am or if I amn't, how would I actually accomplish this given that I have an OK understanding of the concepts at work but a weak grasp of the terminology and no programming ability? Is there a plugin that could do it?


    I think what makes sense to me is using the custom fields. However this article isn't simple enough. For one thing, wordpress does not appear to allow me to enter php when writing posts. At least when I use '<' or '>' they are converted to character codes. Or, I suppose, wordpress has a php parser that won't recognize what I entered because it is malformed for some reason.

  4. Kafkaesqui

    Posted 8 years ago #

    "How does that make it into a new page?"

    Again we're talking about a couple different solutions (no matter which option one chooses from above). The first requires a custom Page template providing the code that will collect and display your specified content. The second involves creating a PHP document that resides outside your templating structure (though can incorporate your theme and layout) which includes this 'special' code.

    "If I am or if I amn't"

    Hmm. Amn't...

    Anyway, what I'm talking about, no matter the way you choose to go about it, is setting up a specialized SQL query that will collect this specific content, with additional code dedicated to displaying it in the manner you desire. Whether tagged in the post or separated into custom fields the query can be adapted to grab all related information (post time, author, etc.).

    Now, I can certainly help out and write up some of the code (or start looking about for a possible plugin), but I'd rather not until you actually pick a method... :/

    Opinion-wise, I like option 1 (custom fields). It is a very WP way of going about this. Custom fields exists in part for just this sort of associative content unitizing, and offers the potential to expand the uses you might want to put it to (example off the top of my head: a modified search displaying just the quotation text for results). Perhaps the one thing going against it is that we're talking about redundant content, but this is minor since with either option your going to take extra steps to designate the bits of important text.

  5. elpen
    Posted 8 years ago #

    Amn't. Since you called me on it I had to check and see if I'd made it up or not. Apparently not. I only use it when I need sleep. Anyway.

    I also like 1, primarily because it seems more elegant. Your assertion that the content would be redundant is an interesting one. It would be, in the sense that the content occurs in the body of a post. It wouldn't be, in the sense that it is a way to access and re-present portions of the primary content in a way that doesn't semantically or structurally privilege that content in its initial context. By which I mean, more simply, it enables us to focus on specific, contextually valid, elements within the content of a post without elevating those elements to the status of a post. Or: a quote in context is subservient but, since we're working with a database, if we later wish to collect all quotations or to reuse specific quotations we can do so without disrupting the structure of the original post in which they occurred. I hope at least one of those explanations was coherent. The quotes remain redundant but the redundancy is justifiable.

    I prefer to make all entries for one day as one post. I prefer not to interrupt the flow of my thought with additional posts for each facet of my thought I suspect will have future relevance. I feel that the greatest strength of a tool like WP is it's flexibility. It isn't a full blown CMS and I don't want one. It is an excellent tool for manipulating sequential textual and hyper-textual thought. I use to use it when it was beta but stopped. I've kept a diary in a plain text file for several years now. I don't want to change how I enter information but I would like more options in how I manipulate and present that information. I'm sorry it introduces redundancy but hope the functional and philosophical explanations of that redundancy reduces its repugnance.

    Quotations are just one example, anyway. Story ideas, whatifs, comments on wine, bourbon, women, work, and music are all fair game. Say I write an idea that isn't a plot but could add texture to a story, e.g. "genetically engineered mice keep the floors free of crumbs but, because they are unable to evacuate waste outside of a special pheromone treated 'nest,' do not contribute to the mess." And a few months later I write "he begins as someone who routinely turns gold into lead and only reluctantly leads the rag-tag group of rejects to victory." I'd want to tag both with something like 'story_stuff' because seeing all those ideas together one after the other might be useful. Redundant, yes, pointless, no. I need to sleep. It's 4am. I'm excited about this idea, though. If you are sincere in your offer of assistance I'd be more than happy for your help. If you can send me email through this site I invite you to do so.

    Thanks for your help and suggestions.

  6. Kafkaesqui

    Posted 8 years ago #

    RE: Amn't -- I was not "calling" you on it; merely pointing out a contraction I've never cozied to. But then that's not your fault. ;)

    Redundancy is not necessarily a bad thing (as you apparently understand). I've worked with one user to set up functionality for recipes through such means, and while placing ingredients and prep details in custom fields could also be considered redundant (as they're discussed in the post), calculated categorization of the information let's you build into your content the sort of semantic structures that get Web 2.0 gurus salivating!

    What support I'm offering I think we can handle publicly, right here. There's no telling who else may benefit from this discussion and subsequent code. There's a goal here to answer one problem yet solve a hundred (or more!). But it's also getting real late for me now, so I'll put up some sample code to test out the idea in a followup reply.

  7. Kafkaesqui

    Posted 8 years ago #

    Ok, as I don't believe I need to explain the custom field entry part of this, here's a code statement that can be used to display them:


    Simplest method for implementing this is to create a Page (Write > Write Page) for your 'quotations.' You do not need to provide content for it, but you will want to create and assign a Page template to this Page, one which guts out The Loop portion of the template and replaces it with my custom code at the link above.

    Keep in mind you can modify the loop to any layout you want, as well as make use of any of the regular post-related template tags. The main character here is the following from my code:

    <?php echo apply_filters('the_content', $post->meta_value); ?>

    This replaces the_content() from your standard post loop, printing out the value to your custom field rather than the post's content. I applied the content filters to it so as to retain the look of a post entry.

    Note: The modified loop handles each custom field as its own entry or pseudo-post. If you find it necessary to organize each post's custom fields as combined entries, we'd have to first jigger in a merge of sorts.

  8. elpen
    Posted 8 years ago #

    I'm still waking up -- get up in time to enjoy Saturday? nonsense! -- but I wanted to thank you for helping me on this. What you've provided works well already and I need to play around with the other template tags. The merging you describe might be interesting, I'm not sure yet. One thing that would definitely be interesting is if specific categories redirected. Say I file several entries under "musing, life, quotations" because they are musings on life and contain quotations. I might like to be able to click "quotations" and get a quotes page like the one you just provided the code for. Would that be possible?

  9. elpen
    Posted 8 years ago #

    I should clarify. I realize I can place a separate link to the quotes page but was wondering if that link could automatically occur in place of the category link.

  10. Kafkaesqui

    Posted 8 years ago #

    The idea of subdividing under categories seems an easy one to tackle. I've already written a plugin that allows one to get search results based on custom field content. Adapting the plugin to work with category queries would be trivial, but I'll have to see if it can be made to override a post's content with the custom field value, or perhaps output the value in a way that makes it easy to handle on the users part (such as say providing a the_quotation() (or again, whatever) template tag function).

    As for linking, it all depends on how the links would be expected to operate and display, and where. One limit here is that I've yet to wrap my brain around the url rewrite features in WordPress, so my providing a linkable solution would run along the lines of appending a url query ( /?key=quote ) to the url for a category. But, one thing at a time...

Topic Closed

This topic has been closed to new replies.

About this Topic