14 January 2009

How to display the related posts (Related Posts)

Related Posts or as "the link that bekaitan," "articles on the same category," "articles that mesh," "post-related" or are named, is the title of the post-related and usually displayed based on naming label (category), Realated This post is usually a link that will show the posting under the sole right column comments. The advantage of the post with a related, of course, will make it easier for visitors to our blogs to find related articles without having to go and open the pages one by one in the link label. To have a confused picture see below :





































I do need discussed extensively so, certain know all meaning. OK directly to the installation process :)

Step I:

Entrance on the Template -> Edit HTML -> then enter the code below between the javascript code <head> .. </ head> or more easily find the code </ head> course, then the code above letakan code </ head> -> do not forget saved

<script type="text/javascript">

//<![ CDATA [

var relatedTitles = new Array ();

relatedTitlesNum var = 0;

var relatedUrls = new Array ();

related_results_labels function (json) (

for (var i = 0; i <json.feed.entry.length; + + i) (

var entry = json.feed.entry [i];

relatedTitles [relatedTitlesNum] = entry.title. $ t;

for (var k = 0; k <entry.link.length; k + +) (

if (entry.link [k]. rel == 'alternate') (

relatedUrls [relatedTitlesNum] = entry.link [k]. href;

relatedTitlesNum + +;

break;

)

)

)

)

removeRelatedDuplicates function () (

var tmp = new Array (0);

var tmp2 = new Array (0);

for (var i = 0; i <relatedUrls.length; + + i) (

if (! contains (tmp, relatedUrls [i])) (

tmp.length + = 1;

tmp [tmp.length - 1] = relatedUrls [i];

tmp2.length + = 1;

tmp2 [tmp2.length - 1] = relatedTitles [i];

)

)

relatedTitles = tmp2;

relatedUrls = tmp;

)

function contains (a, e) (

for (var j = 0; j <a.length; j + +) if (a [j] == e) return true;

return false;

)

printRelatedLabels function () (

var r = Math.floor ((relatedTitles.length - 1) * Math.random ());

var i = 0;

document.write ( '<ul>');

while (i <relatedTitles.length & & i <20) (

document.write ( '<a href="' <li> relatedUrls[r] + +'">' + relatedTitles [r] + '</ a> </ li>');

if (r <relatedTitles.length - 1) (

r + +;

Else ()

r = 0;

)

i + +;

)

document.write ( '</ ul>');

)

//]]>

</ script>

Step II:

Entrance on the Template -> Edit HTML -> do not forget to check the Expand Widget Templates -> find the code below.

<b:if cond='data:post.labels'>

<data:postLabelsLabel/>

<b:loop values='data:post.labels' var='label'>

<a expr:href='data:label.url' rel='tag'> <data:label.name/> </ a> <b:if cond='data:label.isLast != "true"'> , </ b: if>

</ b: loop>

</ b: if>

If you have met, enter the code red under the code above.

<b:if cond='data:post.labels'>

<data:postLabelsLabel/>

<b:loop values='data:post.labels' var='label'>

<a expr:href='data:label.url' rel='tag'> <data:label.name/> </ a> <b:if cond='data:label.isLast != "true"'> , </ b: if>

<b:if cond='data:blog.pageType == "item"'>

<script expr: src = ' "/ feeds/posts/default/- /" + data: label.name + "? alt = json-in-script & callback = related_results_labels & max-results = 10"' type = 'text / javascript '/>

</ b: if>

</ b: loop>

</ b: if>

In the editing process on the HTML code is done, Do not forget to save

Step III:

Entrance on the Template -> Element -> page and create a new elemet or click on "Add a Page Element" -> copy-paste the code below and be sure to give the name of the title for example, "Articles on the same category" -> then do not forget to save .

<script type="text/javascript">

removeRelatedDuplicates ();

printRelatedLabels ();

</ script>

Step IV:

Related post so that this does not appear on the main page and only appear on a single page post and we need the addition of some code, how:

Entrance on the Template -> Edit HTML -> do not forget to check the Expand Widget Templates -> find the code below, sebisanya title search in accordance with the input that we, as an example, where before I give the articles on the same category, if it is found two entries to the code red.

Note: this code HTML13 have not made this standard search, you should ignore it because every element certainly different, simply search title only.

<b:widget id='HTML13' locked='false' title='Article the category that same' type='HTML'>

<b:includable id='main'>

<b:if cond='data:blog.pageType == "item"'>

<! - Only display title if it's non-empty ->

<b:if cond='data:title != ""'>

<h2 class='title'> <data:title/> </ H2>

</ b: if>

<div class='widget-content'>

<data:content/>

</ div>

<b:include name='quickedit'/>

</ b: if>

</ b: includable>

</ b: widget>



No comments:

Post a Comment