Tải bản đầy đủ - 0 (trang)
Hack 97. Add Contextual Search to Your Blog

Hack 97. Add Contextual Search to Your Blog

Tải bản đầy đủ - 0trang

searchformisjustamatterofeditingyourtemplate.Every

pagethatwillhostaY!QsearchmustincludetheJavaScriptY!Q

library.Openyourtemplateandaddthefollowingcode

somewherebetweentheandtagsinthepage:










src="http://yq.search.yahoo.com/javascript/yq.j



Next,you'llneedtoaddsomeHTMLtothesectionofthe

templatethatdescribeshowpostsshouldbedisplayed.Here'sa

simplebitofHTMLfromaBlogger(http://www.blogger.com)

templatethatdescribeshowtodisplaythetextofapost:













<$BlogItemBody$>







Andhere'sthesamecode,withtheadditionofaY!QSearch

RelatedInfolink:



































<$BlogItemBody$>






























onclick="returnactivateYQ(this



















The
tagwiththeclassyqcontexttellsY!Qwhattohighlight

whensomeoneclickstheSearchRelatedInfolink.Andthe

createstheSearchRelatedInfolink.Withintheform,the

hiddenelementnamedcontexttellsYahoo!whatinformationis

relatedtothesearch.Inthiscase,theBlogger-specific

<$BlogItemBody$>tagsetsthevalueofcontexttothefulltextofthe

postwhentheweblogispublished.

Youcouldalsonarrowthisvaluetothetitleofthepostbyusing

the<$BlogItemTitle$>taginstead.Otherweblogsystemshave

specialtagsforcategoriesrelatedtothepostorapostexcerpt.

Youmightneedtoexperimentwiththecontexttoseewhich

informationgivesthebestrelatedresults.

Onceyousaveyourtemplatechangesandrepublishyour

weblog,youshouldseetheSearchRelatedInfolinkafterevery

post,asshowninFigure6-10.

Whenareaderclicksthelink,anewwindowappearswithinthe

page,highlightsthecontext,andshowsthetopfewrelated

searchresults,asshowninFigure6-11.

Atthispoint,thereadercanreviewthetopresults,clickoneto

visitanothersite,closetheRelatedSearchResultsbox,ortype

hisownqueryinthesearchfield.Eventhoughhetypeshisown

searchquery,Y!Qstillretainsthecontextofthepost.Figure612showstheY!QSearchResultspage,alongwiththekeywords

extractedfromthecontexttext.

Thereadercanreviewthekeywordsandrerunthesearchwith

adifferentcontext,orhecancompletelyturnofftherelated

searchfeaturetofindmoregeneralresults.

Thisexamplehasshownthebareminimumneededto

implementY!Q.Buttherearequiteafewoptionsyoucan

customize,mostwithhiddenformelementsyoucanaddtothe



Y!QHTML.Herearesomeofthepossiblecustomizations:



Figure6-10.Y!QSearchRelatedInfolinksona

weblog



SearchSpecificSites

YoucanuseahiddeninputtagnamedsiteRestrictiontolimit

Y!Qresultstoasinglewebsite,includingyourownsite.Set



thevalueattributeofthetagtoalistofsitesseparatedby

spaces.



NumberofResults

Bydefault,you'llseethetopthreeresultsinaY!Qbox,but

youcanchangethiswithahiddeninputtagnamed

YSTResultsMax.



Figure6-11.Y!QRelatedSearchResultsbox



MoreContext

Ifthere'ssomecontextyou'dliketoprovidebeyondwhat

yourreaderssee,youcanuseahiddentagnamed

siteContextforabriefparagraphoftext,orahiddentag

namedptoaddspecifickeywordstothecontext.



CustomLogoorText

YoucanaddyourownlogoortexttotheY!Qboxwith

hiddeninputtagsnamedc1,c2,andc3.Thevalueofthe

tagscanbeplaintextorHTML,soyoucouldincludethe

HTMLnecessarytohaveyourownlogointheY!Qbox,for

example.



LookandFeel

Youcanplaywiththeentirelookandfeeloftheboxby

creatingyourownstylesheet.ThedefaultstylesheetforY!Q

(http://yq.search.yahoo.com/javascript/defaultTheme.css)

isagoodbasisforbuildingyourown.



Figure6-12.Y!QSearchResultspage



YoucanfindafulllistofY!Qcustomizationoptionsfor

publishersat

http://yq.search.yahoo.com/publisher/embed.html.

ByaddingaY!Qsearchtoyourweblog,you'llbegivingyour

readersasmartersearchtoolthatletsyousetthecontextfor

theirresearch.







Hack98.PostPhotostoYourBlog



Ifyoutakeafewminutestoentersomeinformation

aboutyourweblogatFlickr,youcanpostphotosdirectly

toyourweblogwithasingleclick.

Eventhoughmanyweblogsystemsoffertoolstohelpyou

uploadandincludeimageswithyourposts,youmightfindthat

Flickrisanicealternativetothestandardphototools.Onceyou

uploadaphototoFlickr[Hack#67],youhaveseveraloptions

forincludingthatphotoinyourweblogposts.



6.8.1.BlogThis

ThemostdirectwaytosendaphotofromFlickrtoyourweblog

isthroughtheBlogThisbuttonaboveeachofyourphotos,as

showninFigure6-13.

ToenabletheBlogThisbutton,youneedtogiveFlickrsome

informationaboutyourweblog.



Figure6-13.TheBlogThisbuttonaboveaphoto

atFlickr



6.8.1.1.Configuringaweblog.

SettingupFlickrtoposttoaweblogisasimpleprocess.Click

YourAccountatthetopofanypageatFlickrandthenclickYour

BlogsunderthesectionlabeledBlogging.You'llfindalistofany

weblogsyou'vealreadysetup,oryoucanclick"Setupanew

blog"toaddanewweblogtoyouraccount.

ThefirststeptosettingupanewweblogistellingFlickrwhich

weblogtoolyouuse.Flickrsupportsthefollowingweblog

systems:



Blogger



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Hack 97. Add Contextual Search to Your Blog

Tải bản đầy đủ ngay(0 tr)

×