• 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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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.

    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 🙂

    Thread Starter snotty

    (@snotty)

    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?

    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.

    Thread Starter snotty

    (@snotty)

    Thank you Skippy and Moshu!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Insert an extra paragraph on the home page.’ is closed to new replies.