the_content
-
hi, i am new to plugins develpmment. i am scanning the content of a post using the add_filter(‘the_content’) hook. this works fine but if the post has bees separated into multiple pages using <!–nextpage–> the_content stores only the first page. is there a way to get to the content before it is explode’d by the nextpage trigger?
p.s. and what is TBD? π
-
the_content doesn’t have only the first page. It has whatever is being displayed on the page you’re looking at. If somebody loads the first page of the post, then the_content will have the first page. If they then go to the next page, then the_content will get the second page.
So the short answer is no, you can’t access the whole post with a simple filter like that, only the portion being actually displayed.
Now, you can access the whole post array using a filter on the_posts. This happens before the page is displayed at all, right after the posts are pulled out of the database. So if you just need all the posts to be displayed, that might suit you well.
well ok, but this means if want to parse the whole content of a multiple-pages-post i have to cycle the whole array which is not performace optimized if the blog has many posts.
i am wokring on a toc plugin so parsing all entries content is not the best solution for my purpose.the_posts should only contain the posts that are actually going to be displayed, not all the posts on the blog. So it still might work for you. Give it a shot, see what pops out.
otto42 10x for the hints. i rewrite v0.2 from the scratch and it’s looking good :).
can i somehow check if the caller is the index site (in most cases with several posts) or it single page with only one post on it? πHave a look in the Codex for
is_single()andis_home()etc., listed (I think) under the “Conditional Tags” Codex article.On the original topic, I’ve always thought
the_contentcontains the current post’s to-be-displayed content, whether it be the excerpt before themoretag, or be it the full post, or paginated post pages. In other words, when you go to the next page, your filter that hooks ontothe_contentwill act on the second page content. This is more efficient and (I think) the right way to do it if you’re looking to filter post content.PS: TBD = To Be Done, also often used for “To Be Determined”.
Tank you, alresha. I’ve just checked is_single() and is_home() out. But this are template tags. I dodn’t know but I think they can not be executed within a plugin -> they didn’t work with a test I just made.
The poblem is that on my site and mabe also on others the main page shows only the last post as a whole and only excerpts form the last 2-10 posts e.g. Excerpts are with stripped HTML, so after inserting a TOC at the beginning of every post, a excerpt shows only the HTML-stripped TOC and nothing from the post itself and that’s stupid …xqt, are you trying to show html in an excerpt, if so, there’s a plugin already to do that.
No, I am not. I am adding to a TOC to the posts. But the_excerpt is taken from the_posts, so when adding a TOC at the beginning of a post and its shown after that in the excerpt, what you see is only a HTML-stripped TOC. And that’s fine for the purpose of the plugin … I’ve just re-thinked my problem … whta I need is after manupulating the_posts to once again manupulate the_excerpt, I thnik
1) You can always just check the current URL to see what kind of page you’re on. Or you could dig up the WP code itself and see how
is_page()and so on makes the decision.2) How about hooking onto
the_postsand dump your TOC into a private variable first, then hook ontothe_contentand insert your TOC?Now talking of this problem as a plugin in general, you must realize that not a lot of themes do what you’re doing—show the latest post in full, and show only excerpts for the remainder. This is an exception rather than the rule, I think.
The normal behaviour would be that each post shows only what’s before the
moretag (or automatically generated excerpt), and the full post is only shown on Single pages. You need to think over carefully where TOC’s are supposed to appear, and how you’re going to handle these “normal” situations for other users, if you’re planning to release this plugin for general use.Personally, I do write paginated posts and I’ve thought about a TOC before. But I would not want a TOC on archive list pages, I’d only want it to show in single-post pages.
alresha, this are a really thoughfull …thoughts π you mention. That is exact why I wanted to add_filter only on a single post page and not on a list. But on the other hand there are blogs (I’ve seen) that that show the whole content of every one post even on list pages, e.g. last 10 posts on the main page. That’s why I am thinking of making also a configuration page where the user can easily conf the plugin.
I’ve checked once again your suggestion with is_single and is_home and found out that I misused is_single() yesterday. It works just fine. You can look at it on my homepage.
The topic ‘the_content’ is closed to new replies.