Jump to content

Recommended Posts

Posted

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

Posted (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 by kongondo
  • Like 3
Posted

<?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 possible
if(($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>
Posted
      <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

Posted

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.

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...