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. Minun viime post: Google AdSense Nyt Lokit Into Your sivustot mainitsin, että näyttämällä nopeasti esikatsella sisältöä voisi olla hyödyllistä joissakin tilanteissa. 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. Varsinkin, jos haluat veloittaa merkintä-maksut kokonaisuudessaan. I'll kuvata esimerkiksi siten, että voit saada käsityksen siitä, mistä aloittaa huomioon ottaen tämän omalla sivustoja. The key component in making this work is the substr ($content,0,300) function. Keskeinen osa tätä työtä on substr ($ sisältöä, 0300)-funktiota. You specify the length of content by declaring a start (0) and the end (300). Voit määrittää pituus sisältöä julistamisesta start (0) ja lopussa (300). You can then output a shortened version of $content and store it in a separate variable. Tämän jälkeen voit tulostaa lyhennetty versio $ sisällön ja tallentaa sen erilliseen muuttujaan. Great to use as a “preview” for your content. Suurten ja käyttää sitä "Esikatselu" teidän sisältöä. Note: the number refers to the numbers of characters in the provided string, not words. Huom: numero viittaa määrän merkkejä, että jos merkkijono, ei sanoja.

What you need to do is figure out the existing variables you’re outputting on each content page (likely found within your template). Mitä sinun tarvitsee tehdä, on selvittää olemassa olevien muuttujien olet ulos jokaisesta sisällön sivu (todennäköisesti löytyy oma malli). This part goes beyond the scope of this article. Tämä osa menee pidemmälle kuin tämän artiklan soveltamisalan piiriin. All sites are set up with slightly differently variables and even grab content from different sources…this is not an exact science. Kaikki sivustot ovat perustaneet kanssa hieman eri muuttujia ja jopa napata sisältöä eri lähteistä ... tämä ei ole tarkkaa tiedettä.

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. Minä oletan, tietosi on peräisin MySQL-tietokantaan ja $ id on numero, joka viittaa peräkkäin sisällön tietokanta. This first snippet shows a row being queried in preparation for it to be cut down into a preview. Tämä ensimmäinen pätkä osoittaa peräkkäin että hakuja valmistelua, jotta se voidaan kaataa osaksi esikatselu.

  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. Tämä on vieläkin helpompaa, kun sinulla on jo oma sisältö on merkkijono. In that case you wouldn’t have to run a query on it again. Tällöin sinun ei tarvitse suorittaa haku uudelleen. There are also applications in which you would want to have this preview show before you content. On myös sovelluksia, joissa sinulla haluaisi olla esikatselu näyttää, ennen kuin sisältö. 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): Tuossa tapauksessa olisi vain tarvetta integroida jotain tällaista oman malleja (ja kyllä siellä on enemmän kuin yksi tapa tehdä tämä):

  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: Minun varajäsenen kokoonpano, joissa kävijät tarvitse ostaa pääsy sinun pitäisi muuttaa myös ensimmäinen, jos ilmoitus tarkistaa, jos käyttäjä on kirjautunut sisään tekemällä:
if(isset($go) && isset($user)) if (isset ($ go) & & isset ($ user))

There’s some security and usability you need to consider when implementing this which I didn’t get into. On joitakin tietoturvaan ja käytettävyyteen sinun täytyy harkita, kun täytäntöönpanossa jota ei päästä. As shown above isset () is another very handy function in php as it allows you to set triggers in conjunction with if statements. Kuten edellä on esitetty isset () on toinen erittäin kätevä toiminto PHP, koska sen avulla voit asettaa käynnistää yhdessä jos julkilausumat. This can make a webpage very dynamic. Tämä voi tehdä verkkosivun hyvin dynaaminen.

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 . Jos et ole vielä niin pitkälle, joiden koodaus kieli, toivon, että tämä ainakin antaa sinulle joitakin ajatuksia siitä, mitä voit tehdä. Saat lisätietoja auttaa tarkistaa php.net: http://us3.php.net/substr. Just getting started with php/mySQL?: Increase Earning Potential With These PHP/mySQL Tutorials Juuri aloittanut php / mysql?: Lisäys tuottava potentiaali Nämä PHP / MySQL Oppaat



Leave A Comment: Jätä kommentti:

Comments RSS Feed Kommentit RSS-syöte

6 Minus 3 = 6 Minus 3 =

Custom Theme by Rob Malon | Content & Design © 2008 - Rob Malon [dot] Com. Custom Theme: Rob Malon | Sisältö & Design © 2008 - Rob Malon [piste] com. "));
"));