Novice@PHP Posted July 23, 2010 Share Posted July 23, 2010 I don't think I'm grasping this concept one little bit. can take me months too unfortunately. What I have today is this line of code echo '<li><?php dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '" class="footer-thumb" width="40px" height="40px"'); ?><a href="' . get_permalink($id) . '">' . get_the_title($id) . '</a></li>'; It doesn't work because it creates a syntax error. I know it's simple too but still can't get my head round this kind of coding. Thanks to everyone who takes their time to reply. Quote Link to comment https://forums.phpfreaks.com/topic/208696-help-with-echoing-something-thanks/ Share on other sites More sharing options...
Genesis730 Posted July 23, 2010 Share Posted July 23, 2010 I'm no expert but don't you need to escape the quotes so the echo doesn't end before you want it to? Also you're trying to target your link to a PHP value, but the code isn't in PHP, at least from the code provided, if that's the case you would need the link to be like this <a href="<?PHP echo get_permalink($id); ?>"> <?PHP echo get_the_title($id) . '</a></li>';?> The whole thing would look something like this, let me know how it goes... <?PHP echo "<li><?php dp_attachment_image($post->ID, \'thumbnail\', \'alt=\'" . $post->post_title . "\' class=\"footer-thumb\" width=\"40px\" height=\"40px\""); ?><a href="<?PHP echo get_permalink($id); ?>"> <?PHP echo get_the_title($id) . '</a></li>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/208696-help-with-echoing-something-thanks/#findComment-1090302 Share on other sites More sharing options...
Novice@PHP Posted July 23, 2010 Author Share Posted July 23, 2010 I'm no expert but don't you need to escape the quotes so the echo doesn't end before you want it to? Also you're trying to target your link to a PHP value, but the code isn't in PHP, at least from the code provided, if that's the case you would need the link to be like this <a href="<?PHP echo get_permalink($id); ?>"> <?PHP echo get_the_title($id) . '</a></li>';?> The whole thing would look something like this, let me know how it goes... <?PHP echo "<li><?php dp_attachment_image($post->ID, \'thumbnail\', \'alt=\'" . $post->post_title . "\' class=\"footer-thumb\" width=\"40px\" height=\"40px\""); ?><a href="<?PHP echo get_permalink($id); ?>"> <?PHP echo get_the_title($id) . '</a></li>'; ?> Doesn't work but thanks for the advice. Still trying to do it lol. Quote Link to comment https://forums.phpfreaks.com/topic/208696-help-with-echoing-something-thanks/#findComment-1090403 Share on other sites More sharing options...
wildteen88 Posted July 23, 2010 Share Posted July 23, 2010 I thinks that is what you want to do. echo '<li>'. dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '" class="footer-thumb" width="40px" height="40px"'). '<a href="' . get_permalink($id) . '">' . get_the_title($id) . '</a>'. '</li>'; Quote Link to comment https://forums.phpfreaks.com/topic/208696-help-with-echoing-something-thanks/#findComment-1090408 Share on other sites More sharing options...
Novice@PHP Posted July 24, 2010 Author Share Posted July 24, 2010 I thinks that is what you want to do. echo '<li>'. dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '" class="footer-thumb" width="40px" height="40px"'). '<a href="' . get_permalink($id) . '">' . get_the_title($id) . '</a>'. '</li>'; Tjis works much better than anything I tried. Though one issue is that it doesn't echo both inside the <li> but rather image outside and url inside. I tweaked it a little and got it to display them in separate <li>'s but this isn't what i need. Any ideas why they aren't inside the same <li> tags? (by they I mean the .dp_attatchment_image and the permalink fucntion. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/208696-help-with-echoing-something-thanks/#findComment-1090771 Share on other sites More sharing options...
DavidAM Posted July 25, 2010 Share Posted July 25, 2010 echo '<li>'. dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '" class="footer-thumb" width="40px" height="40px"'). '<a href="' . get_permalink($id) . '">' . get_the_title($id) . '</a>'. '</li>'; if dp_attachment_image() or get_permalink() or get_the_title() are echoing, or printing or otherwise outputting text, it will appear before the output from the echo that is outputting the LI. The way this code is written, you are expecting these three functions to return a string not output a string. If these functions do in fact echo the code, you should use something like this: echo '<li>'; dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '" class="footer-thumb" width="40px" height="40px"'); echo '<a href="'; get_permalink($id); echo '">'; get_the_title($id); echo'</a></li>'; which is kind of ugly; and probably whey some PHP native functions (like print_r) have a paramter called $return which can be set to true to return the string; and defaults to false to output the string. Quote Link to comment https://forums.phpfreaks.com/topic/208696-help-with-echoing-something-thanks/#findComment-1090820 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.