Movable Type: Specify only one keyword from MTEntryKeywords
-
25-09-2019 - |
Question
I have several keywords (1~3 words) stored in <MTEntryKeywords>
field separated by commas.
I want to take out the first keyword from MTEntryKeywords.
Example 1:
In the Keywords field I have entered: gadgets,phone,apple,
Want to display: gadgets
Example 2:
In the Keywords field I have entered: food,coffee,apple,
Want to display: food
Any ideas?
Solution
This is untested, but something like this should do the trick (assuming you're using a recent enough version of MT)
<mt:entrykeywords regex_replace="/^([^,]+)(,.*)?$/","$1">
Basically, the regular expression there is saying "keep only everything up to, but not including, the first comma".
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow