WordPress: seotud postituse kohandamine

wordpress

Kui kasutate WordPressi, peaks üks teie nõutavatest pistikprogrammidest olema seotud Post sisse panema. Sellest hoolimata märkasin, et märksõnade hulk, mida postitati koos minu igapäevaste lugudega, moonutas tõesti seotud postituse tulemusi.

Samuti olin üllatunud, et pistikprogramm Seotud postitused pakkus ainult seotud postituste loendit enne postitus, mida loete! Mis oleks, kui muudaksite oma meelt (nagu ma sageli teen!) ... Kas te ei peaks esitama ka postitusi, mis avaldati pärast originaali, kuid olid siiski seotud?

Selle tulemusena tegin pistikprogrammi mõned väiksemad muudatused. Esiteks muutsin postituste viitamiseks nii enne kui ka pärast praegust postitust rida 91:

. "AND post_date> = '$ now'" kuni (UUENDATUD: 11):. "AND post_date! = '$ Now'". "JA post_date <= CURDATE ()"

Teiseks postitab Del.icio.us automaatselt oma ajaveebi igapäevaseid lugemisi kindla autori alla (nii et ma ei vahetaks kunagi parooli ega lõhuks automaatset postitamist). Selleks lisasin lihtsalt teise päringuparameetri, et jätta see autor otsitavatest postitustest välja, lisades eelmise järele järgmise rea:

. "JA post_author! = 4"

Autori numbri leidsin lihtsalt oma kasutajate seast üles otsides. Ma ei tee asju keerulisemaks, kui liitun teise tabeliga - see võib vähendada nende tulemuste kuvamise kiirust ja aeglustada laadimisaega. See toob kaasa inimeste pettumuse ja lahkumise.

Seotud postituste kuvamise eelised

Seotud postitused on fantastiline tööriist mis tahes ajaveebi jaoks. Seotud postitused tugevdavad otsingumootori tulemusi, suurendades märksõnu linkide kaudu, mis on otsingumootori algoritmide oluline element.

Seotud postitused pole ainult a SEM tööriist siiski. Seotud postitused on säilitamise tööriist, mis hoiab teie saidil kasutajaid. Nad ei pruugi leida oma maandumisel seda, mida nad otsisid - kuid kui esitate neile täiendavaid viiteid, võivad nad jääda!

20 Kommentaarid

  1. 1
  2. 2
  3. 3

    wow.. this is a neat trick. Even though I do not have wasabi related posts plug-in, i have Simple Tags plug-in for related posts and I am guessing it must be using the same postdate < condition. Thanks for the tip, let me check my plug-in code and see if I can tweak it to give better results.

  4. 4

    Chandoo, Simple Tags doesn’t use a postdate condition – I believe it creates the related posts live, with each page view (unless you have the cache turned on). That’s not the most efficient thing for the server, but it does mean that it will get the best matches, whether they were posted before or after the post being viewed.

    Doug – sorry for going off topic a little…

  5. 6

    Great post! But I do want to pick a few nits.

    Your justification for “(not) joining to another table” because:

    "it could reduce the speed at which these results are displayed and slow down the load time"

    is offbase and an example of premature optimization which inhibits maintainability, and it’s a shame to see people with a sizable audience recommend such things because it spreads misinformation.

    The SQL join you speak of, assuming your have reasonable indexes in place will increase your response time by at most mikrosekundit. You’d have to have tons and tons of traffic before anyone would notice even a half-second difference. Now yes, if you force yourself you can write so really braindead SQL code that will perform terribly, but an additional join on keyed data is not an example of that.

    Also, rather than advocate hacking someone’s published plugin, I’d really like to see you advocate enhancing it and then working to get your enhancement included in the actual plugin itself. As is, you might get some amateur coders to apply your changes and then later upgrade to the new version of the plugin and they loose the changes but can’t figure out what went wrong. Your change is benign, just a loss of functionality, but some hacks can cause a site to break if a future revision of the core plugin is used over top of the hacked one.

    JMTCW. Keep up the good work otherwise. 🙂

    • 7

      Tere, Mike!

      Thanks for responding – I’m not sure I agree, though. I didn’t prematurely optimize… in fact, I found the best way to get all the functionality I needed with no need to make additional changes. In my book, that should be every developers target.

      I also said that it võiks affect performance. I didn’t bother testing or trying because it wasn’t necessary given the manner that I optimized the plugin. Once again – I got 100% of the functionality I needed without doing a join or adding indexes, etc. That’s the right solution in my book.

      I do agree with you on your other notes, though. I am leery of republishing plugins, feels like I’m getting exposure off of someone else’s work. I referenced the author’s blog on this – so perhaps he’ll take these into consideration as features for future release.

      PS: Fixed the editing! 🙂

      • 8

        @Douglas: I?m not sure I agree, though. I didn?t prematurely optimize? Once again – I got 100% of the functionality I needed without doing a join or adding indexes, etc.

        Well, I guess that’s the difference between someone who is viewing programming from perfective of profession and a craft vs. someone who is a practioner just trying to get something done (and I don’t mean that perjoratively; on some mailing lists I play the letter role against the former. 🙂

        It’s similar to how an accountant or lawyer tells a business owner “I wouldn’t do that” and the business owner, not steeping in all the ramifications that the professionals are aware of as being *potential* ignores their advice because it seems like too much effort, and plows ahead. God knows I’ve been that business owner in the past and have plowed ahead against all advice, though much to my chargin later. 🙂

        @Douglas: I am leery of republishing plugins, …

        No, that’s not exactly what I was saying. What I was saying is that since it’s open-source you can contribute your changes back to the original author it they’ll accept, and you can do it proactively by contacting and offering. I currently work as a marketing consultant and website implementor for niche print publishers and use Drupal for web technology, and the Drupal community is always contacting plugin authors (Drupal calls them “modules”) and offering to help improve other’s modules.

        Lihtsalt mõte.

        P.S. Thanks for the editing fix.

        • 9

          Good points, Mike!

          I may tinker with the plugin to add that option of “Only display Posts Prior to the Post Displayed”. I think the second option is a little more proprietary for my blog, but I’ll check and see it it may be of interest to the author.

  6. 11
  7. 13

    Doug – I may be missing something here. It seems that

    AND post_date <= '$now'

    doesn’t prevent posts made after that particular post from being included, so much as it prevents inclusion of posts that you may have set to be published in the future.

    Hope that makes sense and thanks for the great blog.

  8. 15

    @Mike: Well, I guess that?s the difference between someone who is viewing programming from perfective of profession and a craft vs. someone who is a practioner just trying to get something done

    Interesting distinction. While it would be nice to have everything running at the absolute best it can be, in many cases that seems impractical. I strive to find a balance in my programming between how I would like something to run and how much $ or time it will take to get it there.

    I strive to do the minimum it takes to accomplish the purpose I’m try to achieve. To spend more time would not be cost effective.

    In short, unless that loss in efficiency was noticeable in my blog I would not spend the extra time, If it’s noticeable than I would decide whether the additional time would be worth the result. Perfection is not always the best solution.

    • 16

      @Dwayne: I strive to do the minimum it takes to accomplish the purpose I?m try to achieve. To spend more time would not be cost effective.

      Of course if always doing the minimum means that you don’t learn better techniques causing you to repeat the minimum many times in the future rather than allow you to avoid it, then you’ve made a false achievement. Yes, many tasks don’t need extra effort but I’ve witnessed many people take shortcuts like this in the past and they were some of the least productive and/or least value-creating people I knew (some of them were unfortunately my employees, hence why I really noticed their lack of productivity.)

      @Dwayne: In short, unless that loss in efficiency was noticeable in my blog I would not spend the extra time, If it?s noticeable than I would decide whether the additional time would be worth the result. Perfection is not always the best solution.

      I think you missed my points. First I was saying that Doug was optimizing for unnoticable efficiencies, not me, but more importantly if you are going to implement a hack that can cause future maintainability issues for goodness sake don’t publish it for other’s use without at least telling them of the kind of maintainability problems it might cause for them later.

      The irony of your comment is that taking the quick and easy route often ends up costing you a lot more time in the future when you install a security update for your WordPress, loose your hacked functionality and want it back. Now you have a haystack with a missing needle and you now need to figure out where the needle used to be.

      Spend extra time on performance? Bah, generally not needed. Spend extra time on maintainability? Yes, it often pays for itself in the long run.

      Wrapping up, yes it’s human nature to dismiss warnings for things that have never caused oneself pain. Feel the pain once and you’ll be a lot more likely to heed those warnings from others who have already felt that pain.

  9. 17

    One thing I should say; I do think Doug’s hack would be a good addition to WordPress, at least as a user option. It does seem rather silly to limit related posts to only those that came before.

    ALSO, I would like to ask Doug to post about how his daily posts are posted from del.icio.us; that would be an interesting topic.

  10. 20

Mis sa arvad?

Sellel saidil kasutatakse rämpsposti vähendamiseks Akismetit. Vaadake, kuidas teie andmeid töödeldakse.