In brief
- Use the NOT operator - (minus sign) in the feed url to exclude a search term.
- For multiple search terms, use AND NOT (+-).
- Follow the feed in a reader or use it to create a dynamic list in your blog.
Image: Kismalac (public domain) |
B excluding A |
Blogger's database superpowers mean you can filter posts by topic, combining them, if you like, in complex ways.
These combinations use Boolean logical operators AND, OR, and NOT.
This tutorial is about the NOT case, which excludes posts from a set by labels. Or, if you prefer, by keyword.
B but not A.
I've previously explained how to use NOT to exclude posts for a specialized blog page. Read on if you want to do the same thing to your blog feed.
Tailored feeds
There I also credit Sam Nordberg, who explains how to exclude posts from a feed based on the words in them. You'd do that to exclude topics you aren't into from a feed that you otherwise are.
My contribution is to adapt this to labels; also to add the AND and OR logical (Boolean) operators to the search vocabulary for the feed url.
These operators work in the basic blog feed modified by a search parameter q=
. Search terms can be combined. There's an example below.
NOT and AND NOT
NOT excludes one set of posts from a "universe" of blog posts. This can be all posts, or a subset defined by a label, keyword, or phrase.
You can exclude all posts that include the phrase "Elon Musk" from the
universe of all the blog posts with
&q=-"Elon Musk."
Adapted from Steve Jurvetson (CC BY 2.0) |
To exclude a second search term (and a third, etc.), AND NOT (+-
) is required.
To also exclude posts that mention "bitcoin," add +-bitcoin.
You might do this, Sam suggests, if you are interested in a blog enough to want to subscribe in a feed reader, but don't want to read about either of those two things.
(That's Sam's implied suggestion, but the examples are mine: if you love Elon and/or crypto, don't hold it against him.)
If you actually are fascinated only by the bitcoin posts, but
can't stand to read about Musk, you can start with the universe of all
bitcoin posts, rather than of all posts, and exclude Elon as
follows: &q=bitcoin +-"Elon
Musk."
(The quote marks are necessary around any search term of more than one word.)
Notice these are words and phrases, not labels. It's easy to change the syntax
to be by label for one or all search terms, for example,
&q=label:bitcoin
+-"Elon Musk
."
Phrases or labels?
But not every blogger is so meticulous. So phrases might be better than labels when you are subscribing to someone else's feed.
Sam is subscribing, and it makes perfect sense for him to exclude by words and phrases, not labels.
As Sam puts it, "use this trick to help filter the junk from a Blogspot blog."
But for completeness, here is an example of a feed url for this blog that (1) includes all posts about feeds that (2) are not labeled "things that changed" and (3) do not mention Elon Musk:
https://too-clever-by-half.blogspot.com/feeds/posts/default?by-date=true&q=label:feeds+-label:"things that
changed"+-"Elon Musk"
Here's the dynamic list you can generate with that feed:
Note that this post is not in that list even though it bears the "feeds" label. It is excluded by +-"Elon Musk
."
Recap
You can do the same thing in a blog feed, though the syntax is different. This report is the third in a series of three about doing that.
The first of these explains feeds and search operators, which this posts does not try to do.
Read that one first.
The second explains the feed of all posts that bear both A and B (logical AND).
The third describes the feed that combines all the posts with label A with all the posts with label B (logical OR).
Those posts mirror reports describing how to use similar searches to display the search results (and, or, and not) on a page in your blog that you can link to.
This post about NOT (and AND NOT) feeds corresponds to a post about a NOT/AND NOT page.
The page posts are good for displaying select posts on your blog.
The feed stuff is good for creating feed-based scripts, and for filtering "junk" from the feeds of other people's blogs.
And maybe other things I haven't thought of—let us know.
Related posts below.
Tailored feeds
•
Logical AND
•
Logical OR
• About feeds
Dynamic lists
•
Tailored pages
Nice mod. I usually just follow the label feeds to get just those items, but it dawns on me now that you could use this same tactic to get a feed of *only* the labels you are interested in, all in one single highly-customized feed, rather than subscribing to 10 or 15 different feeds of labels you like.
ReplyDeleteThe only problem now is getting more people to use Blogger or Wordpress or services that provided this kind of feature set...
Thanks, Sam! I think you mean using the "or" operator (|) to merge label feeds, right?
Delete