question
stringlengths 0
34.8k
| answer
stringlengths 0
28.3k
| title
stringlengths 7
150
| forum_tag
stringclasses 12
values |
---|---|---|---|
I have a plugin that expects there to be a default "uncategorized" category with ID=1. I've inadvertantly deleted the uncategorized category. Is it possible to recreate the category as ID=1? When I look at a default WP install, I see that the table "wp_terms" has uncategorized as the first record with id 1. It also appears that the "wp_term_relationships" and "wp_term_taxonomy" tables are in play in this regard. How would one go about recreating this category? | You need 3 steps: 1.Creating a term in wp_terms with ID is 1 2.Insert a term_taxanomy into wp_term_taxonomy with term_id is 1, and taxonomy must be category 3.Insert a term_relationships into wp_term_relationships with object_id is 1 and term_taxonomy_id is 1 Run below code in PHPMYADMIN to re-create this category! <code> INSERT wp_terms(term_id, `name`, slug) VALUES (1, 'Uncategorize', 'uncategorized'); INSERT wp_term_taxonomy(term_taxonomy_id, term_id, taxonomy, parent) VALUES (1, 1, 'category', 0); INSERT wp_term_relationships(object_id, term_taxonomy_id, term_order) VALUES (1, 1, 0); </code> | Default category got deleted. How to get it back as ID=1? | wordpress |
I am looking for SQL code that I can run from phpmyadmin to remove all registered users on the blog that do not have any post associated with them. | <code> <?php /** * Plugin Name: Delete Non Authors */ function delete_non_authors() { global $wpdb; $non_authors = $wpdb->get_col( "SELECT DISTINCT $wpdb->users.ID FROM $wpdb->users LEFT JOIN $wpdb->posts ON $wpdb->users.ID = $wpdb->posts.post_author WHERE $wpdb->posts.ID IS NULL" ); foreach ($non_authors as $user_ID) wp_delete_user($user_ID); } register_activation_hook(__FILE__, 'delete_non_authors'); ?> </code> Drop this in a file, name it something like <code> delete-non-authors.php </code> , upload it to your plugins folder, activate, and you're done! (You can then de-activate). | Code to remove authors with no posts connected to them | wordpress |
Symptoms: Can't view ANY previous Posts, but the correct totals are listed by class - published, draft.... When creating a new post - no save or publish button Unable to administer ANY plug-ins - error message: You do not have sufficient permissions to access this page What Has Changed? Upgraded from 3.0.2 to 3.0.1 or something like that, I was clearly on 3.x What Have I Attempted? validated the roles and access values were correct for the admin user in database tables Created a new admin Changed admin user values to something else and back Changed to default template Disabled ALL plug-ins Re-installed latest version What would you do next? | I had some problems upgrading to 3.0.3 on a multi-site installation. I had used the automatic upgrade and it failed, but luckily, downloading and extracting the new files from WP.org and uploading them directly fixed it. I would try that first. If that doesn't work, try re-uploading your backup files. You did make a backup, right? | Upgrade Nightmare - No Posts, Permissions Issues and Can't Create a new post | wordpress |
Is there anyway to disable custom dragging and sorting of the posting fields in admin? From time to time, the fields gets dis-ordered, and I have to sort them back to the way I want it, witch is kinda annoying. I want this also because I'm going to have other editors on the site, and I want a standardized order for everybody. I also want the excerpt-field to be above the content-field. Is all this possible? | I can answer the last part: "I also want the excerpt-field to be above the content-field. Is all this possible?" The only way to move anything above the content field is via JavaScript--there are no php hooks or filters up there. It's kind of a lame workaround because you can usually see (visually) the jump as the fields reorder. But AFAIK it's the only way to do this. <code> jQuery(document).ready( function($) { // On DOM ready move the excerpt field above the WYSIWYG field if( document.getElementById('postdiv') && document.getElementById('postexcerpt') ) { jQuery('#postexcerpt').insertBefore('#postdiv'); } else if( document.getElementById('postdivrich') && document.getElementById('postexcerpt') ) { jQuery('#postexcerpt').insertBefore('#postdivrich'); } }); </code> | Default, locked sorting of posting fields | wordpress |
I need to publish a audio file that I want to make available to listen and not to download any idea how to do it? Is there any free WP plugin for that? Something where user cannot save the audo using any webbrowser plugin like DownloadHelper etc. | Have you looked at either Audio Player or XSPF ? I've had good success with both of those. | audio streaming plugin but with no save option? | wordpress |
Here is my form: <code> <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform" class="validate"> <?php if($user_ID) : ?> <?php else : ?> <div class="label_container"> <div class="left"> <label for="author" class="label label_name">Name*</label> </div> <div class="right"> <label for="email" class="label label_email">Email*</label> </div> </div> <div class="input_container"> <input id="name" name="author" class="required input_text input_name" type="text" value="" /> <input id="email" name="email" class="required input_text email input_email" type="text" value="" /> </div> <?php endif; ?> <div class="label_container"> <label for="comment" class="label label_comment">Comment</label> </div> <textarea id="comment_box" class="required input_comment" name="comment" cols="40" rows="6"></textarea> <p><input name="submit" class="input_submit" type="submit" id="submit" tabindex="5" value="Submit Comment" /> <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /></p> <input type="hidden" id="redirect_to" name="redirect_to" value="<?php echo get_bloginfo('wpurl');?>/comment"> <?php do_action('comment_form', $post->ID); ?> </form> </code> I have required fields on all inputs, but it is only working on the comment text field. Any ideas? | First of all, I highly recommend using the <code> comment_form() </code> function. It's all of the above code in one line (more if you need to tweak parts of the code). You can designate name and email as required in the settings section of your admin area: | How do I make wordpress comment fields required? | wordpress |
Is there an app for the Windows Phone (7) that allows submission to WordPress? Having used the WordPress app on the Blackberry, I'm looking for one that is similar to that, but for the WP7. I've had a look and not found anything, though there are rumours (potentially unsubstantiated) that one is being created.. | Official page: http://windowsphone.wordpress.org/ Was kinda hard to find, I basically guessed URL in few tries in analogy to android.wordpress.org :) | WordPress on WP7 | wordpress |
Is there some plugin or some way to integarate any of the following : Cubepoints Achievements with either of the following : Favorite (default in bp) Vote it Up Emo Votes | I'm the author of the Achievements for BuddyPress plugin, and it's lucky I saw your question. I don't often read this site. I can't talk for Cubepoints, but with Achievements, it is easy to extend support to other plugins. For developer documentation, see http://achievementsapp.com/developer/add-support-for-a-plugin-non-custom-post-type/. If either of those vote plugins are super popular and well-written, I'll add support to the core of Achievements. Favourites (activity stream favourites, yes?) should work with Achievements. I'll put it on the to-do and check support for hte next release. | Integration of Cubepoints/Achievements | wordpress |
Is there any way to get wordpress to check for, download private theme updates? I found this plugin for private plugin updates.... http://w-shadow.com/blog/2010/09/02/automatic-updates-for-any-plugin/ I'm looking for the same thing but for themes. | It's quite possible. I've been doing this for years with my Version Checker plugin. I do not distribute it openly, but in essence it checks a private version API , and then tosses the extra results into the update_core, update_plugins and update_themes site transients. WP then takes it seamlessly from there courtesy of the WP patches I supplied when I was developing it. | Automatic Updates For Private And Commercial Themes? | wordpress |
How can I find out in which sidebar was a widget dropped? From inside that widget. More precisely from the <code> form() </code> function. Can I automatically remove the widget if it's not added in the appropriate sidebar? | See this thread: stackexchange-url ("Limit widget to certain sidebar?") | Get the sidebar ID in which the current widget was dropped | wordpress |
I'd like to have the home page have a menu title of "Home" and a different page title "What we can do for you". How to do this without going into code. Is there any plug in to do this? | You don't need a plugin if you're using the built in menus - in Appearance -> Menus, click on a menu item and you can change it's navigation label. The label is what shows in the menus. | How to have "Page Title" different than "Menu Title" in wordpress 3.0.3? | wordpress |
How can I get the number (count) of, let's say, text widgets from a sidebar? for eg. if I drop 4 text widgets in the sidebar, I want to get this number somehow from another widget | Call wp_get_sidebars_widgets(), and loop through each sidebar. Off the top of my head, text widgets have an ID like widget_text-$i. | Count widgets of a certain type | wordpress |
i started a new blog and i see that there are two pages it starts out with: Home About i want to add a third one but instead of having it load up an internal page, i want to have this go to an external link. is this possible ? | Admin Dashboard -> Appearance -> Menus If the theme is WP 3.0 ready, you will have an option to add a custom link (ie external link) on the left side, and you can drag and drop it into the order you want. Justin Tadlock wrote an awesome post about 3.0 menus - http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus If your theme isn't 3.0 ready, I believe you can still use the custom menu widget. | how can i add a menu link that goes to an external page | wordpress |
I'm attempting to dynamically create a text widget, add it to a named sidebar widget that my theme has already created ($sidebar_id = 'home-header-widget'), then populate the text widget with some preset content. I'm getting an error as indicated above at line 35 (commented below). Any ideas what I'm doing wrong? <code> Parse error: syntax error, unexpected '[' in C:....widgettest.php on line 35 <?php /* Plugin Name: Widget Test */ function cb_activate_widgettest(){ $ops = get_option('widget_text'); // find an $id that works... $ops[$id] = array( 'title' => '', 'text' => 'bar', // content? ); update_option('widget_text', $ops); $sidebar_id = 'home-header-widget'; $sidebars_widgets = get_option('sidebars_widgets'); $sidebars_widgets[$sidebar_id] = ["widget_text-$id"]; //this is line 35 update_option('sidebars_widgets', $sidebars_widgets); } register_activation_hook(__FILE__, 'cb_activate_widgettest'); ?> </code> | This part triggers it: <code> = ["widget_text-$id"] </code> Copy paste gone wrong or something? Square brackets used this way make no sense to PHP. | Plugin could not be activated because it triggered a fatal error, unexpected '[' | wordpress |
I like to have a clean blog, and I also like that comments that are replies to other comments actually are replies to other comments. Some people don't mind that difference too much and just leave another comment instead of a reply. That's alright, but I'd like to fix it so that my blog stays clean and so that things are clearer to myself. Is there a way that I can "move" a regular comment so that it becomes a reply to a certain comment instead? | first, if you're not already using it, you need wordpress threaded comment . you can stylize it with css of course. after that, if someone comments the post, and you think it was supposed to be a reply to some other comment, you can do it with move wordpress comments or just do it manualy... | Is it possible to move a comment that should be a reply to another comment? | wordpress |
On the right rail here: http://www.julianamaeberger.com/soma/sample-testimonial-3/ I am showing a random post "Testimonial". Below that I am showing all featured images for the category "Testimonial" so that you can flip through the images and choose where you want to go next. I want to highlight the image that is related to the content above, but can't figure out how to do it. This is my first time building templates, so I may be going about it the wrong way. Any help in the right direction would be much appreciated. Here is the code for the right rail: <code> <div class="rightcolumn"> <div class="testimonial"> <h3>Testimonials</h3> <?php $postslist = get_posts('category_name=testimonial&numberposts=1&orderby=rand'); foreach ($postslist as $post) : setup_postdata($post); ?> <?php the_content(); ?> <?php endforeach; ?> </div> <div class="carousel default"> <div class="jCarouselLite"> <ul class="portfolio"> <?php $postslist = get_posts('category_name=testimonial&numberposts=-1&order=DES'); foreach ($postslist as $post) : setup_postdata($post); ?> <li> <?php the_post_thumbnail( 'nav' ); ?> </li> <?php endforeach; ?> </ul> </div> <script type="text/javascript"> $(".default .jCarouselLite").jCarouselLite({ btnNext: ".default .next", btnPrev: ".default .prev", visible: 3, scroll: 3, speed:100 }); </script> </div> </div> </code> | How you want to highlight this image is specific to your layout, but it probably involves setting a class to the <code> <li> </code> surrounding it? You can do this by comparing the ID of the post you have displayed with the ID of the post of which you are showing the thumbnail. In your first loop you save the ID: <code> $current_testimonial_id = get_the_ID(); </code> In your second loop you compare it to the current thumbnail: <code> <li <?php if ( get_the_ID() == $current_testimonial_id ) { echo ' class="highlighted"'; } ?>> </code> A quick tip if you are working with multiple loops: most template functions accept post ID parameters, so you don't have to use the <code> setup_postdata() </code> function which sets some global variables. This is handy if you need the "main" post query again after your extra loop. So the following code works just a well for the second loop: <code> <ul class="portfolio"> <?php $testimonials = get_posts('category_name=testimonial&numberposts=-1&order=DESC'); foreach ($testimonials as $testimonial) : ?> <li <?php if ( $testimonial->ID == $current_testimonial_id ) { echo ' class="highlighted"'; } ?>> <?php echo get_the_post_thumbnail( $testimonial->ID, 'nav' ); ?> </li> <?php endforeach; ?> </ul> </code> | How to show a featured image as current? | wordpress |
I'd like to have my header banner change every day, chosen (e.g. randomly) from a list/folder of images. So far I only found plugins that select a random banner per post or per page view, neither is what I want. Do you know of a plugin, or any other way? Edit: Example. I'm adding a folder to my wordpress installation. This folder contains some header images. Every 24 hours, an random image is chosen from this folder and becomes the header image for 24 hours, until another random image is chosen. Actually, I don't care how exactly the image is chosen - I'm fine with rotating through all images in the folder as well. The only thing I care about is that the chosen image stays there for 24 hours. Basically it's the same as if I were picking a new header image manually every day. | <code> <div id="header"> <?php mt_srand((int)date('z')); $headers=glob(PATH_TO_FILES .'/*.jpg'); $header=mt_rand(0,count($headers)-1 ); ?> <img id="header-image" `src="<?php echo URL_TO_FILES . '/'.basename($headers[$header]); ?>" alt="header" /> </div> </code> replace your current header with this. I will of course help you implement this further if you need help. (or if you need the code explained) | How to rotate the header image per day? | wordpress |
I am looking for a wordpress plugin that allows my users to customize which posts are appearing on the home page. The users should have a settings page where they can select which categories and tags they´d like to see posts from. Do you know if anything like that has been developed? Free or premium. | I am looking for a wordpress plugin that allows my users to customize which posts are appearing on the home page. Not sure there's any particular plugins for this, but it's certainly possible with a few functions. The users should have a settings page where they can select which categories and tags they´d like to see posts from. Easier than providing a settings page that's seperate from the profile page, i'd actually suggest adding a couple of new fields to the user's profile page, you can call the section home preferences or whatever you like. Example follows... Step 1 - Add custom fields to the user profile page Here i took the same approach as Mike did when answering: stackexchange-url ("How to add custom form fields to the user profile page"), firing on two actions to account for user profile saves and admin user edits. <code> add_action( 'show_user_profile', 'home_prefs_profile_fields' ); add_action( 'edit_user_profile', 'home_prefs_profile_fields' ); function home_prefs_profile_fields( $user ) { $um = get_user_option( 'taxonomy_selection', $user->ID ); $tags = ( isset( $um['post_tag'] ) ) ? $um['post_tag'] : array(); $cats = ( isset( $um['categories'] ) ) ? $um['categories'] : array(); ?> <div id="home-prefs"> <h3>Home Preferences</h3> <table class="form-table"> <tr> <th> <label for="tax_input[post_tag]">Tags</label><br /> <span class="description">Choose which tags you want to display on the home page.</span> </th> <td> <ul id="tag-checklist"> <?php wp_terms_checklist( 0, array( 'taxonomy' => 'post_tag', 'selected_cats' => $tags ) ); ?> </ul> <br class="clear" /> <hr /> </td> </tr> <tr> <th> <label for="post_category">Categories</label><br /> <span class="description">Choose which categories you want to display on the home page.</span> </th> <td> <ul id="category-checklist"> <?php wp_category_checklist( 0, 0, $cats, false ) ?> </ul> </td> </tr> </table> </div> <?php } </code> Information on the term and category checklists can be found in the source(no docs yet). http://core.trac.wordpress.org/browser/tags/3.0.2/wp-admin/includes/template.php#L217 Step 2 - Handle saving data on profile/user update Again, two actions, depending on whether it's a user saving profile changes or another user making changes to another user's profile. <code> add_action( 'personal_options_update', 'save_home_prefs' ); add_action( 'edit_user_profile_update', 'save_home_prefs' ); function save_home_prefs( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) return false; $data = array(); if( isset( $_POST['tax_input'] ) ) { foreach( $_POST['tax_input'] as $taxonomy => $term_ids ) if( !taxonomy_exists( $taxonomy ) ) continue; else $data[$taxonomy] = array_map( 'intval', $term_ids ); } if( isset( $_POST['post_category'] ) ) $data['categories'] = $_POST['post_category']; update_user_meta( $user_id, 'taxonomy_selection', $data ); } </code> NOTE: It wouldn't hurt to add further sanitization to the above. Step 3 - Adjust the CSS Indent children terms, float the main list items, so busy taxonomies don't consume so much height. <code> add_action( 'admin_print_styles-user-edit.php', 'tax_checklist_css' ); add_action( 'admin_print_styles-profile.php', 'tax_checklist_css' ); function tax_checklist_css() { ?> <style type="text/css"> .children { text-indent: 20px } #tag-checklist li { float:left;width:30% } #category-checklist li { float:left;width:30% } #category-checklist li li { float:none;width:auto } </style> <?php } </code> NOTE: 30% width on the list items basically gives you the appearance of 3 columns of terms, you're welcome to adjust the CSS to suit. This could also just as easily be turned into an enqueue, which will provide some level of caching, inline CSS is quicker to test is all... ;) Step 4 - Filter home query based on user prefs Add a filter onto home queries based on user configured settings for tags and categories. <code> add_action( 'pre_get_posts', 'do_user_post_selection' ); function do_user_post_selection( $query ) { if( !is_home() || !is_user_logged_in() ) return; if( isset( $query->query_vars['post_type'] ) && ( 'nav_menu_item' == $query->query_vars['post_type'] ) ) return; if( 1 < did_action('wp') ) return; global $current_user; $tax_selection = get_user_option( 'taxonomy_selection', $current_user->ID ); if( empty( $tax_selection ) ) return; if( isset( $tax_selection['categories'] ) && ( is_array( $tax_selection['categories'] ) ) && ( !empty( $tax_selection['categories'] ) ) ) $query->set( 'category__in', $tax_selection['categories'] ); if( isset( $tax_selection['post_tag'] ) && ( is_array( $tax_selection['post_tag'] ) ) && ( !empty( $tax_selection['post_tag'] ) ) ) $query->set( 'tag__in', $tax_selection['post_tag'] ); return; } </code> NOTE: You don't have to use a <code> pre_get_posts </code> filter, you could use <code> parse_query </code> or pass values into a <code> WP_Query </code> object, i personally just find the chosen hook easy to use(and it's what i'm use to using). UPDATE: Move the home prefs elements to the top of the profile page. <code> function move_prefs() { ?> <script type="text/javascript"> jQuery(document).ready(function($){ $('#home-prefs').prependTo('#your-profile'); $('input[type=checkbox]').attr('disabled',false); }); </script> <?php } add_action( 'admin_head-user-edit.php', 'move_prefs' ); add_action( 'admin_head-profile.php', 'move_prefs' ); </code> NOTE: There's a slight HTML update to the <code> home_prefs_profile_fields </code> function also required, i've updated the function as appropriate in Step 1 . RE: Checkboxes showing disabled from subscribers(see comments). The reason this occurs is due to a capability check in the term checklist functions, these functions are typically used on post creation type screens, so expect the user to have the capability to assign terms to a post(or type), this obviously doesn't apply to this particular case so we can safely remove the disabled attribute from them(jQuery above has been ammended with the appropriate change). Hope that helps... :) | Filter index page plugin | wordpress |
I would like to change the order in which users are displayed in the admin. At the moment it seems that they are order by the username. I think I have found the right place in the wp-admin/users.php, which is around line 187: <code> ORDER BY user_login"); </code> I am not 100% sure if this is right as I don't know much about the code. Could anyone confirm if I am in the right place and what I should do to change the order. Also is it only possible that I could have an ascending or descending order for example, A,B,C,D,E or E,D,C,B,A? It would be idea if I could specify the order differently, for example, C,A,D,B,E or similar. Thanks | Nope, the line you found seems to be some basic preliminary query. Selection of users for display in table seems to be handled by <code> WP_User_Search </code> class. Luckily it can be hooked into easily. Try this (changes order to descending): <code> add_action('pre_user_search', 'change_user_order'); function change_user_order($query) { $query->query_orderby = ' ORDER BY user_login DESC'; } </code> PS I am not sure if this can interfere with something else, so might require checks to only run on that specific page. | How to change the order in which users are displayed in admin? | wordpress |
I need a function that returns true when the author is an admin or an editor or of a certain role. I can't use is_single because I have set up a forum and there are a million singles out there and I need a different layout for THE posts (the ones written in the blog by admins and editors) than from the forum entries | <code> author_can() </code> seems to fit. Example: <code> if( author_can( get_the_ID(), 'administrator' ) ) </code> | A function that returns true when the Author is a certain role is_author(admin)? | wordpress |
I am using Manifest 1.01 by Jim Barraud on my site www.inteftrust.org. I'd like to know how can I get full width with this theme. Thanks. | yes, go to your /wp-content/themes/manifest_v1.1/style.css and edit the following IDs to look like this: <code> #siteWrapper{ margin: 0 auto; padding-top: 15px; width: 97%; text-align: center; position: relative; } #coreContent{ float: auto; width: auto; margin-top: 8px; } #footer{ width: 97%; margin: 40px auto 0; padding: 20px 0 35px 0; border-top: 4px double #ccc; color: #666; text-align: center; } </code> besides that - I see you have some blue image just below this Intef image... I believe one of them is not meant to be there? try this CSS I provided with firebug first to see what you'll get... or just play with firebug and see how you can change themes appearance and then apply it to style.css | How to edit my theme for full width? | wordpress |
i just want this code to be added in my functions.php, so that it will directly display after my post ends currently i am adding this code to my single.php, but i want to add this is in functions.php, this code is use to fetch all the tweets of the respective account, the code is here <code> <?php function parse_twitter_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix) { $feed = str_replace("&lt;", "<", $feed); $feed = str_replace("&gt;", ">", $feed); $clean = explode("<content type=\"html\">", $feed); $amount = count($clean) - 1; echo $prefix; for ($i = 1; $i <= $amount; $i++) { $cleaner = explode("</content>", $clean[$i]); echo $tweetprefix; echo $cleaner[0]; echo $tweetsuffix; } echo $suffix; } function the_twitter_feed($username) { // $username = "Mba_"; // Your twitter username. $limit = "5"; // Number of tweets to pull in. /* These prefixes and suffixes will display before and after the entire block of tweets. */ $prefix = ""; // Prefix - some text you want displayed before all your tweets. $suffix = ""; // Suffix - some text you want displayed after all your tweets. $tweetprefix = ""; // Tweet Prefix - some text you want displayed before each tweet. $tweetsuffix = "<br>"; // Tweet Suffix - some text you want displayed after each tweet. $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $limit; $twitterFeed = get_transient($feed); if (!$twitterFeed) { $twitterFeed = wp_remote_fopen($feed); set_transient($feed, $twitterFeed, 3600); // cache for an hour } if ($twitterFeed) parse_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix); } ?> </code> | I'm not sure why you don't just insert the code in the single.php, or use Denis's solution, but if you want to hook into <code> the_content </code> you can do so by putting the following in your functions.php file: <code> function append_the_content($content) { $content .= 'PUT YOUR FUNCTION HERE'; return $content; } add_filter('the_content', 'append_the_content'); </code> This will add directly to the end of <code> the_content </code> . You can call your Twitter function above this and it should work. You'd be better off using a theme framework with some custom hooks because hooking into <code> the_content </code> in this way can get very buggy very fast depending on what other filters/hooks your theme and plugins are using to modify <code> the_content </code> . I don't know why it happens, I just know that it does. | write in functions.php | wordpress |
How difficult would it be to add an option for "nofollow" to the Link editor's existing "Link Relationship(XFN) options list? Alternately, or better yet, in addition, add an item to the "Bulk Actions" listing called "Make links no follow" that would make all selected links rel="nofollow". I'd like to add this feature to my theme's functions.php | Alternatively you can undo the code that disables the relationship box by re-pointing the enqueue to the xfn.js script.. First create a modified version of that script, like so.. <code> jQuery(document).ready( function($) { //$('#link_rel').attr('readonly', 'readonly'); $('#linkxfndiv input').bind('click keyup', function() { var isMe = $('#me').is(':checked'), inputs = ''; $('input.valinp').each( function() { if (isMe) { $(this).attr('disabled', 'disabled').parent().addClass('disabled'); } else { $(this).removeAttr('disabled').parent().removeClass('disabled'); if ( $(this).is(':checked') && $(this).val() != '') inputs += $(this).val() + ' '; } }); $('#link_rel').val( (isMe) ? 'me' : inputs.substr(0,inputs.length - 1) ); }); }); </code> Save as xfn.js and place into a plugin's folder or the current theme's folder. NOTE: It's a direct copy of the original(existing) script enqueued by WordPress, i've left original code that sets the rel input to read-only so you can see what's been changed(one line). Then add this to your plugin code, or theme's functions.php, and uncomment the appropriate line in the code sample.. <code> function switch_xfn_src( $src, $handle ) { if( 'xfn' == $handle ) //$src = plugins_url( '/xfn.js', __FILE__ ); // For use inside plugin //$src = get_bloginfo( 'stylesheet_directory' ) . '/xfn.js'; // For use inside theme return $src; } add_filter( 'script_loader_src', 'switch_xfn_src', 10, 2 ); </code> Job done... :) | How to add an option for "nofollow" to the Link editor's existing "Link Relationship(XFN) options list? | wordpress |
i tried this code, it is not giving me any 404 page instead it is giving me the same page back, now i think the submit buttons needs to be configured <code> function the_taxonomy_dropdown($taxonomy) { $id = "{$taxonomy}-dropdown"; $terms = get_terms($taxonomy); echo "<select name=\"{$id}\" id=\"{$id}\">"; foreach($terms as $term) { echo '<option value="'; echo get_term_link(intval($term->term_id),$taxonomy); echo '">' . "{$term->name}</option>"; } echo "</select>"; } add_action('init','jquery_init'); function jquery_init() { wp_enqueue_script('jquery'); } </code> this code was provided to me by one of the person from this website, i just modified it, this works but its just showing me the home page again | Just a standard HTML form will do! <code> <form action="<?php echo home_url('/'); ?>" method="get"> <p><?php wp_dropdown_categories('taxonomy=taxonomy-1&name=taxonomy-1'); ?></p> <p><?php wp_dropdown_categories('taxonomy=taxonomy-2&name=taxonomy-2'); ?></p> <p><input type="submit" value="Search!" /></p> </form> </code> Just replace <code> taxonomy-1 </code> and <code> taxonomy-2 </code> with the names of your taxonomies. Important If you registered your taxonomy with a custom <code> query_var </code> , you'll need to match it in the <code> name </code> argument of <code> wp_dropdown_categories() </code> . Also, querying multiple taxonomies is not supported as of 3.02 - you'll need the 3.1 beta, a plugin or stackexchange-url ("additional filters"). | drop-down list another query | wordpress |
<code> function validate_username( $username ) { $sanitized = sanitize_user( $username, true ); $valid = ( $sanitized == $username ); return apply_filters( 'validate_username', $valid, $username ); } </code> in wp-includes/registration.php i want to change <code> $sanitized = sanitize_user( $username, true ); </code> to <code> $sanitized = sanitize_user( $username, false ); </code> I couldnt success to write add_filter in there, somehow its not working. Can you write a filter for this please? | Like so: <code> function my_validate_username( $valid, $username ) { $sanitized = sanitize_user( $username, false ); $valid = ( $sanitized == $username ); return $valid; } add_filter('validate_username', 'my_validate_username', 10, 2); </code> | add_filter return value | wordpress |
i have a function of custom taxonomies to display a drop down list on my website, which is working fine, but there is one problem, the default value is a custom taxonomy, but that i dont want, i want a custom word, like select cause the current default value, when i select it, it is not redirecting to the corresponding page, if you wanna chaeck it, goto my website, on the home page i have kept that drop-down list www.mbas.in and the code of the function is <code> function the_taxonomy_dropdown($taxonomy) { $id = "{$taxonomy}-dropdown"; $js =<<<SCRIPT <script type="text/javascript"> jQuery(document).ready(function($){ $("select#{$id}").change(function(){ window.location.href = $(this).val(); }); }); </script> SCRIPT; echo $js; $terms = get_terms($taxonomy); echo "<select name=\"{$id}\" id=\"{$id}\">"; foreach($terms as $term) { echo '<option value="'; echo get_term_link(intval($term->term_id),$taxonomy); echo '">' . "{$term->name}</option>"; } echo "</select>"; } add_action('init','jquery_init'); function jquery_init() { wp_enqueue_script('jquery'); } </code> what i do for keeping default value as Select ???? | Not sure exactly what you're asking. Do you just want to include a blank value before the list of terms? Would this work: <code> echo '<option value="#"> - Select - </option>'; </code> (inserted just before the line foreach($terms as $term) { ) | drop-down list taxonomy problem | wordpress |
I'd like to add some code to my plugin populate a specific sidebar (if it exists) with a text widget containing preset content. Assuming that the sidebar I'm trying to preset is referenced by ID as "my-widget", how would I preset the content's of that widget with a text widget containing the text "Hello World"? | You need to do this in two steps. First create the actual widget. Find a widget ID that does not exist, and toss in an extra entry in (off the top of my head) the widget_text option, which corresponds to the text widget config. Off the top of my head, it'll look something like: <code> $ops = get_option('widget_text'); // find an $id that works... $ops[$id] = array( 'title' => 'foo', 'text' => 'bar', // content? ); update_option('widget_text', $ops); </code> Next, add it to your sidebar (again, off the top of my head): <code> $sidebars_widgets = get_option('sidebars_widgets'); $sidebars_widgets[$sidebar_id][] = ["widget_text-$id"]; update_option('sidebars_widgets', $sidebars_widgets); </code> I'm no longer 100% sure on the actual option names, but the general idea is as above. Also, if you want extensive examples of sidebar manipulation (including heaps of inanities related to API changes related to WP upgrades), check the inc/upgrade.php file of my theme: http://www.semiologic.com/software/sem-reloaded/ Or my Subscribe Me plugin: http://www.semiologic.com/software/subscribe-me/ | How to preset a sidebar widget with default content via script? | wordpress |
What is the correct method to refer to images from within your plugin code, so that no matter what the folder is named, they resolve correctly? I had an issue where a user downloaded my plugin twice, then used the 2nd downloaded file to install it. Since Windows automatically named duplicate files foldername(2).zip, when my plugin was uploaded to the site, it was placed in a folder named "foldername(2). So since my images were linked to wp-content/plugins/foldername/img/foo.png, none of the images were showing up. | I am not sure about this specific example but in general <code> plugins_url() </code> is fitting function for this. Example from Codex: <code> plugins_url('/images/wordpress.png', __FILE__); </code> | How to link to images in my plugin regardless of the plugin folder's name | wordpress |
I have a custom post type that I want to display the page you are on and how many pages total in this manner "Page 3 of 5" (meaning you are on page 3 of a 5 page post). These don't have to be links, just plain text numbers. I'd still like to keep the standard function of the wp_page_links parameter "next_or_number" set to "next", but add this other page indicator. I've tried experimenting with making my own funciton with some of the variables in the wp_page_links function on line 567 of the post-template.php file but I didn't get anywhere. | The current / total page count is set up by <code> setup_postdata() </code> which runs at the beginning of the loop. So, if you're in the loop, all you have to do is this: <code> global $page, $numpages; echo "Page $page of $numpages"; </code> If you need to do that outside of the loop, do this first: <code> global $page, $post, $numpages; // This next line is optional: sets a new global $post variable $post = get_post(123); setup_postdata($post); echo "Page $page of $numpages"; </code> | Display "Page 3 of 5" for a paginated post | wordpress |
Running IIS 7 and WP 3.0. I've got a web.config that has the necessary rewrite rules to make permalinks work, and they're working. However, if I point to n-nexus.realtimepublishers.com/content/?feed=rss2, the server first generates an HTTP 404. Weirdly, it then delivers the RSS feed. The problem is that the initial 404 makes things like FeedBurner and Safari barf; Firefox displays the feed properly (you can see the 404 error in Live HTTP Headers, though). What the heck am I not configuring properly? UPDATE: Disabled all plugins. No change. Boo. | The 404 is typical of WP thinking it has got no posts. Seeing that you actually have posts, I'm prompted to ask if you've plugins that mess around with query arguments or that override the loop partially or entirely? If so, they might be missing a few lines of code to allow WP to "know" it has found posts. | How do you make RSS feeds work under IIS 7? | wordpress |
I display a random post loop on a page. I'd like to put a "refresh" link to refresh the content of the loop via ajax. Is this possible? This is my loop if it helps: <code> <ul id="content-inner" class="thumb-grid clearfix"> <?php query_posts('posts_per_page=20&orderby=rand'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <li> <a href="<?php the_permalink(); ?>"> <img src="<?php echo $my_image_url = get('thumbnail'); ?>" alt="" /> <span class="title"><?php the_title(); ?></span> <span class="feat"><?php $articletags = strip_tags(get_the_tag_list('',', ',''));echo $articletags;?></span> </a> </li> <?php endwhile;?> <?php endif; ?> <?php wp_reset_query(); ?> </ul> </code> | Shouldn't be too tricky. First: create a javascript file and add this: <code> jQuery(document).ready(function($){ $('#refresh-links-id').click(function(e){ e.preventDefault(); $.post(ajaxurl,{action:'jpb_random_loop'}, function(data){ $('#content-inner').fadeOut(250).empty().append( data ).fadeIn(250); }); }); }); </code> Save that file in your theme directory somewhere (could be in a subdirectory too). For this to work, the refresh link should not be inside <code> ul#content-inner </code> . Pretty basic jQuery post call, though. Next, add this to your theme's <code> functions.php </code> file: <code> function jpb_template_redirect(){ if( <conditions under which this javascript should execute> ){ wp_enqueue_script( 'random-loop', '<url to the javascript file above>', array( 'jquery' ), '1.0' ); } } function jpb_random_loop_cb(){ query_posts('posts_per_page=20&orderby=rand'); if (have_posts()) : while (have_posts()) : the_post(); ?> <li> <a href="<?php the_permalink(); ?>"> <img src="<?php echo $my_image_url = get('thumbnail'); ?>" alt="" /> <span class="title"><?php the_title(); ?></span> <span class="feat"><?php $articletags = strip_tags(get_the_tag_list('',', ',''));echo $articletags;?></span> </a> </li> <?php endwhile; endif; die(); } add_action( 'template_redirect', 'jpb_template_redirect' ); add_action( 'wp_ajax_jpb_random_loop', 'jpb_random_loop_cb' ); add_action( 'wp_ajax_nopriv_jpb_random_loop', 'jpb_random_loop_cb' ); </code> That will tie everything together. Just make sure the logic is correct in the <code> template_redirect </code> function so that the javascript is included in the right pages. | Ajax loop refresh on click | wordpress |
Generally on our wordpress blogs,there will be a label "Wordpress" displayed on title bar .Does any body have idea how to hide or remove it? Update : Here is a website's screenshot,which shows the label : My website is powered by wordpress multisite installation and like many people I wanted it as self branded even though I keep link back to wordpress.org at footer . Is it inappropriate to do this ? Thanks in advance ! | I personaly don't think you should really do this, and I would leave it there if I were you - it is in fact a way to support WordPress, and don't forget you got it for free. ;) but, if you really want to do it, go to /wp-admin/admin-header.php and remove <code> &#8212; WordPress </code> from this line: <code> <title><?php echo $title; ?> &lsaquo; <?php bloginfo('name') ?> &#8212; WordPress</title> </code> | Removing label 'Wordpress' from title bar | wordpress |
This code: <code> <?php the_terms($post->ID, 'type') ?> </code> Gives: <code> <a href="/archives/type/image" rel="tag">Tag</a> </code> What do to if I want to display only "Tag" word, not link eg. <code> Tag </code> Thanks! | While you can specify separators and such in <code> the_terms() </code> arguments, it assumes that you actually want links. You can discard unwanted HTML by using filter: <code> add_filter('the_terms', 'no_terms_links', 10, 2); function no_terms_links($term_list, $taxonomy) { if ('type' == $taxonomy) return wp_filter_nohtml_kses($term_list); return $term_list; } </code> Or just use deeper <code> get_the_terms() </code> function and iterate through its return to build your own markup. | Formating the_terms() function output | wordpress |
Well, I'm using my own taxonomy for custom post type. It looks like this: <code> register_taxonomy("our_gallery", array("gallery"), array("hierarchical" => true, "label" => "Types", "singular_label" => "Type", "rewrite" => true)); </code> I have created a few "types"/categories in my admin panel like "Black and white", "Landscapes" and so forth... Anyways I can't figure out how to get these categories out? I mean - display them on my gallery page just next to gallery items? I've tried: <code> <?php $cat = get_the_category(); var_dump($cat); ?> </code> And it displays an empty array - "array(0) { }". How to get access to my own categories? get_the_category('our gallery') and ('gallery') also gives an empty array... Thanks a lot :) | I think you are getting confused by terminology here. Category is a <code> taxonomy </code> . Specific categories you create are <code> terms </code> . our_gallery is <code> taxonomy </code> . Landscapes is <code> term </code> . our_gallery is not <code> category </code> . It is its own <code> taxonomy </code> and has nothing to do with category <code> taxonomy </code> . <code> get_the_category() </code> function explicitly fetches <code> terms </code> of category <code> taxonomy </code> . To get <code> terms </code> of our_gallery <code> taxonomy </code> you need more generic function <code> get_the_terms() </code> . | Getting Wordpress custom taxonomy/category? | wordpress |
I would like to display all my category items under a single parent but I failed to do so now I'm creating a new menu link for each category and dragging it into place in the custom menu screen. Is there an easier and automatic way of doing this? | If you need to use a custom menu, then what you're doing is probably the only way. "Select All" in the Categories meta box on the admin menus screen, "Add to menu", and then reorder the category items as you like. But if you just want an automatic list of categories, then why not just call wp_list_categories() in your theme? | How to automatically generate custom menu item from categories? | wordpress |
Couldn't find anything in the related questions, so here goes: I have a post which, when viewed on the site, is returning a redirect loop. The error page is showing an address for the post that originated when the post was added to a category that was subsequently deleted. www.macrowikinomics.com/innovation-communities/business-economics/will-facebook-be-your-crm-provider is the correct address, but it keeps redirecting to www.macrowikinomics.com/innovation-communities/guest-authors/will-facebook-be-your-crm-provider/. Guest-authors was the old category obviously. My thought was it might be the automatic canonical URL redirect feature. Despite adding the disable canonical url function (src = Mark Jaquith) it continues to redirect to this old address. Cleared the cache and cookies and still it goes. Tried it in another browser and I continue to get the error. There is also no cache plugin running on the site. Could it be something in the pretty permalinks? They're using the format /%category%/%postname%/ Many thanks for any thoughts you can provide. | Do you use a plugin called Redirection? It has a setting that will automatically create redirects when a post permalink is changed, and if the post is renamed and then changed back to the original name, you get a loop. And if a category is removed, WP will reassign a post to the default category and that may be part of it, too. Also, check .htaccess for any hardcoded 301 redirects. | How to reset canonical URLs / fix redirect loop | wordpress |
All right, so we're probably all familiar with the typical way to ensure that your main CSS file is refreshed when you load the page (busting the browser cache), right? <code> <link rel="stylesheet" type="text/css" media="all" href="<?php echo get_stylesheet_uri(); echo '?'.filemtime( get_stylesheet_directory() . '/style.css'); ?>" /> </code> I need to do the same thing on another CSS file. Yes, my style.css file has its own set of @import "css/myFile.css" which are working fine, but humor me, if you will. So, back to header.php, right after that first link, and before the call to wp_head(): <code> <?php $cssFile = get_stylesheet_directory_uri().'/css/other.css'; ?> <link rel="stylesheet" type="text/css" media="all" href="<?php echo $cssFile; echo '?'.filemtime($cssFile); ?>" /> </code> And this leads to a warning (as part of the href attribute of the link when the browser gets the page): Warning: filemtime(): stat failed for http://localhost/wordpress/wp-content/themes/my_theme/css/other.css the path to the file seems to be built correctly (and the other.css file is there), but filemtime (stat, actually) fails on it. How come? Other recommended ways to include the 'latest' version of a CSS file other than style.css? Should I go with wp_register_style instead? If so... how can I tell wp_register_style to bust the browser cache (ie: get me the latest version of the css file, even if the browser has it cached)? Thanks in advance | You're using the file's path in the first call, but its URL in the second. So it won't work. | Cache busting CSS files other than style.css | wordpress |
I am trying to modify the support links under the help section (Contextual help).I want to replace these Documentation on Using Themes and Support Forums with my own .So I removed the links in wp-admin folder from many pages under admin section .But for plugin pages,I can't able to find the files to remove. Is there any way to replace or remove the links site wide ? | But for plugin pages,I can't able to find the files to remove. For dealing with plugin/registered pages that you won't necessarily know the hooks for, something like this will work... <code> add_action( 'admin_head', 'set_plugin_help_text'); function set_plugin_help_text() { global $_registered_pages; if( !empty( $_registered_pages ) ) foreach( array_keys( $_registered_pages ) as $hook ) add_contextual_help( $hook, "Your generic plugin page help text" ); } </code> NOTE: I purposely didn't use the contextual help action(as used in RodeoRamsey's answer) because it doesn't work for the above approach(so it wasn't without reason, i notice the other answer got more votes and i presume that *may* be why). Of course do note that the custom-background, custom-header and the theme editor pages under the themes menu also count as registered pages, so they'll naturally be effected by the above code (you can always factor some exclusion code into the above to deal with that though). EDIT BELOW: Additionally if you want to modify the help text for pages that aren't registered, ie. those that exist physically in WordPress and are used by WordPress, you can use the following approach. <code> add_filter( 'contextual_help_list', 'wp_help_info_replace', 10000000, 2 ); function wp_help_info_replace( $help, $screen ) { if( in_array( $screen->id, array( 'post', 'edit-post' ) ) ) $help[$screen->id] = 'Simple example help text'; return $help; } </code> In the above example i'm targetting edit.php and post-new.php , be sure to pay attention to the array values that refer to the screen ID, this value does not match what you'd typically expect to see as the pagehook, i would suggest echo'ing out the screen ID for screens where you're unsure about what the ID may be. | Modify links under 'help section'? | wordpress |
How can one get the blog ID as well as the database prefix of the main blog in a wordpress multisite installation? Is the main blog's ID always 1? Also how can the main blog's table prefix be acquired from within the mu-plugin's code? | Use the constant <code> BLOG_ID_CURRENT_SITE </code> . And to get the database table prefix, use; <code> $main_blog_prefix = $wpdb->get_blog_prefix(BLOG_ID_CURRENT_SITE); </code> | How to get the main blog's id and db prefix from a mu plugin? | wordpress |
Since upgrading to WP 3.0.1, a couple of my sites no longer display the update link to 3.02/3.03 on the Dashboard or on the Updates page. On one site, I tried re-applying permissions, but this didn't change a thing. There are no plugins related to 'hiding' update/nag messages. All the sites have been around since 2.7. | Try flushing out the transient data(options prefixed with <code> _site_transient_update_ </code> - wp_options table), WP will recreate them for you anyway. Not always a solution but tends to work for me when i have that problem. You can do this by adding the following lines to your current theme's functions.php (in wp-content/themes/YOURTHEME/functions.php). <code> delete_option( '_site_transient_update_core' ); delete_option( '_site_transient_update_themes' ); delete_option( '_site_transient_update_plugins' ); </code> NOTE: You probably only need the first one, but i usually flush them all if i'm flushing one(can't hurt to have a refresh). Load any page up once, admin page, post page, whatever, then remove the code(it only needs to run for one page load). | Missing Update Link to 3.02/3.03 on Dashboard | wordpress |
I have a function that defines a custom field on a post type. Say the field is "subhead". When the post is saved, I want to do some validation on the input, and display an error message on the post edit screen if necessary. Something like: <code> // Handle post updating function wpse_update_post_custom_values($post_id, $post) { // Do some checking... if($_POST['subhead'] != 'value i expect') { // Add an error here $errors->add('oops', 'There was an error.'); } return $errors; } add_action('save_post','wpse_update_post_custom_values',1,2); </code> I'm trying to hook this to the save_post action, but I can't figure out how to handle errors. There doesn't appear to be an error object passed into the function, and if i create my own WP_Error obj and return it, it's not respected by whatever mechanism spits out errors on the post edit page. I currently have an on-page error message inside my custom meta box, but this is less than ideal--I'd rather have a big, red, up-at-the-top error like WP normally displays. Any ideas? UPDATE: Based on @Denis' answer, I tried a few different things. Storing errors as a global didn't work, because Wordpress does a redirect during the save_post process, which kills the global before you can display it. I ended up storing them in a meta field. The problem with this is that you need to clear them out, or they won't go away when you navigate to another page, so I had to add another function attached to the admin_footer that just clears out the errors. I wouldn't have expected that error handling for something so common (updating posts) would be this clunky. Am I missing something obvious or is this the best approach? <code> // Handle post updating function wpse_5102_update_post_custom_values($post_id, $post) { // To keep the errors in $errors = false; // Do some validation... if($_POST['subhead'] != 'value i expect') { // Add an error here $errors .= 'whoops...there was an error.'; } update_option('my_admin_errors', $errors); return; } add_action('save_post','wpse_5102_update_post_custom_values',1,2); // Display any errors function wpse_5102_admin_notice_handler() { $errors = get_option('my_admin_errors'); if($errors) { echo '<div class="error"><p>' . $errors . '</p></div>'; } } add_action( 'admin_notices', 'wpse_5102_admin_notice_handler' ); // Clear any errors function wpse_5102__clear_errors() { update_option('my_admin_errors', false); } add_action( 'admin_footer', 'wpse_5102_clear_errors' ); </code> | Store errors in your class or as a global, possibly in a transient or meta, and display them in admin notices on POST requests. WP does not feature any flash message handler. | Add validation and error handling when saving custom fields? | wordpress |
i'm using this sql.. but it does not work <code> UPDATE wp_options SET option_value = replace(option_value, 'http://old.com, 'http://new.com') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_options SET option_value = replace(option_value, 'http://old.com', 'http://new.com') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = replace(guid, 'http://old.com,'http://new.com'); UPDATE wp_posts SET guid = replace(guid, 'http://old.com','http://new.com'); UPDATE wp_posts SET post_content = replace(post_content, 'http://old.com, 'http://new.com'); UPDATE wp_posts SET post_content = replace(post_content, 'http://old.com', 'http://new.com'); UPDATE wp_faquestion SET QuestionAnswer = replace(QuestionAnswer, 'http://old.com, 'http://new.com'); UPDATE wp_faquestion SET QuestionAnswer = replace(QuestionAnswer, 'http://old.com', 'http://new.com'); UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://old.com, 'http://new.com'); UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://old.com', 'http://new.com'); </code> | I do this all the time to move a site from our staging server to the live domain. I use PHPMyAdmin to export the database as an SQL file, then open it up in a text editor and do a global find and replace on the old url to change it to the new url. The use the SQL script to import the new SQL file to the new database, and copy the file across. Works like magic every time. | How do I move a Wordpress site to another server? | wordpress |
How can I set up wordpress to recognize <code> www.example.com/wp-content/uploads/2010/12/history.pdf </code> as something like <code> www.example.com/about/pdf-download/ </code> I also want the user not to see the actual link but the new one. | Do you just need to redirect that one specific request (for /wp-content/uploads/2010/12/history.pdf to /about/history.pdf)? Or do you need to to handle many requests (say, for /wp-content/uploads/2010/12/* to /about/*)? If it's the former, use a symbolic link (or, if you're not on Unix/Linux/BSD, whatever equivalent your OS offers). If it's the latter, use mod_rewrite (or, if you're not using Apache, whatever equivalent your Web server offers). | Custom Download Link | wordpress |
How can I add a nofollow option to my blogroll links editor? Attempted to just type "nofollow" into the "rel" input box, but its auto deleted onblur. If I turn javascript off (thanks to Matt's suggestion below), It works, but when I check the source on my site, the rel attribute looks like this... rel="nofollow"onclick="javascript:pageTracker._trackPageview('/outbound/blogroll/www.site.com'); | I know of three ways around this and unfortunately they all suck: Hack a core file Use a plugin Temporarily turn off scripgs in your browser and change them in the edit links section. | Make blogroll links no-follow? | wordpress |
I found a image accorian menu plugin based on mootools farework. Please suggest if any based on jquery framework. | Thanks to @t31os. This is what i was looking for: http://wordpress.org/extend/plugins/accordion-image-menu/ | Jquery based image accordian plugin | wordpress |
I've been bashing my head against my desk all afternoon trying to figure this out. I've got a custom post type all set up, with hierarchical set to "true" and I can assign parents and see the relationship in the back end. Which is great. Except I want to list the children (and siblings) of my special new post type. I found this code <code> <?php if($post->post_parent) $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php } ?> </code> which works perfectly when I put it into a page template for pages. But it returns squat for the custom post template. I thought "$post-> post_parent)" might be the issue -- but it's not: <code> <h1 class="page-title"><a href="<?php echo get_permalink($post->post_parent) ?>" title="<?php printf( __( 'Return to %s', 'your-theme' ), wp_specialchars( get_the_title($post->post_parent), 1 ) ) ?>" rev="attachment"><span class="meta-nav">&laquo; </span><?php echo get_the_title($post->post_parent) ?></a></h1> </code> (lifted from an attachment template) does give me a back link to the parent. -- so maybe it has something to do with wp_list_pages? Maybe it's something else? I'd appreciate any ideas. Thanks in advance, Martin | As name hints <code> wp_list_pages() </code> is intended for use with pages. As in "a page page". It uses <code> get_pages() </code> internally, which has <code> post_type </code> argument that defaults to <code> page </code> . I am not sure at all this is supposed to work for non-pages, but you can try to pass your custom post type as that <code> post_type </code> argument. | wp_list_pages doesn't work in hierarchical custom post type | wordpress |
I'm using the excellent PHP Code Widget plugin, and want to create a widget that displays the post thumbnail (aka featured image) for the most recent 'project' post. Here's the code I have so far, but it isn't producing the desired result. This actually outputs nothing. <code> <?php global $post; $args = array( 'post_type' => 'project', 'posts_per_page' => 1, ); $thumbnails = get_posts($args); foreach ($thumbnails as $post) { setup_postdata($post); ?> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'thumbnail' ); ?></a> <?php } </code> Any suggestions on what I need to change for this to work? | Moving here so comments don't turn into a mess. Basically there are two things that can go wrong here: Fetching of posts. Check that <code> $thumbnails </code> gets correct post and only one. I am not sure if that is the issue, but <code> get_posts() </code> docs list <code> numberposts </code> argument instead of <code> posts_per_page </code> that is listed for <code> query_posts() </code> . That might make a difference. Messing with global variables. For this usage I wouldn't touch global <code> $post </code> at all, directly or with <code> setup_postdata() </code> either. Just use non-loop versions of functions that can fetch things you need by post id - <code> get_permalink() </code> and <code> get_the_post_thumbnail() </code> . | How can I show the post thumbnail from the most recent of a certain post type, in widget? | wordpress |
I'm not sure if this setting is handled in my wordpress installation or by Feedburner but right now my feedburner feed is displaying the feedburner favicon. How can I set it to use my blogs favicon? | As @Rarst pointed out, there is no implementation of a favicon in the RSS spec (although there does seem to be one for Atom). Feedburner (and other readers) rely on the de-facto standard that the favicon exists at the website root; <code> http://example.com/favicon.ico </code> Some clients may also try <code> .png </code> or <code> .gif </code> , but your safest bet is the standard <code> .ico </code> . How to get your favicon working with Feedburner Favicons for XML/RSS feeds Wikipedia Favicon | How do I set my Feedburner feed to use my favicon? | wordpress |
How can I make a link like this? <code> http://www.lifecellskin.us/Dev/About </code> the "Using_Permalinks" part, A is Capital letters. But WP automatically convert upper case to lower case. I'm trying to convert an old site that made by only html to a WP platform site. Some links to the site look like this: <code> http://www.lifecellskin.us/About </code> The site is already indexed by SEO. so I don't want to lose SE rankings. Thanks for reading this, and hope somebody will be able to shed some light on it... | The page URLs are defined by the slugs, and by default they are formatted and lower-cased by the function <code> sanitize_title_with_dashes() </code> . However, this function is called via a filter, and you can unhook the filter so it doesn't get called: <code> remove_filter( 'sanitize_title', 'sanitize_title_with_dashes' ); </code> Just doing this is probably not a good idea, as it will not remove the spaces and other weird stuff in the slug. I suggest you copy the existing function, remove the part that lowercases it, and hook it up again: <code> add_filter( 'sanitize_title', 'wpse5029_sanitize_title_with_dashes' ); function wpse5029_sanitize_title_with_dashes($title) { $title = strip_tags($title); // Preserve escaped octets. $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title); // Remove percent signs that are not part of an octet. $title = str_replace('%', '', $title); // Restore octets. $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title); $title = remove_accents($title); if (seems_utf8($title)) { //if (function_exists('mb_strtolower')) { // $title = mb_strtolower($title, 'UTF-8'); //} $title = utf8_uri_encode($title, 200); } //$title = strtolower($title); $title = preg_replace('/&.+?;/', '', $title); // kill entities $title = str_replace('.', '-', $title); // Keep upper-case chars too! $title = preg_replace('/[^%a-zA-Z0-9 _-]/', '', $title); $title = preg_replace('/\s+/', '-', $title); $title = preg_replace('|-+|', '-', $title); $title = trim($title, '-'); return $title; } </code> | How can I make Capital letter ( upper-case ) permalinks? | wordpress |
I'm tasked with making a site that has 'families'. Each family has a gallery, a 'region', and a 'name', both of which are searchable upon. My initial thoughts about this were to create a template for a child page of 'Families' that contains 2 custom fields (name and region), and just use some gallery plugin on each page. My question: Is there a better mechanic in Wordpress to solve the problem I'm presenting? I'm a developer, so I see this readily as several tables in a custom CMS that I'd just whip up over the weekend ("6 hours tops, promise!") that would quickly get out of hand, so I'd love to leverage my knowledge of WP to get this done more efficiently. | you could make category for each family (name), and a (sub)category for each region, and then assign custom templates to each category using category templates plugin . or - in case you want to use pages instead of posts/categories - then you don't need this plugin but instead just create additional page templates for each family.. both ways will give you a box when you go to create new post / new page which will be on the right side - and there you will be able to choose a custom template for each post/page. for gallery, I recommend NextGEN - you can create separate gallery for each family, and assign them (gallery categories) to post categories or pages. NextGEN will give you lots of options. | Approach to creating a site with this structure | wordpress |
I just came back to my site from dinner and was unable to find any posts listed in the dashboard. After snooping around, I found that my .htaccess file was modified, and some new files were added to my home directory. I deleted the .htaccess code, and the files (they all started with PE). I see that in the last hour a few posts regarding this have been posted on the wp.org forum site. Is anyone else having trouble with this? Is there any more code for me to delete? thanks. | See FAQ: My site was hacked « WordPress Codex and How to completely clean your hacked wordpress installation and How to find a backdoor in a hacked WordPress and Hardening WordPress « WordPress Codex . Do a good job cleaing or you'll be doing it all over again. Who is your host? Check with them, too. Some hosts are better than others when it comes to security and helping with cleaning up after hacks. | Wordpress cracked? Posts not found in dashboard | wordpress |
I have a pretty specific requirement to show different text in a field label on the user profile page based on the current user's role. I can't seem to figure out how to check whether the current use is an "author". I am looking for a function like: <code> is_user_in_role($user, "author"); </code> I imagine this is pretty simple, but I have searched for too long without an answer so I thought I would post it here. | If you only need this for current user <code> current_user_can() </code> accepts both roles and capabilities. | How to check if a user is in a specific role? | wordpress |
I've created my own custom post type using this tutorial: http://thinkvitamin.com/code/create-your-first-wordpress-custom-post-type/ Everything works fine, but I'm having major problem with "Read more" feature. As we all know <code> <!--more--> </code> adds <code> <span id="more-[number]" /> </code> at the start of hidden more paragraph. In my case this span breaks whole markup. See for yourself: <code> <p>This is normal paragraph and should be visible everywhere.</p> <!-- everything below is available only after clicking "Read more..." button --> <p><span id="more-[postnumber] />This is read "more" paragraph that will be displayed only on a "single" page.</p> <p>And another "more" paragraph.</p> </code> In my case it creates this strange code: <code> <p>This is normal paragraph and should be visible everywhere.<br/> <span id="more-[postnumber] /></br>This is read "more" paragraph that will be displayed only on a "single" page.</p> <p>And another "more" paragraph.</p> </code> So the more feature in my case doesn't even work and doesn't even display "Read more" button. Any ideas? [EDITED] Ok, so I've added whitespace after and before my <code> <!--more--> </code> tag, so the post looks like this in admin panel now: <code> This is normal paragraph and should be visible everywhere. <!--more--> This is read "more" paragraph that will be displayed only on a "single" page. And another "more" paragraph. </code> And it outputs the whole text because more span is getting an additional paragraph (why? :O): <code> <p>This is normal paragraph and should be visible everywhere.</p> <p><span id="more-[postnumber] /></p> <!-- I believe it shouldn't be in the additional <p> tag and that's the point --> <p>This is read "more" paragraph that will be displayed only on a "single" page.</p> <p>And another "more" paragraph.</p> </code> And about "more button" - I'm using the_content unfortunately... And nothing helps, when I type 'TRUE' as the second parameter - the_content('Read more...', TRUE); - it hides everything BEFORE more tag (so it shows two last paragraphs and hides the first one). What's that? :O | The quicktag will not operate and is ignored in Templates, such as single.php, where just one post is displayed. http://codex.wordpress.org/Function_Reference/the_content | "More" span making trouble | wordpress |
Anyone know how to override noindex on certain categories? I only want a few of my categories to be index but the rest not, in the All in one SEO plugin I have a setting that says "Use noindex for Categories" What I was wondering if there was any way of overriding this on some categories but leave it in place for the majority of categories? | From quick look at code this is getting concatenated into <code> $meta_string </code> variable, that is echoed without passing through any filter and so not easily modifiable. Likely for more precise control you need to disable this option in plugin and insert tag with your own code. | All In One SEO Plugin - Category INDEX | wordpress |
I'm trying to fix a site which has been injected with external spam. After inspection I found out that the external content (so far just html advertising different kinds of drugs, no scripts) was in the static pages created by w3 total cache. How can I find out what part is responsible for this? The obvious answer would be the w3 total cache plugin itself, but the pgcache is actually writeable by any part of wordpress so it might be any other plugin or even the WP core. I have searched the web for this problem but found nothing directly relevant. Of course wordpress is updated to the latest version available (3.0.2) as is every installed plugin. It does not depend on the theme as it happened with two different ones. | It is prolly injected in your files. Look at the plugin files, search for eval or base64. | Spam injected in w3 total cache page cache | wordpress |
If I have a page with ID 123, I know my template file <code> page-123.php </code> will be called to render it, but if my theme is used across a network, could a page in a different site also have ID 123? I assume, if so, that I'll need to sniff <code> $current_site </code> and requiring an alternate template file if it's not the site I'm targeting. I already assume slugs aren't unique across a network. | Nope, they aren't unique. So yes - you'd have to check current site and do that.... or use a theme with a custom menu? | Are page/post IDs unique across a whole network? | wordpress |
Ok guys, i have problem when using some trics from here or other sites. I <code> m trying to use this method of adding custom user fields. But, when i add this, everytime i save it </code> s all ok, but when i come back to edit something different in user profile, those new fields just goes blank, and if i did not input again my data in those fields and save my profile, those fields goes blank in DB. So, something is not ok that need to show me what i did just saved. As I told, it`s all ok until i open again my profile for editing. Ok, here is code, http://pastebin.com/u9syYRF3 | You have specified the value of the <code> <textarea> </code> in a <code> value </code> attribute, but for a <code> <textarea> </code> you must put it between the two tags: <code> <textarea rows="10" cols="60" name="adsense_336" id="adsense_336" class="regular-text" ><?php echo esc_attr( get_the_author_meta( 'adsense_336', $user->ID ) ); ?></textarea> </code> | Update users custom profile fields | wordpress |
I have just changed the theme on my blog, and because of a small page width, it breaks the layout. Most of my earlier images (attached in posts) are around 600px in width, and now I need to resize all of them them proportionately to 450px. How do I resize them all at one shot? Is there a plugin for this? P.S.: Writing a CSS rule is a good option, and I've already done that. But I figure resizing the images would also knock off the download overhead for each page! | I asked stackexchange-url ("a similar but broader question"), and I still need to research and write a complete answer. In the meantime here are some pointers that might help you: I wrote stackexchange-url ("a set of plugins that resizes all images to the size used in the editor"). It works by converting <code> <img src="image.jpg" width="200" height="400"/> </code> to <code> <img src="image-200x400.jpg" width="200" height="400"/> </code> ( Resize img tags ) and catching and generating those missing intermediate sizes on request ( On-Demand Resizer ). You should be able to do the first part in bulk, and then let the second plugin handle the new images. It also works with partial information: <code> image-200x.jpg </code> will return a proportionally-resized image 200 pixels wide. Regenerate Thumbnails indeed re-creates images at different sizes, but I don't think it also updates your post content to refer to these images? Even worse, if it deletes the old intermediate sizes, your post will still reference the now non-existing <code> image-600x400.jpg </code> instead of <code> image-450x300.jpg </code> . | Resizing all images | wordpress |
I am looking for a simple example on how to create a user bar or a simple theme with it that can serve me as example. What I meant is something like we have here on Wordpress Answers if u get above the logo you have a userbar with information when user is logged in and options to login/register when user is not logged in. I did a small search around here with the terms navigation bar and user bar but didnt find anything for the header. | If you're looking for an example how this can be done, grab the current development version of wordpress. It's already everything in there you might need / can imagine. If you don't want to make use of 3.1 but 3.0, use the 3.1 code as the example you're asking for. The user bar is located in admin-bar.php and class-wp-admin-bar.php . Your theme needs to support <code> admin-bar </code> and the code takes care on it's own by point-cutting the <code> wp_head </code> hook - which you should have in your theme in any case. Script and CSS styles are named 'admin-bar' as well. So it's basically copying over the files to your site, enabling theme support for it and if there are some 3.1 only functions used therein, work around those. You can additionally move those files to your theme, rename functions and classes to reflect your namespace to have this a bit more separated. A benefit to make use of that is that your site will be compatible when updating to 3.1. | User bar above logotipo? | wordpress |
The codex doesn't seem to say how one would go about adding a description to a custom widget registered with <code> wp_register_sidebar_widget() </code> . The default description seems to be the name of teh widget itself. <code> function myFunc(){ /* widget code */ } wp_register_sidebar_widget( 'wdgt1', 'Site Map', 'myFunc', array() ); </code> | Here's what you looking for: <code> class WP_Widget_Sitemap extends WP_Widget { function WP_Widget_Sitemap() { $widget_ops = array( 'classname' => 'widget_sitemap', 'description' => __( "This is the description" ) ); $this->WP_Widget( 'sitemap', __('Site Map'), $widget_ops); } function widget() { ... } function form() { ... } function update() { ... } ... </code> See: http://codex.wordpress.org/Widgets_API#Developing_Widgets | How to add a description to Widgets? | wordpress |
I've tried to explain the benefits of WordPress to others; comparing it to static sites is easy, as (most) everything can be done online with WP. I have more difficulty comparing and contrasting with other content management systems such as Drupal. I realize that there is no perfect system for every use, but what features - if any - of WordPress would you point out as being easier or more useful, compared to other tools? I am particularly interested in features regarding use of WP as a CMS, not just a blog. | Hi @Grant Palin : My use of WordPress is almost exclusively CMS, and the other software I have experience with is Drupal (2 years ago, but have continued to follow it) and DotNetNuke (5 years ago, and I haven't looked back.) I also reviewed Joomla about 3+ years ago and found is to be both too complex and too inflexible, so I never seriously considered it. Anyway, I can only speak with any real authority about how WordPress compares with Drupal as a CMS, and as luck would have it I wrote a blog post about exactly topic last week: 17 Reasons WordPress is a Better CMS than Drupal | What are the advantages of WordPress over other systems? | wordpress |
I have seen on some websites that you can sort posts server-side by passing in some queries like so: <code> domain.com/?sort=date </code> or <code> domain.com/?sort=name </code> How would I do this with WordPress posts on a page? | The display of posts is controlled by WordPress Loop. It has a lot of possible arguments, but they are rarely exposed in URL (especially if using pretty permalinks). But it is possible to make use of arguments by manually adding them to URL. For sorting see Orderby Parameters . Your example would be something like: <code> domain.com/?orderby=date domain.com/?orderby=title </code> | Server-side sorting of posts | wordpress |
I'm just wondering how I would go about redirecting to the latest post when you go to the web site? Similar to http://gregorywood.co.uk/ Many thanks :) Suleiman | Try this (as plugin or theme's functions.php): <code> add_action( 'template_redirect', 'redirect' ); function redirect() { if ( is_home() && ! is_paged() ) : wp_redirect( get_permalink() , 301 ); exit; endif; } </code> | Redirect homepage ( www.sitename.com ) to the latest post | wordpress |
Call me stupid but I coudn't figure out how to do it. For text input I would just: <code> <input type="text" name="option_name" value="<?php echo get_option( 'option_name' ); ?>" /> </code> and then hook it into workdpress using <code> register_setting() </code> . I could then get its value thru <code> get_option('option_name') </code> . How should I do that with checkboxes and radio buttons? | I tend to store multiple options as an array, so i'd have something like this.. <code> <?php $options = get_option( 'myoption' ); ?> <input type="checkbox" name="myoption[option_one]" value="1"<?php checked( 1 == $options['option_one'] ); ?> /> <input type="checkbox" name="myoption[option_two]" value="1"<?php checked( 1 == $options['option_two'] ); ?> /> </code> However it does depend how the callback function that sanitizes the incoming data deals with the saved value(the callback you should be defining as the third parameter of <code> register_setting </code> ). Personally when i'm dealing with checkboxes I don't set the array key, where as others may choose to set the key to 0(or whatever instead)... So my code actually tends to look like this.. <code> <?php $options = get_option( 'myoption' ); ?> <input type="checkbox" name="myoption[option_one]" value="1"<?php checked( isset( $options['option_one'] ) ); ?> /> <input type="checkbox" name="myoption[option_two]" value="1"<?php checked( isset( $options['option_two'] ) ); ?> /> </code> If i'm only dealing with checkboxes my sanitization callback will look something along the lines of.. <code> public function on_option_save( $options ) { if( !is_array( $options ) || empty( $options ) || ( false === $options ) ) return array(); $valid_names = array_keys( $this->defaults ); $clean_options = array(); foreach( $valid_names as $option_name ) { if( isset( $options[$option_name] ) && ( 1 == $options[$option_name] ) ) $clean_options[$option_name] = 1; continue; } unset( $options ); return $clean_options; } </code> Ripped that straight from one of my plugin classes(a plugin with only checkbox options), but it's not code you can expect to work if you copy, it's there for illustration only.. For radios, if you're not using multiple selection it goes something like this.. <code> <?php $options = get_option( 'my_option' ); ?> <input type="radio" name="myoption[option_three]" value="value1"<?php checked( 'value1' == $options['option_three'] ); ?> /> <input type="radio" name="myoption[option_three]" value="value2"<?php checked( 'value2' == $options['option_three'] ); ?> /> </code> NOTE: It would of course to be wise to check the key is set before comparing against it's value (i've left that out of the above to keep it short). Did the above help? If not, just let me know what needs clarifying... (or what i'm missing).. RE: <code> checked() </code> You can find where the function is defined(in WordPress) here. http://core.trac.wordpress.org/browser/tags/3.0.2/wp-includes/general-template.php#L2228 The first parameter is basically a conditional statement, and the second parameter(if you want to define it) is what to check against. The default value to compare against is TRUE ... so if were to do <code> checked( 1 == 1, true ) </code> i'd be checking if 1 == 1 is equal to true. If the conditional hits a match, then you get <code> checked="checked" </code> returned to you.. NOTE: I'm rubbish at explaining things, so if the above needs further clarification I won't be offended... just let me know.. ;) | How to use checkbox and radio button in options page? | wordpress |
How can I extend the functions of the WordPress 3.1 admin bar in my plugins? I am looking for specific hooks and filters to use in adding links or other features to the admin bar. A good example of what has already been done is the Yoast WordPress SEO (Wordpress Plugin). Currently there is no documentation available on extending the admin bar. According to The Codex there are two filters to turn it off or not show it: <code> no_admin_bar() </code> & <code> show_admin_bar() </code> | Yoast's plug-in is actually a very good example if all you want to do is add menus. Basically, the admin bar is just an alternate set of links to the same plug-in admin pages you have in the sidebar. To add the top-level SEO menu, Yoast does the following: <code> $wp_admin_bar->add_menu( array( 'id' => 'wpseo-menu', 'title' => __( 'SEO' ), 'href' => get_admin_url('admin.php?page=wpseo_dashboard'), ) ); </code> This adds a menu named "wpseo-menu" to the admin bar and directs users to the plug-in's dashboard when they click the link. Child links are added in a similar fashion: <code> $wp_admin_bar->add_menu( array( 'parent' => 'wpseo-menu', 'id' => 'wpseo-kwresearch', 'title' => __( 'Keyword Research' ), '#', ) ); </code> You just specify the "parent" of the menu you're adding. Then you can go as deep as you need to, calling <code> $wp_admin_bar->add_menu() </code> when you need to and specifying the appropriate information. For reference, the variable, <code> $wp_admin_bar </code> is an instance of the class <code> WP_Admin_Bar() </code> within WordPress. It has several different methods and properties, but the one you're most interested in here is, obviously, <code> add_menu() </code> . This method accepts certain parameters: title - default false href - default false, parent - default false - pass the ID value for a submenu of that menu id - defaults to a sanitized title value. meta - default false - array of any of the following options: <code> array( 'html' => '', 'class' => '', 'onclick' => '', target => '' ); </code> But the rest of the <code> WP_Admin_Bar() </code> class is pluggable. It just depends on what exactly you're trying to do and how you want to do it. See Also: SVN of Yoast's plug-in: read halfway through the file to find the menu definitions in <code> wpseo_admin_bar() </code> PHPXref of class <code> WP_Admin_Bar() </code> | Is the new WordPress 3.1 admin bar pluggable and how can I extend it? | wordpress |
Is is possible to get a page's permalink from the slug alone? I'm aware that you can get the page's permalink from the ID using <code> get_page_link() </code> : <code> <a href="<?php echo get_page_link(40); ?>">Map</a> </code> I'm curious if there is any way to do the same with the slug of a page: <code> <a href="<?php echo get_page_link('map'); ?>">Map</a> </code> | You're talking about Pages right? Not Posts. Is this what you looking for: <code> get_permalink( get_page_by_path( 'map' ) ) </code> <code> get_permalink( get_page_by_title( 'Map' ) ) </code> <code> home_url( '/map/' ) </code> | Get page link from slug? | wordpress |
I would like to provide our WP users (authors) with a tinyMCE editor instead of standard <code> textarea </code> for their "Biographical Info" on the Profile page. I have spent a lot of time searching online for plugins and references for how to accomplish this without a satisfying solution. Any tips would be appreciated. | I found a very helpful blog post which shows exactly how to accomplish what I am after with only three small changes to the <code> user-edit.php </code> page. First Change I had to add a class name to the <code> <textarea> </code> tag for the description. <code> <textarea name="description" id="description" rows="5" cols="30" class="CLASS_NAME_HERE"><?php echo esc_html($profileuser->description); ?> </textarea><br /> </code> Second Change I had to add a function call to <code> wp_tiny_mce() </code> like so. <code> <?php wp_tiny_mce( false, array( "editor_selector" => "CLASS_NAME_HERE" )); ?> </code> Note, the first argument of <code> wp_tiny_mce </code> (if true) will display the really stripped down version of the editor (like you'd see on the Quick Post). Third Change By default, Wordpress will strip out certain tags (those defined in $allowedtags) from the user description field. So, I found a plugin which basically removes the html restrictions. The plugin is called Weasel's Html Bios . | How to use tinyMCE for user "biographical info"? | wordpress |
I'm setting up a site with a theme that takes advantage of the "featured image" feature of WordPress. Since my end users are not the most tech saavy in the world, I'd like to set things up so that the categories would have a default "featured image" assigned to the post. In the event of multiple categories assigned to a post, then it would simply take the first one. Is there an existing plugin or a way to code this? | In your template where you have the Featured Image displayed: <code> <?php the_post_thumbnail( 'thumbnail' ); ?> </code> you can make it conditional on whether the Featured Image is set, then have it default to whatever you want if it's not set. One way to do this is to put all the default images in a directory and name them for the categories, eg. news.jpg and reviews.jpg then instead of using <code> <?php the_post_thumbnail( 'thumbnail' ); ?> </code> to display your Featured Image you'd use this: <code> <?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { the_post_thumbnail('thumbnail'); } else { ?> <img src="whatever/directory/<?php $category = get_the_category(); echo $category[0]->cat_name; ?>.jpg" /> <?php } endif; } ?> </code> So in this example above if the post is in the news category and your writer didn't set the Featured Image it'll default to the image stored at <code> http://www.yoursite/whatever/directory/news.jpg </code> . | Can I set a default featured image for a category? | wordpress |
i want to change the address of the file attachment link to wordpress [example: http://www.sitename.com/category/sub-category/article.html /attachment/ image etc.]. i did research on the subject a few days, but could not get any results.. looking at the structure of the connection! after " .html ", " / " mark does not look very nice to come. also the " attachment " as the fixing of that section, for WordPress users of different languages are missing a very large. i mean; rewrite.php file links to the author for the "author" from the base. this too, edit with the help of a simple function; global $wp_rewrite; $wp_rewrite-> author_base = ' example '; $wp_rewrite-> flush_rules(); i can not for this " attachment " :/ i tried so hard but i could not deal with this problem... anyway, i wanted to ask you! i'm not a coder ( i'm a graphic designer ). i want to do, so maybe things can make the limits of logic (: image.php file as it is sufficient to open a url more sense to me ... this link; http://www.sitename.com/category/sub-category/article.html /attachment/ image whether such; http://www.sitename.com/category/sub-category/article.html ?file= image i do not know would not open the image.php file in the form of " ?file=image ". so i can carry out your suggestions. thank you in advance. regards, Metin METE | Actually, you can always just use a query parameter, even if you have the "pretty" permalinks enabled. So instead of <code> /category/sub-category/article.html/attachment/image </code> you can go to <code> /?attachment=image </code> . The only case when this "breaks down" is when you go to <code> /category/sub-category/article.html?attachment=image </code> , because WordPress gets confused: it tries to query for a post and an attachment at the same time. However, this is very simple to handle: check for the request, and if it is an attachment remove the other parameters. <code> add_action( 'parse_request', 'wpse5015_parse_request' ); function wpse5015_parse_request( $wp ) { if ( array_key_exists( 'attachment', $wp->query_vars ) ) { unset( $wp->query_vars['name'] ); unset( $wp->query_vars['year'] ); unset( $wp->query_vars['monthnum'] ); } } </code> Now you only have to change the generated attachment URLs. Since they are almost in the correct format, we can just so some search and replace: <code> add_filter( 'attachment_link', 'wpse5015_attachment_link', 10, 2 ); function wpse5015_attachment_link( $link, $id ) { // If the attachment name is numeric, this is added to avoid page number conflicts $link = str_replace( 'attachment/', '', $link ); $attachment = get_post( $id ); $link = str_replace( '/' . $attachment->post_name . '/', '?attachment=' . $attachment->post_name, $link ); return $link; } </code> | attachment url rewrite | wordpress |
Can someone explain to me please how exactly Bad Behavior works? On their official site, they say that it uses HTTP headers, IP, and meta fingerprinting - but I would like some specifics on its mechanisms, not a simple description. To be more precise - how does it profile malicious activity (what kind of activity triggers "falls outside the bounds of a normal human browsing the web"), what does it look for in HTTP headers and metadata? Anyone? thanks! =) PS for mods - please could you add 'bad-behavior' tag? thanks | Bad Behavior does two things: It checks the HTTP request and sees if it is as per the standard or not. Usually spammers don't write their scripts so well as to be fully compliant with the HTTP standard. Bad Behavior can make out poorly scripted HTTP requests from properly scripted ones (which would be sent by genuine visitors using well-designed Web browsers, etc.), and then blocks the improper HTTP requests. It checks the IP address of the machine that sent the HTTP request against a database of known spammer IPs. If the IP address matches one in the database, Bad Behavior will block the request before it gets to the Wordpress engine, thereby conserving your CPU and bandwidth. The spammer that sent the HTTP request will get nothing in the response. This is not done by default - to enable this functionality, you need to be a member of Project HoneyPot, as you rightly mentioned. When you sign up for this Project, you will get a "key" that you need to enter in the plugin settings page to enable this functionality. Hope this helps. Regards Vijay Padiyar | How exactly does Bad Behavior plugin work? | wordpress |
i migrated a wordpress site from one domain to another. I still have images and links that seem to be pointing to my old domain name. where can i get a list of all places in wordpress that hardcode or has the domain name in it. the only place i saw was in the database in the wp_posts table in the guid column. where else should i be looking? | Don't worry about changing the guid, you'll be fine if you never update that field. The main places you'll need to update are in the post_content column of wp_posts (for links and images), and in the wp_options table (for widget data). Before you do any database replacing, though, read through this thread: stackexchange-url ("Easily Move a WordPress Install from Development to Production?") There are some helpful tips there, and there are plugins that will do most of the work for you. | how do i find out why links point to my old domain | wordpress |
I am using wordpress mu. My blog administrators are unable to edit users - getting the message: You do not have permission to edit this user. I have checked my plugins etc and cannot find the cause. Is there a solution to this problem? | this is set in wp-config.php: define( "EDIT_ANY_USER", true ); | You do not have permission to edit this user | wordpress |
I have inherited a situation where our team supports over 100+ separate WordPress installs for various clients. I am looking to make the whole process a bit more efficient. For all of those in a similar situation of managing a large number of Wordpress installs: Are there any tools or techniques that are helpful? The thought of migrating all of these to 3.0.2 by logging in or writing a script from scratch both sound particularly unappealing. | Well it depends on how/where they are hosted. If if they are hosted on different servers or the same I would still use the command line and a script file. If they all have different usernames/passwords you going to have to write a lot. Pre-planning will save you a ton of time in maintenance. First it would be best to get some data on all the sites, for instance versions. Here is an example of a script file for multiple servers, http://www.cyberciti.biz/tips/execute-commands-on-multiple-linux-or-unix-servers.html but in your case you would do something like <code> grep wp_version wp-includes/version.php </code> to get all the version info. Of course if they all have diff admin passwords you would have to include each one. An alternative would be to write a script to crawl the sites to grab the meta generator tags ( though they are sometimes disabled). I would also do a mass backup using the command line and a similar script, possibly automated to a date based dir and using an sql dump. You can then also update to the latest version for all 100+ servers using a command to run a script file. The big drawback would by incompatible plug-ins/themes or if any core code was edited, this is why I would try and gather as much data as possible to avoid any issues with keeping them up to date. I do not know of anyway to automate getting a list of active plugins though, so you might have to manually get some info and hopefully you have command line access to the sites. It might take a while to set this and and perfect it, but the benefit is that you can tell your boss it takes 2 weeks, and that will leave you with 1.9 weeks of free time. | Adminstering Large Number of Wordpress Sites | wordpress |
Title is little bit :S sorry :) For example,we have paginate links function that output html something like this <code> <span class='page-numbers current'>some number</span> </code> How can I filter that,to remove that span,class,to apply my own html tags,styles,tnx in advance.I just want to apply my own styles and html tags,is this possible? | Use a custom pagination function: my source: <code> function fb_paging_bar( $args = array() ) { $defaults = array( 'range' => 4, 'custom_query' => FALSE, 'previous_string' => __( '&laquo;&laquo;&laquo;', FB_GREYFOTO_TEXTDOMAIN ), 'next_string' => __( '&raquo;&raquo;&raquo;', FB_GREYFOTO_TEXTDOMAIN ), 'view_fp' => TRUE, 'view_lp' => TRUE, 'before_output' => '<div class="postlink">', 'after_output' => '</div>' ); $args = wp_parse_args( $args, apply_filters( 'fb_paging_bar_defaults', $defaults ) ); $args['range'] = (int) $args['range'] - 1; if ( !$args['custom_query'] ) $args['custom_query'] = @$GLOBALS['wp_query']; $count = (int) $args['custom_query']->max_num_pages; $page = intval( get_query_var( 'paged' ) ); $ceil = ceil( $args['range'] / 2 ); if ( $count <= 1 ) return FALSE; if ( !$page ) $page = 1; if ( $count > $args['range'] ) { if ( $page <= $args['range'] ) { $min = 1; $max = $args['range'] + 1; } elseif ( $page >= ($count - $ceil) ) { $min = $count - $args['range']; $max = $count; } elseif ( $page >= $args['range'] && $page < ($count - $ceil) ) { $min = $page - $ceil; $max = $page + $ceil; } } else { $min = 1; $max = $count; } $echo = ''; $previous = intval($page) - 1; $previous = esc_attr( get_pagenum_link($previous) ); if ( $previous && (1 != $page) ) $echo .= '<a href="' . $previous . '" title="' . __( 'previous', FB_GREYFOTO_TEXTDOMAIN) . '">' . $args['previous_string'] . '</a>'; $firstpage = esc_attr( get_pagenum_link(1) ); if ( $args['view_fp'] && $firstpage && (1 != $page) ) $echo .= '<a href="' . $firstpage . '">' . __( 'First', FB_GREYFOTO_TEXTDOMAIN ) . '</a>'; if ( !empty($min) && !empty($max) ) { for( $i = $min; $i <= $max; $i++ ) { if ($page == $i) { $echo .= '<span class="active">' . str_pad( (int)$i, 2, '0', STR_PAD_LEFT ) . '</span>'; } else { $echo .= sprintf( '<a href="%s">%002d</a>', esc_attr( get_pagenum_link($i) ), $i ); } } } if ($args['view_lp']) { $lastpage = esc_attr( get_pagenum_link($count) ); if ( $lastpage && ($count != $page) ) { $count = str_pad( (int)$count, 2, '0', STR_PAD_LEFT ); $echo .= '<a href="' . $lastpage . '">' . __( 'Last', FB_GREYFOTO_TEXTDOMAIN ) . '(' . $count . ')' . '</a>'; } } $next = intval($page) + 1; $next = esc_attr( get_pagenum_link($next) ); if ($next && ($count != $page) ) $echo .= '<a href="' . $next . '" title="' . __( 'next', FB_GREYFOTO_TEXTDOMAIN) . '">' . $args['next_string'] . '</a>'; if ( isset($echo) ) echo $args['before_output'] . $echo . $args['after_output']; } </code> also you can hook inside the function for custom format and variables. also an example: <code> function change_fb_paging_bar_defaults($args) { $args['previous_string'] = ''; // empty string $args['next_string'] = ''; return $args; } add_filter('fb_paging_bar_defaults', 'change_fb_paging_bar_defaults'); </code> in your template sonly use the function: <code> fb_paging_bar(); </code> | Add filter on html tags,attributes on specific function in wordpress | wordpress |
Recently, I had to move to another domain and had to recreate all my MySQL tables on the enw server. I noticed that for some posts, the number of comments is doubled. Example - http://inversekarma.in/scraps/you-dont-mess-with-the-rajinikanth/. In the above post, there's only 4 comments, but the comment count shoes 8 comments. I am not sure it is not a theme-related issue, as this happens only for a few posts. Can someone show me how to write a MySQL query to recount the comments for all posts? Or maybe a plugin? | Try this code: WARNING: THIS IS JUST PSEUDOCODE! <code> $entries = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_type IN ('post', 'page')"); foreach($entries as $entry) { $post_id = $entry->ID; $comment_count = $wpdb->get_var("SELECT COUNT(*) AS comment_cnt FROM wp_comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'"); $wpdb->query("UPDATE wp_posts SET comment_count = '$comment_count' WHERE ID = '$post_id'"); } </code> Or you might want to try solution from this page (although it's not the proper way as you will add another query for every post) | Resetting comment count | wordpress |
I've got a custom meta box for a custom post type which will be the only metabox I plan to show in the main column (except the native title box). I want to move the native Expert box/field inside my Custom Meta Box. I'm able to create a field called Excerpt in my Meta Box, however I only know how to save this to the Custom Fields, not the original location that the native Except saves to. | Just name the field 'excerpt'. E.g.: <code> <textarea name="excerpt" id="excerpt"><?php echo esc_html( '$post->post_excerpt' ); ?></textarea> <!-- if it is a textarea field --> </code> or <code> <input name="excerpt" id="excerpt" value="<?php echo esc_attr( '$post->post_excerpt' ); ?>" /> <!-- if it is a text field --> </code> | Replace the Post Excerpt Meta Box with a Field in My Custom Meta Box | wordpress |
I have two custom meta fields that I've enabled for each post, scottb_customHeader and scottb_customTitle These work fine as long as I'm using the full edit feature to edit posts. However, when I click "Quick Edit", then click "Update", my custom meta values for the post are cleared out. What do I need to do to resolve? Code is below... <code> add_action('save_post', 'custom_add_save'); function custom_add_save($postID){ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $postID; } else { // called after a post or page is saved if($parent_id = wp_is_post_revision($postID)) { $postID = $parent_id; } if ($_POST['scottb_customHeader']) { update_custom_meta($postID, $_POST['scottb_customHeader'], '_scottb_customHeader'); } else { update_custom_meta($postID, '', '_scottb_customHeader'); } if ($_POST['scottb_customTitle']) { update_custom_meta($postID, $_POST['scottb_customTitle'], '_scottb_customTitle'); } else { update_custom_meta($postID, '', '_scottb_customTitle'); } } } function update_custom_meta($postID, $newvalue, $field_name) { // To create new meta if(!get_post_meta($postID, $field_name)){ add_post_meta($postID, $field_name, $newvalue); }else{ // or to update existing meta update_post_meta($postID, $field_name, $newvalue); } } </code> | Add a hidden flag to the post edit form along with your custom fields. Something like <code> <input type="hidden" name="my_hidden_flag" value="true" /> </code> Then, wrap all of your custom save_post stuff in a check for this flag. Then you don't have to check for the autosave constant any more either--if the flag doesn't exist, it's either a quick edit or an autosave. <code> function custom_add_save($postID){ // Only do this if our custom flag is present if (isset($_POST['my_hidden_flag'])) { // called after a post or page is saved if($parent_id = wp_is_post_revision($postID)) { $postID = $parent_id; } if ($_POST['scottb_customHeader']) { update_custom_meta($postID, $_POST['scottb_customHeader'], '_scottb_customHeader'); } else { update_custom_meta($postID, '', '_scottb_customHeader'); } if ($_POST['scottb_customTitle']) { update_custom_meta($postID, $_POST['scottb_customTitle'], '_scottb_customTitle'); } else { update_custom_meta($postID, '', '_scottb_customTitle'); } } } </code> | "Quick Edit" > update clears out my custom meta values | wordpress |
I am trying to run an automatic update from Wordpress 3.0 to 3.02. However, I get the following error message: "Unable to locate WordPress Root directory. Installation Failed" I also cannot install plugins on the same server. The error message for the plugins is quite similar: "Plugin could not be deleted due to an error: Unable to locate WordPress Plugin directory." I have contacted the host but they have not been much help. Any ideas would be greatly appreciated. Thank you! Jeff | Jeff, unfortunately this looks like a problem with your hosting setup, so your host will be the only one who can help. If they can't, and the problem doesn't correct itself, I'd recommend exporting your site and moving to a more supportive host. In the meantime, though, who is your current host? If you have FTP access, try manually updating a plug-in by transferring the new files to your server. If that works, then you can manually update WordPress using the standard upgrade instructions . If you don't have FTP access and still can't auto-update, there's not much more we can do without going through your host directly. | Automatic updates not working/plugins not installing | wordpress |
How can I remove the Featured Image meta box? I've tried using the <code> remove_meta_box </code> function and specifying the boxes ID but it doesn't seem to work like it does for the other native meta boxes. Here is the specific code I tried: <code> add_action( 'admin_menu', 'remove_thumbnail_box' ); function remove_thumbnail_box() { remove_meta_box( 'postimagediv', 'post', 'side' ); } </code> | I haven't had time to test this but this looks like it should work for you. <code> add_action('do_meta_boxes', 'remove_thumbnail_box'); function remove_thumbnail_box() { remove_meta_box( 'postimagediv','post','side' ); } </code> Check this for more info. Edit: The main change here is that you need to attach the function to do_meta_boxes instead of admin_menu | Remove the Featured Image Meta Box | wordpress |
I had used the ZD Video Plugin for WP a long time, and now, since my move to WP 3.0.2, it doesn't work anymore. To embed a YouTube video using the plugin, I would just write [zdvideo]url-of-youtube-video[/zdvideo] Now I need to go back to plain YouTube embedding. How do I write a MySQL query that searches for <code> [zdvideo]*[zdvideo] </code> and replaces it with <code> * </code> ? | What about these two queries? <code> UPDATE wp_posts SET post_content = REPLACE(post_content, '[zdvideo]', ''); UPDATE wp_posts SET post_content = REPLACE(post_content, '[/zdvideo]', ''); </code> | Search and replace text across all posts | wordpress |
I have a plugin that I use on all my new sites to set up site defaults (deletes the "hello world" post, the "about" page, the "Mr WordPress" comment, etc...) I'd like to add a routine that removes all the default links under "Blogroll". I'm not sure what function to call. Any ideas? | Haven't tested this yet, but it should do the trick in 3x: <code> // Get all the existing links $arr_args = array( 'hide_invisible' => 0 ); $arr_links = get_bookmarks( $arr_args ); // Run through the list and delete 'em foreach($arr_links as $obj_link) { wp_delete_link($obj_link->link_id); } </code> Of course, you'd only want to do this once, and only on a fresh install as it deletes all links. Alternately, you could hardcode an array of default link slugs/ids and loop through that instead. Depends where and when you're running this thing. | Remove Default Blogroll Links via Plugin script | wordpress |
Here's the setup: The client uses a proprietary custom-coded PHP CMS and is wanting to move to WordPress with BuddyPress. The old, custom CMS has a roster functionality, which I'm using BuddyPress custom fields to replace. The custom fields are basic contact info (Phone, Fax) and company info (Text field). What is the best way to import these? It seems my two options are: Create a pretty large SQL query that reformats this data between databases (I'm about 3 hours into doing it this way so far) Export it into some sort of JSON format and use the Ning importer. If the best option is using the Ning importer, know where I can get an example Ning user list CSV so I may format the user data accordingly? If the best option is using a big MySQL query, what are some things I should look at in terms of row values WordPress expects? Many thanks! | I ended up writing a bunch of MySQL statements. My process went: Add users into wp_users. Add first name into wp_usermeta. Add last name into wp_usermeta. Add nickname into wp_usermeta. Add last activity into wp_usermeta. (This is important for BuddyPress; otherwise, users won't show up in the members-loop) Add name to BuddyPress. Add custom "phone" field to BP. Add custom "fax" field to BP. Add custom "company" field to BP. If anybody doing something similar comes across this question and would like the SQL I used, feel free to message me. After half a dozen people requested the SQL code I have, I've written a blog post that includes the full SQL I used, plus a basic importer script. See: http://aendrew.com/content/importing-proprietary-user-database-buddypress-boss | Importing users to Buddypress with custom fields | wordpress |
I'm sure there is a simple reason/answer for this: Why does <code> echo 'Archive for '. the_time('Y'); </code> give me <code> 2010Archive for </code> ? I had expected it would give me <code> Archive for 2010 </code> | As most template tags that start with <code> the_ </code> this one echoes time and not returns it (which template tags that start with <code> get_the_ </code> do). First <code> the_time() </code> fires and echoes year, then its return ( <code> null </code> ) gets concatenated and echoed with string. So: <code> echo 'Archive for '; the_time('Y'); </code> Or: <code> echo 'Archive for ' . get_the_time('Y'); </code> | Why does this echo values in the wrong order? | wordpress |
Does anyone know of a way to add code to the functions.php file which will automatically force all posts belonging to a custom post type to be "private" and/or "password protected" with a default password set? I am specifically referring to creating a new post or editing an existing post thus ensuring a post belonging to a specific custom post type never changes... | You can hook onto <code> save_post </code> , <code> wp_insert_post </code> or <code> wp_insert_post_data </code> to modify the post object prior to it being inserted or saved. Using <code> save_post </code> or <code> wp_insert_post </code> the callback would need to declare two args and would receive the post object as the second incoming variable.. (and i'm showing you to cover the alternatives, TheDeadMedic's example would be fine to). For setting default values for a particular post type for new posts you can use a small hack by hooking onto <code> default_content </code> (although <code> default_title </code> would also work to), like the example i gave stackexchange-url ("here"). You essentially need two functions, one to modify post objects at the time of save/insert and one to set default post object values, here's an example of the two necessary functions(again noting you can swap my save_post callback for the example already given by TheDeadMedic). <code> add_action( 'save_post', 'check_type_values', 10, 2 ); function check_type_values( $post_id, $post ) { if( $post->post_type ) switch( $post->post_type ) { case 'my_custom_type': $post->post_status = 'private'; $post->post_password = ( '' == $post->post_password ) ? 'some_default_when_no_password' : $post->post_password; break; } return; } add_filter( 'default_content', 'set_default_values', 10, 2 ); function set_default_values( $post_content, $post ) { if( $post->post_type ) switch( $post->post_type ) { case 'my_custom_type': $post->post_status = 'private'; $post->post_password = 'some_default_password'; break; } return $post_content; } </code> Hope that helps... | Forcing all posts associated with a custom post type to be private | wordpress |
I have a plugin which creates a new database table. Upon activating the plugin is there a way to insert all my posts ids into that table? Right now I'm using an action hook to immediately insert the id of new posts I publish. <code> function transfer_post_id($post_ID) { global $wpdb; if (!($wpdb->get_row("SELECT post_id FROM $my_table WHERE post_id = $post_ID" ) ) ) { //if post id not already added $wpdb->insert( $my_table, array( 'post_id' => $post_ID ) ); } return $post_ID; } add_action ( 'publish_post', 'transfer_post_id' ); </code> However there are posts before activating the plugin that I need a way to insert without manually updating each one. | Like so: <code> INSERT INTO $mytable (post_id) SELECT ID FROM $wpdb->posts as posts LEFT JOIN $mytable as dup_check ON dup_check.post_id = posts.ID WHERE dup_check.post_id IS NULL; </code> | Insert all post IDs in new database table | wordpress |
I'm working on a site that has been running for few years and had different maintainers so it's kind of a mess. What I found weird is a lot of entries in <code> wp_postmeta </code> where all the keys are numeric and contain a string like this: <code> wpAjaxe17fbeda4c811052694cd66e93bf1868f720040882f22c2bba8432e030f010c8069596982baf4cc001345db989c7f98c </code> where <code> wpAjax </code> is the fixed part and the rest is a sequence of hexadecimal values (or so they seem). These entries are 1170 and the <code> meta_key </code> ranges from 45511 to 46788 and the last post (as in the one with the greatest ID) referred to one of these meta keys is dated almost three years ago, so I think they might have been created by some plugin which has been long forgotten now. Is there any way to find out if any plugin uses those kind of meta values? I did a search but found nothing. I'd like to know if they're safe to delete because they seem useless and also mess up the post creation page as they fill the custom field dropdown select (I had to modify the code to exclude numeric meta keys). | The best way to know which plugin was adding them is to search/grep your installation for occurrences of <code> 'wpAjax' </code> and <code> "wpAjax" </code> . If you find none (which is likely, since the oldest is 3 years old) safely <code> delete from wp_postmeta where meta_key like 'wpAjax%' </code> , or something along those lines, if the latter statement might match something it shouldn't... (Don't forget to flush memcached along the way if you're using it.) | Uknown meta entries in wp_postmeta | wordpress |
( Moderator's note: The original title was "drop down taxonomy") I want to add a drop-down box filled with my custom taxonomies, so when someone selects any value, it redirects to corresponding page. I tried out this code, which worked <code> <?php wp_dropdown_categories( array( 'taxonomy' => 'name of taxonomy' ) ); ?> </code> The problem is I want a the page to redirect without the user needing to press any buttons. How can I do this? this question was resolved but i want to modify further, i want to add a shortcode, so that i can also call drop-down-list into my post, i tried this but not working <code> add_shortcode('drop','the_taxonomy_dropdown'); </code> but when i call this in my post <code> [drop="location"] </code> its not working, whats the problem? | Hi @ntechi: Here's a function I wrote which I named <code> the_taxonomy_dropdown() </code> to give you what I think you are looking for. <code> function the_taxonomy_dropdown($taxonomy) { $id = "{$taxonomy}-dropdown"; $js =<<<SCRIPT <script type="text/javascript"> jQuery(document).ready(function($){ $("select#{$id}").change(function(){ window.location.href = $(this).val(); }); }); </script> SCRIPT; echo $js; $terms = get_terms($taxonomy); echo "<select name=\"{$id}\" id=\"{$id}\">"; foreach($terms as $term) { echo '<option value="'; echo get_term_link(intval($term->term_id),$taxonomy); echo '">' . "{$term->name}</option>"; } echo "</select>"; } </code> You can put <code> the_taxonomy_dropdown() </code> in your theme's <code> functions.php </code> file and call it from one of your theme's template files like so: <code> <?php the_taxonomy_dropdown('name of taxonomy'); ?> </code> Notice I didn't use <code> wp_dropdown_categories() </code> because it sets the <code> <option> </code> 's values to <code> term_id </code> instead of the term's permalink. You need the permalink in order to set the <code> window.location.href </code> on the client end. Had we used <code> wp_dropdown_categories() </code> it have would added more complexity; it would have required issuing an HTTP GET request with <code> term_id </code> to a page on the server that would then redirect to the term's permalink. But it's much easier to just build the HTML <code> <select> </code> ourselves as I did (and it's more peformant, since it doesn't take an extra HTTP request.) Of course, be sure to remember <code> wp_enqueue_script() </code> jQuery in an <code> 'init' </code> hook, also in your theme's <code> functions.php </code> file: <code> add_action('init','jquery_init'); function jquery_init() { wp_enqueue_script('jquery'); } </code> | Redirect to Post List by Taxonomy on User Selection of Taxonomy Dropdown? | wordpress |
I'd like to modify the properties of a registered style(or script - same applies) before it's been loaded. Right now i'm trying to modify a registered style just before it gets enqueued, so i can point it at another file(ie. change the <code> src </code> property, maybe others to). Looking for some ideas specifically about where to hook on and modify the <code> $wp_styles </code> object so that the enqueue fire as normal, but with my changes to the registered style's properties. I'm making an admin color scheme and thought it would be awesome if i could rewrite/tweak the existing enqueue, instead of adding an additional request to every page(ie. colors-fresh.css + my stylesheet - i'd rather have one request, why include the original stylesheet only to redefine every style in another)... Unregister the style and register my own? - I'd then have to unregister both color schemes(classic/fresh) when i'd prefer to simply hook on and tweak the styles object before the enqueue fires. I'm pretty sure it's possible, but simply lacking the brain power to wrap my head around it right now.. (been wired in too long).. Any suggestions welcome.... ;) | Modify a registered style's path I wanted to tweak the path to one of the WordPress admin stylesheets so i could keep requests down, and because it makes little sense to include two stylesheets, when the one i'm calling redefines all the styling in the stylesheet enqueued by WordPress. The idea is basically to re-point the existing style at a different stylesheet, two hooks are appropriate <code> style_loader_src </code> <code> style_loader_tag </code> . The former provides just the stylesheet URL(or path) and the handle(that's the name the style is registered with), the latter provides the complete HTML string(and handle) for the stylesheet being included. I decided to use <code> style_loader_src </code> to switch the colors stylesheet path(src) because that's literally all i need, to adjust the path and know the current handle, so suits my needs perfectly. Example filter that changes the path to the colors stylesheet. Checks if the handle is the colors stylesheet, and updates the path when it is. <code> function switch_stylesheet_src( $src, $handle ) { if( 'colors' == $handle ) $src = plugins_url( 'my-colors.css', __FILE__ ); return $src; } add_filter( 'style_loader_src', 'switch_stylesheet_src', 10, 2 ); </code> The above filter will basically take the existing colors stylesheet output, eg. <code> <link rel='stylesheet' id='colors-css' href='http://example.com/wp-admin/css/colors-fresh.css?ver=20100610' type='text/css' media='all' /> </code> And convert it to.. <code> <link rel='stylesheet' id='colors-css' href='http://example.com/wp-content/plugins/my-plugin/my-colors.css' type='text/css' media='all' /> </code> I find this method preferable to enqueuing an additional stylesheet, it's one less requests, and there's far less CSS overrides required in whatever styling you're doing, because you're essentially hijacking that request to load your own stylesheet instead. | Is it possible to change the attributes of a registered style or script before it fires? | wordpress |
My shopping cart is being cached by w3 total cache. This is the expected default behaviour. The thing is I can't find an easy solution for this. I am showing my shopping cart on almost every page, so using rejected cookies or something similar is not an option. Is it possible to tell w3 total cache not to cache a single php file like cart_widget.php? Or some other workaround? I know there is the possibility to load the cart via ajax as the plugin does not cache GET requests with parameters (by default). Still, I would like to avoid that extra request. EDIT: Also, w3 total cache is not regenerating the page when I edit the product, is there an easy way to tell w3 total cache to empty the cache for a single page? | W3 Total Cache is a very advanced plugin that has built in ways to handle almost any situation. To exclude a page from being cached use one of the following commands below: <code> define('DONOTCACHEPAGE', true); Disables page caching for a given page. define('DONOTCACHEDB', true); Disables database caching for given page. define('DONOTMINIFY', true); Disables minify for a given page. define('DONOTCDN', true); Disables content delivery network for a given page. define('DONOTCACHCEOBJECT', true); Disables object cache for a given page. </code> To make W3 Total empty the cache on your product edit you can hook the following function in when the product is saved: <code> w3tc_pgcache_flush_post($post_id); </code> To implement fragment caching wrap the functions or lines of code that you don't want to cache in an mfunc: <code> Example 1: <!-- mfunc any PHP code --><!-- /mfunc --> Example 2: <!-- mfunc -->any PHP code<!-- /mfunc --> Example 3: <!--MFUNC --> echo rand(); <!--/mfunc --> Example 4: <!-- mclude path/to/file.php --><!-- /mclude --> Example 5: <!-- mclude -->path/to/file.php<!-- /mclude --> </code> | WP-e-Commerce and W3-Total-Cache integration problem | wordpress |
I'm using the mysql GREATEST() function to compare two table fields and display in a loop either one with the highest integer value. The 2 fields consist of vote scores for posts: UP or DOWN. <code> function vote_results($post_id) { global $wpdb; $table = $wpdb->prefix . "post_votes"; $results = $wpdb->get_row( "SELECT GREATEST (up, down) FROM $table WHERE voted_post_id = $post_id" ); echo $results->up; //echo if highest value echo $results->down; //echo if highest value } </code> Then in my loop I call the function but get <code> Notice: Undefined property: stdClass::$up </code> for <code> echo $results->up; </code> and the same notice for <code> down </code> . I'm not sure what I'm doing wrong here. | I think you want to use <code> get_var() </code> , not <code> get_row() </code> - looking at the documentation , MySQL's <code> GREATEST </code> just returns a single value. <code> $results </code> will then just be the value of the greatest (be it <code> up </code> or <code> down </code> ). If you want the greatest <code> up </code> and the greatest <code> down </code> , use; <code> $wpdb->get_row("SELECT GREATEST(up) AS 'up', GREATEST(down) AS 'down' ...") </code> | greatest() function returns undefined property | wordpress |
What are the capabilities that a super-administrator has that an administrator does not have? The codex page on user capabilities does not have a list of capabilities of the super-admin. It lists only the capabilities of the administrator. | The super_admin has access to all admininstrator APIs and also the multi-site functions. If you go to the codex page, it will say so: http://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table You can find the multisite functions here: http://codex.wordpress.org/Function_Reference#Multisite_functions If you want to do a more fine-grain investigation of what it can call, I suggest you get familiar with the WP code. The funtion you should grep for is_super_admin Hope this helps. | What are the differences in capabilities between the super-administrator and administrator? | wordpress |
( Moderator's note: The original title was: "submit button in wordpress.") I'd like to create a registration form to send an email. I've tried Contact Form 7 but I would like to use my own HTML <code> <form> </code> . I can do the entire coding but I just want to know the code for the "submit" button so that the registrations goes directly to my admin email ID as I don't think the normal HTML code for the submit button will work. Can anyone help me out in this? | Hi @ntechi: While you might be able to do something on the client with jQuery I think your best bet would be to use the Post/Redirect/Get Pattern and submit your registration form via a <code> <form method='post'> </code> action. The code after the screenshot below is a " Page Template " for a " Page " illustrates how to achieve what you've asked for with WordPress. Copy the code to your theme directory as <code> page-contact-form.php </code> (or some other name you like better) and then create a page that has template set to "Contact Form" as you see in the screenshot (note I kept the page template as simple as possible to illustrate the technique; you'll typically have a lot more code in your real live page templates): <code> <?php /* Template Name: Contact Form */ define('ADMIN_USER','mikeschinkel'); if (count($_POST)) { $admin_user = get_userdatabylogin(ADMIN_USER); $registered_email = $_POST['email']; wp_mail($admin_user->user_email, 'New Site Registration', "New Site Registration:\n\tEmail: {$registered_email}."); } ?> <?php get_header(); ?> <?php if (count($_POST)): ?> <p>Hey <?php echo $_POST['email']; ?>, thanks for registering!</p> <?php else: ?> <form method="post"> Email: <input type="text" name="email" /> <input type="submit" value="Register" /> </form> <?php endif; ?> <?php get_footer(); ?> </code> After you've created your page with the above page template it might look something like this on your external site: And this might be what it looks like after a visitor registers: | Programming WordPress to Send an Email on Registration Form Submit? | wordpress |
I've just moved a site I'm developing to WP3.1 so that I can take advantage of and start testing some of the new features. I'm especially liking the <code> has_archive </code> parameter in registering custom post types. I had a post type called 'recipes', and added this line to the args on registering it: <code> 'has_archive' => 'recipe-listings', </code> From what I understand, that should generate the rewrite rules necessary to make /recipe-listings/ be equivalent to /?post_type=recipe . However, I can't seem to get it working. The generic form http://amritafood.com/?post_type=recipe works fine, but http://amritafood.com/recipe-listings/ just goes to 404. What else do I need to do to get custom post type archives working properly? Has anyone else worked it out yet? | I asked the question too soon. And thanks to @Jan Fabry for pointing me in the right direction. In case anyone else has this problem, here's the answer. Any time the rewrite rules are changed (adding a new post type, changing the slug or the has_archive slug, etc.) you have to call <code> flush_rewrite_rules </code> once. It has to be called after the post types are registered. I put it at the very end of my function which registered the post types on 'init', visited the site once, then deleted it out. Now the site works fine. | Setting up custom post type archives in WP3.1? Any luck? | wordpress |
Guys I know this is the stupid question but need a little help, I need to put ads on my homepage as I have on my post page: These are the ads I get on my post page (i.e <code> single.php </code> ). I also want the same thing on my home page over here: I tried using a <code> <div> </code> tag like I did on <code> single.php </code> , but it is not working. | How do you have your home page set up and what template are you trying to modify? Usually it is <code> index.php </code> or <code> home.php </code> , but it can also be <code> front-page.php </code> or even something completely different from defaults. See Template Hierarchy in Codex. | How can I add Google ads to my home page? | wordpress |
Which files do i edit to make the textarea for tag & cat description bigger? Or maybe there's an easier way through functions.php to save having to do it every-time i update wp? Thanks | Hook onto the edit-tags page and insert some additional styling to adjust the textarea, the ID remains the same for post tags, categories and i think other taxonomies to.. Adjust CSS for taxonomy management page Example only, tailor to suit you needs. <code> add_action( 'admin_print_styles-edit-tags.php', 'resize_description_field' ); function resize_description_field() { ?> <style type="text/css"> textarea#tag-description { height:300px!important; } </style> <?php } </code> Hope that helps.. | Making the category & tag Description textarea bigger | wordpress |
i have a form which is displayed after every post, so i coded it in single.php, but the form is too long so i thought of putting it in jquery section, where if the user wants then he/she can click on open and the form will slide down for this purpose i used slide up/down jquery http : //api . jquery . com/slideDown/ i integrated the jquery in proper order in header.php, here is my header.php jquery code <code> <?php wp_enqueue_script("jquery"); ?> <?php wp_head(); ?> <script type="text/javascript" src="<?php bloginfo("template_url"); ?>/functions/js/jquery-1.4.4.js"></script> <script> $(document.body).click(function () { if ($("h6:first").is(":hidden")) { $("h6").slideDown("slow"); } else { $("h6").hide(); } }); </script> <?php woo_head(); ?> </code> and this is my single.php code, ` <code> <div class="post"> <p><h6> <?php echo do_shortcode("[contact-form 2]"); ?></h6> </p> </div> </code> ` but after doing all this thing my sidebar i.e woo_tabs is not proper you can check the image http://i52.tinypic.com/2gxe90p.jpg here my woo tabs instead of coming side by side, it is coming down, is my code right? | Trim your above code down to.. <code> <?php wp_enqueue_script( "my_script", plugins_url( '/your-script-name.js', __FILE__ ), array( 'jquery' ) ); ?> <?php wp_head(); ?> <?php woo_head(); ?> </code> Place your jQuery into a JS file, then enqueue it with jQuery as a dependancy(as above), this will ensure jQuery is loaded before your script is. Your script also needs to use a no-conflict wrapper , and should be updated to read.. <code> jQuery(document).ready(function($){ $('a#my_id').click(function () { if($("h6:first").is(":hidden")) $("h6").slideDown("slow"); else $("h6").hide(); return false; }); }); </code> Or something to that degree.. NOTE: This is wrong.. <code> <?php wp_enqueue_script("jquery"); ?> <script type="text/javascript" src="<?php bloginfo("template_url"); ?>/functions/js/jquery-1.4.4.js"></script> </code> By doing that you're instructing WordPress to load the included version of jQuery, and then also including your own, so essentially you're loading two versions of jQuery(you only need one, i'd suggest the one WordPress ships with - per above suggested code). Hope that helps.. :) EDIT: jQuery updated inline with request in comments. Accompanying HTML for link to work inline with jQUery. <code> <a id="my_id" href="#showform">My Special Link</a> </code> NOTE: I'm still unclear exactly what this jQuery needs to do for you, so i've simply updated the code posted earlier, i hope that's what you're aiming for... else please please clarify with more details. | need jquery help | wordpress |
I would like to know if it is possible to host a wordpress blog on the subdirectory of a rails application: For instance: I would like to have domain.com/blog instead of having my blog on a subdomain: blog.domain.com . I'm currently using lighttpd, but I can switch to something else if there is a solution. Thanks | You can also set an apache Alias to say /blog is /path/to/wordpress so it's technically not inside your RoR app, you can deploy/make changes to the RoR app all day long then, without the need to worry about overwriting wordpress files. | Host wordpress on a subdirectory of a Rails application | wordpress |
I have my site hosted at http://blog.rgksugan.in . I have set a subdomain in it for my blog. But after landing on my blog whatever other links I click i get the link as http://rgksugan.in/blog/wordpress/stack-overflow/ . I want it to be http://blog.rgksugan.in/stack-overflow What should I do...? | Have you changed the site address to try and remove the wordpress from the URL? This is under Settings then General. You then have two URLs one of which is the actual physical directory and the other is the one you want to appear to the visitors to your website. This should allow you to remove the 'wordpress' element from your public URL, unless I am not understanding your question correctly and there is more to this than meets my eye? | How to solve this problem with my subdomain? | wordpress |
I have come across a function before that displayed the exact SQL code that was used in a loop for example, but can't remember. Can anybody tell me that function? Cheers | Hi @Keith Donegan: If I understand your question correctly I think this is what you are looking for? <code> <?php echo $GLOBALS['wp_query']->request; ?> </code> <code> $wp_query </code> is a global variable that contains the current query run by the loop. If you run the above code anytime while the loop is still active or even right after the loop it should give you the SQL from the loop. Just make sure you inspect it before letting something else run that uses <code> query_posts() </code> again. | How to display sql query that ran in query? | wordpress |
Is there a way to limit the size (dimensions) of the image a user can upload to their profile? It looks like Wordpress does do some kind of limiting as uploading a 1024x768 image the result gets scaled down to 360x270, but where is that configured, either in the UI (which I haven't found) or through code? This is the section of the user profile I'm referring to: | It looks like the author image section of the User Profile editor was from the " Author Image " plugin. I didn't suspect that at first because I didn't know that plugins were allowed to modify that screen, so I thought it was just a build-in Wordpress function and that the plugin just allowed for easy display. As it doesn't look like the plugin has a settings page I ended up just modifying the plugin itself. For those curious, the file to modify is <code> sem-author-image-admin.php </code> and the variable is about 3/4 of the way down, just search for the comment <code> // Set a maximum height and width </code> and you'll find it. (There's no guarantee that this will remain the same in future versions and upgrading the plugin will most likely break this, just an FYI) | Limit author image size | wordpress |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.