Trying to get PHP code to work in wordpress

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crazyfish
Forum Newbie
Posts: 2
Joined: Wed Oct 29, 2008 8:35 am

Trying to get PHP code to work in wordpress

Post by crazyfish »

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've posted at wordpress support but never got a reply. I believe I am heading in the right direction I'm just not sure how to debug this.

I'm trying to get the below code to work:

Code: Select all

<?php posts_nav_link(' ','<img src="'.bloginfo('template_directory').'/images/left.png" />','<img src="'.bloginfo('template_directory').'/images/right.png" />'); ?>
but this is what it outputs which is all messed up.

Code: Select all

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>
 
it should be

Code: Select all

<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>
 
Thanks in advance!
crazyfish
Forum Newbie
Posts: 2
Joined: Wed Oct 29, 2008 8:35 am

Re: Trying to get PHP code to work in wordpress

Post by crazyfish »

I'm not sure I follow, I'm using bloginfo to get the location of the theme folder because that's where the images are. PHP is outputting the template URL outside of the <img> tags which is why it's not working.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Trying to get PHP code to work in wordpress

Post by requinix »

Huh. Thought you made a typo.

That link is still helpful.
Displays information about your blog, mostly gathered from the information you supply in your User Profile and General Options from the WordPress Administration panels (Settings → General). It can be used anywhere within a page template. This always prints a result to the browser. If you need the values for use in PHP, use get_bloginfo().
Post Reply