Tag Info

New answers tagged

0

I am working with something similar but having no success. I have installed my own custom theme. I have also installed Jetpack to use the mobile theme. When I update the ID for my primary sidebar to 'sidebar-1' as required by the Jetpack mobile theme my widgets disappear from the front and backend and the default sidebar widgets are displayed. Any ideas how ...


0

Your widget is part of a plugin (per the first sentence of the question), so what you are really talking about is making a plugin administration page, which you would do with add_menu_page, add_submenu_page, or one of the more specialize menu page functions. That is the nutshell version of the answer. There are a lot of questions and answers here about ...


0

Either go and extend the class, or copy, paste and rename it (not recommended). class Child_Theme_Widget extends Parent_Theme_Widget { // just re-define/override the parent theme widgets methods (functions) here }


0

The Archive widget is using wp_get_archives() to display the archive. If you want to target all the wp_get_archives() functions, you can use the getarchives_where filter to add your custom post type: add_filter( 'getarchives_where', 'custom_getarchives_where' ); function custom_getarchives_where( $where ){ $where = str_replace( "post_type = 'post'", ...


0

I'm still eager to hear of an action that applies to this use case, but here's a more brute-force approach, if nothing else turns up: // within My_Widget class definition private static $metaboxes_added = false; // to ensure we don't add them more than once // inside My_Widget class constructor add_action( 'init', array( $this, 'add_metaboxes' ) ); // ...


0

How about doing it with some javascript? I can think of a way: 1) Already add additional widgets to the sidebar, and make them hidden with css 2) On page load use some jquery to calculate the effective height of the post(main content area). This will also take images into account, instead of just words. 3) And comparing the height of main content and ...


1

Use the function t5_word_count() from this answer and extend the method widget() in your widget class: public function widget( $args, $instance ) { if ( ! is_singular() ) return; $content = get_the_content( '', TRUE ); $words = t5_word_count( $content ); if ( 50 > $words ) return; // print you widget }


0

Try to replace 'post__in' => array($instance['postsToShow']), with 'post__in' => explode(",", $instance['postsToShow']), to feed the post__in with an array. Your current array looks like array("123,456,789") but should be like array("123", "456", "789")


0

If $instance['postsToShow'] is a comma-separated string of IDs, then array($instance['postsToShow']) creates an array consisting of one element equal to literally 1236, 1234, 1235, which is not what you want. Use php's explode to convert your string to an array: 'post__in' => explode( ',', $instance['postsToShow'] )


2

I ran into this problem with one of my plugins, and am deeply indebted to this article for pointing me in the right direction. The key is that the third parameter you get in the callback includes the widget's basename (derived from its class). I used a slightly different AJAX function than the example you linked to, but here's what I came up with: ...


0

$_post = get_queried_object(); $post_id = $_post->ID; It's somehow like that how single_post_title() gets the title.


0

Try using $wp_query global variable: global $wp_query; $postid = $wp_query->post->ID;


4

You just need to use the alternate syntax for foreach. From the php manual: The foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable. There are two syntaxes: foreach ...


0

The Answer is: $(document).ready(function() { $("#f-submenu").hide(); $("#m-submenu").hide(); $("#i-submenu").hide(); $(".widget ul li > a:not(ul li ul li>a, ul li+li ul li>a,ul li+li+li ul li>a )").attr("href", "javascript:hideMenu();showSubMenu('m-submenu')"); $(".widget ul li+li > a:not(ul li ul li>a, ul li+li ul li>a,ul ...


0

Your code deletes keys from widgets. One of those keys is named 'class'. When WordPress looks for the 'class' key it is missing and PHP reports that. I think you want this: $groups_sidebars = array(); foreach ( retrieve_widgets() as $widget ) { if ( array_key_exists( 'groups-sidebar', $widget ) ) $groups_sidebars[] = $widget; } ...


2

It's not clear what you mean by break other widgets, but you could try to add wp_reset_postdata() after your while loop to restore the global $post variable, or try this instead get_posts( array('post_type' => 'jobs','posts_per_page' => '8') ); to see if that makes any difference.


2

Use wp_reset_postdata() function after while loop to reset custom wp_query as shown in following code so that it will not break other wordpress loop. <?php // Create and run custom loop $custom_posts = new WP_Query(); $custom_posts->query('post_type=jobs&posts_per_page=8'); while ($custom_posts->have_posts()) : ...


0

I am not sure what you mean by "the actual name". If you need the class name, look in the source of the theme for extends WP_Widget. Other widget information is stored in the $wpdb->options table under keys starting with widget_. Once you find that you can use get_option( 'widget_name' ); to get information about active widgets, including the "instance" ...


3

Your code fails because of a PHP syntax error. Things to note: Your problem is a result of your failure to indent your code correctly, resulting in things being missed. Your editor should be able to reindent code, and it should auto-indent as you type. There are no excuses for this, and it's a 100% avoidable situation You do not have error logging turned ...


1

Your problem is due to your trying to include a file over the http protocol. That kind of include is disabled on your server-- hence the message saying pretty much just that. Use get_template_directory instead, which will give you a filesystem path. If that does not solve it, post your code in more context. Disjointed like that, it is near impossible to ...


1

It sounds like you'll need the plugins_url() function which generates the URL for the plugins directory and can handle any alternate configuration (such as if you moved it to the /mu-plugins/ directory, a personal favorite of mine). The Codex documentation is good, but here's a quick example. Let's say you're making this in a plugin that in ...


0

You can't distribute/install a widget all by itself. There are several ways to extend WordPress: Themes Plugins Or, more rarely, Must Use Plugins "Widget" is not an extendable feature. There is no way to drop that in directly, so the widget code has to be written into a theme or into a plugin. In your case, it sounds like the latter, so put the image in ...


2

You can try this custom CSS code to enable multiple title lines for the widgets in the backend: function custom_css_wpse_98587() { echo "<style> .widget-top{height:auto !important;} .widget-title h4, .widget-title span.in-widget-title{ white-space:normal; } </style>"; } ...


1

Your script is at /wp-content/themes/responsive-child-theme/nowplaying-example.php but you are including /nowplaying-example.php. That is not going to work. You need to provide the complete path for that include: include(get_stylesheet_directory().'/nowplaying-example.php'); Assuming I have read that right, and assuming that the files are actually there. ...


0

Try passing the post ID as the second parameter: the_field('sub_title', $instance['post_id']);


1

Check if this works for you: Put this code in jQuery(document).ready( function(){ function media_upload( button_class) { var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment; jQuery('body').on('click',button_class, function(e) { var button_id ='#'+jQuery(this).attr('id'); /* console.log(button_id); ...


0

I used MoreFields and MoreTypes for this type of task. Works wonderfull (except the User has to put in some IDs). MoreFields: User put in some ID on each page MoreTypes: Sidebar List with alls Sidebars <div id="custom-sidebar"> <?php $fields = get_post_custom(get_the_ID()); /* echo '<pre>'; ...


0

There's a brute force method you can use. When you register your sidebar, you give it an ID and a name, then you use that ID and name on the sidebar template to display it. What if you appended the ID of the page to that identifier? So instead of 'mainsidebar' you had 'mainsidebar'.$post->ID? Step 1: In functions.php do a WP_Query loop to grab all the ...


1

The default widgets do not offer any hooks for that. You have to replace the default widget and add your field to the new class. The other option would be using JavaScript to insert the field, and a filter for 'update_option_widget_' . $widget->id_base to save the value. I think the separate class is the cleaner approach.


0

I switched the method="post" and the action="" (rather than get/and a url). For some reason, that fixed it. Am not sure why "get" was having such a hard time, as it still continued to redirect if I switched back the method. Regardless, thank you to s_ha_dum for trying to help.


0

A bit of a guess but if the search works but returns you to the home page it sounds like get_permalink( $post->ID ) is not giving you the right values. Look at the page source to confirm. That implies that $post is not set, or not accessible, so put global $post; in your function before you try to use that variable. I'd suggest something like this right ...


4

As alluded to by @Michael in the comments, the CSS classes for widgets depend on the sidebar they're in more than the widget themselves. Those widget-specific CSS classes can be useful, but not when you're trying to style every widget. It sounds like you may be able to use a normal element selector that targets anything in your sidebar, though I'm unclear ...


2

The data in the options table is stored as serialized arrays. Use get_option() to get the data and unserialize them. array_walk( get_option( 'widget_text' ), function( $d ){ if ( ! empty( $d['title'] ) ) { printf( '<p>Title: %s<br>Text: %s</p>', $d['title'], htmlentities( $d['text'] ) ); } } ); If ...


1

Set the width of the div to 100% and remove the float for the media query used for smaller screens like this: @media screen and (max-with 600px){ .widget-area{ float: none; width: 100%; } } And for the desktop view: @media screen and (min-with 600px){ .widget-area{ float: left; width: 25%; } } BTW, this is just CSS related and has nothing to do ...


0

You need to set the width of each div (first, second, third, forth) to 25% and use float:left.


2

The default Recent Posts Widget code is in includes/default-widgets.php but you should not be hacking Core code. Copy that function to your theme's functions.php, rename it, and create your own customized widget.


1

Have a look in wp-includes\default-widgets.php. /** * Recent_Posts widget class * * @since 2.8.0 */ class WP_Widget_Recent_Posts extends WP_Widget { function __construct() { $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") ); ...


0

Go to appearance > widgets, then drag the meta box into your sidebar...


1

If you are going to display a particular instance of a widget you are going to have to know which instance that is. Hard-coding that instance value is not flexible, certainly, but unless you have some other way to identify the widget I don't see an option. If you can work out some other way to identify the widget you could crawl the array. For example, you ...


0

It's not easy, but a colleague and I did it. Some of this is specific to our use case, and it will not be very performant on larger catalogues, but it technically works. As there's not way of telling if this is the case before fetching the items, we display all items on a page and simply display:none on the out of stock items. Again, this is a workaround ...


1

I'd recommend the plugin Widget Logic to handle all your needs. You can just add logical tags to the individual widgets on the sidebar. http://wordpress.org/extend/plugins/widget-logic/


1

You can filter sidebars_widgets and remove the widget you don’t need. Example with a search widget; uncomment the debug code to find the correct identifier. if ( ! is_admin() ) add_filter( 'sidebars_widgets', 'remove_specific_widget' ); function remove_specific_widget( $widgets ) { if ( ! is_single( 402 ) ) // Post ID, title, slug, or array of ...


1

It is a bit tricky to get the ID fropm the form because it is created dynamically. Normally I use this JS to trigger an event when the save button is pressed: jQuery(document).ready( function($) { $( '.widget-control-save' ).on( 'click', function() { // grab the ID of the save button var saveID = $( ...


0

$instance['page_id'] should be the post ID of the selected post. So … function widget($args, $instance) { $post = get_post( $instance['page_id'] ); echo $post->post_content; // you should add the common filters here var_dump( $post ); // more data } … should be a good start. To save the last value in the configuration form use selected(): ...


0

This can be done by calling the widget inside a shortcode. Generally shortcodes can be inserted into any post or pages. This plugin will cover the widgets into shortcode ** Widget Shortcode ** Adds a [widget] shortcode which enables you to output a widget anywhere you like. Can be found here http://wordpress.org/extend/plugins/widget-shortcode/


0

To display elsewhere in a page, you can call the display function in the appropriate php file of your theme using the function echo _random_image()


2

@tf is almost there, I think. You can use JS on your widget's admin form, as I've done it before (though not for validation). Within your widget's constructor, add an action: add_action( "admin_print_scripts-widgets.php", array( __CLASS__, 'register_my_validation_script' ) ); Then create the corresponding function inside your widget's class: function ...


0

This is not WP-specific. Your widget most likely already has a form. That form has a name/ID (if not, give it one). What you want to do is check onsubmit of the form for certain conditions. Suppose that is your form: <form name="myWidgetForm" ... > <input type="number" name="width" /> <input type="number" name="height" /> ...


0

I am not sure I followed your code correctly, but you could try to set all data into one array: name="unique_widget_name[<?php echo $this->get_field_name($i); ?>]['name']" Very similar question, but not identical: How to store widget fields data as an array?


0

Create a sidebar $type . '_sidebar' Register the sidebar $type . '_sidebar' (e.g dog_sidebar) Pass the type as GET argument to the widget.php (create some menu entries or something else where you link to e.g. wp-admin/widgets.php?sidebar_type=dog_sidebar) Filter out every sidebar that should not be displayed. You can use this function: global ...



Top 50 recent answers are included