Chestii-trestii asemanatoare (related articles on Blogger)  

Thrown (Ţâpat) in

Anumite platforme de bloage, cum ar fi WP, au asa-zise "plugin-uri" care arata cititorului articole similare. Si cum orice se poate face oriunde, in mod sigur asta poate fi implementata si pe blogger / blogspot.

Exista doua modalitati de baza de a arata aceste articole asemanatoare (eu le zic Chestii-trestii). Una din modalitati este ca ele sa apara imediat dupa articolul de baza, pe pagina articolului - aceasta este varianta Jackbook, modificata dupa Hoctro. O alta metoda este sa arati aceste articole intr-un widget, pe care-l poti muta oriunde, inclusiv dupa articol - aceasta fiind noua varianta Hoctro. Iata ambele variante in continuare.

A) Widget Mobil (Hoctro II)

1. Obtine o cheie Ajax Feed API de la Google.

2. Follow the instructions from this article Hacking Technique: How To Modify and add Widget to the Template, in particular section C.1, and add this CSS style code to the header, right in front of the </head> tag. Remember to replace YOUR-KEY text with the new key.

<script src='http://www.google.com/jsapi/?key=YOUR-KEY' type='text/javascript'/>
<script src='http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js' type='text/javascript'/>

3. Baga intre b:section with id:sidebar, dupa cum apare in acest screencapture de la Hoctro:

Ideal este ca acest cod de widget sa fie copied & pasted in interiorul sectie sus-mentionate, intre un />, pe o linie noua, si alt <b:widget id='... .

<b:widget id='Blog3' locked='false' title='Blog Posts' type='Blog'>
<b:includable id='nextprev'>
</b:includable>
<b:includable id='backlinks' var='post'>
</b:includable>
<b:includable id='post' var='post'>
</b:includable>
<b:includable id='commentDeleteIcon' var='comment'>
</b:includable>
<b:includable id='status-message'>
</b:includable>
<b:includable id='feedLinks'>
</b:includable>
<b:includable id='comment-form' var='post'>
  <div class='comment-form'>
    <a name='comment-form'/>
    <h4 id='comment-post-message'><data:postCommentMsg/></h4>
    <p><data:blogCommentMessage/></p>
    <a expr:href='data:post.commentFormIframeSrc' id='comment-editor-src' style='display: none'/>
    <iframe allowtransparency='true' class='blogger-iframe-colorize' frameborder='0' height='275' id='comment-editor' scrolling='auto' src='' width='100%'/>
    <data:post.iframeColorizer/>
  </div>
</b:includable>
<b:includable id='backlinkDeleteIcon' var='backlink'>
</b:includable>
<b:includable id='feedLinksBody' var='links'>
</b:includable>
<b:includable id='postQuickEdit' var='post'>
</b:includable>
<b:includable id='comments' var='post'>
</b:includable>
<b:includable id='main'>
<!-- *****************http://hoctro.blogspot.com*****Oct,2008********** -->
<!-- ***Related Articles by Labels Written by Hoctro- Take Four******* -->
<!--b:if cond='data:blog.pageType == "item"'-->
<div class='widget-content'>

<h5>Related Articles</h5>
<div id='data2007'/><br/><br/>
<h6>Related Article Widget by <u><a href='http://hoctro.blogspot.com/2008/10/new-and-improved-related-articles.html'>Hoctro</a></u></h6>

<script type='text/javascript'>

// Incorporating modified by Jackbook to the next line, thank you very much.
var homeUrl = "<data:blog.homepageUrl/>";
var maxNumberOfPostsPerLabel = 8;
var maxNumberOfLabels = 10;
var urlArray = new Array();
<b:if cond='data:blog.pageType == "item"'>
maxNumberOfPostsPerLabel = 15;
</b:if>
<b:if cond='data:blog.pageType == "item"'>
maxNumberOfLabels = 4;
</b:if>
var titleArray = new Array();
var titleTest = 0;

function relInitialize() {
var labelArray = new Array();
var numLabel = 0;

<b:loop values='data:posts' var='post'>
<b:loop values='data:post.labels' var='label'>
textLabel = "<data:label.name/>";

var test = 0;
// Do not add identical labels from posts
for (var i = 0; i &lt; labelArray.length; i++)
if (labelArray[i] == textLabel) test = 1;
if (test == 0) {
labelArray.push(textLabel);
var maxLabels = (labelArray.length &lt;= maxNumberOfLabels) ?
labelArray.length : maxNumberOfLabels;

if (numLabel &lt; maxLabels) {
      var url = homeUrl + 'feeds/posts/default/-/'
+ encodeURIComponent(textLabel);
      var feed = new google.feeds.Feed(url);
      feed.setNumEntries(maxNumberOfPostsPerLabel);
      feed.load(function(result) {
        if (!result.error) {
          var container = document.getElementById("data2007");
          for (var i = 0; i &lt; result.feed.entries.length; i++) {
            var entry = result.feed.entries[i];
            titleTest = 0;
            for (var i = 0; i &lt; titleArray.length; i++)
              if ( titleArray[i] == entry["title"] ) titleTest = 1;
            if (titleTest == 0 ) {
              titleArray.push(entry["title"]);
              var div = document.createElement('div');
              var a = document.createElement('a');
              a.href = entry["link"];
              // Adding an if statement to exclude current post.
              // Addition from Jackbook.com. Thank you
              if( a.href!=location.href ) {
                var txt = document.createTextNode(entry["title"]);
                a.appendChild(txt);
                div.appendChild(a);
                container.appendChild(div);
              } // if not home page
            }// if titleTest
          } // for
        }// if result is not error
      }); // feed.load
      numLabel++;
     }
    }
    </b:loop>
    </b:loop>
   }
   google.load("feeds", "1");
   google.setOnLoadCallback(relInitialize);
</script>
</div>
<!--</b:if>-->
</b:includable>
</b:widget>

Poti modifica Related Articles cum vrei tu, inclusiv schimband in Articole asemanatoare. Asta-i traducerea mea dupa versiuna originala Hoctro.

B) Fixat sub articol (Jackbook)

Jackbook s-a uitat la versiunea originala a lui Hoctro (nepublicata aici), nu i-a placut si-a modificat-o cum se vede mai jos. Pentru a o folosi, du-te in sablon si copy & paste acest cod sub <data:post.body/> (pe care il vei gasi probabil ca <p><data:post.body/></p>; nu conteaza, paste sub el).

<b:if cond='data:blog.pageType == &quot;item&quot;'>
            <div class='similiar'>
                <!-- **************************************Jan,2007****************** -->
                <!-- *****************Related Articles by Labels - Take Two****************** -->

                <!--

                Modified by JackBook.Com to make it easier to use.
                1. Now, users don't need to change anything to use this widget. just copy and paste, and done!
                2. The current article will also be listed, now it's no more.
                -->

                <div class='widget-content'>
                <p/><h3>Related Posts by categories</h3>

<div id='hoctro'>
        Widget by <u><a href='http://hoctro.blogspot.com'>Hoctro</a></u> | <u><a href='http://www.jackbook.com/' title='Related Posts on Blogger Modified by JackBook.Com. Read More?'>Jack Book</a></u>
    </div>
                <div id='data2007'/><br/><br/>
                    <script type='text/javascript'>

                    var homeUrl3 = &quot;<data:blog.homepageUrl/>&quot;;
                    var maxNumberOfPostsPerLabel = 5;
                    var maxNumberOfLabels = 10;

                    function listEntries10(json) {
                      var ul = document.createElement(&#39;ul&#39;);
                      var maxPosts = (json.feed.entry.length &lt;= maxNumberOfPostsPerLabel) ?
                                     json.feed.entry.length : maxNumberOfPostsPerLabel;
                      for (var i = 0; i &lt; maxPosts; i++) {
                        var entry = json.feed.entry[i];
                        var alturl;

                        for (var k = 0; k &lt; entry.link.length; k++) {
                          if (entry.link[k].rel == &#39;alternate&#39;) {
                            alturl = entry.link[k].href;
                            break;
                          }
                        }
                        var li = document.createElement(&#39;li&#39;);
                        var a = document.createElement(&#39;a&#39;);
                        a.href = alturl;

                        if(a.href!=location.href) {
                            var txt = document.createTextNode(entry.title.$t);   
                            a.appendChild(txt);
                            li.appendChild(a);
                            ul.appendChild(li);   
                        }
                      }
                      for (var l = 0; l &lt; json.feed.link.length; l++) {
                        if (json.feed.link[l].rel == &#39;alternate&#39;) {
                          var raw = json.feed.link[l].href;
                          var label = raw.substr(homeUrl3.length+13);
                          var k;
                          for (k=0; k&lt;20; k++) label = label.replace(&quot;%20&quot;, &quot; &quot;);
                          var txt = document.createTextNode(label);
                          var h = document.createElement(&#39;b&#39;);
                          h.appendChild(txt);
                          var div1 = document.createElement(&#39;div&#39;);
                           div1.appendChild(h);
                          div1.appendChild(ul);
                          document.getElementById(&#39;data2007&#39;).appendChild(div1);
                        }
                      }
                    }
                    function search10(query, label) {

                    var script = document.createElement(&#39;script&#39;);
                    script.setAttribute(&#39;src&#39;, query + &#39;feeds/posts/default/-/&#39;
                     + label +
                    &#39;?alt=json-in-script&amp;callback=listEntries10&#39;);
                    script.setAttribute(&#39;type&#39;, &#39;text/javascript&#39;);
                    document.documentElement.firstChild.appendChild(script);
                    }

                    var labelArray = new Array();
                    var numLabel = 0;

                    <b:loop values='data:posts' var='post'>
                      <b:loop values='data:post.labels' var='label'>
                        textLabel = &quot;<data:label.name/>&quot;;
                        var test = 0;
                        for (var i = 0; i &lt; labelArray.length; i++)
                        if (labelArray[i] == textLabel) test = 1;
                        if (test == 0) {
                           labelArray.push(textLabel);
                           var maxLabels = (labelArray.length &lt;= maxNumberOfLabels) ?
                                  labelArray.length : maxNumberOfLabels;
                           if (numLabel &lt; maxLabels) {
                              search10(homeUrl3, textLabel);
                              numLabel++;
                           }
                        }
                      </b:loop>
                    </b:loop>
                    </script>
                </div>

            </div>

</b:if>

Este important de retinut ca daca mai ai si alte widgets care vrei sa apara numai pe pagina articolului, este bine sa le pui inainte de acest ultim </b:if>. Ca si A), poti schimba Related Posts by categories in Articole Asemanatoare.

Jackbook a publicat propriile instructiuni in engleza, iar altii au scris un update. A publicat chiar codul separat intr-un fisier text, si a facut un sablon demo care poate fi descarcat.

C) Discutie

Ambele widgeturi pot fi configurate in numarul de articole per subiect cat si in numarul de categorii. Cauta declaratiile de variabile (var) si modifica-le dupa plac. In testarea mea prima (A) are problema ca apare chiar si pe prima pagina. Daca te uiti in cod, vei gasi ca statement-ul <b:if cond='data:blog.pageType == &quot;item&quot;'> este commented out, sugerand ca Hoctro fie n-a terminat widgetul, fie nu a putut rezolva aceasta problema. Iata de ce recomand versiunea B), chiar daca ai mai putin control la cum si unde apare. Daca insa ai avut succes cu prima varianta, nu ezita sa ma anunti printr-un comentariu. In orice caz, nu-mi cere ajutor prin email sau IM intrucat nu-l pot oferi; intreaba prin comentarii, ca toti cei interesati sa poata beneficia.

20090810 UPDATE: Vrei mai multe articole tehnice pentru Blogger / Blogspot? Este modificarea de aici curenta, sau am facut una noua, cu acelasi efect, dar mai buna? Toate modificarile aduse de mine acestui sablon (template) pot fi gasite in Zamolxis ChangeLog. Seria lucrand la fatada va gazdui de-acu’ incolo articole despre PR, media persuasion si eventual imaginea Romaniei.

Thank you for reading (mulţam fain pentru cetire)! Publicat Saturday, November 01, 2008 . Similar articles under the following categories (poţi găsi articole similare sub următoarele categorii): (Subscribe) . Dacă ţi-a plăcut articolul, PinIt-uieste-l, ReddIt-eaza-l, stumble-uieste-l altora, trimite-l pe WhatsApp yMess şi consideră abonarea la fluxul RSS sau prin email. Ma poti de asemenea gasi pe Google. Trackback poateputea fi trimis prin URL-ul de sub Comentarii.
Aici vei găsi ştiri inedite, articole hazoase, perspective originale in politică, societate, economie şi relaţii interumane. QUESTIONS (Intrebări)? We got Answers (Răspunsuri există)!  
blog comments powered by Disqus