In my recent post: Google AdSense Now Logs Into Your Sites I mentioned that displaying a quick preview of your content might be useful in some scenarios. În ultimii meu post: Google AdSense Acum Rapoarte-vă la site-uri am menţionat că afişarea o scurtă previzualizare a conţinutului dvs., ar putea fi utile în anumite scenarii. Particularly if you want to charge subscription fees for full content. I’ll illustrated with an example so you can get an idea of where to start in accomplishing this with your own sites. În special dacă doriţi să perceapă taxe de abonament pentru întregul conţinut. Voi ilustrate cu un exemplu, astfel încât să puteţi obţine o idee de unde să încep în realizarea acestui cu propriul dvs. site-uri. The key component in making this work is the substr ($content,0,300) function. De componentă cheie în a face acest lucru este substr ($ continut, 0300) funcţie. You specify the length of content by declaring a start (0) and the end (300). Puteţi specifica lungimea de conţinut de către un început de declarare (0) şi sfârşitul (300). You can then output a shortened version of $content and store it in a separate variable. Aveţi apoi posibilitatea de ieşire o versiune de $ conţinut şi-l va stoca într-o variabilă separată. Great to use as a “preview” for your content. Marea de a folosi ca un "preview" pentru dvs. de conţinut. Note: the number refers to the numbers of characters in the provided string, not words. Notă: se referă la numărul de numere de caractere prevăzute în şir, nu cuvinte.

What you need to do is figure out the existing variables you’re outputting on each content page (likely found within your template). Ce trebuie să faceţi este să-mi dau seama de variabilele existente, pe care sunteţi afişarea de conţinut de pe fiecare pagină (probabil găsit în şablonul dvs.). This part goes beyond the scope of this article. Această parte merge dincolo de domeniul de aplicare a prezentului articol. All sites are set up with slightly differently variables and even grab content from different sources…this is not an exact science. Toate site-urile sunt prevăzute cu puţin diferit de variabile şi chiar apuca de conţinut din diferite surse ... asta nu este o ştiinţă exactă.

I will assume your data is coming from a mySQL database and $id is a number that refers to a row of content in your database. Vom presupune dvs. de date este provenind de la o baza de date MySQL şi $ id-ul este un număr care se referă la un rând de conţinut în baza dumneavoastră de date. This first snippet shows a row being queried in preparation for it to be cut down into a preview. Acest lucru arată un fragment primul rând queried fiind în curs de pregătire pentru a fi tăiat-o în jos într-o previzualizare.

  1. $result = mysql_query ( "SELECT id,content FROM table WHERE id={$id}" , $db ) ;
  2. $row = mysql_fetch_row ( $result ) ;
  3. echo $row [ 0 ] ; //The value of id
  4. echo $row [ 1 ] ; //The value of content
  5. $content = $row [ 1 ] ; //Store it into something we can identify easily

This is even easier when you already have your content in a string. Aceasta este chiar mai uşor atunci când aveţi deja dvs. de conţinut într-un şir de caractere. In that case you wouldn’t have to run a query on it again. În caz că nu v-ar trebui să rulaţi o căutare pe-o din nou. There are also applications in which you would want to have this preview show before you content. Există, de asemenea, aplicaţii, în care veţi dori să aveţi această previzualizare înainte de a vă arăta de conţinut. In that case you would only need to integrate something like this into your templates (and yes there is more then one way to do this): În acest caz ar trebui doar să integreze ceva de genul asta în şabloanele dumneavoastră (şi da, există mai apoi un mod de a face acest lucru):

  1. $previewcontent = substr ( $content , 0 , 300 ) ;
  2. if ( isset ( $go ) ) { //If set then they have seen the preview already
  3. echo $content ; //Display your usual content
  4. } else { //First time viewing this page
  5. echo "Article preview:<br><br>" . $previewcontent ;
  6. echo "See this entire post<a href= \" showcontent.php?id=" . $id . "&go=yes \" >here</a>" ;
  7. //Or you could add something like this (instead of lines 6 & 7) for paid/subscription content
  8. if ( isset ( $user ) ) { //If a user is logged in…
  9. echo "Go ahead and <a href= \" showcontent.php?id=" . $id . "&go=yes \" >view</a>" ;
  10. } else { //$user is not set - insert login/signup link/form below
  11. echo "To view this solution please click <a href= \" yoursignupscript.php \" >here</a> to purchase access." ;
  12. }

In my alternate configuration where visitors need to purchase access you should also change your first if statement to check if a user is logged in by doing: În meu alternativ de configurare în cazul în care vizitatorii trebuie să cumpere de acces ar trebui, de asemenea, dacă vă schimbaţi prima declaraţie pentru a verifica dacă un utilizator este autentificat de către face:
if(isset($go) && isset($user)) if (isset ($ du-te) & & isset ($ utilizator))

There’s some security and usability you need to consider when implementing this which I didn’t get into. Există unele de securitate şi utilizare, trebuie să ia în considerare la punerea în aplicare a prezentului care nu am a-şi lua. As shown above isset () is another very handy function in php as it allows you to set triggers in conjunction with if statements. După cum se arată de mai sus isset () este un alt foarte la îndemână, în funcţie php ca acesta vă permite să setaţi declanşează dacă în legătură cu declaraţiile. This can make a webpage very dynamic. Acest lucru se poate face o pagina de web foarte dinamic.

If you’re not that far yet with a coding language, I hope this at least gives you some ideas of what you can do. For additional help check out php.net: http://us3.php.net/substr . Dacă nu sunteţi încă atât de departe cu un limbaj de codificare, sper ca acest cel puţin vă oferă unele idei de ce puteţi face. Pentru ajutor suplimentar verifica php.net: http://us3.php.net/substr. Just getting started with php/mySQL?: Increase Earning Potential With These PHP/mySQL Tutorials Doar începe cu PHP / MySQL?: Creşterea Aceste castiguri Potentiali Cu PHP / mySQL Tutoriale



Leave A Comment: Lăsaţi un comentariu:

Comments RSS Feed Comentarii RSS Feed

7 - 3 = 7 - 3 =

Custom Theme by Rob Malon | Content & Design © 2008 - Rob Malon [dot] Com. Tema la comandă de către Rob Malon | Design & Content © 2008 - Rob Malon [punct] com. "));
"));