0

I am trying to create code to display certain default WordPress widgets on my e-commerce site.

I have 6 content boxes which display WordPress widgets:

• Pages

• Latest Posts

• Archive (last 12 months)

• Blog Post Categories

• Blog Calendar

• Blog Tag Cloud

I was originally using other functions to do this: wp_get_archives, wp_list_categories, etc. and the code I was using worked just fine.. However when I was looking for a way to also include the Blog Calendar and the Tag Cloud widgets, I stumbled across the "the_widget" function. So I thought it wouldn't be a bad idea to use this same function for all of my external widgets. (am I wrong here???)

I have actually read the Reference page for this function.. Unfortunately the reference page is incomplete and there are not enough examples on this page or elsewhere on the web to help me figure out how to structure my code. Specifically I don't know what arguments to use to do the following:

~ Limit the number of archive links to only the last 12 months

~ Not display the widget title

~ Limit the recent posts to just the last five posts

~ Limit the number of tags in the tag cloud

I cannot find ANYTHING anywhere on the web that would help me figure this out.. Hoping someone here knows the magic answers..

  • Are the things you want to do possible by editing the different widgets on the backend? If you can, then there should be arguments that would do this, but it is a little bit of a broad question. – s_ha_dum Aug 29 '13 at 23:39
  • Thanks.. I got a response that gave me a direction to move in.. – Crystal Jones Aug 31 '13 at 2:33
0

So I thought it wouldn't be a bad idea to use this same function for all of my external widgets. (am I wrong here???)

If you are comfortable looking at PHP code to get the argument list of each widget, if you are trying to make it more difficult for you (or other admins) to be able to easily change the settings of each widget in the widget form and if you are able to handle a few PHP coding errors while testing, then this function may be for you.

If you prefer drag an drop placement and the convenience of the widget form on the widget page to change options or to add or remove the widget, then this function may not be for you.

Specifically I don't know what arguments to use to do the following ...

Look at the widget code (in the \wp-includes\default-widgets.php WordPress file) for the widget you are referring to. The list of arguments is in the code. The arguments may not be all in one place or even documented as arguments.

For example, in the WP_Widget_Archives PHP class there are 3 settings:

$instance['count']
$instance['dropdown']
$instance['title']

You can find them by looking through the code. You can set them in your call to the_widget(). Here I set the title to be empty. What effect that has on the widget code can be seen by testing the change in a web page and seeing what happens.

// Other code.

$instance = array();
$instance['title'] = '';

// Other code.

the_widget( 'WP_Widget_Archives', $instance, $args );
| improve this answer | |
  • Thanks.. this might be exactly what I was looking for.. Gonna go have a play at this.. – Crystal Jones Aug 30 '13 at 5:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.