Display all posts with same title

Lets use the build in features WordPress has to offer. It is almost always not adviced to use custom SQL whenever WordPress offers native functions to perform the specific duty. To query our posts, we will make use of WP_Query. The only problem is, WP_Query does not support the feature where we look for posts … Read more

Adding classes to dynamic sidebar

You haven’t actually said what the problem is. But I can see one for starters – dynamic_sidebar in your if conditions will echo out the widgets immediately. If you want to check a sidebar has widgets, use is_active_sidebar: is_active_sidebar( ‘sidebar-1’ ); // True/false

How to List all Sidebars in a Metabox

Try this: <?php $sidebar_options = array(); $sidebars = $GLOBALS[‘wp_registered_sidebars’]; foreach ( $sidebars as $sidebar ){ $sidebar_options[] = array( ‘name’ => $sidebar[‘name’], ‘value’ => $sidebar[‘id’] ); } ?> This prints out( with my registered sidebars ): Array ( [0] => Array ( [name] => Language Menu [value] => sidebar-1 ) [1] => Array ( [name] => … Read more

How to exclude certain widget from showing up on home/front page? [duplicate]

I’ve found the exact solution to my question here: https://wordpress.stackexchange.com/a/17687/92505 Here’s the exact code I used after some modification to make it work on my situation. Add the following code to functions.php where ‘sidebar-1’ is your sidebar ID. ‘recent-posts’ is the name of the widget your want yo hide. 12 is the length of the … Read more

Display Custom Taxonomy in Sidebar in Two Columns

As a follow up to @Rutwick Gangurde Answer, here’s an example. Notes: Put it in your functions.php file, call it in the template file. Alter the output by inspecting the $term inside the foreach loop Read the comments inside the function – function wpse25433_terms_list( $cat = array(‘categories’), $el=”li”, $echo = true ) { global $post; … Read more

Best approach for loading a sidebar Only if the screen max-width is >900px?

On my website I load the recent comments per AJAX for window sizes above 480px: if ( 480 < jQuery(window).width() ) { jQuery(document).ready( function() { jQuery.get(‘http://toscho.de/?rc’, function(data) { jQuery(data).insertBefore(‘#inner’); } ); } ); jQuery(‘#posts’).after(‘<div class=clear>&#160;</div>’); } This code is quite old and not very elegant. But it may give you a hint for the right … Read more

Add featured image to sidebar [closed]

Instead of modifying the sidebar or templates itself, why not create a plugin with a widget that does just what you need. This way you don’t hard code and keeps thing dynamic. This will also allow you to move the widget around at will you keep your templates clean, simple and maintainable do it the … Read more

Call sidebar from a template

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 between two fixed strings. You can … Read more

is_active_sidebar() Always Returns False

The is_active_sidebar(‘Test’); function works correctly if the correct slug is used. I think that the problem is that you are constructing the sidebar ID like this: $sidebarID = preg_replace(“/[\s_]/”, “-“, strtolower($page->post_title)); Then prepending sidebar- to it … register_sidebar(array( ‘name’ => $page->post_title, ‘id’ => ‘sidebar-‘.$sidebarID, // But you are using the unmodified title as the slug … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)