Trying to get PHP code to work in wordpress

Discussion in 'PHP' started by crazyfish, Oct 26, 2008.

  1. #1
    I'm trying to use images for the next page and prev page links but I'm not very good with PHP so I think I am messing something up. If I put the relative path to the template the images work but if I try to call the images based on the template folder it fails. I'm trying to get the below code to work:

    <?php posts_nav_link(' ','<img src="<?php bloginfo('template_directory'); ?>/images/left.png" />','<img src="<?php bloginfo('template_directory'); ?>/images/right.png" />'); ?>
    
    Code (markup):
    I'm pretty sure it's just my syntax that's wrong I get a parsing error.
     
    crazyfish, Oct 26, 2008 IP
  2. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php posts_nav_link(' ','<img src="<?php bloginfo('template_directory'); ?>/images/left.png" />','<img src="<?php bloginfo('template_directory'); ?>/images/right.png" />'); ?>

    you start a php code segment with <?php
    then in the function call you state src="<?php
    and there you start another code segment
    but you are already in the code segment

    '<img src="'.bloginfo('template_directory').'/images/left.png" />'

    should work?
     
    juust, Oct 26, 2008 IP
  3. crazyfish

    crazyfish Active Member

    Messages:
    1,110
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Hi Thanks for the suggestion, this is what I tried:

    <?php posts_nav_link(' ','<img src="'.bloginfo('template_directory').'/images/left.png" />','<img src="'.bloginfo('template_directory').'/images/right.png" />'); ?>
    Code (markup):
    This is the html it outputs, which doesn't work.

    http://mydomain.com/testwp/wp-content/themes/black bloghttp://mydomain.com/testwp/wp-content/themes/black blog<a href="http://mydomain.com/testwp/?paged=2"><img src="/images/right.png" /></a>
    Code (markup):
    That's the right path but it's placing the URL outside of the a and img tags. Did I not add your suggestion properly?
     
    crazyfish, Oct 26, 2008 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    That should work??
    Post more codes here?
     
    ads2help, Oct 26, 2008 IP
  5. crazyfish

    crazyfish Active Member

    Messages:
    1,110
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    80
    #5
    More code like what? I posted the exact PHP code I'm trying to use and what it output which if it was formatted correctly would display properly but the html is all messed up.

    What else would help?
     
    crazyfish, Oct 27, 2008 IP
  6. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #6
    Can wee see the output HTML, and what it should output?
     
    blueparukia, Oct 27, 2008 IP
  7. crazyfish

    crazyfish Active Member

    Messages:
    1,110
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    80
    #7
    This is the output with the above PHP code

    http://mydomain.com/testwp/wp-content/themes/black bloghttp://mydomain.com/testwp/wp-content/themes/black blog<a href="http://mydomain.com/testwp/"><img src="/images/left.png" /></a><a href="http://mydomain.com/testwp/?paged=3"><img src="/images/right.png" /></a> 
    Code (markup):
    The html for each image should come out like this:

    <a href="http://mydomain.com/testwp/"><img src="http://mydomain.com/testwp/wp-content/themes/black blog/images/left.png" /></a><a href="http://mydomain.com/testwp/?paged=3"><img src="http://mydomain.com/testwp/wp-content/themes/black blog/images/right.png" /></a>
    Code (markup):
    As you can see it is placing the path to the template file outside of the html tags.
     
    crazyfish, Oct 27, 2008 IP