Topic: How to change a long blog post to not show all of it on the home page

Problem:

If you create long Simple Posts, they can take up a lot of space on your blogs home page.  I wanted to only have a portion of the blog post to display and have a MORE... indicator display.  When they click on MORE, it will show the whole blog post.  I have seen this in other blog tools and it is missing in Nibbleblog. 

Resolution:
I used my basic PHP skills to change two files to make it work for Simple Posts.

Step 1: make a copy of these two files
/admin/views/post/new_simple.bit
/admin/kernel/helpers/post.class.php


Step 2:
Modify the admin interface screen on the Simple Post form to remind that this feature is available:
File to change:  /admin/views/post/new_simple.bit
Old code:
    // TITLE
    include('includes/title.bit');
   
    // CONTENT

New code:   
        // TITLE
    include('includes/title.bit');
  // added hint for getting the MORE to display   
  echo "use ::: (three colons) on a separate line to crop article and display the MORE indicator on blog main page";
    // CONTENT
   
Step 3:
Modify the display to show the MORE indicator on the main page and strip the more indicator on the display of the full post

File to change:  /admin/kernel/helpers/post.class.php


Old code under the "public static function content($full=false)" function:

            if($full)
                  $html = $post['content'][0];
            else
                  $html = $post['content'][1];

New code:
            if($full)
                {
                  $html = $post['content'][0];
                  // CUSTOM  start - change to remove the ::: more indicator when looking at the full text
                 $html = str_replace(":::"," ",$html);  // strip out more indicator when showing whole article
                  // CUSTOM  end                
                 }
            else
               {
                // CUSTOM  start - replace the ::: with the MORE indicator and link to full article
                   $more_indicator = 0;
       
                  $blog_entry = $post['content'][1];
                  $more_indicator = strpos($blog_entry, ":::");  // starts counting at 0
       
                  if ($more_indicator!=0)
                    {
                      $html = substr($blog_entry, 0, $more_indicator);
                      $the_link = Url::post($post,FALSE);  // link for full post
                
                      $html = $html . '<a href="' . $the_link . '">' ."[more]</a>";
                    }
                  else
                   {
                     $html = $post['content'][1];
                   }       
                  // CUSTOM  end                
                }
   
Step 4:
Upload the changed files
Create a new Simple Post with 2 paragraphs and put in the ::: characters on a blank line in between two paragraphs.    Publish the entry and check your main page to see that only one paragraph shows and the MORE indicator appears.  Click on the MORE and you should be taken to a page with the full 2 paragraphs shown.


Other info:
You can see where in the indcluded hanges I made to use something besides ::: and [more].
I did not modify the rest of the files to do the same trick for Video Post or Quote Post.
I only tested this with the Simpler theme and Nibbleblog 4.0.3
I make no claims that the PHP code is pretty, but it is easy to read

Re: How to change a long blog post to not show all of it on the home page

I do not understand you, why do you not use page break on TinyMCE ?

3 (edited by topicsent 11-04-2014 21:51:23)

Re: How to change a long blog post to not show all of it on the home page

I think you are missing the point.  The main page of the blog current shows 6 posts.  If each one is 900 lines long, good lucking finding where one start and ends.

My tweak allows you to create the same Simple Post, but add the ::: characters where you want only up to that much of the text shown on the blog page.  The ::: is replaced with the [More] link to the full blog post.


See www TheFlashCard org for an example.

Re: How to change a long blog post to not show all of it on the home page

Hi, what jano is saying is that this functionality is already present in Nibbleblog. When creating a Simple Post, the TinyMCE editor (if you are not using Markdown version) has a button (3rd to the right in Nb 4.0.3) named "Page break". This inserts a line in the editor so that the text below is only shown when viewing the complete post. It also adds the "Read more" link to the post instead of the "Permalink".

Re: How to change a long blog post to not show all of it on the home page

It does not seem to work with the Simpler2 theme

Re: How to change a long blog post to not show all of it on the home page

I've just tested this and it is true that Simpler2 is not showing the "Read more" link when using a page break. Maybe Diego forgot to add it when updating the theme.

Re: How to change a long blog post to not show all of it on the home page

Page break works a treat, however with the Simpler2 theme, I don't see the 'read more' instead the usual permalink, I could hack the code but an official release/update would be better

My 2p worth!

Re: How to change a long blog post to not show all of it on the home page

I had to modify the Echo Theme a little as well.

Nevertheless I am using the MarkDown-Version and you do only have to add

 <!-- pagebreak --> 


where you want the page to be cut off and a Read More to be placed.

Re: How to change a long blog post to not show all of it on the home page

Whether it's the Pagebreak method or the method you described in this article, in both the case the author has to manually add some piece of code in the post to make it work.

I was wondering if there is any way like, "Read more" link automatically getting added to the posts which are having, say, more than 100 words ? Simply putting - an automatic method where the author doesn't have to manually insert particular code/tag in the post

Re: How to change a long blog post to not show all of it on the home page

aviartz wrote:

I was wondering if there is any way like, "Read more" link automatically getting added to the posts which are having, say, more than 100 words ? Simply putting - an automatic method where the author doesn't have to manually insert particular code/tag in the post

It will be a nice feature. I think Diego needs more programmers in this community who can contribute to the code.

Re: How to change a long blog post to not show all of it on the home page

This is awesome, does it work with 4.0.3?

Re: How to change a long blog post to not show all of it on the home page

Thank you topicsent for posting this!

I have searched with absolutely zero luck for any code to add the more button to the page break method to shorten full posts.

This still works flawlessly!