Last active
August 29, 2015 13:58
-
-
Save q2amarket/9949229 to your computer and use it in GitHub Desktop.
The hook will allows to limiting display long characters (as defined in condition) for Question view and will add `read more` link. It will expand all question content when click on read more link.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/* | |
* hook: Add read more link to the question view q-content | |
* | |
* hook by: Q2A Market | |
* author: Jatin Soni | |
* url: http://www.q2amarket.com | |
* version: 1.00 | |
* | |
* Description: | |
* The hook will add 'read more' link to the | |
* question's content after defined number of characters | |
* and hide rest of the characters. | |
* | |
* usage: | |
* Place below code into your theme or plugin layer | |
* | |
* function q_view_content(){} | |
* | |
* Disclaimer: | |
* This program is distributed in the hope that | |
* it will be useful, but WITHOUT ANY WARRANTY; | |
* without even the implied warranty of MERCHANTABILITY | |
* or FITNESS FOR A PARTICULAR PURPOSE. | |
* | |
* See the GNU General Public License for more details. | |
*/ | |
public function q_view_content($q_view) | |
{ | |
if (!empty($q_view['content'])) { | |
$this->output('<div class="qa-q-view-content">'); | |
// remove div tag from content | |
// but there is a risk if someone add | |
// div within the content | |
$tag = 'div'; | |
// Again adding entry-content to support core | |
$this->output('<div class="entry-content">'); | |
// displaying content based on character count | |
if (strlen(strip_tags(preg_replace("/<\/?" . $tag . "(.|\s)*?>/", '', $q_view['content']))) > 100) { // change 500 with your number | |
$this->output('<div id="descitem">'); | |
$str = substr(preg_replace("/<\/?" . $tag . "(.|\s)*?>/", '', $q_view['content']), 0, 100) . '...<a href="#" id="readmore">read more</a>'; // change 500 with your number | |
$this->output_raw($str); | |
$this->output('</div>'); | |
$this->output('<div id="fullcont" style="display:none">'); | |
$this->output_raw(preg_replace("/<\/?" . $tag . "(.|\s)*?>/", '', $q_view['content'])); | |
$this->output('</div>'); | |
} else { | |
// this will output content without readmore | |
// if there is less then defined character count | |
$this->output_raw(preg_replace("/<\/?" . $tag . "(.|\s)*?>/", '', $q_view['content'])); | |
} | |
$this->output('</div>'); // end of entry-content | |
$this->output('</div>'); // end of qa-q-view-content | |
//javascript to show hide divs | |
$this->output(' | |
<script> | |
$("#readmore").click(function(){ | |
$("#fullcont").show(); | |
$("#descitem").hide(); | |
return false; | |
}); | |
</script> | |
'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment