Help me deal with posts on WordPress . It is necessary to display the last 3 posts on the main page and for each post I could indicate the number of words that should be displayed there.

For example:

  • for the first post you need 16 words
  • for the second post 22 words
  • for the third - 19

The problem is to specify different lengths of posts. I have tried the recent posts extended plugin, but there you can specify the length of the posts, but it will be the same for everyone.

Or maybe I can use some other widget for this purpose. Thank! enter image description here

  • for this, it is enough to specify <-- more --> in the post and it will be cut off as you like. - BOPOH
  • <- more -> just does not work, it does not cut the post, and there is actually no more clickable button. - Mariana
  • it means that you somehow add it up wrongly, it works fine for me, when inserting into a post, visual formatting or text was opened? Those. if you insert in post - tag becomes visible or not? If it is visible, it means that it is not so inserted; if it is not visible, it means that somehow you display the wrong posts - BOPOH
  • Maybe I really do not add it correctly. I am writing A my new postA my new postA my new postA my new postA I tried and text formatting and visual, with no results. - Mariana

1 answer 1

It is necessary that this feature supports the pattern. You can divide the post text by <!--more--> using the get_extended() function.

Updated

You can use this function either directly in the template, or in the function.php file. Since you display a list of posts on the main one, this happens outside the main output cycle of posts. Most likely, an additional request is made in the template of the main page (or in function.php ), in which the last three records you need are returned.

To output a passage to the separator by the post ID write such a function in function.php (or insert all the code in the appropriate place of the template):

 function the_short_content( $ID ) { $post = get_post( $ID ); $content_parts = get_extended( $post->post_content ); $short_content = apply_filters( 'the_content', $content_parts['main'] ); echo $short_content; } 

Then you can call it in the template instead of the_content() .

  • And it is possible more in detail about function where exactly it needs to be added? In function.php - Mariana
  • @Mariana Completed the answer - tutankhamun