Page 1 of 1

newbie wordpress theme designer needs a little php help

Posted: Wed Mar 03, 2010 3:28 pm
by artwork architects
hello,

just registered on the forum, full of knowledge i will need a few months to digest.

i have looked for a solution to my problem, but have yet to find a good answer.

im hopeing you guys and girls can help me out.

first off heres some background:

i am a young graphic designer, looking to setup on my own freelancing. i use wordpress often, and have "hacked" away at multiple themes so they do what i want. now i am designing my own them from scratch. all theme design is done, everything works (and validates). my next task is adding theme options.


i have successfully added "theme options in the form of text. for things like google verify codes, etc.

now what i want to do is add remove certain divs from the site. (social networking icons) i will have multiple icons available and if the theme user has a profile on that site he/she can input the address and the icon will appear on the site, if they dont it wont show up.

these are image icons with div onclick functions to send user certain webpages (defined in the theme options)

i have successfully managed to add a text box in the theme options for the user to input web address.

and also managed to get this inputted info into the divs through use of <?php echo get_option(' '); ?>

like this:

<div id="flick" onclick="window.open('<?php echo get_option('flickr_code'); ?>','newwindow');"></div>

this works great, but i want the div to dissappear if no address is provided in the theme options.

so in the template file i need something like this:

if theme option 'flickr_code' contains text print:

<div id="flick" onclick="window.open('<?php echo get_option('flickr_code'); ?>','newwindow');"></div>

i hope this explains what i need, im fine with html/css but php is still rather new to me.

i hope someone can help

Re: newbie wordpress theme designer needs a little php help

Posted: Wed Mar 03, 2010 4:26 pm
by greyhoundcode
artwork architects wrote:so in the template file i need something like this:

if theme option 'flickr_code' contains text print:

<div id="flick" onclick="window.open('<?php echo get_option('flickr_code'); ?>','newwindow');"></div>

Code: Select all

<?php
    $socialCode = get_option('flickr_code');
 
    if ($socialCode)
        echo <<<HTML
<div id="flick" onclick="window.open('$socialCode','newwindow');"></div>
HTML;
?>
Or something similar? If you are repeating this sort of operation for a variable number of bookmarks or whatever then it might be best to encapsulate it in a generic form within your theme functions file.

Re: newbie wordpress theme designer needs a little php help

Posted: Wed Mar 03, 2010 4:38 pm
by artwork architects
greyhoundcode wrote:
artwork architects wrote:so in the template file i need something like this:

if theme option 'flickr_code' contains text print:

<div id="flick" onclick="window.open('<?php echo get_option('flickr_code'); ?>','newwindow');"></div>

Code: Select all

<?php
&nbsp; &nbsp; $socialCode = get_option('flickr_code');
&nbsp;
&nbsp; &nbsp; if ($socialCode)
&nbsp; &nbsp; &nbsp; &nbsp; echo <<<HTML
<div id="flick" onclick="window.open('$socialCode','newwindow');"></div>
HTML;
?>
Or something similar? If you are repeating this sort of operation for a variable number of bookmarks or whatever then it might be best to encapsulate it in a generic form within your theme functions file.
thank you sooooooo! much, this works perfectly.

your probably right about putting it in functions file, but it works for now (first release of theme) might try and de clutter it when i get my head around php a bit more.

thanks again