papillonstudios Posted October 7, 2010 Share Posted October 7, 2010 Im not sure f this is the right spot for this or not but... I have a website that has a content box that has a fixed height and width. How would i make it so after the box is full it puts a link to read more at the bottom of it? Also images may be used as well. Its also for a wordpress blog Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 7, 2010 Share Posted October 7, 2010 This has been addressed several times. The most recent I recall is here: http://www.phpfreaks.com/forums/index.php/topic,304652.0.html It's not pixel perfect. It never will be. Read that thread and then post some code if you can't get a solution! Good luck. Quote Link to comment Share on other sites More sharing options...
jammesz Posted October 7, 2010 Share Posted October 7, 2010 Use this to get you started: <?php$text="PHP is proud to announce TestFest 2010. TestFest is PHP's annual campaign to increase the overall code coverage of PHP through PHPT tests. During TestFest, PHP User Groups and individuals around the world organize local events where new tests are written and new contributors are introduced to PHP's testing suite.Last year was very successful with 887 tests submitted and a code coverage increase of 2.5%. This year we hope to do better.TestFest's own SVN repository and reporting tools are back online for this year's event. New to TestFest this year are automated test environment build tools as well as screencasts showing those build tools in action.Please visit the TestFest 2010 wiki page for all the details on events being organized in your area, or find out how you can organize your own event.";$limit=200;echo substr($text,0,$limit);echo '<hr>';echo substr($text,$limit);?> of course you'll need to solve the problem of it cutting words in half but that shouldn't be too hard Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted October 8, 2010 Author Share Posted October 8, 2010 ok i have came up with this code here: <?php $entry = the_content(); $limit = 200; if (strlen($entry) > || strlen($entry) == $limit) { substr($entry,0,$limit); echo '<a href="#"><img src="<?php bloginfo("template_url"); ?>/images/readmore.png" class="readmore" /></a>' } ?> but i forget what the proper way to say if $entry is greater than 200 or equal to 200 then do this. if that right i do get this error when i load the page Parse error: syntax error, unexpected T_BOOLEAN_OR in /Users/GamingFusion/Sites/rbrwp/wp-content/themes/RedBarRadio/index.php on line 139 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 8, 2010 Share Posted October 8, 2010 if( $value1 >= $value2 ) { Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted October 8, 2010 Author Share Posted October 8, 2010 ok its not working right it says the post has zero characters. <?php $entry = the_content(); $limit = 200; if (strlen($entry) >= $limit) { substr($entry,0,$limit); echo '<a href="#"><img src="<?php bloginfo("template_url"); ?>/images/readmore.png" class="readmore" /></a>'; } echo 'This post has: ' . strlen($entry) . ' Characters'; ?> OUTPUT : Kelt yaders piat keropas jergyadera kertyuades fertyseras omniriea kerod miaset tirase neruasera jerta kertyua eatdertasen accusa ntium reue kertsdea Haseistique orci ferodeaser vasaecer dimagna nasertad ace ultricies pharetras malesuada orcgertyae nec accumanera semis ertsertas mierty uadesaso nec sit amet erosertaera kertya. Lorem ipsum dolor sit amnsetuer adipiscing elit. Mauris fermentum dictum magna. Sed laoreet aliquam leo. Ut tellus dolor, dapibus eget, elementum vel, cursus eleifend, elit. Aenean auctor wisi et urna. Haseistique orci ferodeaser vasaecer dimagna nasertad aceultricies pharetras malesuada orcgertyae nec accumanera semis ertsertas mierty uadesaso nec sit amet erosertaera kertya. Lorem ipsum dolor sit amnsetuer adipiscing elit. Mauris fermentum dictum magna. Sed laoreet aliquam leo. Ut tellus dolor, dapibus eget, elementum vel, cursus eleifend, elit. Aenean auctor wisi et urna. Haseistique orci ferodeaser vasaecer dimagna nasertad ace ultricies pharetras malesuada orcgertyae nec accumanera semis ertsertas mierty uadesaso nec sit amet erosertaera kertya. Lorem ipsum dolor sit amnsetuer adipiscing elit. Mauris fermentum dictum magna. Sed laoreet aliquam This post has: 0 Characters Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted October 8, 2010 Author Share Posted October 8, 2010 Ok putting all the text in the variable like this works <?php $entry = 'Kelt yaders piat keropas jergyadera kertyuades fertyseras omniriea kerod miaset tirase neruasera jerta kertyua eatdertasen accusa ntium reue kertsdea Haseistique orci ferodeaser vasaecer dimagna nasertad ace ultricies pharetras malesuada orcgertyae nec accumanera semis ertsertas mierty uadesaso nec sit amet erosertaera kertya. Lorem ipsum dolor sit amnsetuer adipiscing elit. Mauris fermentum dictum magna. Sed laoreet aliquam leo. Ut tellus dolor, dapibus eget, elementum vel, cursus eleifend, elit. Aenean auctor wisi et urna. Haseistique orci ferodeaser vasaecer dimagna nasertad aceultricies pharetras malesuada orcgertyae nec accumanera semis ertsertas mierty uadesaso nec sit amet erosertaera kertya. Lorem ipsum dolor sit amnsetuer adipiscing elit. Mauris fermentum dictum magna. Sed laoreet aliquam leo. Ut tellus dolor, dapibus eget, elementum vel, cursus eleifend, elit. Aenean auctor wisi et urna. Haseistique orci ferodeaser vasaecer dimagna nasertad ace ultricies pharetras malesuada orcgertyae nec accumanera semis ertsertas mierty uadesaso nec sit amet erosertaera kertya. Lorem ipsum dolor sit amnsetuer adipiscing elit. Mauris fermentum dictum magna. Sed laoreet aliquam'; $limit = 200; if (count($entry) >= $limit) { substr($entry,0,$limit); echo '<a href="#"><img src="<?php bloginfo("template_url"); ?>/images/readmore.png" class="readmore" /></a>'; } echo 'This post has: ' . count($entry) . ' Characters'; ?> but now it doesnt want to show the content. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 8, 2010 Share Posted October 8, 2010 EDIT: Missed your last post. I see you've already figured out the first part . . . If I replace the function call to the_content() with $entry = "[that whole entry in your last post]"; It returns this (HTML source). You need to remove the <?php ?> tags on this line, since you're inside php already. <a href="#"><img src="<?php bloginfo("template_url"); ?>/images/readmore.png" class="readmore" /></a>This post has: 1189 Characters Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 8, 2010 Share Posted October 8, 2010 Why did you change to count()? That function counts elements in an array. Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted October 8, 2010 Author Share Posted October 8, 2010 Just thought i would give it a try i changed it back though Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted October 8, 2010 Author Share Posted October 8, 2010 ok i took out the if statement kuzz i should have a link to the post always anyways so heres my code now just have to get it to work with the the_content(); <?php $entry = the_content(); $limit = 200; substr($entry,0,$limit); ?> <a href="#"><img src="<?php bloginfo('template_url'); ?>/images/readmore.png" class="readmore" /></a> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 8, 2010 Share Posted October 8, 2010 Since you haven't posted that function, there's no way to tell what needs to be done to get it to play nicely . . . Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted October 8, 2010 Author Share Posted October 8, 2010 its a wordpress blog but heres the function for it. function the_content($more_link_text = null, $stripteaser = 0) { $content = get_the_content($more_link_text, $stripteaser); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); echo $content; } Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 8, 2010 Share Posted October 8, 2010 The problem you're experiencing is due to the fact that the function uses echo rather than return. As soon as you invoke the function, it echos everything to the screen instead of allowing you to store the output in a variable, therefore $entry has no value. I'm going to stop short of recommending you change the function to return the value, instead of echoing it because I'm nearly 100% certain doing that will cause a virtual shitstorm of problems. You can try it if you want, but I doubt it will give you good results. Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted October 8, 2010 Author Share Posted October 8, 2010 would i be able to just let it echo the entire thing then just have the height set to a certain height(which it is) and have it only display what will fit in the container? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 8, 2010 Share Posted October 8, 2010 Honestly, CSS is about my weakest area. It sounds like it would work, but I really can't say for sure. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.