Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom Write Panels for Theme WordPress

  • SOLVED

Hi,

I am in need of 4 custom write panels for my wordpress theme.

I am currently using code that displays 2 custom write panels. Everything is working well, but I now need to add more write panels, and the code will have to be re-worked since it was only a "quick-fix" to my earlier problem.

I am going to need 4 custom write panels total. 1 should always display on all the "Pages" pages, and the other 3 should always display on all of the "Posts" pages. Also, I'd like to be able to add new write panels fairly easily in the future if at all possible.

I've pasted the code I am currently using here:
[[LINK href="http://www.pastie.org/private/lahampsfls2e3yulvrfhva"]]http://www.pastie.org/private/lahampsfls2e3yulvrfhva[[/LINK]]

If you need any further info from me please just let me know.

Thanks a lot.

Answers (2)

2010-04-01

Buzu B answers:

already working on it...


Buzu B comments:

Ok, so the only think you have to do is to add the arrays to the corresponding array. For example:

$new_meta_boxes_2 =
array(
"image2" => array(
"name" => "portimage",
"std" => "",
"title" => "Enter the URL of the full-size image for the gallery/portfolio page.",
"description" => "EXAMPLE: http://www.yourdomain.com/images/coolimage.jog"),
"image3" => array(
"name"=>"portimage2",
"std"=>"",
"title"=>"This is the title",
"description"=>"The description"
)
);


that will add a new meta box to the posts page.
Remember that $new_meta_boxes adds boxes to pages and $nes_meta_boxes_2 adds them to posts.


Buzu B comments:

By the way, the array I added was image3


WP Answers comments:

Excellent - works great.

Can you please have a look at my logic below. I would like to add and if statement so that it only displays the chunk of code below if 'portimage1' has a value. So the logic is:

if portimage1 has a value {
display my code below
}


<div class="img_frame_port">
<div class="fade"><a href="<?php echo get_post_meta($post->ID, "portimage2_value", $single = true); ?>" class="pirobox_gall_ss" title="<?php if(get_post_meta($post->ID, "portimage_value", $single = true) != "") : echo get_post_meta($post->ID, "portimage_value", $single = true); ?><?php endif; ?>"><img src="<?php echo get_post_meta($post->ID, "portimage1_value", $single = true); ?>" /></a></div><!-- end fade -->
</div><!-- end img_frame_port -->



Also, am I calling on those value correctly by using the below or should I be doing it differently?

<?php echo get_post_meta($post->ID, "portimage2_value", $single = true); ?>


WP Answers comments:

Also, one more thing...

Is there any way to prevent these custom entries from showing up under the "Custom Fields" panel below the excerpt? (its kind of pointless to list them twice, and I want to make the interface as clean as possible for the user). This would be great.


Buzu B comments:

You would do something lik:

$portimage1 = get_post_meta($post->ID, 'posrtimage1', true);

if($portimage1 != ''){
//print your code here
}

Then I guess when you do this:

<?php echo get_post_meta($post->ID, "portimage2_value", $single = true); ?>

you are not getting anything. Am I right? well, if that's the case try this:

<?php echo get_post_meta($post->ID, "portimage2_value", true); ?>


WP Answers comments:

Hi,

The single = true code was working, but I was just curious if it was the correct way to do it for future reference.

I had to make a slight mod to your code (I added "_value" to portimage1 in the if statement) but the loop is now working without any issues. Thank you very much.

Any ideas about how to hide the custom fields panels? I just read that you can add "_" and underscore to the variable name and it will hide the custom fields entries, but I tried adding it to portimage1 2 and 3 but the custom fields still got generated.


Here is the working loop:

<?php $portimage1 = get_post_meta($post->ID, 'portimage1_value', true);
if($portimage1 != ''){ ?>
<div class="img_frame_port">
<div class="fade"><a href="<?php echo get_post_meta($post->ID, "portimage2_value", $single = true); ?>" class="pirobox_gall_ss" title="<?php if(get_post_meta($post->ID, "portimage_value", $single = true) != "") : echo get_post_meta($post->ID, "portimage_value", $single = true); ?><?php endif; ?>"><img src="<?php echo get_post_meta($post->ID, "portimage1_value", $single = true); ?>" /></a></div><!-- end fade -->
</div><!-- end img_frame_port -->
<?php } ?>


Buzu B comments:

<blockquote>
Is there any way to prevent these custom entries from showing up under the "Custom Fields" panel below the excerpt? (its kind of pointless to list them twice, and I want to make the interface as clean as possible for the user). This would be great.
</blockquote>

I guess it is possible if there is a hook to it. I have never heard of it, and just did a quick search and didn't find anything. If you know the hook, I'll be happy to help.


WP Answers comments:

Here check out this link and let me know if this is helpful at all:

[[LINK href="http://www.livexp.net/wordpress/create-invisible-wordpress-custom-fields.html"]]Create invisible custom fields[[/LINK]]


Buzu B comments:

I guess that is how you do it. Give it a try, you just have to modify the part of the arrays. Where it says


"name"=>"text",

try with

"name"=>"_text",

I have never tried that before and cannot guarantee it'll work. But you can try and if it doesn't you can always go back.

<blockquote>
I had to make a slight mod to your code (I added "_value" to portimage1 in the if statement) but the loop is now working without any issues. Thank you very much.
</blockquote>

Yeah, I didn't see you add a _value before saving the data.

<blockquote>
I just read that you can add "_" and underscore to the variable name and it will hide the custom fields entries, but I tried adding it to portimage1 2 and 3 but the custom fields still got generated.
</blockquote>did you added it the way I suggest above in this reply? if so, then I don't know how to do it. I guess we can find out, but right now I don't know how to do it, not even if it is possible to do it.


Buzu B comments:

It actually should work, I mean adding the "_" because that is the way the wordpress does it. they have a bunch of data saved that way and it doesn't show in the custom fields box.


WP Answers comments:

Ah ok. It worked! (adding the underscore "_" )

"name"=>"_text"

It doesn't hide already stored items, but if I create a new post, the custom fields don't show up. This is perfect though, just what I was looking for.

Thank you again for all your help. Very much appreciated.

2010-04-01

Brandon Dove answers:

If you're adding custom write panels, you should really be using the "Magic Fields" plugin. It makes this process a snap. http://magicfields.org


WP Answers comments:

Thanks for the info, but this is going to be part of a premium wordpress theme for sale, so I need it to be part of the theme.