[Plugin: WPeMatico] How to change the number of words shown in the post
-
I just tried using WpeMatico . Would like to know a coulpe fo things?
1. How can I change the number of words displayed in the posts? I don’t see that option in the settings.
2.Images are not displayed next to the posts.
Thanks in advance,
Vasudev
-
Yes, exactly. I’m having the same issue as spida2. It seems as though the code changes in limiting the post size, somehow deactivates WPeMatico’s post template. I’ll keep trying things to see if I can find a solution.
It’s not deactivating it, it’s just stripping it out.
If your template is thus:
<div> {content} <a href="link">link</a>
Then the code starts the count at the first
<
and strips from xxx characters, therefore stripping out the final link.It’d be great if the template tags could accept a substr function. something like
{content|115}
of `substr({content},115}) would do. But alas, not yet.The problem is, we can’t trim the
{content}
at source without editing the plugin directly, in which case, we’d lose any edits on update.I’ll have a play and see if I can come up with an edit that’ll sort it for you.
*Edit*
OK, this is possible but it’ll take some time. I’ll be back
I haven’t tested it in the wild, or on masses of posts across masses of feeds. You’ll need to edit one of the plugin’s core PHP files too, so back yo’ s**t up! if it breaks anything it’s your own fault.
Remember, if you update this plugin, any edits you make directly to the code will be overwritten, so it’ll stop working. I’M NOT THE DEVELOPER and I don’t know him. I’m just a well meaning coder willing to give abit of spare time to earn some good karma.
Anyhoo…
Open:
wp-content/plugins/wpematico/app/wpematico_dojob.php
add the following function RIGHT AT THE TOP so it’s the first function in the file (that way, you don’t wreck anything else):
function snippetgreedy($text,$length=64,$tail="...") { $text = trim($text); if(strlen($text) > $length) { for($i=0;$text[$length+$i]!=" ";$i++) { if(!$text[$length+$i]) { return $text; } } $text = substr($text,0,$length+$i) . $tail; } return $text; }
Credit function taken from here: https://snipplr.com/view/9520/php-substring-without-breaking-words/
Now, search for:
$content = str_ireplace($vars, $replace, ($this->job['campaign_template']) ? stripslashes($this->job['campaign_template']) : '{content}');
(prob around line 400 ish)
Above that you’ll see 2 arrays:
$vars
and$replace
, we’re gonna edit them slightly in a minute, but not yet. Directly above those 2 arrays add this:$substrcontent = '';//initialise variable $replacewith = '';//initialise variable if($this->job['campaign_template'] && stripos('@'.$this->job['campaign_template'],'substrcontent')){ preg_match_all("/\{substrcontent|\d+\}/", $this->job['campaign_template'], $theNum); $theNum = str_replace('}','',$theNum[0][1]); if(strlen($content) >= $theNum){ $substrcontent = '{substrcontent|'.$theNum.'}'; $replacewith = snippetgreedy($content,$theNum,'(...)'); } }
this bit:
(...)
is the end of the trimmed content, so that could be...
or...and theres more...
or anything you like.Now, those 2 arrays need editing, so add
$substrcontent,
AT THE BEGINNING of$vars
and add$replacewith,
AT THE BEGINNING of$replace
Save and upload.
You’ve now got a brand new template tag:
{substrcontent|xxx}
which allows for a number to dictate how long you want the content to be. For instance:{substrcontent|100}
will trim the content to 100 characters{substrcontent|250}
will trim it to 250 characters. It’ll do it intelligently too, so won’t strip in the middle of a word but strip at the end of the word soonest after your xxx characters adding(...)
at the end.If you use
{substrcontent|}
(no number) it’ll default to 64 characters. if you use{substrcontent}
it’ll do nothing, so don’t do that!The best thing is it only trims the content of the post in the feed, leaving your template as is, so a template of
<div> {substrcontent|10} <a href="https://google.com">link</a> </div>
and a post of
1234567890 abcdefghijklmnopqrstuvwxyz
will trim to your database as:
<div> 1234567890(...) <a href="https://google.com">link</a> </div>
Which I believe solves all the above problems!
I’m not 100% this is the best way to do this, but it works.
Let me know how you get on.
Well, not much luck yet. But the problems are all me. Not you or your code. You (MyShadowSelf) have been more than generous with your help and I thank you. So, if you can handle some simple questions, that would be great.
Now, those 2 arrays need editing, so add $substrcontent, AT THE BEGINNING of $vars and add $replacewith, AT THE BEGINNING of $replace
So, do I put $substrcontent before $vars, or after, or at the top of the list below it….
Same with $replacewithSecond,
is this link type<div>
{substrcontent|10}
link
</div>supposed to go into the WPeMatico template setting or elsewhere.
I know, these must be rudimentary questions, but I haven’t even taken an online tutorial on php, so I’m running on empty here. lol
Lol
I knew you’d be back Monkus!
Very rudimentary questions, but hey, you’re learning and that’s how you learn.
Arrays aren’t the most obvious thing to get your head around, but you’ll definitely have a lightbulb moment one day and wonder what all the fuss was. Before I post the code, I suggest you have a look here:
https://php.net/manual/en/language.types.array.phpAn Array is basically just a list, defined by wrapping it in the
array()
function.Now, by “add to the beginning”, I mean INTO the array. So they’ll look like this:
if ($this->job['campaign_enable_template']){ $vars = array( $substrcontent, '{content}', '{title}', '{permalink}', '{feedurl}', '{feedtitle}', '{feeddescription}', '{feedlogo}', '{campaigntitle}', '{campaignid}' );
and
$replace = array( $replacewith, $content, $item->get_title(), $item->get_link(), $feed->feed_url, $feed->get_title(), $feed->get_description(), $feed->get_image_url(), $this->job['name'], $this->jobid );
Your second:
The PHP code has basically given you a brand new template tag for use in the admin interface. You can add anything in there to format the post, or you can add nothing. so you could add:
<div> {substrcontent|100} <a href="https://google.com">link</a> </div>
And the post would be wrapped in a
div
, trimmed to 100 characters (intelligently) with a link at the end. Or you could add:{substrcontent|100}
And it wouldn’t be wrapped, wouldn’t have a link, but would be trimmed.
You add this here:
https://www.[YOURDOMAIN.COM]/wp-admin/admin.php?page=WPeMatico&subpage=edit&jobid=%5BID%5D&_wpnonce=%5B123456789%5DAny good?
MyShadowSelf-
Thanks for your work in this thread. I am trying to get this running, and following along with your instructions. I modified the wpematico_dojob.php and uploaded it. When I use
<div>
{substrcontent|200}
{permalink}
</div>as a post template, the draft post that gets created consist of the :
post title
{substrcontent|200}
and then a link to the source.Looks like it doesn’t recognize the new template tag. Could it be that this particular feed doesn’t have a body text, or is it more likely my code is in the wrong place?
Followup:
It appears the feed is resposnible – other feeds work fine.
If that is the case, would checking the length of the post content and give it a ” ” value if = 0 be a good solution?Also of note : I think the image path (if provided) counts in the total character count. Experimenting with this now.
How do I add Google Adsense script along with the {content} tag. It’s just ignoring the Adsense script i guess. Any idea how to do that?
Hi deepakeapen
Could you start a new thread for this?
I’ll have a go at answering it in therecheers
Hi, sorry but in my wp-o-matic version 1.0RC4-6 there isn’t wp-content/plugins/wpematico/app/wpematico_dojob.php but there is /wp-content/plugins/wp-o-matic/wpomatic.php.
There are some differences in code:
$content = str_ireplace($vars, $replace, ($this->job['campaign_template']) ? stripslashes($this->job['campaign_template']) : '{content}');
is
$content = str_ireplace($vars, $replace, ($campaign->template) ? $campaign->template : '{content}');
and if I insert
$substrcontent = '';//initialise variable $replacewith = '';//initialise variable if($this->job['campaign_template'] && stripos('@'.$this->job['campaign_template'],'substrcontent')){ preg_match_all("/\{substrcontent|\d+\}/", $this->job['campaign_template'], $theNum); $theNum = str_replace('}','',$theNum[0][1]); if(strlen($content) >= $theNum){ $substrcontent = '{substrcontent|'.$theNum.'}'; $replacewith = snippetgreedy($content,$theNum,'(...)'); } }
not work. Why?
Thanks
MyShadowSelf,
Sorry, but I’m using a translator, because my language is Portugues.Estou having a problem with the plugim WPEMATICO. When it’s down to the first post, and the next day not posted the blog, the plugin low again last posting, even if repeated. How to solve this? note: 100 campaign he is only 20.
Thanks
Configuring WPematico to display the author of the article?
Before migrating to wordpress I also utilize the FeedGator which is free functions have a very jewel in the panel that you can limit each post and very easy to specify the source with a link to the author of the post.In the current version I’m running on my new aggregator I’ve been accused of plagiarism on the grounds that the feed was added to WPeMatico made ??the aggregation
completely.This is not bad, but it would be a wonder in the control panel under the APCA
at the time of registering each feed / RSS you have the option:Place this file: eg: cnn.com
and woe to activate a link to every article and link added to the name
we specified beyond the read more.Help me for God’s sake.
this is the site: https://www.idnews.com.br
wow, many posts … and it’s actually all about creating excerpts or automated pagination – wouldn’t it be a better idea to simply add support for adding pagination tags to cut off posts at configurable positions (i.e. after xxx words)?
just looking at the built-in rewriting engine, it seems to ideally suited to implement this.
that doesn’t seem too complicated, does it?
– woccax
thanks MyShadowSelf and all of you.
I’m taking some fixes for new version ??
- The topic ‘[Plugin: WPeMatico] How to change the number of words shown in the post’ is closed to new replies.