Forums

1 post on front page only (33 posts)

  1. JayWalker
    Member
    Posted 4 years ago #

    Hello everyone,

    Anybody got any idea how I can display one post on the front page only, without changing the Reading Options?
    In the reading options one can set the maximum number of posts in one page to "1".
    But this doesn't work for my case, since I want several posts to appear on any normal page except the front page.

    Tricky problem, I know...
    Anyone who can help me? Thanks for your help!

    Jay

  2. JayWalker
    Member
    Posted 4 years ago #

    Very sorry i accidentally double-posted this forum topic. I had deleted the old one if I could...

  3. Jinsan
    Member
    Posted 4 years ago #

    What do you define as normal page? There are several solutions to this problem, but I can't quite understand the extent to which you want the solution.

    For example, do you want a frontpage which has only the single post on the front page and nothing else? Do you want to display other posts on the same page in summary or as links? Do you want the front page as the only post, then by clicking it will display it and other posts on the same page?

    As I say there are many solutions, but you will have to be a bit more specific. There are a few plugins that actually deal with this, I believe.

    In the end, make sure that the reading option works with another theme, otherwise you may have problems later. Reading>Options should work by default.

    You can also try this:

    http://wordpress.org/support/topic.php?id=28937
    http://wordpress.org/support/topic.php?id=27305

    I do urge that if the reading option doesn't work and you use this plugin, it may or may not work, even if it does, I'm certain you will face problems later.

  4. ifelse
    Moderator
    Posted 4 years ago #

    I've written a post on how you can do this without resorting to plugins. This is also preferable to changing the reading options as it doesn't affect how many posts are shown on other pages besides the front page i.e. pagination isn't broken for archives and search pages.

  5. Kafkaesqui
    Moderator
    Posted 4 years ago #

    Good post ifelse.

    You may want to add something about templates in 1.5 users could have to deal with, in that if a theme--or someone's custom setup--is using index.php for more than just the "home" page, they might have issues with your code. Or you could suggest they use something like:

    if(is_home()) {
    query_posts('posts_per_page=1');
    }

    which would cover all the bases.

  6. ifelse
    Moderator
    Posted 4 years ago #

    Thanks for the feedback, Kafkaesqui.

    "If a theme is using index.php for more than just the "home" page, they might have issues with your code."
    Hopefully, the first step that I added in the post (making a copy of index.php and renaming it to home.php) should make that a non-issue as home.php should only be used for the front page.

    However, if anyone doesn't want to retain a home.php page as well, then Kafkaesqui use of the is_home conditional will work perfectly well in the index.php.

    BTW, if there's something else which I've overlooked however, feel free to point it out:-)

  7. JayWalker
    Member
    Posted 4 years ago #

    Thank you for your great reply, guys!

    @ Jinsan: You suggested correctly. The link you've posted dealt with the very same problem as I had. Still, as I am a PHP-idiot, I didn't quite understand the answer...

    @ ifelse & Kafkaesqui: Very nice of you to write a post just for my case. Thanks a lot!
    Please excuse my PHP-ignorance, but how do I tell WordPress that the front page is called "Home" and what the names of other pages are? Sorry, I'm a bit confused...

  8. Kafkaesqui
    Moderator
    Posted 4 years ago #

    "Hopefully, the first step that I added in the post..."

    That would also take care of it. :)

    JayWalker: Revisit ifelse's post (if you haven't already) and follow the point about creating a home.php.

  9. JayWalker
    Member
    Posted 4 years ago #

    I don't have a header, footer or sidebar. I have made it all into one page. How do I alter ifelse's code then? Leave out "get_header()"?

  10. ifelse
    Moderator
    Posted 4 years ago #

    "Please excuse my PHP-ignorance, but how do I tell WordPress that the front page is called "Home" and what the names of other pages are?"
    No need to apologise:-) WP has a number of special files that it'll look for in a theme.

    One of these is a home.php. If you have a file called home.php in your themes directory i.e. /YOUR_BLOG/wp-content/themes/THEME_NAME/home.php

    then that'll be used for the home page. If you don't have one, you can copy the index.php and rename it to home.php. All you then have to do is call query_posts('posts_per_page=1'); as I'd shown on the post.

    If you place a link to your blog or let us know what theme you're using, it may be a bit easier for us to describe specifically what you need to do.

  11. ifelse
    Moderator
    Posted 4 years ago #

    "I don't have a header, footer or sidebar. I have made it all into one page. How do I alter ifelse's code then? Leave out get_header()?"
    Which version of WP are you using? 1.5 or 1.2?

  12. JayWalker
    Member
    Posted 4 years ago #

    <i>No need to apologise:-) WP has a number of special files that it'll look for in a theme.</i>

    Aaaah!! Finally there is this page I've been looking for so long. Thanks ifelse! I was blind but now I can see. :)

    I'm using Version 1.5. Does that make a difference?

  13. ifelse
    Moderator
    Posted 4 years ago #

    "I'm using Version 1.5. Does that make a difference?"
    Nope, what you have is fine. WP 1.5 is what'll you'll need:-) All you have to do is make the call to query_posts before you go into The_loop.

  14. JayWalker
    Member
    Posted 4 years ago #

    Hey, that seems to work!
    Thanks a lot ifelse for your great help!

  15. JayWalker
    Member
    Posted 4 years ago #

    Hold on. There is a mistake. The content on the front page is missing after I've put in the query_posts command. How come?

  16. JapaneseTrash
    Member
    Posted 4 years ago #

    This is exactly the information I was looking for. I've done everything your post on IfElse says to do, but no joy yet. I'm at http://japanesetrash.com if you need to take a look.

  17. ifelse
    Moderator
    Posted 4 years ago #

    I've done everything your post says to do, but no joy yet.
    That's because the Benevolance theme uses the old WP1.2 method of retrieving posts i.e. instead of
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    it uses
    foreach($posts as $post) { start_wp();

    Hence, the_loop will need to be modified to the new WP1.5 way of doing things before you can use this technique.

  18. JayWalker
    Member
    Posted 4 years ago #

    ifelse, after including the query_posts there is no more post on the front page at all. What to do?

  19. ifelse
    Moderator
    Posted 4 years ago #

    Do you have a link?

  20. JayWalker
    Member
    Posted 4 years ago #

    http://www.leidartikel.de/wordpress/

    When you click on the column title "Leidartikel" the page that appears contains 1 article, the way it should be. But the front page doesn't...

  21. Root
    Member
    Posted 4 years ago #

    That is the default behavior. Single post for singles. All the latest posts on the front. It will stay that way until you change it.

  22. ifelse
    Moderator
    Posted 4 years ago #

    Can you check that the post has some content? That particular post (the latest one) when viewed individually appears to be devoid of content.

    Another randomly chosen post appears fine.

  23. JayWalker
    Member
    Posted 4 years ago #

    You are 100% right. That was exactly the problem. It works now. Thanks so much, ifelse, for your great help today!

  24. ifelse
    Moderator
    Posted 4 years ago #

    No problem. Glad I could help:-)

  25. JapaneseTrash
    Member
    Posted 4 years ago #

    Thanks for all the help. Here's my code on home.php . Now I get the following error on http://japanesetrash.com:

    Parse error: parse error in /home/httpd/dbannon/japanesetrash.com/html/wp-content/themes/benevolence/home.php on line 29

  26. ifelse
    Moderator
    Posted 4 years ago #

    The if/endifs and while loops haven't been been properly closed. You're probably after something like this (There's been a quick attempt to fix your code made but no promises).

    BTW, in future, for large code chunks, could you stick it in a text file and include a link or use this site. If you could edit your post to do this, it'll be much appreciated by everyone here:-)

  27. JapaneseTrash
    Member
    Posted 4 years ago #

    First of all, thanks for the advice about posting code, it's much appreciated.

    Secondly, you're a real champ for helping me out with this. I've got a lot to learn and your patience and instruction has been awesome. The home.php page now works!

  28. breger
    Member
    Posted 4 years ago #

    I have recently implemented "Page To Front" plugin also and wondered if there is any way to get rid of the date for the post. I want it to almost act like a static page and it seems odd to leave a date for the post in there.

  29. JayWalker
    Member
    Posted 4 years ago #

    An update and new problem to this case: It works fine now to only display the one latest post on the front page with

    <?php query_posts('posts_per_page=1'); //returns only the front page ?>

    added in the home.php page right before the loop. However, I would like to display the latest post of ONE category only. Suppose I've got 5 categories and only want the latest post of category 1 to appear on the front page. How do I do that?
    Changing the code to

    <?php query_posts('category=1&posts_per_page=1'); //returns only the front page ?>

    did not help. Neither did 'category=categoryname'. Does anybody know the solution?

    Jay

  30. unveiled
    Member
    Posted 4 years ago #

    Have you tried this?

    <?php query_posts('cat=1&posts_per_page=1'); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic