Add Dynamic Multiple Boxes Wordpress - wordpress

I've created a custom post type in wordpress called Product, and created a custom box called "What's Included". How would I create an "Add New Included Item", to create dynamic boxes?
It would look similar to how you can add multiple custom fields, but instead of one field, it's a "What's Included" object.
Any ideas?
'What’s Included' => array(
array( '_wi_title', 'Title'),
array( '_wi_thumbnail', 'Thumbnail'),
array( '_wi_title', 'Description', 'textarea')
),

Have you considered using a custom taxonomy? Sounds like it would fit your needs perfectly, although it is indeed possible to create a dynamic form in a custom meta box. A non-hierarchal taxonomy would allow you to repeat items you include often, as well.

Related

Add fields to wordpress footer

I have a wordpress widget on my footer with contact details and the widget has editable fields:
Title
Email
Phone
Fax
Address
How can I edit this widget to include additional fields? I am new to wordpress and I am unsure if this is possible. In the help documentation for the widget it says the following:
How do I add additional fields to the contact widget?
Adding additional fields to the contact widget is as simple as adding a WordPress filter.
Here is an example:
add_filter( 'wpcw_widget_contact_custom_fields', function( $fields, $instance ) {
$fields['cellphone'] = [
'order' => 2,
'label' => __( 'Cellphone:', 'YOURTEXTDOMAIN' ),
'type' => 'text',
'description' => __( 'A cellphone number that website vistors can call if they have questions.', 'YOURTEXTDOMAIN' ),
];
return $fields;
}, 10, 2 );
However I am unsure as to where I would have to add this information
Widgets were originally designed to provide a simple and easy-to-use way of giving design and structure control of the WordPress Theme to the user, which is now available on properly "digitized" WordPress Themes to include the header, footer, and elsewhere in the WordPress design and structure. Widgets require no code experience or expertise. They can be added, removed, and rearranged on the Theme Customizer or Appearance > Widgets in the WordPress Administration Screens.
more details
2> visit blog i follow
if the widget don't have optionnal fields options altering it with new code can be the wrong approach. If the widget is updated you will loose your update.
The right way is to create a new widget with all the functions you need, maybe you can fork the existing widget and implementing your field.
Or you can just edit the footer.phpand including the widget logic in it.
Docs :
Widget api
Template development in wordpress

Any way to add metaboxes in custom settings page of custom post type in wordpress? [duplicate]

This question already has an answer here:
Add meta box to WordPress options page
(1 answer)
Closed 4 years ago.
Hi I would like to add metaboxes under custom settings page which is under a custom post type. I can create metaboxes for custom post types also I can create a theme options. But can't find any way to add the metaboxes on a custom settings page. Like my post type hierarchy is like below:
Products
- All item
- Add Item
- Product Category
- Product Settings
I want to add the metaboxes & create a options page on that settings page. Can you please guide me through this one.
I've been trying to follow this gist but can't find a way.
https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/options-and-settings-pages/theme-options-cmb.php
Also can you let me know if I can achieve something by tweaking this code where key|value operates
$cmb = new_cmb2_box( array(
'id' => $this->metabox_id,
'hookup' => false,
'show_on' => array(
// These are important, don't remove
'key' => 'options-page',
'value' => array( $this->key, )
),
) );
I've created the settings page by this code
add_submenu_page('edit.php?post_type=ch_product_showcase', 'Product Showcase Settings', 'Showcase Settings', 'edit_posts', basename(__FILE__), array( $this, 'chProductShowcaseSettingsOptions') );
I've done it many times. Use this code and tweak it to your needs:
https://gist.github.com/turtlepod/5203512
Found as a link in the comments of this page:
https://gist.github.com/bueltge/757903
Originally posted here:
Wordpress - Add meta box to options page
Normally I don't like answering with links to another site, but in this case the code is on gist and hopefully will never go away!

wordpress custom archive pages

I'm developing a wordpress page and I'm looking for the best practices to send custom DB queries. I created a archive page with a list of artists. These names are stored in a custom post type's custom taxonomy. Now I want to code links on every name, which should lead the visitor to a page where all the posts that have this artists name in this custom field.
I know how to create the custom DB query, but how do I submit the name? Just over a normal POST-request? Is there a convenient way to do this within WP?
Thanks for your help.
Dan
you said in your question "custom post type's custom taxonomy"
you can create a custom taxonomy template to list all posts under a particular taxonomy. you can use this detailed tutorial how to use taxonomy.
http://code.tutsplus.com/tutorials/introducing-wordpress-3-custom-taxonomies--net-11658
I think the best way to do this would be store the artists name as a meta value attached to the post. Then you could use Wordpress inbuilt meta query to easily output all posts with the artists name stored as a meta value.
$meta_query_args = array(
array(
'key' => 'artist',
'value' => 'John Doe',
'compare' => '='
)
);
$meta_query = new WP_Meta_Query( $meta_query_args );

Adding custom taxonomy to media gallery in wordpress admin

I have added a custom taxonomy to Media, which is showing up as a text field in the Media admin section. I would like this to be the typical checkbox format as it exists in the custom post type admin page. Is there a way to override this in the functions to make this custom taxonomy show in checkboxes, so the user could easily choose which image belongs to a specific taxonomy entry?
Here is the code I used to bring the taxonomy into the Media Gallery:
register_taxonomy('Categories',array('project', 'slides', 'attachment'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'categories' ),
));
In the first line, by adding 'attachment' to the array, it added the Project Categories field in the Media Gallery. Now I just need to make this a list of checkboxes containing the current taxonomy entries. Any thoughts on how to achieve this?
I found this article, but having never used filters, it was a bit perplexing as to how to make this work for me:
https://wordpress.stackexchange.com/questions/29858/adding-category-tag-taxonomy-support-to-images-media
You are most of the way there. To render a taxonomy category as a special HTML display, like a list of checkboxes, the best method is to use the built-in WordPress Walker class. It is made exactly for this sort of thing.
http://codex.wordpress.org/Function_Reference/Walker_Class
I use this very method to create a new "SLP_Tagalong" walker class that renders a list of my taxonomy categories as a list of checkboxes (I only show text names but it could easily show the marker images) whenever anyone edits a store location.
I have the modified Walker Class I can share if you would like to see it. I'd post here but it is 150 lines. Send me a PM and I'll shoot it back that way.
I am sure the walker class would have worked successfully, but looking at the codex reminded me of string theory and existentialism. The upside is with WP 3.5.1, when you associate a taxonomy to 'attachment' set to Hierarchal, the checkbox appears in the Media Library by default.
YAY!!
This may not answer the question posed thoroughly though so I will leave it open for anyone who wants to stab at this.

Creating "ON/OFF News Links" functionality for a block created with View Module

I'm a drupal newbie who needs some advice...
I have a news list block at homepage, created with View Module. It is listing all added news' title and link. Everything is cool so far. Now I need to add an ON/OFF option at admin side for homepage news block. When the setting is ON, it will work as it is. When it is OFF, only the titles will be listed with no linking to news detail page.
So, now where should I add this ON/OFF option? I have only add/edit/delete pages for each news, there is no common news page to add such option. Should I create an admin page with such ON/OFF option in? Also I think I need to create a db table to keep this ON/OFF status. and controlling this value at homepage block, if it is 1 or 0, and displaying links according to db value :/
it looks too long way
Create db table
Create an page with ON/OFF option in
add php codes to update db for admin's choice
get the db value in homepage block to display links, etc.
is there any shorter, better way to do what I need?
Appreciate helps so much!!! Thanks a lot!!
You definitely don't need to create any database tables for something like that. If you want a basic admin page, you will need to write a simple module though. First follow this quick start guide for setting up a basic module. (Note: You don't need to add those database queries in your .install file)
Once you have your module enabled...
1) In your mynewmodule.module file, add a menu entry to tell Drupal where your admin page can be accessed:
function mynewmodule_menu() {
return array(
'admin/settings/mynewmodule' => array(
'title' => 'My New Module',
'description' => 'Change settings for news display.',
'page callback' => 'drupal_get_form',
'page arguments' => array('mynewmodule_admin_form'),
'acces callback' => 'user_access',
'access arguments' => array('administer site configuration'),
),
);
}
2) Also in your mynewmodule.module file, add a function to create the form you just referenced in the menu entry:
function mynewmodule_admin_form() {
$form = array();
$form['mynewmodule-on-off-switch'] = array(
'#type' => 'checkbox',
'#title' => t('Enable news links'),
'#description' => t('Control whether news items are linked to stories'),
'#default_value' => variable_get('mynewmodule-on-off-switch', 1),
);
return system_settings_form($form);
}
3) Clear your cache to make Drupal recognize your admin page (you need to clear any time you make changes to mynewmodule_menu()). You can clear it here: admin/settings/performance
4) Visit admin/settings/mynewmodule to see your admin form. The way it works is when you save the configuration, Drupal will save a variable called "mynewmodule-on-off-switch" (same name as the array key in the form) to the variables table in the database. You can get this value anywhere by using variable_get().
create a form at admin/settings/on-off-switch.
on the form submit function, variable_set('on/off switch', $value) (try using booleans for the value).
then on the view theme, check for variable_get('on/off switch', $default_value) before printing the links.
Drupal's weakness, IMHO, is the sheer number of admin settings to configure to get a site up, and you don't want to be adding to that.
What I would do is to have the view expose two different blocks, one with the full view, one with the abbreviated view. Then all the configuration can be done through the block interface, which will be much more flexible in the long run. By, for example: using wildcards or php code for block visibility; showing different views to users with different roles; allowing visitors to control which view they see; exposing the two views to the theming engine more cleanly; and integration with any other module that works with blocks.

Resources