Character/Word limit on homepage posts for WordPress & Magento’s full integration by (fishpig)

I’ve recently included a wordpress install with full integration into magento using the fishpig plugin. I am struggling to limit the character/word count for posts on the homepage.

FishPig have documented a widget for posting excerpts including the following code:

Read More
<block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" as="recent_posts" template="wordpress/sidebar/widget/categoryposts.phtml">
    <action method="setTitle"><title>Latest Posts</title></action>
    <action method="setPostCount"><post_count>5</post_count></action>
    <action method="setExcerpt"><display>on</display></action>
    <action method="setExcerptLength"><length>30</length></action>
    <action method="setDate"><date>on</date></action>
    <action method="setCommentNum"><comments>on</comments></action>
</block>

i would assume i could imitate the “setExcerptLength” into a post as “setPostLength” and include in my wordpress.xml within the homepage block

<block type="wordpress/post_list" name="wordpress_post_list" template="wordpress/post/list.phtml">
    <block type="wordpress/post_list_pager" name="wordpress_post_list_pager">
        <action method="setPostLength"><length>30</length></action>
    </block>
</block>

however these seems to have no effect.

I assume that all wordpress functions have been converted into xml with the full integration so i cannot take the usual root.

Any help on this would be greatly appreciated.

Related posts

Leave a Reply

3 comments

  1. Having recently integrated wordpress into magento using the fishpig plugin i’ve also found the excerpt length to have no effect.

    Without digging into the code too much my solution has been as follows.

    Rather than use the xml insert the following directly in your page content. Make sure to delete any xml you have added.

    {{block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" post_count="5" title="Latest Blogs" excerpt="on" excerpt_length="250" date="off" comment_num="off" template="wordpress/sidebar/widget/post-hp.phtml"}}
    

    In your template directory

    app/design/frontend/default/your_template/template/wordpress/sidebar/widget/
    

    Make a new file, post-hp.phtml

    Copy the contents of categoryposts.phtml into this new file.

    Find and replace

    <p class="post-excerpt"><?php echo $post->getPostExcerpt() ?></p>
    

    With

    <p class="post-excerpt"><?php $content = $post->getPostExcerpt(); $content = strip_tags($content); echo substr($content, 0, 250); ?> ...</p>
    
  2. You will have to edit categoryposts.phtml. Change the line

    <p class="post-excerpt"><?php echo $post->getPostExcerpt() ?></p> 
    

    to

    <p class="post-excerpt"><?php  echo substr($post->getPostExcerpt(),0,$post["excerpt_size"]) ?> </p>
    

    Make sure you set the length from 30 to something high like 700 if you have an image

  3. For all you visual learners….you can also do it manually by clicking the “Insert More Tag” icon within the kitchen sink on the “create new post” page.

    enter image description here

    Just choose a line break area, 4-6 paragraph lines usually does the job…and click the button.