WordPress.org

Ready to get started?Download WordPress

Forums

WPeMatico
[resolved] How to change the number of words shown in the post (30 posts)

  1. Vasu_webseries
    Member
    Posted 3 years ago #

    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

  2. monkus
    Member
    Posted 3 years ago #

    I too would like to know how to limit the size of the post also. So far, great plugin!!!

  3. MyShadowSelf
    Member
    Posted 3 years ago #

    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, '[&hellip;]');
                $text = implode(' ', $words);
                $text = apply_filters('the_excerpt',$text);
              }
                    return $text.' <a href="'.get_permalink().'">Read Full Article and Comment &raquo;</a>';
    
    }

    in archive.php, find
    the_content('<span class="read-more">Read full story &raquo;</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.

  4. MyShadowSelf
    Member
    Posted 3 years ago #

    '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.jpg

    Now, 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.

  5. MyShadowSelf
    Member
    Posted 3 years ago #

    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 :)

  6. monkus
    Member
    Posted 3 years ago #

    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.

  7. MyShadowSelf
    Member
    Posted 3 years ago #

    Monkus: The above code should work for you, Just make sure you replace the_content() in single.php too.

  8. monkus
    Member
    Posted 3 years ago #

    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.......

  9. MyShadowSelf
    Member
    Posted 3 years ago #

    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

  10. monkus
    Member
    Posted 3 years ago #

    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.

  11. monkus
    Member
    Posted 3 years ago #

    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.

  12. monkus
    Member
    Posted 3 years ago #

    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.

  13. MyShadowSelf
    Member
    Posted 3 years ago #

    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} &raquo;</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.

  14. keithp
    Member
    Posted 3 years ago #

    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
    }

  15. MyShadowSelf
    Member
    Posted 3 years ago #

    Add the function posted above to wp-content/themes/YourTheme/functions.php

    Add those other lines to both archive.php and single.php where you find the call to the_content()

  16. spida2
    Member
    Posted 3 years ago #

    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 to echo 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?

  17. monkus
    Member
    Posted 3 years ago #

    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.

  18. MyShadowSelf
    Member
    Posted 3 years ago #

    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

  19. MyShadowSelf
    Member
    Posted 3 years ago #

    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: http://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="http://google.com">link</a>
    </div>

    and a post of

    1234567890 abcdefghijklmnopqrstuvwxyz

    will trim to your database as:

    <div>
    1234567890(...)
    <a href="http://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.

  20. monkus
    Member
    Posted 3 years ago #

    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 $replacewith

    Second,
    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

  21. MyShadowSelf
    Member
    Posted 3 years ago #

    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:
    http://php.net/manual/en/language.types.array.php

    An 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="http://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:
    http://www.YOURDOMAIN.COM/wp-admin/admin.php?page=WPeMatico&subpage=edit&jobid=ID&_wpnonce=123456789

    Any good?

  22. mmtang
    Member
    Posted 3 years ago #

    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?

  23. mmtang
    Member
    Posted 3 years ago #

    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.

  24. deepakeapen
    Member
    Posted 3 years ago #

    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?

  25. MyShadowSelf
    Member
    Posted 3 years ago #

    Hi deepakeapen

    Could you start a new thread for this?
    I'll have a go at answering it in there

    cheers

  26. pazzosono
    Member
    Posted 3 years ago #

    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

  27. attorresi
    Member
    Posted 3 years ago #

    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

  28. totranquilo
    Member
    Posted 3 years ago #

    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: http://www.idnews.com.br

  29. woccax
    Member
    Posted 2 years ago #

    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

  30. etruel
    Member
    Plugin Author

    Posted 2 years ago #

    thanks MyShadowSelf and all of you.
    I'm taking some fixes for new version ;)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic