How do you keep and remove content in outright wordpress?
-
Light word with https://www.advancedcustomfields.com/ ♪ There is a need to create a distinctive view of which to include advanced custom fields♪ I see it in this way, I turn it into random fields.
class CustomWidget extends WP_Widget { function __construct() { parent::__construct( 'custom_widget', // Base ID __('CustomWidget', 'text_domain'), // Name array( 'description' => __( 'Some CustomWidget', 'text_domain' ), ) ); } // widget actual processes public function widget( $args, $instance ) { echo "<p>custom widget appear</p>"; echo "<p>". the_field('widget_banner') . "</p>";
} // outputs the content of the widget
public function form( $instance ) {} // outputs the options form on admin
public function update( $new_instance, $old_instance ) {} // processes widget options to be saved
}
// register Foo_Widget widget
function register_foo_widget() {
register_widget( 'CustomWidget' );
}
add_action( 'widgets_init', 'register_foo_widget' );
line
custom widget appear
is removed, but here is an arbitrary fieldthe_field('widget_banner')
No, although there's one in the adminke, it's filled, and I'm pushing to keep it and it's still there.I do. https://support.advancedcustomfields.com/forums/topic/acf-and-widgets/ but the guys in the comments have the same problem.
That's what's making arguments on the front.
array(10) { ["name"]=> string(14) "Виджеты" ["id"]=> string(9) "sidebar-1" ["description"]=> string(36) "Добавьте сюда блоки" ["class"]=> string(0) "" ["before_widget"]=> string(64) "
" ["after_widget"]=> string(8) "
" ["before_title"]=> string(4) "
" ["after_title"]=> string(5) "
" ["widget_id"]=> string(15) "custom_widget-2" ["widget_name"]=> string(12) "CustomWidget" }
-
There's a description of Custom Widgets. https://codex.wordpress.org/Widgets_API , there is still a need to be created for its withdrawal
add_action()
add_action( 'widgets_init', function(){ register_widget( 'My_Widget' ); });
You.
widget
♪form
andupdate
to contain a https://codex.wordpress.org/Widgets_API#ExampleThis is yours. https://ru.stackoverflow.com/questions/583385/%D0%9A%D0%B0%D0%BA-%D0%B2%D1%8B%D0%B2%D0%B5%D1%81%D1%82%D0%B8-%D1%8D%D0%BA%D0%B7%D0%B5%D0%BC%D0%BF%D0%BB%D1%8F%D1%80%D1%8B-%D0%BF%D0%BE%D0%BB%D1%8C%D0%B7%D0%BE%D0%B2%D0%B0%D1%82%D0%B5%D0%BB%D1%8C%D1%81%D0%BA%D0%B8%D1%85-%D1%82%D0%B8%D0%BF%D0%BE%D0%B2-%D0%B2-%D1%88%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD%D0%BD%D0%BE%D0%B9-%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B5-wordpress/584030?noredirect=1#comment784036_584030 ? That's where I explained how to get out.
In the view, you can remove this field or so:
<?php the_field('widget_banner'); ?>
or so:
<?php echo get_post_meta(get_the_ID(), 'widget_banner', true) ?>
provided that you created this field
widget_banner
which is tied topost_type -> post
and put it in the cycle, see the example on the picture (line 69-70):result:
Admin.