[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
-
I too would like to know how to limit the size of the post also. So far, great plugin!!!
1: If you’re talking about the length of the posts in an archive list, you can use this code that works ok for me:
Add this function to wp-content/themes/YourTheme/functions.php:
function custom_trim_excerpt($length) { global $post; $explicit_excerpt = $post->post_excerpt; if ( '' == $explicit_excerpt ) { $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); } else { $text = apply_filters('the_content', $explicit_excerpt); } //$text = strip_shortcodes( $text ); // optional $text = strip_tags($text,'<div><strong><em><blockquote><img><a>'); $excerpt_length = $length; $words = explode(' ', $text, $excerpt_length + 1); if (count($words)> $excerpt_length) { array_pop($words); array_push($words, '[…]'); $text = implode(' ', $words); $text = apply_filters('the_excerpt',$text); } return $text.' <a href="'.get_permalink().'">Read Full Article and Comment »</a>'; }
in archive.php, find
the_content('<span class="read-more">Read full story »</span>');
change to:
echo custom_trim_excerpt(110);
where ‘110’ is the number of words you want to display.
That will cut all excerpts to ‘110’ words long with a link to read more.2: “Images are not displayed next to the posts”
Check your WPeMatico settings. All images should be set to cache in “settings”, check they’re not over-ridden per campaign. If they’re not being cached, make sure the caching directory os set to CHMOD 777.Hope this helps some.
‘s me again
RE: number 2
Just found the exact same issue on my install. It’s not a CHMOD problem, I was foolish to jump to conclusions. If only you could forgive me…
The issue actually appears to be due to the muppets who I’m (and you’re) getting your feed from. There are spaces in the URL of the images, at least, there are spaces in the filename of the images. The space is then made valid by replacing it with %20 when the file is saved to your uploads directory and added to the post.
However, the browser request to the file converts that %20 back into a space
EG:
Image name: idiot webmaster.jpg
Saved as: idiot%20webmaster.jpg
Posted as: idiot%20webmaster.jpg
Requested as: idiot webmaster.jpgNow, this will be fixable, but it’ll take some core changes to the plugin (I expect) so it’ll not only take me a while to figure it out, but these changes will be wiped out on update. As such, I’ll probably submit them to the original developer when (and if) I manage to suss it out.
Well, that was suprisingly easy!
This bugfix is only tested in WPeMatico V 0.7Beta. As always, back everything up before you make changes. You do this at your own risk.
Open: wp-content/plugins/wpematico/app/wpematico_dojob.php
On Line 331 find:
$name = substr(strrchr($imagen_src, "/"),1);
Change that to:
$name = str_replace(array(' ','%20'),'-',substr(strrchr($imagen_src, "/"),1));
That should change all spaces and %20 in filenames to a hyphen as it saves to the uploads dir and as it writes to the post.
I ASSUME that will work for you as it has worked for me. Remember that any changes you make won’t affect already posted posts, so you’ll have to delete all old posts and start again. Luckily I found this before going live, so I’m alright ??
Hey MyShadowSelf,
Thanks for the help, but if Vasu_webseries is having the same problem as myself, we want to limit the post size on just the syndicated post pages. We want to take an RSS feed that is delivering the entire article, and not just an excerpt, to show only a limited amount of that article so we can link back to the full article with a “Read the whole article here” link. Right now, if the feed sends the entire post, then the entire post shows up on our blog, which can upset the author. Any help is greatly appreciated.Monkus: The above code should work for you, Just make sure you replace
the_content()
in single.php too.MyShadowSelf,
I see what you mean. That looks great. My only problem (and I’m sure I’m making this hard on myself) is how do I implement this only for the syndicated feeds I get from WPeMatico. I have original content also and do not want to limit those posts. Hmmmmmm…….Simples:
$excludeArray = array(1,2,3,4,5,6,7,8,9,10);//array of Category IDs containing your WPeMatico Auto Posts $category = get_the_category(); $iCatId = $category[0]->cat_ID; if(in_array($iCatId,$excludeArray)){ echo custom_trim_excerpt(110);// echo the trimmed text } else { the_content();// etc }
Incase you don’t know, to get the numeric ID of a Category, just hover over the “edit” link in admin
MyShadowSelf,
You have got it goin bossa nova! That is great. Just one tweak is causing me problems. This piece of code:return $text.’ Read Full Article and Comment »‘;
}
The permalink it gets is the permalink from my site. So you go to the post page, read to the bottom, click the link and it takes you to the same page you are on. I know there is some short code to use in WPeMatico to link to the original article. So, I’m trying to remove the permalink from functions.php and let WPeMatico do it. I’ll let you know how it goes.
Did I mention that I don’t know the first thing about code. I just remove things and see if it works, if not, I put it back and try something else. Can be fun, but can also make you crazy. Luckily right now it’s fun.
Well, I successfully removed the permalink back to my site, but the short code in WPeMatico must be overridden by the changes in the php, because it doesn’t seem to work when the post length is limited. I’ll keep seeing what I can come up with. Any help is greatly appreciated. Thanks again.
Did I mention that I don’t know the first thing about code. I just remove things and see if it works, if not, I put it back and try something else.
Dude, that’s how I started. 7 years on and I make my living from coding!
Back to your prob: You’re overthinking it. Put all the PHP code back to where you’d limited the length of the post in single.php.
Now, login to wp-admin, go to your WPeMatico campaigns and choose any campaign. Scroll to the bottom and look for “Post Template”. Click “enable post template”.
Add the following in the text area:
{content} <a href="{permalink}">Read Original Article: {title} »</a>
Edit that code to your needs, but I’m assuming that seeing as you’re already hacking PHP to bits, you’ve got a decent grasp on HTML.
All my campaigns use post templates.
One warning though, if you decide to put an image in the post template (I use the rss source’s logo), it will get added to the media library every time a new story comes in. I have 1000’s of duplicate logo’s in my library.
Is it a bug or a feature? I don’t know, but I’m guessing it’s a slight bug. I’m getting round it by removing the images and using a CSS trick to display them instead.
Shawdowshelf where do i put the following code?
Do I put it in my single. php
Where at in my theme i place that code? Also do I have to place the other code you posted above.
I am trying to do the same thing Monkus is doing. I want to post only a couple of paragraphs of the original article. I do not want to post the whole article on my blog.
$excludeArray = array(1,2,3,4,5,6,7,8,9,10);//array of Category IDs containing your WPeMatico Auto Posts
$category = get_the_category();
$iCatId = $category[0]->cat_ID;if(in_array($iCatId,$excludeArray)){
echo custom_trim_excerpt(110);// echo the trimmed text
} else {
the_content();// etc
}Add the function posted above to
wp-content/themes/YourTheme/functions.php
Add those other lines to both
archive.php
andsingle.php
where you find the call tothe_content()
Hey, your plugin is brilliant! It works very reliable and offers an easy approach to customizing.
Yet, I have a problem with trimming posts. The theme I use doesn’t have archive.php nor single.php. It just offers head.php, index.php and footer.php.
I added the aforesaid function to function.php, but changing
the_content();
in index.php toecho custom_trim_excerpt(200);
worked only partially: the text was trimmed to 200 words, but the link to the original URL as specified in the WPMatico template wasn’t generated anymore. My WPMatico template looks like this:{content} <a href="{feedurl}">Source ({feeddescription})</a>
Switching back to
the_content();
enables the link to the source again, but then again I get no trimming.Do you have a suggestion what else I could try?
- The topic ‘[Plugin: WPeMatico] How to change the number of words shown in the post’ is closed to new replies.