can someone give some examples of code that I can use in the tag and category loop pages, which will give out the content near a word?

Here is an explanation. The default function of the category and tag pages is to show a list of posts that are in the specific tag or specific category.

I want for example for tag pages to have the following behavior:

  • show all the posts that have the specific tag (default behavior)
  • instead of showing the beginning of the post text or excerpt, show 5 words before the tag that appears in the text, the tag, and 5 words after it.
  • make the tag in bold
  • add 3 dots in the end and 3 dots in the beginning
  • if the tag word/s appear too near the beginnig of the article (so there are less than 5 words from the beginning of the article, show the article from the beginning)

So if a post has the following text:

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

And that post has the "tag" five centuries, the excerpt should be:

...It has survived not only five centuries, but also the leap into...


Your Answer

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

Browse other questions tagged or ask your own question.