I need a read more button link in my Magento CMS pages.
I got some long cms texts. I need a Read More link to collapse them.
The Read More link has to be always after the first paragraph or ofter 250 character or any other limitation. But it is better when I can place the link myself in the magento backend by adding some kind of shortcode. like [readmore] or something. Doesn't matter what.
this is an example what im trying to do. <a href="http://www.feestding.nl/themakleding/beste-thema-s/halloween-kostuums/" rel="nofollow">http://www.feestding.nl/themakleding/beste-thema-s/halloween-kostuums/</a>
example of the feature <a href="http://jedfoster.com/Readmore.js/" rel="nofollow">http://jedfoster.com/Readmore.js/</a>
how can i do it?Answer1:
Download <em>readmore.js</em> and add it into your <em>page.xml</em> of your template. Make sure your path is correct and you have proper jquery already in use, if not then link the jquery file as well.
In backend, always put your contents inside a div with a specific class like below to make the read more link appear
Depending on where you want the read more to display either in cms pages, category pages or product pages, you have to add the following readmore script accordingly in those pages. You can also add the script in your CMS pages from the editor in backend.
There are couple of options that we can use with <em>readmore.js</em>, follow the documentation <a href="http://jedfoster.com/Readmore.js/" rel="nofollow">here</a>
Beware of jQuery conflicts, you might need to use noConflict() to make this readmore script work. Hope you can make this work.Answer2:
You can achieve this functionality by implementing a custom extension. I will show you the steps that we need to take to achieve this. So our extension should have a name
First step is activating our module. For this add this file in etc/modules
<config> <modules> <Programmerrkt_AdvancedCms> <active>true</active> <codePool>local</codePool> </Programmerrkt_AdvancedCms> </modules> </config>
Next step is to define configuration of our module. Let us do that.
<config> <modules> <Programmerrkt_AdvancedCms> <version>1.0.0</version> </Programmerrkt_AdvancedCms> </modules> <frontend> <layout> <updates> <programmerrkt_advancedcms> <file>programmerrkt_advancedcms.xml</file> </programmerrkt_advancedcms> </updates> </layout> </frontend> </config>
This file tells to Magento that our module has a layout file for frontend section. That's it. Our layout file is the heart of our module. It is going to hold the important parts of our module. Let us define our layout file.
<layout> <cms_page> <reference name="head"> <action method="addItem"> <type>skin_css</type> <name>css/customcss/readmore.css</name> </action> <action method="addItem"> <type>skin_js</type> <name>js/jquery1.js</name> </action> <action method="addItem"> <type>skin_js</type> <name>js/customjs/readmore.js</name> </action> </reference> <reference name="before_body_end"> <block type="core/template" name="readmore.script.template" template="programmerrkt/advancedcms/readmore/script.phtml" /> </reference> </cms_page> </layout>
So here we defined layout for
cms_page handler. Magento will look for this layout handler whenever a request for CMS page is made. So this handler would be a perfect handler for us. Next we added jquery and readmore.js in header section. Then at last we defined a template file
Now our script.phtml should look like this.
As you can see
readmore() method is called on an element with an id
readomore-demo. So it is required that, you need to enclose all the content your cms page inside this id. Demo is shown here.
<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/EmK7D.png" data-original="https://i.stack.imgur.com/EmK7D.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
We are done. Our output will look like this.
<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/Hy5Me.png" data-original="https://i.stack.imgur.com/Hy5Me.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/PLzVa.png" data-original="https://i.stack.imgur.com/PLzVa.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
So only thing you need to change is edit
script.phtml file according to your needs.
<strong>Note:</strong> Remember you need to add jquery for proper working of this module. If you have jquery installed, then remove the code that add jquery in layout file. Also you need to download
readmore.js and has to include it in
skin/frontend/<your_package/<your_theme>/js/customjs/readmore.js. Similarly add css file in
skin/frontend/<your_package/<your_theme>/css/customcss/readmore.css. You can use this css file to decorate links appear in your cms page.
readmore.js requires jquery greater than 1.7.0
Hope it helps.