Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To accomplish this you need to read the RSS of the blog, from RSS you need to read the Title and the description, after reading the whole description and title you need to trim the description to your desired number of letters. After that you need to check weather the description last word has been completed or not and then you need to remove a the last word if not completed and put the "...".</p> <p>First we will make a script to trim the description and to put "..." in last:-</p> <pre><code>&lt;?php global $text, $maxchar, $end; function substrwords($text, $maxchar, $end='...') { if (strlen($text) &gt; $maxchar || $text == '') { $words = preg_split('/\s/', $text); $output = ''; $i = 0; while (1) { $length = strlen($output)+strlen($words[$i]); if ($length &gt; $maxchar) { break; } else { $output .= " " . $words[$i]; ++$i; } } $output .= $end; } else { $output = $text; } return $output; } </code></pre> <p>Now we will define the variables in which we store the values:-</p> <pre><code>$xml=("http://your-blog-path/rss/"); global $item_title, $item_link, $item_description; $xmlDoc = new DOMDocument(); $xmlDoc-&gt;load($xml); $x=$xmlDoc-&gt;getElementsByTagName('item'); </code></pre> <p>Now, we will make an array and store values in it. I am only taking 3 because you have asked it the way. You can change it to anything (The number of post you want to show, put that in the loop)</p> <pre><code>for ($i=0; $i&lt;3; $i++) { $item_title[$i] = $x-&gt;item($i)-&gt;getElementsByTagName('title')-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $item_link[$i] = $x-&gt;item($i)-&gt;getElementsByTagName('link')-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $item_description[$i] = $x-&gt;item($i)-&gt;getElementsByTagName('description')-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; } ?&gt; </code></pre> <p>Now echo all these values, Link is the value where your user will click and he will be taken to your blog:-</p> <p>FIRST RECENT POST:</p> <pre><code>&lt;a href="&lt;?php echo $item_link[0]; ?&gt;"&gt;&lt;?php echo $item_title[0]; ?&gt;&lt;/a&gt; &lt;?php echo substrwords($item_description[0],70); ?&gt; </code></pre> <p>SECOND RECENT POST:</p> <pre><code>&lt;a href="&lt;?php echo $item_link[1]; ?&gt;"&gt;&lt;?php echo $item_title[1]; ?&gt;&lt;/a&gt; &lt;?php echo substrwords($item_description[1],70); ?&gt; </code></pre> <p>THIRD RECENT POST:</p> <pre><code>&lt;a href="&lt;?php echo $item_link[2]; ?&gt;"&gt;&lt;?php echo $item_title[2]; ?&gt;&lt;/a&gt; &lt;?php echo substrwords($item_description[2],70); ?&gt; </code></pre> <p>Hope this can solve your problem. By the way Nice question.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload