WordPress.org

Ready to get started?Download WordPress

Forums

Adding image to "read more" link under "limit post" plugin (15 posts)

  1. iceq
    Member
    Posted 4 years ago #

    Hello

    I am using limit-post plugin by Alfonso Sánchez-Paus Díaz y Julián Simón de Castro (thats a long name isnt it :D ) .

    Before using this plugin, I used the more tag with image integrated in it, using the following code:

    <?php the_content('<img src="/al-rasid/personal/wp-content/uploads/more.gif" alt="read more" title="Read more..." />'); ?>

    However, for the plugin to work, I have to replace that code with:
    <?php the_content_limit(750); ?>
    ( 750 is a variable, the number of letters to cut the post on)

    So in this new code, I dont know hot to add the image that I want to replace the "more" with.

    I tried making up this code and placing it in the index, which is actually a mix of both old and new codes, but it didnt work properly either.

    <?php the_content_limit(750,'<img src="/al-rasid/personal/wp-content/uploads/more.gif" alt="read more" title="Read more..." />'); ?>

    I noticed a line in the plugins php (you can see it via clicking on the plugin's link ), which is:

    function the_content_limit($max_char, $more_link_text = 'تابع للقراءة والتوقيع&larr;', $stripteaser = 0, $more_file ='') {

    I made some change, adding the more image's url, as follows:

    function the_content_limit($max_char, $more_link_text = 'تابع للقراءة والتوقيع&larr;', $stripteaser = 0, $more_file ='/3areda/wp-content/uploads/more.gif') {

    However, it didnt work. The image didnt show up.

    I searched the plugin's website, but nothing is mentioned about the "$more_file" tag and how to use it. And the blog is in spanish or portugesse, and I am unfamiliar with these.

    Any help will be appreciated.

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    I'm really not so good at this stuff...but in this part of the code....its telling the plugin what to output

    else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
            $content = substr($content, 0, $espacio);
            $content = $content;
            echo $content;
            echo "<a href='";
            the_permalink();
            echo "'>"."..."."</a>";
            echo "<br /><br />";
            echo "<a href='";
            the_permalink();
            echo "'>".$more_link_text."</a></p>";
       }
       else {
          echo $content;
       }
    }

    so couldn't ya throw the image in there somewhere maybe?

    else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
            $content = substr($content, 0, $espacio);
            $content = $content;
            echo $content;
            echo "<a href='";
            the_permalink();
            echo "'>"."..."."</a>";
            echo "<br /><br />";
            echo "<img src="/al-rasid/personal/wp-content/uploads/more.gif" />";
            echo "<a href='";
            the_permalink();
            echo "'>".$more_link_text."</a></p>";
       }
       else {
          echo $content;
       }
    }

    I have no idea if this will work, and you may have to play around with it a bit..... Just a wild guess....

    Also, if you're using images as part of your theme, why not drop them into your themes images folder and link like this?
    <img src="<?php bloginfo('template_url'); ?>/images/more.gif" />

  3. iceq
    Member
    Posted 4 years ago #

    Thank you my friend.
    I tried your suggestion and a bunch of others, but none is working.

  4. Limits the displayed text length on the index page entries and generates a link to a page to read the full content if its bigger than the selected maximum length.

    *squint*

    Why not just edit your theme to use the_exceprt and then control the length of your excerpt by putting this in the functions.php

    function new_excerpt_length($length) {
    	return 20;
    }
    add_filter('excerpt_length', 'new_excerpt_length');

    Where 20 is changed to how ever many words you want. 100, whatever :) (note this is WORDS, not characters...)

    Then on your theme you'd put in:

    <?php the_excerpt() ?>
    <span class="read_more"><a href="<?php the_permalink(); ?>"><img src="/al-rasid/personal/wp-content/uploads/more.gif" alt="read more" title="Read more..." /></a></span>

    If you're dead set on the plugin,

    change this:

    echo "<a href='";
            the_permalink();
            echo "'>".$more_link_text."</a></p>";
    echo "<a href='";
            the_permalink();
            echo "'><img src='"/al-rasid/personal/wp-content/uploads/more.gif"' alt='"read more"' title='"Read more..."' /></a></p>";

    You may need to play around with the " and ' mind you :/

  5. iceq
    Member
    Posted 4 years ago #

    Hello. I thank you deeply for taking this clearly precious time to help me :) Sadly though, nothing worked for me. I hope it is a mistake ive made.

    As for the first solution, I did the following:

    In the Index, I found:

    <?php if(function_exists('the_content_limit')) { ?>
    <?php the_content_limit(500);  ?>

    I replaced them with

    <?php the_excerpt() ?>
    <span class="read_more"><a href="<?php the_permalink(); ?>"><img src="/al-rasid/personal/wp-content/uploads/more.gif" alt="read more" title="Read more..." /></a></span>

    Then, in functions.php, whose full content is:

    <?php
    require_once(TEMPLATEPATH . '/controlpanel.php');
    if ( function_exists('register_sidebars') )
        register_sidebars(2);
    ?>

    just before the ?>' , I added:

    function new_excerpt_length($length) {
    	return 20;
    }
    add_filter('excerpt_length', 'new_excerpt_length');

    However, nothing works. It reports syntax errors all the time.

    __________________________

    With the second solution U suggested, I tried the following combinations, None of them worked, either give fatal error, or the post content doesnt load at all , though the full index show up.

    echo "'><img src='"/al-rasid/personal/wp-content/uploads/more.gif"' alt='"read more"' title='"Read more..."' /></a></p>";

    echo "'><img src="/al-rasid/personal/wp-content/uploads/more.gif" alt='"read more"' title='"Read more..."' /></a></p>";

    echo "'><img src='/al-rasid/personal/wp-content/uploads/more.gif' alt='"read more"' title='"Read more..."' /></a></p>";

    echo "'>'<img src='"/al-rasid/personal/wp-content/uploads/more.gif"' alt='"read more"' title='"Read more..."' />'</a></p>";

  6. You have have other issues with the functions solution, so let's look at your plugin...

    Okay, I'm pretty sure the second error is from all the " and ' out there.

    I know this is bad HTML, but lets start easy:

    echo "<a href='";
    the_permalink();
    echo "'><img src=/al-rasid/personal/wp-content/uploads/more.gif alt=".$more_link_text." /></a></p>";
  7. iceq
    Member
    Posted 4 years ago #

    I am really thankful.

    The code worked for two of my blogs perfectly. THe first code you posted (before youe edited, also worked).

    Yet the third blog didnt go ok, despite its the same theme and the same code structure of the limit post plugin.

    Using ur first code (before you edited it, without the alt tag) nothing appeared at all where the "read more" or the image should appear.

    The second code that you edited however, managed to show only a "read more" text, but not the image.

    What could the reason be ?

    ( theme is different in all of the blogs)

  8. Is the image loaded?

    The image tag <img src=/al-rasid/personal/wp-content/uploads/more.gif /> has to point to a real image, so put that URL in your browser and make sure that http://yourdomain.com/al-rasid/personal/wp-content/uploads/more.gif exists :)

  9. iceq
    Member
    Posted 4 years ago #

    Yes , certainly there is a real image in the url path.. it is not shown why. I went through the process again, uploaded the plugin and activated then edited, adding the code you provided, yet its still the same...

  10. Can you share the URL? I may be able to dig up something if I look at it, but right now I've no idea.

  11. iceq
    Member
    Posted 4 years ago #

    here it is
    http://www.3areda.com/

    Thank you in advance, even if no solution is found :)

  12. The image doesn't exist.

    http://www.3areda.com/al-rasid/personal/wp-content/uploads/more.gif is where it's looking and there's no image there.

  13. iceq
    Member
    Posted 4 years ago #

    Oh, not that, the real valid url I added to the template ends weith "sign_now.gif" which is the "more" in that other site.
    After I made my last post here, I removed the more code and replaced it with the original one that donesnnt contain the image. When you asked me about the site, I re-added the image, but then I put the other mistaken code that I used with another website (on of the two that worked).

    Now, I fixed the code with the image that Do exist (http://www.3areda.com/wp-content/uploads/sign_now.gif) , and still it doesnt appear.

    Thanx again

  14. Except that in your code it called that more.gif ;)

    Anyway, looking at it now, I see this:

    <img src=/3areda/wp-content/uploads/sign_now.gif alt=تابع للقراءة والتوقيع&larr; />

    That points to this image: http://www.3areda.com/3areda/wp-content/uploads/sign_now.gif

    Which? Is still a 404. See how that works?

    The image is ACTUALLY here : http://www.3areda.com/wp-content/uploads/sign_now.gif

    So change it to /wp-content/uploads/sign_now.gif

  15. iceq
    Member
    Posted 4 years ago #

    Oh I must be have been very distracted to not have noticed that :)

    It now works 100% Thank you again for your valuable help.

Topic Closed

This topic has been closed to new replies.

About this Topic