Jump to content

help with echoing something thanks


Novice@PHP

Recommended Posts

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.

Link to comment
Share on other sites

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>'; ?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.