$30
Custom Write Panels for Theme
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:
http://www.pastie.org/private/lahampsfls2e3yulvrfhva
If you need any further info from me please just let me know.
Thanks a lot.
WP Answers | 04/01/10 at 4:58pm
| Edit
(2) Possible Answers Submitted...
-

Last edited:
04/01/10
6:35pmBuzu B says:already working on it...
- 04/01/10 5:18pm
Buzu B says: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" => "<b>EXAMPLE:</b> 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. - 04/01/10 5:19pm
Buzu B says:By the way, the array I added was image3
- 04/01/10 5:37pm
WP Answers says: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); ?>
- 04/01/10 5:52pm
WP Answers says: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. - 04/01/10 5:57pm
Buzu B says: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); ?>
- 04/01/10 6:09pm
WP Answers says: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 } ?>
- 04/01/10 6:11pm
Buzu B says:
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.
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. - 04/01/10 6:13pm
WP Answers says:Here check out this link and let me know if this is helpful at all:
Create invisible custom fields
- 04/01/10 6:23pm
Buzu B says: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.
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.
Yeah, I didn't see you add a _value before saving the data.
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.
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.
- 04/01/10 6:26pm
Buzu B says: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.
- 04/01/10 6:35pm
WP Answers says: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.
- 04/01/10 5:18pm
-

Last edited:
04/01/10
5:31pmBrandon Dove says: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
- 04/01/10 5:38pm
WP Answers says: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.
- 04/01/10 5:38pm
This question has expired.
Current status of this question: Completed





