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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Problems with excerpts on WP blog site

    Hi Guys,

    I've got a slight problem with excerpts on a theme I've been trying to sort out on my website.

    What it is , the home page is made up of numerous blocks showing excerpts from various articles. These exceprts are 100 characters in length, but are returned for display on the home page as plain text, when in fact the first sentence of each article is using a H3 heading tag.

    PHP Code:
    <div class="limit">

            <?php the_content_limit('100'); ?>

          </div>
    The code above is what I think is returning the 100 character excerpt, but what I want to try to do is get the first sentence only as H3 & not the full 100 characters.

    If anyone can shed some light or at least point me in the right direction, I would be most grateful.

    Thanks Taffy

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Without seeing the whole script that you have, it's going to be hard
    to say how it's actually displaying the first 100.

    But below is a little test you can try that will pick-out text between
    two HTML tags ... in your case <h3> and </h3>. You can't just stick
    it into your WP script ... but maybe if you find where their functions are,
    you can do something with the parts that pertain to the first 100 characters.

    PHP Code:
    <?php

    $string
    ="This is a test for <h3>Text in the Header</h3> function to extract text.";

    echo 
    ExtractString($string,"<h3>","</h3>");

    function 
    ExtractString($str$start$end){
    $str_low strtolower($str);
    $pos_start strpos($str_low$start);
    $pos_end strpos($str_low$end, ($pos_start strlen($start)));
       if ( (
    $pos_start !== false) && ($pos_end !== false) ){
       
    $pos1 $pos_start strlen($start);
       
    $pos2 $pos_end $pos1;
       return 
    substr($str$pos1$pos2);
       }
    }

    ?>
    The output of the test script is: Text in the Header



    .

  • #3
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Additional code as requested

    Hi thanks for trying to help me out, I did take a look at the place where the code is, but I just can't seem to make any progress on this at all. I don't know, but looking at the code below, I just thought if "limit" was/is a variable of set length containing different characters, then how would I use the code you posted in order to query that variable and return what is inside the h3 tags..? Sorry but my knowledge of php is terrible

    This is the entire block of code that deals with an area of the page called featured right. Hope it makes more sense to you than it does to me !

    PHP Code:
    <div id="featuredright">
        <?php $recent = new WP_Query("cat=".get_theme_mod('featuredcat')."&offset=1&showposts=4"); while($recent->have_posts()) : $recent->the_post();?>
        <div id="featuredpost">
          <div class="thumb">
            <?php tj_thumbnail('featuredrightthumbw''featuredrightthumbh'); ?>
          </div>
          <!--end: thumb-->
          <h2><a href="<?php the_permalink(); ?>" rel="bookmark">
            <?php the_title(); ?>
            </a></h2>
          <div class="byline">
            <?php the_author_posts_link(); ?>
            //
            <?php the_time('M jS, Y'?>
          </div>
          <div class="limit">

           <?php the_content_limit(100); ?>       

          </div>
          <!--end: limit-->
          <div class="clear"></div>
        </div>
        <!--end: featuredpost-->
        <?php endwhile; ?>
      </div>
      <!--end: featuredright-->
    You will notice there is a H2 tag used also, but this is the actual url of the article & therefore not really what I want.

    Regards Taffy

  • #4
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Can you post a link to your test page so we can see the actual output being generated?
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #5
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Link as requested, to show current output to site !

    Hi guys, sorry I didn't think I should post a link to my site in case it was seen as spamming ?

    Anyway the link is: Philippines-Virtual-Guide

    As I said earlier, you will notice the main headings throughout the page are using a H2 tag, but these are basically hyperlinks to each article.
    What I want to try to do is make the first sentence (in black) to show as H3
    text as it was meant to do. I can then style just the H3 text instead of styling the whole 100 characters which is currently my only option!

    I don't know if this is relevant, but I was browsing through the code files last night & came across an entry in theme functions.php which was "strip_tags"..? Now not knowing a great deal about php, I could be wrong, but I think maybe this is why I have been unable to style the H3 in the excerpt..? If this is the case, would it not be easy in the long run to just insert an exception to this strip_tags and allow the H3..?

    PHP Code:
    # Limit Post
    function the_content_limit($max_char$more_link_text ''$stripteaser 0$more_file '') {
        
    $content get_the_content($more_link_text$stripteaser$more_file);
        
    $content apply_filters('the_content'$content);
        
    $content str_replace(']]>'']]&gt;'$content);
        
    $content strip_tags($content);

       if (
    strlen($_GET['p']) > 0) {
          echo 
    "";
          echo 
    $content;
          echo 
    "&nbsp;<a href='";
          
    the_permalink();
          echo 
    "'>"."Read More &rarr;</a>";
          echo 
    "";
       }
       else if ((
    strlen($content)>$max_char) && ($espacio strpos($content" "$max_char ))) {
            
    $content substr($content0$espacio);
            
    $content $content;
            echo 
    "";
            echo 
    $content;
            echo 
    "...";
            echo 
    "&nbsp;<a href='";
            
    the_permalink();
            echo 
    "'>"."</a>";
            echo 
    "";
       }
       else {
          echo 
    "";
          echo 
    $content;
          echo 
    "&nbsp;<a href='";
          
    the_permalink();
          echo 
    "'>"."Read More &rarr;</a>";
          echo 
    "";
       }

    Thanks again guys


  •  

    Posting Permissions

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