Check child/parent categories if exists

You can get the current posts category outside the loop by using the get_the_category function. http://codex.wordpress.org/Function_Reference/get_the_category When you have the actual category ( however you got it) you can use get_categories, specifically the ‘child_of’ parameter and pass it the parent cat ID. http://codex.wordpress.org/Function_Reference/get_categories Also have a look at wp_list_catagories, http://codex.wordpress.org/Template_Tags/wp_list_categories#Display_or_Hide_the_List_Heading where you can do something … Read more

Shortcode content filter?

you can use regex to find your the src and use that to append your “files/myimagescript?” to it: function append_myimagescript($attr, $content){ $pattern = ‘/src=”https://wordpress.stackexchange.com/questions/11618/([^”]*)”/i’; $replacement=”files/myimagescript?${1}”; return preg_replace($pattern, $replacement, $content); }

Add function to Simple Twitter Connect to not Tweet pages

Even better answer that doesn’t involve changing the plugin: remove_action(‘transition_post_status’,’stc_publish_auto_check’,10,3); add_action(‘transition_post_status’,’my_custom_publish_rules’,10,3); function my_custom_publish_rules($new, $old, $post) { if ($post->post_type == ‘page’) return; else stc_publish_auto_check($new, $old, $post); } Put it in a theme’s functions.php. Side note: Whenever you’re dealing with a function called by an action or filter hook, then you can easily wrap the call in … Read more

plugin development: problem with functions

The main problem is you are using static callbacks while you should be passing on the object so you have access to your class properties. You can fire off the initialization like this: class Myclass { public function __construct() { // Object method call, instead of a static one add_action(‘init’, array($this, ‘init’)); } public function … Read more

Help with WordPress Query

After calling get_recent_posts() (or any other loop query), you typically have to run a foreach or while loop to cycle through the posts. So, you’ll need to change this: <?php $args = array( ‘tag’ => ‘featured’, ‘posts_per_page’ => ‘3’ ); $recent_posts = wp_get_recent_posts( $args ); ?> <!– Your HTML and WordPress template tags here. –> … Read more

Show top commenters without using a plugin

$output .= “<li>”.(($result->comment_author_url) ? “<a href=””.$result->comment_author_url.””>” : “”).$result->comment_author.(($result->comment_author_url) ? “</a>” : “”).” (“.$result->comments_count.”)</li>”; edit: to show the avatar before the name: $output .= “<li>”.get_avatar($result->comment_author_email, 45).’ ‘.(($result->comment_author_url) ? “<a href=””.$result->comment_author_url.””>” : “”).$result->comment_author.(($result->comment_author_url) ? “</a>” : “”).” (“.$result->comments_count.”)</li>”;

Default Gallery Edit/Template Editable?

Put this code in your functions.php and check. function custom_gallery( $output, $attr ){ global $post, $wp_locale; static $instance = 0; $instance++; // We’re trusting author input, so let’s at least make sure it looks like a valid orderby statement if ( isset( $attr[‘orderby’] ) ) { $attr[‘orderby’] = sanitize_sql_orderby( $attr[‘orderby’] ); if ( !$attr[‘orderby’] ) … Read more

Need to add class=”lightbox” for every single post image

One way you can accomplish it is this way: functions.php add_action( ‘wp_enqueue_scripts’, ‘your_lightbox_callback’ ); function your_lightbox_callback(){ if( is_single() /* or whatever here */ ) { wp_register_script( ‘your-lightbox’, get_bloginfo( ‘template_url’ ) . ‘/lightbox-class.js’ ); wp_enqueue_script( ‘your-lightbox’ ); } } lightbox-class.js var $j = jQuery.noConflict(); $j( document ).ready( function() { $j( ‘#whereveryourpostsare img’ ).addClass( ‘lightbox’ ); } … Read more