Андрей Posted September 18, 2013 Share Posted September 18, 2013 the entire article is 300 characters in a certain field, you must first display 100 characters and a link to more details when clicked, to fully show the full article as to limit the number of characters In hac habitasse platea dictumst. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae. more Link to comment Share on other sites More sharing options...
kongondo Posted September 18, 2013 Share Posted September 18, 2013 (edited) TEXTAREA COUNTER http://modules.processwire.com/modules/textarea-counter/ http://processwire.com/talk/topic/2343-char-counter-for-texttextarea-fields/ Source Code: https://github.com/boundaryfunctions/TextareaCounter TextAreaCounter.module: https://gist.github.com/somatonic/4252958 TextAreaCounter.js: https://gist.github.com/somatonic/4252962 Edited September 18, 2013 by kongondo 3 Link to comment Share on other sites More sharing options...
Андрей Posted September 18, 2013 Author Share Posted September 18, 2013 thank you Link to comment Share on other sites More sharing options...
kongondo Posted September 18, 2013 Share Posted September 18, 2013 (edited) Actually, Andrew, I have just realised the above may not be what you want. The above limits how many characters you can type. If on the other hand, you are looking for something that will trim the amount of text entered to a certain number, there was some code posted here on the forums but can't find it at the moment... Here it is, by Ryan http://processwire.com/talk/topic/22-how-to-build-a-news-page/?p=51 Edited September 18, 2013 by kongondo 3 Link to comment Share on other sites More sharing options...
Андрей Posted September 19, 2013 Author Share Posted September 19, 2013 <?php// make our own summary from the beginning of the body copy// grab the first 255 characters$summary = substr($story->body, 0, 255);// truncate it to the last period if possibleif(($pos = strrpos($summary, ".")) !== false) { $summary = substr($summary, 0, $pos);} where to insert the code Ryan, below is my code that I use to display the <div id="main"><?php echo $page->main; ?> <?php foreach($pages->get("/sections/")->children as $child) : ?> <div class="one_third first column_container"> <div class="portfolio-image-holder"> <div class="portfolio-image"> <a href='<?php echo $child->url; ?>'> <img src='<?php echo $child->images->first()->url; ?>'> </a> </div> </div> <?php echo "<h1><a href='{$child->url}'>{$child->title}</a></h1>"; echo "<p>{$child->text}</p>"; // displaying text in the field ?> </div> <?php endforeach; ?> </div> Link to comment Share on other sites More sharing options...
Manfred62 Posted September 19, 2013 Share Posted September 19, 2013 <div id="main"><?php echo $page->main; ?> <?php foreach($page->children as $child) : ?> <div class="one_third first column_container"> <div class="portfolio-image-holder"> <div class="portfolio-image"> <a href='<?php echo $child->url; ?>'> <img src='<?php echo $child->images->first()->url; ?>'> </a> </div> </div> <?php $summary = substr($child->text, 0, 100); if(($pos = strrpos($summary, ".")) !== false) { $summary = substr($summary, 0, $pos); } echo "<h1><a href='{$child->url}'>{$child->title}</a></h1>"; echo "{$child->text}"; // displaying text in the field ?> </div> <?php endforeach; ?> </div> not tested Link to comment Share on other sites More sharing options...
Андрей Posted September 19, 2013 Author Share Posted September 19, 2013 does not work Error: Call to a member function first() on a non-object (line 50 of C:\OpenServer\domains\localhost\site\templates\head.inc)This error message was shown because you are logged in as a Superuser. Error has been logged. error here $summary = substr($child->text, 0, 100); if(($pos = strrpos($summary, ".")) !== false) {$summary = substr($summary, 0, $pos);} Link to comment Share on other sites More sharing options...
adrian Posted September 19, 2013 Share Posted September 19, 2013 Well chances are that you don't have an images field in that template - that is why it can't find the first() image from it. That code won't be a complete drop-in example for you. I don't imagine you need the entire <div class="portfolio-image-holder"> xxxx </div> section. Start by removing that and see what you get. Link to comment Share on other sites More sharing options...
Андрей Posted September 19, 2013 Author Share Posted September 19, 2013 happened now displayed displays the full article does not reduce the number of characters What are the options? Link to comment Share on other sites More sharing options...
ryan Posted September 22, 2013 Share Posted September 22, 2013 The above code should work. Just make sure you are outputting the truncated version ($summary) and not $child->text. echo $summary; // do this echo $child->text; // do not do this Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now