WordPress.org

Ready to get started?Download WordPress

Forums

Insert an extra paragraph on the home page. (6 posts)

  1. snotty
    Member
    Posted 8 years ago #

    Hi -

    I would like to insert an extra paragraph to appear permanently on the home page only.

    This would be a kind of 'welcome to this blog...'and appear just before the current post.

    How can I do this?

    Thank you.

  2. skippy
    Member
    Posted 8 years ago #

    You need to intercept [The_Loop] (see also [The_Loop_In_Action] for more examples).

    Start a counter before the beginning of your Loop:
    $mycount = 0;

    Then, in the loop at the place you want the static text, you check the value of $mycount:
    if (0 == $mycount) {
    // do your thing here
    }

    And finally, just before the loop ends, you increment $mycount:
    $mycount++;

    In this way, you only execute something on the first pass of the loop.

    An alternate solution would be to place your content above the loop, so that it happens before any posts get sent to the user.

  3. moshu
    Member
    Posted 8 years ago #

    The solution might be slightly different for different themes.
    1. Hardcoded in the index.php template - but if that template file is also used to display other views than the "home", it will appear everywhere
    2. To avoid this, put your text in a conditional tag:
    http://codex.wordpress.org/Conditional_Tags
    3. If there is a home.php template file, you can safely hardcoded it in that file - it is used only for (you guessed) "home" view.

    Edit. Oops, skippy is faster - and he knows way more coding :)

  4. snotty
    Member
    Posted 8 years ago #

    Thanks Skippy - "An alternate solution would be to place your content above the loop, so that it happens before any posts get sent to the user" - in what module would I do that? Wouldn't it then appear on every page?

  5. skippy
    Member
    Posted 8 years ago #

    snotty: your main page is (usually) controlled by index.php.

    yes this would display on every page view; unless you use the conditional tags or home.php, as suggested by moshu.

  6. snotty
    Member
    Posted 8 years ago #

    Thank you Skippy and Moshu!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.