New answers tagged sidebar
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:
...
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
Woothemes offers a free plugin called Woosidebars which I use and works great for adding custom sidebars to any page, category, etc. You can download it here:
http://www.woothemes.com/woosidebars/
Hope this helps.
0
Try using this:
// Get the 'WpForest_soft' custom field value.
$text = get_post_meta( $post->ID, 'WpForest_soft', true );
// Print the value and surrounding markup only if the value tests true.
if ( $text )
printf( '<tr><td class="attr-name">%s</td><td class="attr-detail">%s</td></tr>', __( 'Software Version', ...
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.
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 ...
0
Just tried it on a test install with twenty-something sidebars, all works fine. Note that id parameter should be unique between all of them. name doesn't have to be, but it's nice to keep it unique as well so as to avoid confusion in the admin UI.
register_sidebar( array(
'name' => 'twenty-three',
'id' => 'sidebar-23',
'description' => ...
0
First: is_page() expects a page id, so the call would be is_page(35).
Second: get_sidebar needs to be called from the template (not the functions file).
You probably already have two templates setup:
page.php - In here you'll call get_sidebar('primary');
index.php (assuming your blog is on the home page) - In here you'll call get_sidebar('secondary'); ...
0
The hover effect on the sidebar menu of the link you posted is done via Javascript.
Please open your theme folder (wp-content/themes/wordsmith-anvil/js) and remove the following part on the upper part of the file wsmain.js:
jQuery(document).ready(function($) {
$()
$("aside nav a").append("<span> </span>");
$("aside nav ...
0
There is a body_class set for the home page called full-width-content. That suggests to me that:
The homepage intentionally does not have a sidebar. You will need to edit the template appropriate template file to change that. That should be index.php, home.php, or front-page.php.
or there is a dynamic sidebar for that page but you haven't placed any ...
3
Instead of calling get_sidebar() call get_sidebar( 'somethingelse' );. It will attempt to load sidebar-somethingelse.php and if that doesn’t exist it will load sidebar.php. You can then modify the sidebar-somethingelse.php to load a different sidebar etc
I strongly recommend you look up how the template hierarchy works.
0
look in the sidebar pages that are in the template. All the code you need is already there. You will see something like
if( is_active('sidebar-1')){
get_sidebar('sidebar-1');
}
I am not sure of the exact code as I am not sitting at my computer with the files. ALL you need to do is copy that code and change the names to match your sidebar. There ...
1
Yes, you can separate your code and markup into multiple files. Be aware of scope issues when you use include, but done carefully it should be no problem. Since you are in WordPress and building a theme, I would suggest get_template_part over a raw include.
In many ways, "chopping" up your theme files is what get_template_part is for-- well, at least it is ...
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 ...
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 ...
0
Adding Video from youtube.(I didn't try from other chanels)
Add a new custom field and name it for ex. VIDEO
Add the code to incorporate video in the value Field like this:
If your code is:
<iframe width=”300″ height=”180″ src=”http://www.youtube.com/embed/9bZkp7q19f0” frameborder=”0″ allowfullscreen></iframe>
Extract the src=”value” and ...
0
In youy loop just past this snippet of code.
<?php query_posts('cat=6&showposts=2'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php content('10'); ?>
<?php endwhile; ?>
Replace 10 with any number you want.
Tell me if it works.
1
Impossible with get_sidebar().
From that function’s body:
function get_sidebar( $name = null ) {
do_action( 'get_sidebar', $name );
$templates = array();
if ( isset($name) )
$templates[] = "sidebar-{$name}.php";
$templates[] = 'sidebar.php';
So if you pass a $name or any other custom value to the function, they will be set ...
Top 50 recent answers are included