SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Show snippet from page on homepage

    Hello there,

    I have setup this site: www.casasport.org using a WP template. I'm trying to edit the coding for the homepage. There are three "preview boxes" for pages along the bottom: About, Sponsors, and Player Spotlight. I can point it to the page in the theme options, however if the About page is 500 words or 1000 words it will show everything on that page in the preview box.

    Is there a way to add just a snippet of code to only pull in the first say 25 or 50 words so the homepage can only show that and you need to click the "read more" link to jump to that page?

    I hope I'm explaining myself well enough. If you need me to clarify please don't hesitate to ask.

    Thanks for any and all help. The part of the home.php that includes the home boxes is below.

    Lorne

    PHP Code:
       <!-- BEGIN HOME CONTENT -->
           <!-- begin home boxes -->
            <?php $box1=get_post(get_option('boldy_home_box1'));
                      
    $box2=get_post(get_option('boldy_home_box2'));
                      
    $box3=get_post(get_option('boldy_home_box3')); 
                      if(
    get_option('boldy_home_box1')!= null && get_option('boldy_home_box2')!= null && get_option('boldy_home_box3')!= null){?>
            <div id="homeBoxes" class="clearfix">
                <div class="homeBox">
                    <h2><?php echo $box1->post_title?></h2>
                    <?php echo apply_filters('the_content'$box1->post_content);?>
                    <a href="<?php echo get_option('boldy_home_box1_link')?>"><strong>Read more &raquo;</strong></a>
                </div>
                <div class="homeBox">
                    <h2><?php echo $box2->post_title?></h2>
                    <?php echo apply_filters('the_content'$box2->post_content);?>
                    <a href="<?php echo get_option('boldy_home_box2_link')?>"><strong>Read more &raquo;</strong></a>
                </div>
                <div class="homeBox last">
                    <h2><?php echo $box3->post_title?></h2>
                    <?php echo apply_filters('the_content'$box3->post_content);?>
                    <a href="<?php echo get_option('boldy_home_box3_link')?>"><strong>Read more &raquo;</strong></a>
                </div>
            </div>
            <?php }?>
            <!-- end home boxes -->
           <!-- END HOME CONTENT -->

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,032
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Use the substr() function on the variable holding the text before display to get and/or display only x number of characters of a string.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Zealot Klav's Avatar
    Join Date
    Mar 2002
    Location
    Huddersfield, UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried using the substr function? For example;

    PHP Code:
    echo substr(apply_filters('the_content'$box1->post_content), 050); 
    or

    PHP Code:
    echo apply_filters('the_content'substr($box1->post_content050)); 

  4. #4
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's great, this worked almost perfectly! I got it working, however is it possible to have it pull words not characters?

    This is what I have now:
    PHP Code:
           <!-- BEGIN HOME CONTENT -->
           <!-- begin home boxes -->
            <?php $box1=get_post(get_option('boldy_home_box1'));
                      
    $box2=get_post(get_option('boldy_home_box2'));
                      
    $box3=get_post(get_option('boldy_home_box3')); 
                      if(
    get_option('boldy_home_box1')!= null && get_option('boldy_home_box2')!= null && get_option('boldy_home_box3')!= null){?>
            <div id="homeBoxes" class="clearfix">
                <div class="homeBox">
                    <h2><?php echo $box1->post_title?></h2>
                    <?php echo substr(apply_filters('the_content'$box1->post_content), 0175);?>...
                    <br /><br /><a href="<?php echo get_option('boldy_home_box1_link')?>"><strong>Read more &raquo;</strong></a>
                </div>
                <div class="homeBox">
                    <h2><?php echo $box2->post_title?></h2>
                    <?php echo substr(apply_filters('the_content'$box2->post_content), 0175);?>...
                    <br /><br /><a href="<?php echo get_option('boldy_home_box2_link')?>"><strong>Read more &raquo;</strong></a>
                </div>
                <div class="homeBox last">
                    <h2><?php echo $box3->post_title?></h2>
                    <?php echo substr(apply_filters('the_content'$box3->post_content), 0175);?>
                    <a href="<?php echo get_option('boldy_home_box3_link')?>"><strong>Read more &raquo;</strong></a>
                </div>
            </div>
            <?php }?>
            <!-- end home boxes -->
           <!-- END HOME CONTENT -->


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •