We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: tag_limit

Development and Programming

Daniel Walton's avatar
Daniel Walton
553 posts
19 years ago
Daniel Walton's avatar Daniel Walton

Tag Limit enables you to take html and show only certain tags. for example a … .

Parameters

tag - the tag you wish to show. (default p) num - the number of tags to show. (default 1) offset - offset the first result returned by given amount, if the offset os greater than the number of matching tags you will get nothing returned. class - search for only tags with a certain class. id - same as class but by id. show_tags - ‘off’ will return the match without encasing tags, on will return them. (off or on, default is on) word_limit - limits the word total of the returned data. This can be set to limit on each tag found, should you set ‘num’ to greater than 1, or on the output as a whole, using the below parameter. limit_style - (each or all, default each)

Example usage

Imagine this is your content (please note duplicate id references are invalid in xhtml)

paragraph 1
paragraph 1 with class foo
paragraph 1 with id bar
paragraph 2
paragraph 2 with class foo
paragraph 2 with id bar
paragraph 3
paragraph 3 with class foo
paragraph 3 with id bar
paragraph 4
paragraph 4 with class foo
paragraph 4 with id bar
paragraph 5
paragraph 5 with class foo
paragraph 5 with id bar

Using these tag parameters

{exp:tag_limit tag="p" class="foo" num="2" offset="2"}

You will get

paragraph 3 with class foo
paragraph 4 with class foo

The word limiter functionality comes from EE’s built in word_limit function, so remains the same issues with leaving tags open as with the official word_limit plugin.

You can use class and id together if you so wish, there is no set order that the two parameters need to be (within the html tag).

Current version: 1.3.1

       
Jamie Pittock's avatar
Jamie Pittock
108 posts
19 years ago
Jamie Pittock's avatar Jamie Pittock

That’s cool. What would also be useful would be the ability to take everything but the first paragraph. You could then insert content between the two.

       
Daniel Walton's avatar
Daniel Walton
553 posts
19 years ago
Daniel Walton's avatar Daniel Walton
That’s cool. What would also be useful would be the ability to take everything but the first paragraph. You could then insert content between the two.

Indeed that would be kinda cool, one way you could do it is just give the first paragraph in your entry a class/id different to that of the 2nd/3rd/4th paragraph etc. Or use custom fields in your blog 😊

       
Daniel Walton's avatar
Daniel Walton
553 posts
18 years ago
Daniel Walton's avatar Daniel Walton

1.2

  • With need for dragging out single tags like img, comments, etc i have gone and updated this plugin.

As always please test and mail me bugs.

       
Daniel Walton's avatar
Daniel Walton
553 posts
18 years ago
Daniel Walton's avatar Daniel Walton

1.3

  • Updated the plugin to make it a bit leaner, and cleaner. Also rewritten the first post to explain some the new added functionality.
       
Daniel Walton's avatar
Daniel Walton
553 posts
18 years ago
Daniel Walton's avatar Daniel Walton

1.3.1

  • Fixed a bug with ‘show_tags’ set to ‘on’ that was letting the plugin return all tagdata rather than suitable matches

  • Added ‘offset’ parameter to allow results starting beyond the first match.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Hi Daniel,

Just came across this plugin from seeing another post somewhere on the forums here and I think I must be having a senior moment or something as I have been trying to rack my brain to think of ways to use this.

Do you think you could possibly give me a couple of examples where you could think of using this? I think my brain must have gone into overload over the holiday season or something! 😉

Hope you had a great Christmas and a Happy New Year.

Best wishes,

Mark

       
Daniel Walton's avatar
Daniel Walton
553 posts
16 years ago
Daniel Walton's avatar Daniel Walton

Say you wanted to take the first paragraph from a content field to use as a summary, rather than having a separate summary custom field. Maybe you want to inset google adwords after the first couple of paragraphs. Say you had a custom field which you insert images into, but want to ensure only one image is displayed on your template? I could go on but I won’t. I had a need (which I cannot remember) and this filled the niche.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Fantastic. The ideas (and my brain!) are now flowing! 😉

Thanks for getting my noggin’ going on this one!!

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Is there any way to do this sort of thing?

{exp:weblog:entries weblog="default_site" url_title="testing_tag_limit_plugin" limit="1" disable="member_data|trackbacks|pagination|categories|category_fields"}
<h1>{title}</h1>

{exp:tag_limit tag="p" num="10" class="test"}
{body}
{/exp:tag_limit}

{/exp:weblog:entries}

Say I have this as the entry contents :

Test paragraph 1
Test paragraph 2
Test paragraph 3
Test paragraph 4
Test paragraph 5
Test paragraph 6
Test paragraph 7
Test paragraph 8
Test paragraph 9
Test paragraph 10

How would you (without knowing the amount of p tags with the test class) set the plugin parameters to return all the p tags with the test class. In the example above there are 4 p tags with the test class but how would you let the plugin dynamically know to return all of them instead of having to program the num=”4” parameter?

I’m probably just missing something somewhere I guess?

Best wishes,

Mark

       
gridonic's avatar
gridonic
231 posts
16 years ago
gridonic's avatar gridonic

Hey Mark

The simplest would probably be to put in a value for num that’s pretty unreal to reach, something like:

{exp:tag_limit tag="p" class="test" num="999"}

I suppose. The probability that you’ll have more than 999 paragraphs with the class test is rather small I’d say.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

Yep that’s what I did in the end. Just thought that perhaps if you didn’t supply the num=”“ parameter or if it were blank then might be nice if the plugin just went and output all of them but yep as you say 999 should do it 😉

Thanks again.

Best wishes,

Mark

       
Matt Weinberg's avatar
Matt Weinberg
489 posts
16 years ago
Matt Weinberg's avatar Matt Weinberg

This was perfect for displaying the first bit of recent comments on a sidebar without having to deal with their formatting– thanks!

       
Bruce2005's avatar
Bruce2005
536 posts
16 years ago
Bruce2005's avatar Bruce2005

Is it possible to remove an image if there is one in text?

thanks

       
brittanyA's avatar
brittanyA
184 posts
15 years ago
brittanyA's avatar brittanyA

Useful plugin! Thanks!

Quick question: is there a way to keep multiple tags (if I want to keep p, ol, ul tags, for example)?

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.