Wordpress - "Outside the Loop"

by liban
2 replies
I'll start by admitting I'm in way over my head. That's usually how I learn things, or drown trying...

Anyhow, I want to add a different block of text at the beginning of each category page in a Wordpress blog. The instructions for this are:

"Different Text on Some Category Pages
A slightly more complex possibility is that you want different text to display depending on which category page the visitor is viewing. Then you would add the "default" text to the main category.php file, and create special category-#.php files (with their own version of the text, as described in the Introduction) for each category that needs special text at the top.

This does however create a lot of files in your theme directory, and can be avoided using the following code OUTSIDE the loop:

<?php if (is_category('Category A')) { ?>
<p>This is the text to describe category A</p>
<?php } elseif (is_category('Category B')) { ?>
<p>This is the text to describe category B</p>
<?php } else { ?>
<p>This is some generic text to describe all other category pages,
I could be left blank</p>
<?php } ?>"

I've Googled to no avail, but can't figure out how to accomplish this. What does 'outside the loop' mean? Is there a plug-in that will do this? Are there instructions "for dummies"?
#outside the loop #wordpress
  • Profile picture of the author Tim Dixon
    Not sure if this helps, but here's a page from the Wordpress codex that describes the loop process.
    The Loop in Action WordPress Codex

    Tim
    {{ DiscussionBoard.errors[277885].message }}
  • Profile picture of the author liban
    Thank you so much, Tim! That explains the loop thing, so that even I understood it. The other missing piece of the puzzle was how to figure out the category number. Turns out, you go to Settings > Manage > Category, mouse over the category and it shows the number.

    I'm psyched.
    {{ DiscussionBoard.errors[278085].message }}

Trending Topics