Jump to content

"Read More" function??


Recommended Posts

Hey guys. Im currently working on a university project and I've hit a brick wall with part of my code. Basically, I'm creating a mashup website that creates feeds on the fly, from APIs such as LastFM, YouTube, Flickr and Idiomag. The results are then echoed out into a HTML document, to create a unique artist profile. My question is, how is it possible to have a truncated string within the HTML and be able to click "Read More" to display the full string? If you look at this profile, you'll be able to see what I mean:

 

http://cahamilton.at-uclan.com/fyp/query.php?artist=foo+fighters

 

As the biographies aren't generated by myself (Last FM), I have no control over the length of them. Within my PHP coding, I have a truncate function which looks like this:

 

                $bio_scrape_large = strip_tags($bio_scrape_large,'<p><br><strong><b><u>');

                $bio_scrape_small = substr($bio_scrape_large,0,3000);

echo $bio_scrape_small; ?>

 

Basically, I want to be able to click on a link that says "Read Me" (or something along those lines), to which $bio_scrape_large is echoed out into the HTML. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/147723-read-more-function/
Share on other sites

<script>
function showHide(inID) {
     if (document.getElementById(inID).style.display == 'none') {
          document.getElementById(inID).style.display = 'block';
     } else {
          document.getElementById(inID).style.display = 'none';
     }
}

function Show(inID) {
     if (document.getElementById(inID).style.display == 'none') {
          document.getElementById(inID).style.display = 'block';
     } else {
          document.getElementById(inID).style.display = 'block';
     }
}

function Hide(inID) {
     if (document.getElementById(inID).style.display == 'block') {
          document.getElementById(inID).style.display = 'none';
     } else {
          document.getElementById(inID).style.display = 'none';
     }
}
</script>

Link to comment
https://forums.phpfreaks.com/topic/147723-read-more-function/#findComment-775421
Share on other sites


<a href="javascript:void(0)" onclick="Show('somthing')">read more...</a>
<a href="javascript:void(0)" onclick="Hide('somthing')">read more...</a>
<a href="javascript:void(0)" onclick="showHide('somthing')">read more...</a>

<div id='something' style='display: none'>reas more content</div>

Link to comment
https://forums.phpfreaks.com/topic/147723-read-more-function/#findComment-775424
Share on other sites

<head>

 


<?php

echo"
<script>
function showHide(inID) {
     if (document.getElementById(inID).style.display == 'none') {
          document.getElementById(inID).style.display = 'block';
     } else {
          document.getElementById(inID).style.display = 'none';
     }
}

function Show(inID) {
     if (document.getElementById(inID).style.display == 'none') {
          document.getElementById(inID).style.display = 'block';
     } else {
          document.getElementById(inID).style.display = 'block';
     }
}

function Hide(inID) {
     if (document.getElementById(inID).style.display == 'block') {
          document.getElementById(inID).style.display = 'none';
     } else {
          document.getElementById(inID).style.display = 'none';
     }
}
</script>
";
?>

</head>

 

<body>

 

<?php

echo"

<a href=\"javascript:void(0)\" onclick=\"Show('somthing')\">read more...</a>
<a href=\"javascript:void(0)\" onclick=\"Hide('somthing')\">read more...</a>
<a href=\"javascript:void(0)\" onclick=\"showHide('somthing')\">read more...</a>

<div id='something' style='display: none'>reas more content</div>

";

?>

</body>

Link to comment
https://forums.phpfreaks.com/topic/147723-read-more-function/#findComment-775446
Share on other sites

You can set a DIV element up and set it to hidden.

 

substr(text,0,100)<div style="display:hidden">text</div><a href="#" onclick="this.style.display.show">read more</a>

 

Something like that although my Javascript isn't brilliant so you'll need to look up "javascript display" in Google for the correct way of doing it.

 

substr: show the first 100 characters and show all the text in the DIV.

Link to comment
https://forums.phpfreaks.com/topic/147723-read-more-function/#findComment-775448
Share on other sites

Hey guys. Cheers for your help. Im kind of half way there with the code now, although still having a few problems.

 

I've managed to get it so that the "bio_large" div is loaded into the page, but can't seem to get it to override the previous "bio_small". Rather than trying to explain it, it maybe easier to show you guys. For example: http://cahamilton.at-uclan.com/fyp/query.php?artist=muse

 

Rather than replacing the div_small, div_large is just added onto the end.

 

So far this is what I have:

 

In the <head>

<script>
function showHide(bio_large) {
     if (document.getElementById(bio_large).style.display == 'none') {
          document.getElementById(bio_large).style.display = 'block';
     } else {
          document.getElementById(bio_small).style.display = 'none';
     }
}

function Show(bio_large) {
     if (document.getElementById(bio_large).style.display == 'none') {
          document.getElementById(bio_large).style.display = 'block';
     } else {
          document.getElementById(bio_large).style.display = 'block';
     }
}

function Hide(bio_large) {
     if (document.getElementById(bio_large).style.display == 'block') {
          document.getElementById(bio_large).style.display = 'none';
     } else {
          document.getElementById(bio_large).style.display = 'none';
     }
}
</script>

 

In the <body>

 

<?php echo"

<div id='bio_small'>
$bio_scrape_small<a href=\"javascript:void(0)\" onclick=\"showHide('bio_large')\" class='readmore'>Read More »</a>
</div>

<div id='bio_large' style='display: none'>
$bio_scrape_large<a href=\"#\" onclick=\"Hide('bio_large')\" class='readmore'>« Read Less</a> 
</div>

";?>

 

Apologies, my knowledge of JavaScript is pretty limited. I'm getting there though and there seems to be some form of functionality to it. Again, thanks for the help so far guys  :)

Link to comment
https://forums.phpfreaks.com/topic/147723-read-more-function/#findComment-778435
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.