Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Location
    Edmonton
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    How to get text starting from third line

    Hello,

    I'm the administrator of a wordpress website and I'm new to PHP. One of the issues I ran into is mostly stylistic.

    The homepage slider picks up the first 25 words in a story, including the authors name and position. Since the writer's name and position can be between 3 and 4 words, I'm wondering how I can skip the first two lines of page text.

    Link to the page

    Here is the code:

    <div class="flexslider small">
    <ul class="slides">
    <?php while($featured_posts->have_posts()): $featured_posts->the_post(); ?>
    <li>
    <?php if(has_post_thumbnail()): ?>
    <a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_post_thumbnail('small-nivo-thumb'); ?></a>

    <?php else: ?>
    <a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo get_template_directory_uri(); ?>/images/thumbnails/620x350.png" alt="<?php the_title(); ?>" title="#htmlcaption_<?php the_ID(); ?>" /></a>
    <?php endif; ?>
    <?php if(get_option('reedwan_featured_caption') == 'yes'):?>

    <div class="flex-caption"><h1><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h1><p><?php echo string_limit_words(get_the_excerpt(), 25); ?></p></div>
    <?php endif; ?>
    </li>
    <?php endwhile; wp_reset_query();?>

    </ul>
    </div>

    This is the code directly from the site, Sorry it's a little bit messy.


    Thank you!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    There are a number of ways. The quickest and dirtiest will be the explode/slice and implode methods.
    PHP Code:
    // I presume lines refers to a single \n.
    $excerpt implode(PHP_EOLarray_slice(explode(PHP_EOLget_the_excerpt()), 2)); 
    Then simply replace the get_the_excerpt in that limit words function with the $excerpt variable.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    Daren_Z (09-11-2013)

  • #3
    New to the CF scene
    Join Date
    Sep 2013
    Location
    Edmonton
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks Fou-Lu, I changed out the code to:

    <p><?php echo string_limit_words $excerpt = implode(PHP_EOL, array_slice(explode(PHP_EOL, get_the_excerpt()), 2)); ?></p>

    And it still seems to be grabbing the author's name and title even after I cleared my bowsers cache. The rest of the page seems to be loading properly, so I assume that I put it in correctly.

    Is there something I did wrong?

    Thanks again,

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You musta since there is no way the above would work. The string_limit_words is a function according to your original post and it hasn't been treated as such (the second treats it as a construct which I can GUARANTEE you doesn't exist ).
    You need so separate the $excerpt into its own block of code and simply replace the get_the_excerpt() in the original code with $excerpt. I assume its a string of course based on the string_limit_words function name.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    New to the CF scene
    Join Date
    Sep 2013
    Location
    Edmonton
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Haha, sorry about that, total newb here.

    Got that in place now, but it still doesn't seem to be working (Even after clearing cache).
    PHP Code:
        <!-- Begin Flex Slider Featured -->

    //limit words in featured slider
    $excerpt = implode(PHP_EOL, array_slice(explode(PHP_EOL, get_the_excerpt()), 2));  
                        
                        <div class="flexslider small">
                                <ul class="slides">
                                 <?php while($featured_posts->have_posts()): $featured_posts->the_post(); ?>
                                <li>
                                    <?php if(has_post_thumbnail()): ?>
                                        <a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_post_thumbnail('small-nivo-thumb'); ?></a>
                                    <?php else: ?>
                                        <a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo get_template_directory_uri(); ?>/images/thumbnails/620x350.png" alt="<?php the_title(); ?>" title="#htmlcaption_<?php the_ID(); ?>" /></a>
                                    <?php endif; ?>
                                    <?php if(get_option('reedwan_featured_caption') == 'yes'):?>
                                        <div class="flex-caption"><h1><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h1><p><?php echo string_limit_words($excerpt25); ?></p></div>
                                    <?php endif; ?>    
                                </li>
                                <?php endwhile; wp_reset_query();?>
                                
                                </ul>
                          </div>
                    <!-- End Flex Slider Featured -->
    Does this look correct? It's very possible that I made another complete rookie mistake.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Can you show the $excerpt assignment?
    I can only do what I assume it is. I haven't a clue with the wordpress what these mostly do, but the only one limited by words appeared to be the one you have in the string_limit_words, so that'd be the one to change.
    If its not, the logic is still the same, I just don't know which one it'd be.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    New to the CF scene
    Join Date
    Sep 2013
    Location
    Edmonton
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    The assignment is at the very top of the code I put in (Just below the second comment). I only pasted in the code that you had given me originally.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Oh yes I see it there. I was looking for the blue :P
    Add after it:
    PHP Code:
    var_dump(get_the_excerpt());
    var_dump($excerpt); 
    And post that.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    Daren_Z (09-11-2013)

  • #9
    New to the CF scene
    Join Date
    Sep 2013
    Location
    Edmonton
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Okay, thanks! I got those in there now.

    But now I'm seeing another issue, where do I put your code into the PHP file below? And should the code be showing up in blue like you mentioned earlier?

    PHP Code:
    <?php if(is_home() && get_option('reedwan_featured_slider') == 'On' && get_option('reedwan_slider_style') == 'bigStyle'): ?>
            <?php
            $post_types 
    get_post_types();
            unset(
    $post_types['page'], $post_types['portfolio'], $post_types['gallery'], $post_types['reviews'], $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item']);
            
    $featured_posts = new WP_Query(array('post_type' => $post_types,'showposts' => get_option('reedwan_slider_num_item'),'tag' => get_option('reedwan_featured_tags')
            ));
            
    ?>
            <!-- Begin Flex Slider Featured -->


            <div class="flexslider full">
                    <ul class="slides">
                     <?php while($featured_posts->have_posts()): $featured_posts->the_post(); ?>
                        <li>
                        <?php if(has_post_thumbnail()): ?>
                                <a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_post_thumbnail('big-nivo-thumb'); ?></a>
                            <?php else: ?>
                                <a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo get_template_directory_uri(); ?>/images/thumbnails/1000x500.png" alt="<?php the_title(); ?>" title="#htmlcaption_<?php the_ID(); ?>" /></a>
                            <?php endif; ?>

    <!-- stop the author's name and position from appearing on the site -->
    $excerpt = implode(PHP_EOL, array_slice(explode(PHP_EOL, get_the_excerpt()), 2));  
    var_dump(get_the_excerpt());
    var_dump($excerpt);  
                            
                        <?php if(get_option('reedwan_featured_caption') == 'yes'):?>
                                <div class="flex-caption"><h1><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h1><p><?php echo string_limit_words($excerpt35); ?></p></div>
                        <?php endif; ?>            
                            </li>
                        <?php endwhile; wp_reset_query();?>
                </ul>
          </div>
                        
    <!-- End Flex Slider Featured -->
    <?php endif; ?>
    <div class="clear"></div>
    As you can see, I have the code implemented just above where it calls for the string. But on the site, this code is actually showing up as a string just below the title on the slider

    Screenshot:


    www.thegriff.ca


    I hope I'm not asking too much. I really appreciate all of your help.


  •  

    Tags for this Thread

    Posting Permissions

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