0

What would be the best approach to show only the very last single full post in the home page and in blog page the full (paged) list of blogs showing only its excerpts?

I'm thinking of 2 different ways of getting it: one is (A) choosing 'static page' for frontpage, the other one (B) choosing 'last entries'.

CASE A (static page)

I'd need a script to load full last post content. In 'options > reading' it'd be set to show excerpts and, for instance, 10 posts per page maximum

CASE B (last entries)

I'd need a script to force home page to show only one post (it'd be the last one) and do it in full. Same as in Case A, in 'options > reading' it'd be set to show excerpts and, for instance, 10 posts per page maximum.

.

Right now I'm using Case B. I already got a script inserted in functions.php in order to show only the last post (one). Still I need to force it to be shown in full (or to show the rest as excerpts by default).

The script I got it from here. https://www.webhostinghero.com/change-number-of-posts-on-homepage/

Anyone to help finding the easiest more straightforward solution?

TIA, hip

  • create a page using a custom page template and set it as the static page – inarilo Jun 10 '17 at 17:34
  • Thank yoy @inarilo but I don't want a static front page but to show the whole very last post at each moment – Hip Jun 10 '17 at 21:38
  • the page will be static but the content will be dynamic. create a page template that displays the latest post and then create an empty page (it can have content of you wish, remember to display the content in your template if so), selecting that page template. – inarilo Jun 10 '17 at 21:53
  • Thank you @inarilo I'll go then for option A (static page for front page). No I need to know how to " create a page template that displays the latest post". I'll keep on searching or waiting for someone to throw some light within this thread. – Hip Jun 12 '17 at 10:10
  • developer.wordpress.org/themes/basics/template-hierarchy - you can create or modify front-page.php or you can create a separate page template. check the hierarchy used for pages as well. use codex.wordpress.org/Template_Tags/get_posts with posts_per_page set to 1 to get the latest post. the code for displaying posts is given as well. it's possible that your theme has a template part file for a single post, in which case you can just drop that into the loop after setting up the post data developer.wordpress.org/reference/functions/get_template_part hope this helps :) – inarilo Jun 12 '17 at 10:54
0

You can create or modify front-page.php or you can create a page template that displays the latest post and then create an empty page (it can have content of you wish, remember to display the content in your template if so) and select that page template. In case of the latter, name it according to the page hierarchy. In case of the former, if your theme already has a front-page.php, it is better to create a child theme instead of overwriting the file directly.

Use get_posts with 'posts_per_page' => 1 to get the latest post. The code for displaying posts is given in the link. It's possible that your theme has a template part file for a single post, in which case you can just drop that into the loop after calling setup_postdata.

As a starting point, copy the code from front-page.php if it exists, or else page.php.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.