question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I have attached several images to a post. When viewing the images in the theme, each image is linked to a larger version of itself. I would like to change this link to direct to a specific URL. However, when I change the URL under "Link URL" under attachment options, the link does not stick after clicking "Save All Changes". It always reverts to the link to the image itself. Is there another way to create custom links on attached images? Note: I'm not trying to alter the link TO the image, I'm trying to create a custom link href when the image is clicked.
You say you click the Save All Changes button. I think this means you are trying to edit the images via the Upload/Insert images button above the editor? It's confusing, but this is not the place to edit an individual image that you already inserted into the post. In the Gallery tab you can edit settings for the image in the shared Media browser , but not for already inserted images. You need to do that by clicking on the image and then clicking the first button that appears (showing an image). This will give you a slightly different editing window, with an Update button at the bottom. If the <code> rel </code> attribute of the image link is set to <code> attachment </code> , <code> _fix_attachment_links() </code> will replace the link with permalinks to the attachment when you save the post. So make sure that when you edit the image link, you first click the "None" button to clear this value, or go to the Advanced Settings tab and edit Link Rel so it doesn't contain <code> attachment </code> .
How can I customize the link when an attached image is clicked?
wordpress
I want to use the latest jQuery (and jQuery UI) versions on my admin interface (editing a specific post type that I created). I tried this: <code> // jQuery 1.x wp_register_script('jquery1x', 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', false, null, true); // jQuery UI 1.8.4 PTBR wp_register_script('jquery-ui-custom-pt_BR', THEME_URL . 'js/jquery.ui.datepicker-pt-BR.js', array('jquery1x'), null, true); // jQuery UI 1.8.4 wp_register_script('jquery-ui-custom', THEME_URL . 'js/jquery-ui-1.8.4.custom.min.js', array('jquery1x', 'jquery-ui-custom-pt_BR'), null, true); // jQuery UI 1.8.4 CSS wp_register_style('jquery-ui-custom-css', THEME_URL . 'css/smoothness/jquery-ui-1.8.4.custom.css'); wp_enqueue_style('jquery-ui-custom-css'); wp_enqueue_script('jquery-ui-custom'); </code> And it worked but on other WP admin pages I got some jQuery errors because the overrides of jQuery (since it's loaded twice). If I "deregister" the jQuery and register it again (using the latest) it won't work. That's not the first time that I ran into this problem... All I need is to use the latest version of jQuery on my WordPress admin interface to use some features like Datepicker and Colorpicker.. But until now I can't do this using <code> register_script </code> . If I register it with "jquery" name, it won't update because there's already a jQuery loaded by WordPress on this line: <code> &lt;script type='text/javascript' src='http://website.com/wp-admin/load-scripts.php?c=1&amp;amp;load=jquery,utils,nav-menu&amp;amp;ver=2b05c108d9016a4caa470b8edaf40953'&gt;&lt;/script&gt; </code> And I can't hack into this load-scripts.php file to change the filename since I don't want to change the WordPress core.
Starting with version 3.6 WordPress actively discourages from deregistering "critical" scripts in admin at all. For posed scope (loading newer jQuery in specific part of admin) it would make more sense to load custom copy of jQuery normally and use <code> noConflict() </code> on it right away to isolate it in own variable to be used in custom JS code. Old andswer deregister doesn't work for you because WP concatenates scripts in admin area by default. So when you make jQuery load from elsewhere it falls apart. You can disable concatenation to make it work (add conditionals as needed): <code> add_action( 'admin_init', 'jquery_admin' ); function jquery_admin() { global $concatenate_scripts; $concatenate_scripts = false; wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', ( 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' ), false, '1.x', true ); } </code> PS many thanks for trick with loading latest version from Google, I wasn't aware of it :)
Use latest jQuery in WordPress (admin interface)
wordpress
I have a WordPress custom post-type setup. I've created <code> single-[customposttype].php </code> However instead of displaying only the requested custom-post-type it goes to the URL, then displays all of the posts in the custom-type. Here's a copy of the code i'm currently using: <code> &lt;?php query_posts("post_type=shorts"); while (have_posts()) : the_post(); ?&gt; &lt;div class="header-promo"&gt; &lt;?php echo get_post_meta($post-&gt;ID, "mo_short_embed", true); ?&gt; &lt;/div&gt; &lt;div class="content-details"&gt; &lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; </code> Thanks in advance :)
Just remove <code> query_posts("post_type=shorts"); </code> from your code.
WordPress custom post type Single.php?
wordpress
I am trying to use the <code> orderby </code> parameter in the <code> get_children </code> function as below: <code> $navigation = get_children(array( 'post_parent' =&gt; $parent-&gt;ID, 'orderby' =&gt; 'menu_order' )); </code> But it is having no effect on the result; it is still ordering by the default creation date. Any ideas?
Are you sure you need this specific function? Documentation (both Codex and inline) is verrry confusing. And it supposedly fetches things like attachments, which probably aren't relevant for navigation... Try this: <code> get_posts( array( 'post_type' =&gt; 'page', 'post_parent' =&gt; $parent-&gt;ID, 'orderby' =&gt; 'menu_order' ) ); </code>
get_children() Not Working with orderby Parameter
wordpress
Can I host WordPress/WordPress MU installation on Microsoft's Azure cloud platform? Does anyone have any advice or experience hosting WordPress on Azure?
WordPress seems to be one of the poster children of PHP on Azure , so you can find many resources explaining how to install it .
Hosting WordPress on Azure?
wordpress
Please at first let me explain my question. I use wordpress to create web sites for flash games, so I don't have certain page for post's. I add each game by <code> post-new.php?post_type=game </code> and u can see it's not the regular post for wordpress. I try to use this code from codex: <code> &lt;?php if (is_page() ) { $category = get_post_meta($posts[0]-&gt;ID, 'category', true); } if ($category) { $cat = get_cat_ID($category); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $post_per_page = 4; // -1 shows all posts $do_not_show_stickies = 1; // 0 to show stickies $args=array( 'category__in' =&gt; array($cat), 'orderby' =&gt; 'date', 'order' =&gt; 'DESC', 'paged' =&gt; $paged, 'posts_per_page' =&gt; $post_per_page, 'caller_get_posts' =&gt; $do_not_show_stickies ); $temp = $wp_query; // assign orginal query to temp variable for later use $wp_query = null; $wp_query = new WP_Query($args); if( have_posts() ) : while ($wp_query-&gt;have_posts()) : $wp_query-&gt;the_post(); ?&gt; &lt;div &lt;?php post_class() ?&gt; id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;h2&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;small&gt;&lt;?php the_time('F jS, Y') ?&gt; &lt;!-- by &lt;?php the_author() ?&gt; --&gt;&lt;/small&gt; &lt;div class="entry"&gt; &lt;?php the_content('Read the rest of this entry »'); ?&gt; &lt;/div&gt; &lt;p class="postmetadata"&gt;&lt;?php the_tags('Tags: ', ', ', '&lt;br /&gt;'); ?&gt; Posted in &lt;?php the_category(', ') ?&gt; | &lt;?php edit_post_link('Edit', '', ' | '); ?&gt; &lt;?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;div class="navigation"&gt; &lt;div class="alignleft"&gt;&lt;?php next_posts_link('« Older Entries') ?&gt;&lt;/div&gt; &lt;div class="alignright"&gt;&lt;?php previous_posts_link('Newer Entries »') ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php else : ?&gt; &lt;h2 class="center"&gt;Not Found&lt;/h2&gt; &lt;p class="center"&gt;Sorry, but you are looking for something that isn't here.&lt;/p&gt; &lt;?php get_search_form(); ?&gt; &lt;?php endif; $wp_query = $temp; //reset back to original query } // if ($category) ?&gt; </code> I think it really have to works for posts, but in such case I try to change post for games, try many ways, but don't sucseed yet. Could anyone tell me what I have change in this code? i think that promblem in the begining with 'have post' and 'the loop'. Thanks.
Add the 'post_type' parameter in your query args ( <code> 'post_type' =&gt; 'game' </code> ): <code> &lt;?php if (is_page() ) { $category = get_post_meta($posts[0]-&gt;ID, 'category', true); } if ($category) { $cat = get_cat_ID($category); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $post_per_page = 4; // -1 shows all posts $do_not_show_stickies = 1; // 0 to show stickies $args=array( 'post_type' =&gt; 'game', 'category__in' =&gt; array($cat), 'orderby' =&gt; 'date', 'order' =&gt; 'DESC', 'paged' =&gt; $paged, 'posts_per_page' =&gt; $post_per_page, 'caller_get_posts' =&gt; $do_not_show_stickies ); $temp = $wp_query; // assign orginal query to temp variable for later use $wp_query = null; $wp_query = new WP_Query($args); if( have_posts() ) : while ($wp_query-&gt;have_posts()) : $wp_query-&gt;the_post(); ?&gt; &lt;div &lt;?php post_class() ?&gt; id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;h2&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;small&gt;&lt;?php the_time('F jS, Y') ?&gt; &lt;!-- by &lt;?php the_author() ?&gt; --&gt;&lt;/small&gt; &lt;div class="entry"&gt; &lt;?php the_content('Read the rest of this entry »'); ?&gt; &lt;/div&gt; &lt;p class="postmetadata"&gt;&lt;?php the_tags('Tags: ', ', ', '&lt;br /&gt;'); ?&gt; Posted in &lt;?php the_category(', ') ?&gt; | &lt;?php edit_post_link('Edit', '', ' | '); ?&gt; &lt;?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;div class="navigation"&gt; &lt;div class="alignleft"&gt;&lt;?php next_posts_link('« Older Entries') ?&gt;&lt;/div&gt; &lt;div class="alignright"&gt;&lt;?php previous_posts_link('Newer Entries »') ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php else : ?&gt; &lt;h2 class="center"&gt;Not Found&lt;/h2&gt; &lt;p class="center"&gt;Sorry, but you are looking for something that isn't here.&lt;/p&gt; &lt;?php get_search_form(); ?&gt; &lt;?php endif; $wp_query = $temp; //reset back to original query } // if ($category) ?&gt; </code> Reference: http://codex.wordpress.org/Function_Reference/query_posts#Post_.26_Page_Parameters
Wordpress: category page not for post's
wordpress
I have created some custom widgets for my client to use, but I want to make them stand out amidst the fifteen or so standard widgets in the admin area. How can I do this? I have solved this problem myself and will place the solution here, but please feel free it add a better solution if you have one.
All widgets in the admin area get an <code> id </code> in the style <code> widget-[global_counter]_[widget_key]-[widget_id] </code> , like <code> widget-59_monkeyman_widget_shortcut-5 </code> (installed widget) or <code> widget-11_monkeyman_widget_shortcut-__i__ </code> (an uninstalled widget in the list). If your widget key contains something unique for all your widgets (like your company name), you can use this and add a substring attribute CSS selector (which works in most browsers). In my case <code> div.widget[id*=_monkeyman_] </code> does the trick, so I add a little CSS snippet in the <code> widgets.php </code> admin page header: <code> add_action('admin_print_styles-widgets.php', 'monkeyman_widgets_style'); function monkeyman_widgets_style() { echo &lt;&lt;&lt;EOF &lt;style type="text/css"&gt; div.widget[id*=_monkeyman_] .widget-title { color: #2191bf; } &lt;/style&gt; EOF; } </code> This gives me the following result:
Highlight custom widgets in the admin area?
wordpress
I have multiple "sidebars", but not all of them are the same size. Not all widgets fit in all sidebars (for example, I have a "footer sidebar" where the client can place custom widgets, but they are wide, and don't fit at all in the "real" sidebar). I want to give an indication when a widget is placed in a sidebar where it would not belong (change the header text color, for example). What would be the best way to do this?
I solved it using some CSS, similar to my trick to stackexchange-url ("highlight my own widgets"). The sidebar drop areas are <code> div </code> 's with the class <code> widgets-sortable </code> and they have the <code> id </code> of your sidebar. Your widgets are <code> div </code> 's with class <code> widget </code> , and and <code> id </code> of the form <code> widget-[global_counter]_[widget_key]-[widget_id] </code> . You can combine these to highlight correct or wrong combinations. For example, I have a sidebar called <code> footer </code> that should only contain wide widgets. These widgets are recognizable because their ID includes <code> -wide- </code> . I want these in green, and all other ones in red with a strike through. <code> add_action('admin_print_styles-widgets.php', 'print_widget_hint_style'); function print_widget_hint_style() { echo &lt;&lt;&lt;EOF &lt;style type="text/css"&gt; /* Less specific rule for all widgets */ div.widgets-sortables[id*=-footer] div.widget .widget-title { color: red; text-decoration: line-through; } /* More specific rule for correct widgets */ div.widgets-sortables[id*=-footer] div.widget[id*=-wide-] .widget-title { color: green; } &lt;/style&gt; EOF; } </code>
Limit widget to certain sidebar?
wordpress
I have created dynamic sidebars. They are working fine and appear in the Widgets area. However, I would like to customize the name that appears on each sidebar. So, right now each sidebar is named "Sidebar 1", "Sidebar 2", etc. Instead, I would like them to say something like "About Sidebar", "Toolkit Sidebar". This is not the title (that field is blank and the user can enter whatever text they please). Thank you for any help! Jeff I am not sure how to do that.
Use the 'Name' parameter in your register_sidebar call. E.g., see the following code in the default Twenty Ten theme, line 351. <code> function twentyten_widgets_init() { // Area 1, located at the top of the sidebar. register_sidebar( array( 'name' =&gt; __( 'Primary Widget Area', 'twentyten' ), 'id' =&gt; 'primary-widget-area', 'description' =&gt; __( 'The primary widget area', 'twentyten' ), 'before_widget' =&gt; '&lt;li id="%1$s" class="widget-container %2$s"&gt;', 'after_widget' =&gt; '&lt;/li&gt;', 'before_title' =&gt; '&lt;h3 class="widget-title"&gt;', 'after_title' =&gt; '&lt;/h3&gt;', ) ); // Area 2, located below the Primary Widget Area in the sidebar. Empty by default. register_sidebar( array( 'name' =&gt; __( 'Secondary Widget Area', 'twentyten' ), 'id' =&gt; 'secondary-widget-area', 'description' =&gt; __( 'The secondary widget area', 'twentyten' ), 'before_widget' =&gt; '&lt;li id="%1$s" class="widget-container %2$s"&gt;', 'after_widget' =&gt; '&lt;/li&gt;', 'before_title' =&gt; '&lt;h3 class="widget-title"&gt;', 'after_title' =&gt; '&lt;/h3&gt;', ) ); // Area 3, located in the footer. Empty by default. register_sidebar( array( 'name' =&gt; __( 'First Footer Widget Area', 'twentyten' ), 'id' =&gt; 'first-footer-widget-area', 'description' =&gt; __( 'The first footer widget area', 'twentyten' ), 'before_widget' =&gt; '&lt;li id="%1$s" class="widget-container %2$s"&gt;', 'after_widget' =&gt; '&lt;/li&gt;', 'before_title' =&gt; '&lt;h3 class="widget-title"&gt;', 'after_title' =&gt; '&lt;/h3&gt;', ) ); // Area 4, located in the footer. Empty by default. register_sidebar( array( 'name' =&gt; __( 'Second Footer Widget Area', 'twentyten' ), 'id' =&gt; 'second-footer-widget-area', 'description' =&gt; __( 'The second footer widget area', 'twentyten' ), 'before_widget' =&gt; '&lt;li id="%1$s" class="widget-container %2$s"&gt;', 'after_widget' =&gt; '&lt;/li&gt;', 'before_title' =&gt; '&lt;h3 class="widget-title"&gt;', 'after_title' =&gt; '&lt;/h3&gt;', ) ); // Area 5, located in the footer. Empty by default. register_sidebar( array( 'name' =&gt; __( 'Third Footer Widget Area', 'twentyten' ), 'id' =&gt; 'third-footer-widget-area', 'description' =&gt; __( 'The third footer widget area', 'twentyten' ), 'before_widget' =&gt; '&lt;li id="%1$s" class="widget-container %2$s"&gt;', 'after_widget' =&gt; '&lt;/li&gt;', 'before_title' =&gt; '&lt;h3 class="widget-title"&gt;', 'after_title' =&gt; '&lt;/h3&gt;', ) ); // Area 6, located in the footer. Empty by default. register_sidebar( array( 'name' =&gt; __( 'Fourth Footer Widget Area', 'twentyten' ), 'id' =&gt; 'fourth-footer-widget-area', 'description' =&gt; __( 'The fourth footer widget area', 'twentyten' ), 'before_widget' =&gt; '&lt;li id="%1$s" class="widget-container %2$s"&gt;', 'after_widget' =&gt; '&lt;/li&gt;', 'before_title' =&gt; '&lt;h3 class="widget-title"&gt;', 'after_title' =&gt; '&lt;/h3&gt;', ) ); } /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */ add_action( 'widgets_init', 'twentyten_widgets_init' ); </code>
Changing name of sidebar widget
wordpress
Ok, this is seriously weird and I have no clue what's going on here. I am using WordPress 3.0.1, I create a new blog post, give it a title, paste the following code into the blog post and hits Save Draft. <code> &lt;code lang="php"&gt; // Init curl $request = curl_init(); // Set request options curl_setopt_array($request, array ( CURLOPT_URL =&gt; 'https://www.sandbox.paypal.com/cgi-bin/webscr', CURLOPT_POST =&gt; TRUE, CURLOPT_POSTFIELDS =&gt; http_build_query(array ( 'cmd' =&gt; '_notify-synch', 'tx' =&gt; $_GET['tx'], 'at' =&gt; $your_pdt_identity_token, )), CURLOPT_RETURNTRANSFER =&gt; TRUE, CURLOPT_HEADER =&gt; FALSE, CURLOPT_SSL_VERIFYPEER =&gt; TRUE, CURLOPT_CAINFO =&gt; 'cacert.pem', )); // Execute and get the response and status code $response = curl_exec($request); $status = curl_getinfo($request, CURLINFO_HTTP_CODE); // Close curl_close($request); &lt;/code&gt; </code> Just a code example in my head, but seems like WordPress thinks otherwise, cause when I hit Save Draft, Preview or Publish all I get is a blank page with the following text: Service Temporarily Unavailable The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later. What in the world is going on here??
And of course after I ask the question, I find the solution... Apparently it's caused by a trigger happy Mod_Security. WordPress: 503 Service Temporarily Unavailable when Posting New Posts or Modifying Existing Posts Adding these lines to the .htaccess file makes it go away nicely: <code> &lt;IfModule mod_security.c&gt; SetEnvIfNoCase Request_URI ^/wp-admin/(?:post|async-upload)\.php$ MODSEC_ENABLE=Off SetEnvIfNoCase Request_URI ^/xmlrpc\.php$ MODSEC_ENABLE=Off SecFilterDebugLevel 0 SecFilterDefaultAction "deny,nolog,noauditlog,status:503" &lt;/IfModule&gt; </code>
Why does this snippet in a blog post make WordPress crash?
wordpress
I have my multisite site up and running the main site is mikewills.me . The big problem I am having is performance. It can take several seconds before anything starts showing up. Obviously, this is unacceptable. I have seen some tips like adding <code> &lt;?php flush(); ?&gt; </code> to the header. I am using the the delivered twenty ten theme. The back-end is also running slow. I am trying to determine if it is the host I am using or if it's something that I have configured wrong. Is there any additional things I can look at that may be needed in a shared host environment?
I just ran your page through the NET console on Firebug just so I could see what was loading ... and wow ... you have a lot of things loading that don't need to be. From the looks of things, the following plug-ins are adding scripts and other collateral files to your load which are slowing things down: Fancybox for WordPress RecipePress PowerPress SHJS Syntax Hiliter On top of that, you're loading a SWF JS object, but I don't see any Flash on your home page. Adding extra JavaScript will almost always impact your page load time and site performance. I'm guessing that some of these extra files are hooked on to the <code> init </code> event, and will load on admin pages as well (slowing things down there). But you probably also have a lot of plug-ins adding additional (unnecessary?) filters and hooks that are causing the ~7s load of your page's basic HTML file. Things you can do Turn off all but the most necessary plug-ins. If you're still using more than 5-6, reconsider how things are put together to try dumping a few more. Use a caching system to serve up HTML. W3 Total Cache is pretty good, and it will return static content for things that haven't changed (which means fewer database hits and filter calls = faster HTML return times). Use image sprites for your social media icons and other static images on the home page. There's no need to serve up 7 separate images (i.e. 7 separate requests) for social media and RSS images.
Poor performance on multisite install
wordpress
I have a function <code> get_images() </code> in which I would like to display all image attachments for the current post (or page) in a list with the last image having a <code> class="last" </code> attribute to mark it as the last image in the list. The code below is my first pass at getting the attached images to display, however, its only listing one image out of the loop so my foreach is botched... <code> function get_images() { global $post; $attachment = array_values(get_children(array( 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'order' =&gt; 'ASC', 'numberposts' =&gt; 1 ))); if ( $attachment ) { foreach($attachment as $attachmentImage) { echo '&lt;img src="' . wp_get_attachment_url($attachmentImage-&gt;ID) . '" class="post-attachment" /&gt;'; } } } </code>
This should do it, I think: <code> function get_images() { global $post; $attachment = get_children(array( 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'order' =&gt; 'ASC', 'numberposts' =&gt; -1 ), ARRAY_N ); if ( $attachment ) { $attachment_count = count($attachment); foreach($i=0; $i &lt; $attachment_count; $i++) { $last = ($i == ($attachment_count-1) ) ? ' last' : ''; echo '&lt;img src="' . wp_get_attachment_url($attachment[$i]-&gt;ID) . '" class="post-attachment'.$last.'" /&gt;'; } } } </code>
Display All Post Attachments and Assign Class to the Last Image?
wordpress
( Moderators note: Was originally titled "wp_nav_menu Ancestor class without children in navigation structure") I have a <code> wp_nav_menu </code> in my header which had three pages in it. When I am on one of those pages, the <code> li </code> containing that page in the menu gets the class <code> .current_page_item </code> . These three pages have templates, and these templates contain custom queries to get all posts of a certain content type. In effect, the perceived "children" of this top level page are not actually children, they're just of a content type I've associated with that top level page using a template. I'd like the top level menu items to get a <code> 'current-ancestor' </code> class when the user is browsing a single page of a specific post type, again, associated with that page only in a custom query in the template file. Hope that makes sense - if not, let me know where I lost you! Very much appreciate any help. --Edited for specifics: For example, I have a static page called Workshops that is using a template. Its slug is workshops . The template has a custom get_posts function and loop within it, which pulls and displays all posts of a custom content type called workshops . If I click on one of these workshops' title, I'm taken to the full content of that piece of content. The permalink structure of the custom post type is set to workshops/ postname , so as the user sees it, these pieces of content are children of the Workshops page, when in reality they're all of one content type but unrelated to the page. It's that gap that I need to effectively close in the menu, highlighting the 'Workshops' menu item when browsing content of type 'workshop'. Again, hope that makes sense, I think I said 'workshop' upwards of 20 times in one paragraph!
There's a simpler solution. Forget creating pages for each post type just so you can have nav items, because as you have learned, WP has no way of recognizing that the custom types you are browsing are related to that page. Instead, create a custom link in Appearance-> Menus. Just put the URL that will return your custom type and give it a label, then press "Add to Menu". <code> http://example.com/workshops/ </code> or non-pretty-permalinks: <code> http://example.com/?post_type=workshops </code> this alone will simply create a nav button which displays all posts with that custom post type, and will also add the current-menu-item class when you've clicked that nav item - but it won't yet add the nav class on any URL other than this one Then, once it's created, go into the configuration for that new item, and enter the slug of the custom post type in the "Title Attribute" field (you could also use the description field, but that one is hidden in the admin screen options by default). Now, you need to hook the <code> nav_menu_css_class </code> filter (which gets fired for each nav item) and check if the content being viewed is of the post type indicated in your custom nav item: <code> add_filter('nav_menu_css_class', 'current_type_nav_class', 10, 2 ); function current_type_nav_class($classes, $item) { $post_type = get_query_var('post_type'); if ($item-&gt;attr_title != '' &amp;&amp; $item-&gt;attr_title == $post_type) { array_push($classes, 'current-menu-item'); }; return $classes; } </code> In this case, we're going to check that the Title Attribute field contents aren't empty and if they match the current post_type being queried. If so, we add the current-menu-item class to its class array, then return the modified array. You could modify this to simply match the title of the nav item, but if for some reason you want to title the nav item differently than the plain slug of the post type, using the Title Attribute or Description field gives you that flexibility. Now any time you're viewing a single item (or probably even archive listings) of a post type that matches a nav menu item, that item will be given the CSS class current-menu-item so your highlighting will work. No pages or page templates needed ;-) The URL query takes care of fetching the right posts. Your loop template takes care of displaying query output. This function takes care of recognizing what's being shown and adding the CSS class. BONUS You can even automate the process using <code> wp_update_nav_menu_item </code> , by having menu items automatically generated for all your post types. For this example, you would need first to have retrieved the <code> $menu_id </code> of the nav menu you want this items added to. <code> $types = get_post_types( array( 'exclude_from_search' =&gt; false, '_builtin' =&gt; false ), 'objects' ); foreach ($types as $type) { wp_update_nav_menu_item( $menu_id, 0, array( 'menu-item-type' =&gt; 'custom', 'menu-item-title' =&gt; $type-&gt;labels-&gt;name, 'menu-item-url' =&gt; get_bloginfo('url') . '/?post_type=' . $type-&gt;rewrite['slug'], 'menu-item-attr-title' =&gt; $type-&gt;rewrite['slug'], 'menu-item-status' =&gt; 'publish' ) ); } </code>
Highlighting wp_nav_menu() Ancestor Class w/o Children in Nav Structure?
wordpress
Is it a problem to have a custom taxonomy and a custom post type use the same rewrite structure? I have a custom taxonomy <code> people </code> and a custom post type <code> people_bio </code> . The idea is that you get a list of posts about a person with a short biography on top of the page. I combine them in my <code> taxonomy-people.php </code> template file. The permalink is <code> /people/[person-slug] </code> . Both the custom taxonomy and the custom post type have the <code> rewrite </code> argument set to <code> array('slug' =&gt; 'people') </code> . This appears to work: <code> get_term_link('seth-godin', 'people') </code> returns <code> /people/seth-godin/ </code> , and for a custom post type with slug <code> seth-godin </code> , <code> get_permalink() </code> also returns <code> /people/seth-godin/ </code> . The taxonomy is defined first, and it seems to "win": on a <code> /people/[slug] </code> page, <code> is_tax() </code> is true, while <code> is_single() </code> is false. So, it works, but I don't feel comfortable with it. Is someone more experienced with the rewrite engine, and can you tell me whether this might break other things? The relevant part of the plugin file, called in the <code> init </code> action: <code> register_taxonomy( 'people', 'post', array( 'labels' =&gt; array( 'name' =&gt; 'People', 'singular_name' =&gt; 'Person', 'search_items' =&gt; 'Search people', 'popular_items' =&gt; 'Popular people', 'all_items' =&gt; 'All people', 'parent_item' =&gt; null, 'parent_item_colon' =&gt; null, 'edit_item' =&gt; 'Edit person', 'update_item' =&gt; 'Update person', 'add_new_item' =&gt; 'Add person', 'new_item_name' =&gt; 'New person', 'separate_items_with_commas' =&gt; 'Separate people with commas', 'add_or_remove_items' =&gt; 'Add or remove people', 'choose_from_most_used' =&gt; 'Choose from the most used people', ), 'public' =&gt; true, 'show_ui' =&gt; true, 'show_tagcloud' =&gt; true, 'hierarchical' =&gt; false, 'update_count_callback' =&gt; '', 'rewrite' =&gt; array( 'slug' =&gt; 'people', 'with_front' =&gt; true, ), 'query_var' =&gt; 'people', 'capabilities' =&gt; array(), 'show_in_nav_menus' =&gt; true, ) ); register_post_type( 'people_bio', array( 'label' =&gt; 'People Bio', 'labels' =&gt; array( 'name' =&gt; 'Biographies', 'singular_name' =&gt; 'Biography', 'add_new' =&gt; 'Add new', 'add_new_item' =&gt; 'Add new biography', 'edit_item' =&gt; 'Edit biography', 'new_item' =&gt; 'New biography', 'view_item' =&gt; 'View biography', 'search_items' =&gt; 'Search biographies', 'not_found' =&gt; 'No biographies found', 'not_found_in_trash' =&gt; 'No biographies found in trash', 'parent_item_colon' =&gt; null, ), 'description' =&gt; 'Biography pages of interesting people', 'public' =&gt; true, 'exclude_from_search' =&gt; true, 'publicly_queryable' =&gt; true, 'show_ui' =&gt; true, 'menu_position' =&gt; null, 'menu_icon' =&gt; null, 'capability_type' =&gt; 'post', 'capabilities' =&gt; array(), 'hierarchical' =&gt; false, 'supports' =&gt; array( 'title', 'editor', //'author', 'thumbnail', 'excerpt', //'trackbacks', 'custom-fields', //'comments', //'revisions', //'page-attributes', ), 'register_meta_box_cb' =&gt; null, 'taxonomies' =&gt; array(), 'permalink_epmask' =&gt; EP_PERMALINK, //'rewrite' =&gt; false, 'rewrite' =&gt; array( 'slug' =&gt; 'people', 'with_front' =&gt; true, ), 'query_var' =&gt; true, 'can_export' =&gt; true, 'show_in_nav_menus' =&gt; true, ) ); register_taxonomy_for_object_type('people', 'people_bio'); </code> (I always use all parameters with <code> register_*() </code> , many with their default values, as an extra documentation, as long as the Codex is not up-to-date) The <code> taxonomy-people.php </code> template file: <code> &lt;?php get_header(); $people_biography = get_posts(array( 'numberposts' =&gt; -1, 'post_type' =&gt; 'people_bio', 'taxonomy' =&gt; 'people', 'term' =&gt; $wp_query-&gt;get_queried_object()-&gt;slug, )); ?&gt; &lt;div class="container_24"&gt; &lt;div class="grid_18" id="content" role="main"&gt; &lt;?php if ($people_biography) : foreach ($people_biography as $bio) : ?&gt; &lt;h1&gt;&lt;?php echo get_the_title($bio-&gt;ID); ?&gt;&lt;/h1&gt; &lt;?php echo get_the_post_thumbnail($bio-&gt;ID); echo apply_filters('the_content', $bio-&gt;post_content); ?&gt; &lt;?php endforeach; else: ?&gt; &lt;h1&gt;&lt;?php esc_html_e($wp_query-&gt;get_queried_object()-&gt;name); ?&gt;&lt;/h1&gt; &lt;?php endif; ?&gt; &lt;?php get_template_part( 'loop', 'archive' ); ?&gt; &lt;/div&gt;&lt;!-- .content --&gt; &lt;div class="grid_6" id="default_sidebar"&gt; &lt;?php dynamic_sidebar('default-sidebar'); ?&gt; &lt;/div&gt;&lt;!-- #default_sidebar --&gt; &lt;/div&gt;&lt;!-- .container_24 --&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;?php get_footer(); ?&gt; </code> Update: The generated rewrite rules The output of my stackexchange-url ("Rewrite Analyzer") seems to tell me the taxonomy "wins" for regular taxonomy pages (which is what I noticed), but the custom post type gets all other URLs (including second pages, feeds, ...). This is what I was afraid of, and which I will need to investigate further.
Yes, this will give issues. The four rewrite rules that are generated by the custom taxonomy are also used by the custom post type. The one that you register first gets overwritten by the one that you register after that. Depending on the exact configuration (hierarchical vs. non-hierarchical) similar rules might end up in the final rewrite rules list, but only the first one will "win". This can have the effect that <code> /people/seth-godin/ </code> queries for a custom taxonomy but <code> /people/seth-godin/page/2/ </code> queries for a custom post type.
Issues when rewrite rules collide?
wordpress
I want to add new whole section of custom fields in admin UI of new post page edit post page Could somebody suggest any nice code example?
I think you'll find this a simple and useful tutorial to do what you want: http://wefunction.com/2009/10/revisited-creating-custom-write-panels-in-wordpress/
how to add custom fields into new & update post page?
wordpress
I prefer using tags and have no interest in using the categories. All my posts now are labeled with a category named "Uncategorized" and I want to turn them off! I want no more categories at all. How can I do that? Please help! [Edit] I'm using <code> wordpress.com </code> , not <code> wordpress.org </code>
There is no way at all to remove the uncategorized category from a wordpress.com webblog. It's not even possible with a self hosted wordpress w/o extensively hack the theme and the core. The uncategorized category is a placeholder for a post not having any category. You can't even delete that category to not have any categories. So sorry but the answer is no, there is no way to remove categories . Not on wordpress.com and only with a lot of changing the overall design of wordpress on a own copy.
How to totally get rid of Category in my blog?
wordpress
I've been trying, without success, to remove to sliding of the text: "ggplot+background+grid+colour" From the left sidebar here Any suggestions on how to do this?
Almost missed it, looks fine in Opera. :) Basically these words are not treated as words, but as one giant word. And browsers (well, except Opera) have trouble interpreting how to wrap it. Not sure how to achieve nice wrapping, but quick fix would be adding CSS rule <code> overflow: hidden; </code> to <code> .side-widget ul{} </code>
why does this text overlaps in the sidebar?
wordpress
( Moderator's note: Was originally titled "Wordpress for a static corporate website?") I am looking for a WordPress solution that will give me: a static website, with menu and a few pages, does not look like a blog, looks like a corporate website a very basic look and feel: white background, almost only text, easy to setup and maintain SEO An example of my target is: rachatdecredit.net It is using WordPress, but I cannot find out which theme; perhaps it's a custom-made theme. Anyway, I cannot find a theme that gives a similar result. Would you have a recommendation?
Hi @tuscon : The rachatdecredit theme is almost certainly a custom theme, you can tell from the URL for the stylesheet. Most of the time if a theme is in a directory with the same name as the site it is custom, or at least a child theme: <code> http://www.rachatdecredit.net/wp-content/themes/rachatdecredit/style.css </code> Since you want something very basic, I would suggest you build a custom theme or a child theme of the standard Twenty Theme. WordPress is great for theming because it mostly gets out of the way and lets you do what you want. Much of the complexity of a theme is handling the blogging aspects, so since you don't want those a custom theme should be pretty simple. Since you want simple you might do more work to get an existing theme to work for you than to build it from scratch. Here's a link to an answer I wrote about how to write your own theme: <a href="stackexchange-url Creating your own Theme And here's one about creating a child theme: <a href="stackexchange-url Creating a Child Theme The child theme approach might be easier since you'll be able to start with a working theme and incrementally modify it until you get what you want. If those are not options for you and you really want to use an "off-the-shelf" theme then there are hundreds to choose from. And that's the problem; which one? I could start researching them to find them but I don't know what you'll like so it might be better to just start doing the research on your own. I also don't know if you'll consider commercial themes or only want free. If you must find an off the shelf theme, by googling "wordpress themes" or going here: http://wordpress.org/extend/themes/
Basic Theme for a Static Corporate Website?
wordpress
I'm trying to build a fully W3C compatible blog. But I couldn't find a fully W3C compatible plugin. I want a simple plugin that provides share, tweet and like icons, sociable style. I don't want my readers to click a button to show share buttons, only buttons i want the plugin to provide. Any suggestions?
Best way is to skip plugin, add share buttons manually and then tweak. There is usually some degree of flexibility to share buttons code. But plugins generally disregard that and go for defaults. If you want it to validate perfectly you will likely have to do it button by button.
Is there any W3C compatible Share & Follow plugin?
wordpress
We can order pages by title. Also we can sort them by menu_order. Is it possible, to order pages by menu_order and title at the same time?
Use <code> 'orderby' =&gt; 'title menu_order' </code> or <code> &amp;orderby=title menu_order </code> (depending of the syntax you use for your query parameters).
Order by menu_order and title?
wordpress
( Moderator's note: Was previously titled: "What is the best theme used for a developer like me?") I'm a developer and write a blog to share my knowledge with readers. I'm looking for a theme which is best suited with me but not sure which ones. Please share if you've ever visited a nice theme.
Related Questions As this is a community wiki question, I'll start to link related questions in the hope of use. Not a real answer so far but probably of help. Feel free to extend: stackexchange-url ("What theme is good for posting code?")
Recommended Themes for a Developer-related Topics Blog?
wordpress
i know if you are on a category page..wp automatically ads <code> current-cat </code> class to the child of the parent category you are on. like <code> `&lt;li class="cat-item cat-item-701 current-cat"&gt;&lt;a href="http://goog.com/cat/subcat"&gt;Free Stuff&lt;/a&gt; &lt;/li&gt;` </code> how can i do this for a singlepost page. I have <code> the_category(); </code> in the single.php file and it shows both parent and child category. I want to add a <code> current-cat </code> class to the child cat when i am on the single post page. thanks in advance hopefully i did not confuse you.
<code> the_category() </code> uses <code> get_the_category_list() </code> to do its work, but this function gives you no way to specify classes. However, you can filter the output with the <code> the_category </code> hook. Since you know the format of the current category links, you can so a search and replace on them. It would look something like this (untested): <code> add_filter('the_category', 'highlight_current_cats', 10, 3); function highlight_current_cats($thelist, $separator, $parents) { // The current cat links will look like &lt;a href="[category link]" [other stuff] // We want them it look like &lt;a href="[category link]" class="current-cat" [other stuff] $current_cats = get_the_category(); if ($current_cats) { foreach ($current_cats as $cat) { $cat_link = get_category_link($cat-&gt;term_id); $thelist = str_replace('&lt;a href="' . $cat_link . '"', '&lt;a href="' . $cat_link . '" class="current-cat"', $thelist); } } return $thelist; } </code>
add current-cat class to single post page
wordpress
I tried using <code> &lt;?php $my_id = 7; $post_id_7 = get_post($my_id); echo $post_id_7-&gt;post_content; ?&gt; </code> based on the documentation here . The article I'm trying to retrieve has Short Code, which is picked up by a plugin on my site, and then formatted into HTML. The problem is when I output the post_content to the site, the short code isn't picked up by the plugin, and I effectively just write out the short code straight to the browser. Is there a way to get the short code evaluated properly? Or am I using the wrong function?
Post's object field contains raw content as it is stored in database. This should format it to how it appears when retrieved with template tags: <code> $content = apply_filters('the_content', $content); </code> This filters runs number of formatting functions, including shortcodes parsing. Something close to this: <code> &gt;&gt;&gt;&gt;&gt; the_content 8 (object) WP_Embed -&gt; run_shortcode (1) (object) WP_Embed -&gt; autoembed (1) 10 wptexturize (1) convert_smilies (1) convert_chars (1) wpautop (1) shortcode_unautop (1) prepend_attachment (1) 11 capital_P_dangit (1) do_shortcode (1) </code>
How do you get formatted content of a post using the WordPress API?
wordpress
Ubuntu Server, LAMP stack, freshly self-installed WordPress. Apparently I can't use <code> direct </code> filesystem access method because files are owned by different owners (WP core unpacked by me and files WP creates by <code> www-data </code> ). I tried my credentials for <code> ftp </code> method, but either something goes wrong or there is simply no FTP server installed in stack. Googled up suggestion to install <code> libssh2-php </code> and use <code> ssh </code> method. Filling my credentials (except keys, no idea what to put there) it worked for deleting plugins, but fails to install new ones with following error: <code> Downloading install package from http://downloads.wordpress.org/plugin/serverbuddy-by-pluginbuddy.0.1.6.zip… Unpacking the package… Could not copy file. /var/www/wp-content/upgrade/serverbuddy-by-pluginbuddy.tmp/ </code> I am little lost which method to poke. Should I try to tweak and enforce <code> direct </code> ? Or how to fix <code> ssh </code> ? Or just install some ftp server?
Ideally, you install php-suexec, so that the php script runs as the file's owner. This allows the direct method to be used without requiring any permission changes.
How to configure WP filesystem access in Linux (Ubuntu Server)?
wordpress
Basically exactly what the title says, I am running 3.0.1 and want to be able to quickly flag up posts that have no tags currently assigned to them.
I think this could get resource-intensive quickly, but fastest API way would be to create list of tags and query for posts that do not belong to any: <code> $tags = get_tags(); $ids = array(); foreach ( $tags as $tag ) $ids[] = $tag-&gt;term_id; $posts = get_posts( array( 'tag__not_in' =&gt; $ids ) ); </code> If you have large amount of tags or need to do this often it is probably better to look into building raw SQL query for this.
Is there a quick way to find out what posts haven't been tagged?
wordpress
I'm developing a WP site that lists expensive properties (villas, penthouses, etc) for rent. My client has an agreement with certain schools to list some cheap properties exclusively for their students, and he has previously (in his hard-coded-by-hand html site) had a set username+password that he gives to the schools, to give to their students (the student rentals section being access controlled via htaccess). For their spiffy new WP site, they don't want open/public registration, as the cheap properties are for specific school students and not the general public. But neither do they want to moderate each registration. Additionally, many students will use their own private email accounts (eg gmail), so I can't limit registration by domain name. A user-friendly thing to do would be to create a single user (a "demo user", if you like), and give this username+password to the schools for their students -- all students would then log in under this one user profile. However, it just takes one malicious user to change the profile's password and email-address to cock it up for everyone. In a nutshell, I need a way to create a sub-category of Subscriber, where they can read private posts but NOT edit their own profile, and I can't find anything more "atomic" than the "Read" capability, which seems to include both "read posts" and "edit your own profile". Now, there are a number of ways I can think to do this in WP, but I'm not sure if they will work (or are even possible), and which would be "best practice". 1) Use a Capability manager plugin -- I haven't found one that gives the option to disable "Edit Your Profile". Open to suggestions. 2) Remove the User SubPanel admin menu and redirect to the front-end after login. 3) Some sort of "Demo User" plugin? 4) The other alternative is to restrict or otherwise password protect registrations, but how to do this effectively, without too much hassle on the moderator/admin side, and without too much loss of usability on the end user's side? I initially thought to have "public registration" enabled but just access-control the register/login page with a site-wide username+password which we would issue, but (a) that would be annoying as you'd have to essentially "log in" twice (once for apache and once for wordpress), and (b) I tried using htaccess via AskApache's Password Protector plugin, but I couldn't get around the permalink/404 issue, despite following the example and putting ErrorDocument in the htaccess file, and a blank error.html file in my root. So there you have it... my l33t g00gl3 sk1llz have failed me. My wordpress-fu is not strong.
This solution is purely cosmetic, in that it simply hides via jQuery the fields on the user profile page, but that effectively removes the ability for the user to change the password (admin will still see the fields, and can change any time). Add this to your theme's functions.php file, and you're done. <code> add_action( 'edit_user_profile', 'hide_profile_options'); add_action( 'show_user_profile', 'hide_profile_options'); function hide_profile_options() { if( !current_user_can('install_themes') ) : ?&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function(){ jQuery("#your-profile h3:contains('Personal Options') + table").remove(); jQuery("#your-profile h3:contains('Personal Options')").remove(); jQuery("#your-profile h3:contains('About Yourself') + table").remove(); jQuery("#your-profile h3:contains('About Yourself')").remove(); }); &lt;/script&gt; &lt;?php endif; } </code> You can hide the other blocks, too, if desired... just duplicate the lines and change the h3 contents... For what you're describing, hiding the entire User Profile admin subpanel could work too, but this is a little more precise.
Restricted registrations or removing the ability to edit your password/email
wordpress
I have registered a new taxonomy term using the same code on two different sites. On one site (a vanilla install), If I go to my taxonomy term in the admin menu, I see a 'slug' option for the add category screen. On my other site, with all plugins disabled, this slug option does not appear. Anyone know what might cause this? Register taxonomy code: <code> register_taxonomy( 'my_topics', array( 'post', 'page' ), array( 'hierarchical' =&gt; true, 'label' =&gt; 'my Categories', 'query_var' =&gt; 'topics', 'rewrite' =&gt; array('slug' =&gt; 'topics') ) ); </code>
The value for global_terms_enabled for multisite is stored in wp_sitemeta http://wordpress.org/support/topic/plugin-edit-category-slug-wpmu-how-to-make-it-work-with-last-wpmu-30 I switched this to off and the category slug field reappears. If anyone can comment on whether its safe to switch this off, that would be greatly appreciated.
Category slug field missing with registered custom taxonomy
wordpress
I want to run an update script on pages that haven't been viewed and updated within X days. I'm using post meta to cache some related RSS feed data, and I want it updated once a week or two, but only if the page has actually been viewed within the last two or three weeks, bots included. Is there an internal counter or whatnot that has this data, or am I going to have to build something that stores the UNIX timestamp as post meta upon page view?
Post views log/count is not available natively. It is resource-intensive (database writes are much more expensive than reads) and won't work (if done in pure PHP) with most caching plugins. There is number of plugins/services that offers Analytics via JS- or image-based tracking. Your best bet is to let such service handle analytics and pull data from there.
How to find time last viewed?
wordpress
I am using the "attach" feature in the media library to link a set of images to specific pages. Our custom theme displays these attached images in a particular way. We are setting up Wordpress as a CMS for a client and we don't want them to have to attach images to posts / pages this way because it feels clunky to be editing page, then forcing the user to go to the media section and attach images to that page one by one. I would really like our client to be able to attach a set of images to a post or page in a manner similar to the "featured image" feature. The user should also be able to add, remove and sort the images without leaving the page.
Actually, it's very easy to attach images to posts and pages from directly within the editor. Just click on the Add an Image button (immediately to the right of Upload/Insert) to access the uploader. You can upload as many images as you want to the media gallery for that page and edit the meta information attributed to each. Then click "Save Changes" at the bottom to save the images. As far as WordPress is concerned, these images will be "attached" to the post or page on which you added them ... no need to go to the Media Gallery to do an upload. They'll only show up on the post or page if you click "Insert into Post" after you upload. Update For those of you who haven't used this before ... You can access the uploader through these icons: The uploader itself will appear on the same page - you don't have to go anywhere else to use the feature. You can upload multiple images at once. Either click "Select Files" and select them one at a time, or select a bunch (click-and-drag) and they'll all upload at the same time. Once the images are uploaded, you can manage them inside the post or page's internal gallery. You can re-tag images, change the details attributed to each, and drag them around to re-order things.
Is there a plugin to make attaching images easier?
wordpress
I am trying to figure out how to change the default buttons on the TinyMCE editor in the Wordpress admin. Specifically, I would like to provide an 'insert table' button. How do I do that?
TinyMCE Advanced plugin. I almost never launch a site without it.
How to add 'Insert HTML Table' button to TinyMCE in admin?
wordpress
I'm working on a site which needs to have pages and posts sorted into the same categories. The pages have their own individual hierarchy structure. Is there a way to do this using a custom taxonomy?
Yes, a custom taxonomy is the best way to achieve this. For a cat breeder site I’ve set a taxonomy for colors (in german: Farbe): <code> register_taxonomy( 'farbe', array( 'post', 'page' ), array( 'hierarchical' =&gt; false, 'label' =&gt; 'Farbe (Fell)', 'query_var' =&gt; 'farbe', 'rewrite' =&gt; array('slug' =&gt; 'farbe') ) ); </code> Note the third parameter <code> array( 'post', 'page' ) </code> . Now you can find all posts and page covering the color black at /farbe/black/ . That’s all, WP will do the rest for you. :) Update WordPress will search for a matching template . To link to this taxonomy, add the following code to the meta data box (tags, categories, date etc.) of your posts: <code> echo get_the_term_list( $post-&gt;ID, 'farbe', ' · Farbe: ', ', ', '' ); </code> Output: <code> &lt;a href="http://example.com/farbe/black/" rel="tag"&gt;black&lt;/a&gt; </code> Screenshot for taxonomy “Farbe” in the post edit screen:
Is there a way of storing posts and pages under the same hierarchy?
wordpress
I know that jQuery is loaded, because I can switch out the $ for 'jQuery' and everything behaves as expected, but this will be a messy script if I can't fix this This script: <code> jQuery(document).ready(function(){ $("ul.vimeo_desc_feed li a").click(function(){ alert($(this).attr('href')); return false; }) }); </code> Produces the error $ is not a function This script: <code> jQuery(document).ready(function(){ jQuery("ul.vimeo_desc_feed li a").click(function(){ alert(jQuery(this).attr('href')); return false; }) }); </code> works fine.
You can wrap your javascript inside a self-invoking function, then pass <code> jQuery </code> as an argument to it, using <code> $ </code> as the local variable name. For example: <code> (function($) { $(document).ready(function(){ $("ul.vimeo_desc_feed li a").click(function(){ alert($(this).attr('href')); return false; }) }); }(jQuery)); </code> should work as intended. If I remember correctly the WP-supplied version of jQuery (the one you get if you <code> wp_enqueue_script('jquery') </code> ) puts jQuery in no-conflict immediately, causing <code> $ </code> to be undefined.
$ not defined using jQuery in Wordpress
wordpress
I don't know why the proper classes for menu item are not generated - all the elements in the tree which has subtree get only <code> menu-item menu-item-type-post_type </code> . The elements, which don't have children, get proper classes after being clicked (active). Link: http://lichens.ie/ Part of the menu structure: http://imgur.com/5Lj00.png Code <code> $args = array( 'menu' =&gt; 'Main menu', 'container' =&gt; '', 'menu_id' =&gt; 'nav', ); wp_nav_menu($args); </code> When you visit e.g. http://lichens.ie/view-lichens-by/lichens-by-habitat/ you can see that it has no 'current' class. As well as it's parent. PS Sorry for posting 'not working links' - it's because of reputation limitation Any ideas - help much appreciated.
This is part of code in <code> _wp_menu_item_classes_by_context() </code> that handles current class for pages: <code> // if the menu item corresponds to the currently-queried post or taxonomy object } elseif ( $menu_item-&gt;object_id == $queried_object_id &amp;&amp; ( ( ! empty( $home_page_id ) &amp;&amp; 'post_type' == $menu_item-&gt;type &amp;&amp; $wp_query-&gt;is_home &amp;&amp; $home_page_id == $menu_item-&gt;object_id ) || ( 'post_type' == $menu_item-&gt;type &amp;&amp; $wp_query-&gt;is_singular ) || ( 'taxonomy' == $menu_item-&gt;type &amp;&amp; ( $wp_query-&gt;is_category || $wp_query-&gt;is_tag || $wp_query-&gt;is_tax ) ) ) ) { $classes[] = 'current-menu-item'; </code> IDs must match. It must be of <code> post_type </code> type. Query should be for <code> is_singular </code> . Second point can be excluded, because CSS class for item type is generated correctly. So something goes wrong either with IDs or <code> is_singular </code> conditional. Are you running any secondary loops on page? Most common reason for conditionals to break is improper use of <code> query_posts() </code> .
wp_nav_menu doesn't generate parent/ancestor classes
wordpress
( Moderators note: Was originally titled: "Custom post type problem?" ) I'm having some problems with custom post types where everything is working great except for the sidebars. Here is some code from my <code> sidebar.php </code> : <code> &lt;?php if (is_home()) { dynamic_sidebar('frontpage-sidebar'); } if (is_single()) { dynamic_sidebar('single-post-sidebar'); } .... ?&gt; </code> Normally this works ok except for when I open a single page to check post <code> 'frontpage-sidebar' </code> is not loading as the <code> 'single-post-sidebar' </code> is loading instead. Where is the problem? Here is the code for my custom post type: <code> $labels = array( 'name' =&gt; _x('Tools', 'post type general name'), 'singular_name' =&gt; _x('Tool', 'post type singular name'), 'add_new' =&gt; _x('Add New', 'Tool'), 'add_new_item' =&gt; __('Add New Tool'), 'edit_item' =&gt; __('Edit Tool'), 'new_item' =&gt; __('New Tool'), 'view_item' =&gt; __('View Tool'), 'search_items' =&gt; __('Search Tools'), 'not_found' =&gt; __('No Tools found'), 'not_found_in_trash' =&gt; __('No Tools found in Trash'), 'parent_item_colon' =&gt; '' ); $args = array( 'labels' =&gt; $labels, 'public' =&gt; true, 'publicly_queryable' =&gt; true, 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; true, 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, 'menu_position' =&gt; 2, 'supports' =&gt; array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments','page-attributes') // 'not sure that post can have page-attributes ????' ); register_post_type('tools', $args); </code> How do I load different sidebars on different pages when using custom post types instead of ordinary posts? Thanks.
Hi @user1147 If I understand your question correctly then use are asking why <code> is_home() </code> is <code> false </code> when you are viewing the URL <code> /tools/example-tool/ </code> ? If I understand your question the answer is simply that is_home() is not <code> true </code> for Custom Post Types. Actually <code> is_home() </code> should never be <code> true </code> except for 1.) when on the home page list of posts, or 2.) when a "static page" has been set to be a "Posts page" in the Settings > Reading section of the admin (In my screen shot my "Posts page" has been set to a "Page" -- <code> post_type=='page' </code> -- whose Title is "Home"): So if you want the sidebar to show up I think you'll need to use a different criteria than <code> is_home() </code> . Can you describe in words what you were trying to accomplish this code? UPDATE Based on the comments below and subsequent research after better understanding the problem it appears appropriate values for <code> is_home() </code> and <code> is_single() </code> were never really defined for custom post types . So one of the better solutions to the problem is to create a post type specific theme template page, i.e. <code> single-tools.php </code> if the post type is <code> tools </code> , and define sidebars specifically for that post type. But if you must route everything through one <code> single.php </code> then here are some functions that you could use in place of <code> is_home() </code> and <code> is_single() </code> to achieve the expected results and you can store these in your theme's <code> functions.php </code> file (or one of of the files of a plugin) : <code> function is_only_home() { $post_type = get_query_var('post_type'); return is_home() &amp;&amp; empty($post_type); } function is_any_single() { $post_type = get_query_var('post_type'); return is_single() || !empty($post_type); } </code> Taking your first code example above and applying these function would look like this: <code> &lt;?php if (is_only_home()) { dynamic_sidebar('frontpage-sidebar'); } if (is_any_single()) { dynamic_sidebar('single-post-sidebar'); } .... ?&gt; </code>
is_home() and is_single() Not Working as Expected with Custom Post Types?
wordpress
I would like to be able to refresh the thumbnail cache programmatically, not sure where to hook it, but at present any design changes mean re-uploading loads of images!
You may want to look at the plugin Regenerate Thumbnails by Viper007Bond . Basically, this is how to do it: <code> function regenerateThumbnails() { $images = $wpdb-&gt;get_results( "SELECT ID FROM $wpdb-&gt;posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%'" ); foreach ( $images as $image ) { $id = $image-&gt;ID; $fullsizepath = get_attached_file( $id ); if ( false === $fullsizepath || !file_exists($fullsizepath) ) return; if ( wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $fullsizepath ) ) ) return true; else return false; } } </code> Note: This function is not very scalable. It will loop through all the images and regenerate thumbnails one by one, which may consume a large amount of memory. So, you may want to enhance it.
Can I refresh the thumbnails programmatically?
wordpress
The wordpress crop tool is greyed out for me in Firefox 3.6 (and IE7/8). I have disabled firefox add-ons and tried the solution here: stackexchange-url ("stackexchange-url But this hasn't resolved the issue. Anyone know how wordpress determines whether to enable the crop button? WP version is 3.0.1 thanks,
I'm 99% sure this was caused by the firephp plugin.
Wordpress crop tool greyed out
wordpress
I'm using the built-in SimplePie, AKA <code> fetch_feed() </code> , to retrieve a feed, and I want to be able to adjust the cache time from an admin menu. SimplePie itself is well documented, but not so much the WordPress implementation of it. Any thoughts on the best way to set the cache duration?
Cache duration value (defaults to 43200 seconds) is set when feed object is generated and passed through <code> wp_feed_cache_transient_lifetime </code> filter with additional argument being feed URL. This allows to conveniently filter it both globally and for specific feeds. See fetch_feed() source for this and other hooks you can use to modify its behavior.
How to set the cache for the built-in SimplePie feed parser?
wordpress
I am in the process of cleaning up a site after migrating it from a single install of WP to a multi-site install of WP. I have noticed many, many duplicate custom fields for each post. I assume this is from older versions of plugins that didn't check for the field before adding another. In the migration I am dropping these plugins. Could I just delete these fields in the back-end using SQL or is there a better way? <code> SELECT * FROM `wp_5_postmeta` WHERE `meta_key` IN ("podPressPostSpecific", "aktt_tweeted", "podPressMedia") </code> Only using <code> DELETE </code> obviously.
If you're not going to use those plugins, have at it. No reason to keep them around. Direct SQL query should be fine. Related: <code> add_post_meta() </code> has a nifty argument to prevent this very problem. The fourth argument is a boolean, declaring whether the meta should be singular: <code> add_post_meta( $post-&gt;ID, 'my_foo_bar', 'value', true ); </code> Source: Add Post Meta | WP Codex
Duplicate (or more) custom fields on many posts. Is there an easy way to clean them up?
wordpress
I'm attempting to use wp_enqueue_script('jquery') to load the builtin WP jquery library but my jquery functions aren't working when I do this. Only when I hardcode a reference to the script do my functions work... Example that works... (this is inside my functions.php file, which is adding a dashboard widget)... <code> /* Dashboard Widget */ if(is_admin()) { function my_dashboard_widget_function() { $rss = fetch_feed( "http://mysite/my.rss" ); if ( is_wp_error($rss) ) { if ( is_admin() || current_user_can('manage_options') ) { echo '&lt;p&gt;'; printf(__('&lt;strong&gt;RSS Error&lt;/strong&gt;: %s'), $rss-&gt;get_error_message()); echo '&lt;/p&gt;'; } return; } if ( !$rss-&gt;get_item_quantity() ) { echo '&lt;p&gt;This feed is currently offline&lt;/p&gt;'; $rss-&gt;__destruct(); unset($rss); return; } echo "&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'&gt;&lt;/script&gt;" echo "&lt;script type='text/javascript'&gt;//some jquery methods here&lt;/script&gt;"; </code> Example that does not work... <code> /* Dashboard Widget */ if(is_admin()) { function my_dashboard_widget_function() { $rss = fetch_feed( "http://mysite/my.rss" ); if ( is_wp_error($rss) ) { if ( is_admin() || current_user_can('manage_options') ) { echo '&lt;p&gt;'; printf(__('&lt;strong&gt;RSS Error&lt;/strong&gt;: %s'), $rss-&gt;get_error_message()); echo '&lt;/p&gt;'; } return; } if ( !$rss-&gt;get_item_quantity() ) { echo '&lt;p&gt;This feed is currently offline&lt;/p&gt;'; $rss-&gt;__destruct(); unset($rss); return; } wp_enqueue_script('jquery'); echo "&lt;script type='text/javascript'&gt;//some jquery methods here&lt;/script&gt;"; </code>
You need to enqueue your script at certain points. Rather than just placing the <code> wp_enqueue_script </code> call inside your dashboard widget function, you need to place it in a separate function and hook on to the proper action. So: <code> function add_jquery_to_my_widget() { wp_enqueue_script( 'jquery' ); } add_action( 'init', 'add_jquery_to_my_widget' ); </code>
How can I load jquery library into my dashboard widget?
wordpress
I have strange situation which just started which I seem to be unable to resolved. I am not sure what this might be related to but I think I remember reading somewhere that this has happened to someone else. Upon logging into WordPress then going into the menu management area, then clicking on "screen options" and enabling the view of a menu metabox for a custom post type that was created and then adding a page from that post type to the menu the menu management area started showing a Internal Server Error 500 message. Every other area of the website and admin area works perfectly except for the menu management link. I have attempted everything I can think of in an effort to resolve the problem including removing every plugin and customization made to my <code> functions.php </code> file however I can't get the issue resolved. I was hoping someone here might able to help me resolve this issue or suggest anything to diagnose this issue. Any help is greatly appreciated!
I just figured out my own issue which I am hoping might help others if they get stuck in this situation. Essentially the problem seemed to be that modsecurity caused the 500 Internal Server error because for some reason (which I have yet to understand) the menu page was sending a bunch of data in the response body. To resolve the problem I just needed to add the following to my vhost.conf file and restart apache. Here I doubled the response body size. <code> SecResponseBodyLimit 1572864 </code>
How to fix strange 500 Error after Editing Menu?
wordpress
I can get custom posts to display on my site. However, I want to filter the posts by category. The custom posts are displaying on this page: http://www.africanhealthleadership.org/resources/toolkit/ The custom posts are the tools i.e. Desk Research and Assessment Tool Under Preparation, I only want to show Desk Research. However ALL the tools are displaying under Preparation. I used this code to get the tools to display. Clearly category_name is not working, but I am not sure how to fix. Thank you for any help. <code> &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'portfolio', 'category_name' =&gt; 'preparation' ) ); ?&gt; &lt;?php while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); ?&gt; &lt;?php the_title( '&lt;h2 class="entry-title"&gt;&lt;a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark"&gt;', '&lt;/a&gt;&lt;/h2&gt;' ); ?&gt; </code> `
Can you be more specific?do you mean <code> custom post type </code> or <code> custom query </code> ? AFAIK when using custom post type you cannot directly use <code> category_name </code> since your post are treated in different way. You have to add custom taxonomies in register_post_type and then register them with register_taxonomy() note: please correct me if my statement above is wrong, I'm not go deep with custom post type, at least for now. say you have custom post type named <code> portfolio </code> , custom taxonomy named <code> toolkit </code> with following categories: preparation assessment leadership innovation and you want to show all post in <code> preparation </code> : <code> &lt;?php query_posts( array( 'post_type' =&gt; 'portfolio', 'toolkit' =&gt; 'preparation' ) ); //the loop start here if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; &lt;h3&gt;&lt;?php the_title(); ?&gt;&lt;/h3&gt; &lt;?php the_content(); ?&gt; &lt;?php endwhile; endif; wp_reset_query(); ?&gt; </code>
Displaying custom posts by category
wordpress
I'm getting image fields wrapped in tags and would like to remove the surrounding divs, but only if they are of class "mceTemp". Anyone know of an efficient way to do this? Also, should those Divs even be there?
I agree with hakre - something funky is going on elsewhere, those shouldnt be appearing. As a sidenote, you could use the jQuery unwrap() function to remove those divs. <code> jQuery('div.mceTemp img').unwrap(); </code> http://api.jquery.com/unwrap/
How can I remove using built in wordpress filters
wordpress
( Moderator's note: This question was previously titled "How to add multiple custom page in wordpress" ) I am developing a WordPress site and right now I have a custom home page and others are default WordPress pages. Now I want to add one another custom page for some landing page. It will not be sub-page. This page's layout &amp; design is different. How Can I add this to my wordpress website?
Sounds like what you want is a Custom Page Template It's quite simple, if you want to call your layout "My Special Layout" just create a file in your Theme Directory calling it whatever you like (I'd call it "page-my-special-layout.php" but that's not required) and add the following comment to the top of the template file: <code> &lt;?php /* Template Name: My Special Layout */ </code> After the comment put in whatever HTML you need to design your desired page. Then once you have the Template in your Theme directory and you load the Page Editor in the WordPress admin console you'll be given the option to assign it as your Page Template; simple as that:
Assigning Multiple Layout Designs with Custom Pages in WordPress?
wordpress
If you have a Tumblr blog, you can 'reblog' from other Tumblr blogs, much like a trackback. I follow a couple of Tumblr blogs and sometimes want to quote from those websites. And, on these Tumblr sites, there is a 'notes' section for each post listing each 'reblog'. So my question is: is there some WordPress plugin (or some workaround not requiring a plugin) that will allow me to 'reblog' from a Tumblr site to my WordPress one and have it show up in the 'notes' section of the Tumblr blog? My site is a wordpress.org blog, if that makes a difference. And I am running WordPress 3.0.1. Thanks in advance!
I just did a quick search on the Reblog concept because, admittedly, I've never used Tumblr and had no idea what you were talking about. After reading a bit about it, it started to sound very familiar ... Most blogs today allow you to add a ReTweet (Twitter), Like (Facebook), or Share This (Generic) button directly on the post. These are very network-specific and key in directly to the APIs of various social networking and crowdsourcing applications. Tumblr, since they run a succinct network of blogs, did the same thing. The Reblog button allows you to quickly repost content on your own site within the Tumblr network. As one site mentioned, not very extensible, but still pretty cool. The difference is, each self-hosted WordPress blog is its own web application . So there's not really any way you can have blog authors put up a "share on your own self-hosted application" widget on their sites. Fortunately, there is a solution. Press This Some time ago, WordPress introduced a bookmarklet called Press It. This was a snippet of JavaScript code that lived in your bookmarks toolbar and allowed you to quickly and easily re-post interesting content you found online to your own site. As of WordPress version 2.6, the feature has been replaced by Press This, a similar bookmarklet that allows you to create a post by quoting some text, images, and videos on any web page. To use Press This, go to your Tools sub-panel and drag the "Press This" link into your bookmarks toolbar. When you're browsing the Internet and you find something you like, highlight the text (or don't and you'll use the entire page's content) and click the Press This bookmark. A pop-up window will appear allowing you to instantly edit and post the content you're viewing. As far as showing up in the notes section of a Tumblr blog, that's an entirely different issue. You're looking for a very specific, custom integration between two different platforms ... I have found one plug-in that will automatically post to a Tumblr blog from WordPress, but the last time it was updated was April of 2008 so I'm not sure it'll be too much help. There's also a synchronizing system called Tumblrize that will automatically post your WordPress content to Tumblr, update it when you change things on WP, and update the WP copy if you change things on Tumblr.
Reblog from Tumblr to Wordpress
wordpress
Attempting to create a horizontal scroller using post_thumbnail's. I've made a filterable portfolio section using this tutorial: http://www.wearepixel8.com/blog/filterable-portfolio but my attempts to make it a horizontal scroller have failed, i've tried several different jQuery image scroller plugins to attempt it but none have worked. Can anyone give advice on how to achieve what i'm looking to do? Thanks!
I did it on a few sites. An example is below. If you want the jQuery code for it, I can give it you. It is a list of post thumbnails with their post titles shown below them. paragonhondainfo.com
Horizontal scroller with post_thumbnail's
wordpress
Interesting situation i just ran into. I have a site I am developing in which I have defined specific image sizes I want created whenever a new image is uploaded. Currently lets just say that I defined a specific thumbnail size of 75x75 and a medium sized image of 150x150 pixels. Assuming we proceed to upload a new image using the built in media uploader we would expect that Wordpress will automatically upload and store the original image along with any additional images sizes which I have specified in my functions.php file (in this case the 75x75 and 150x150 pixel images). First of all, the above illustrated example is indeed working perfectly and I am very happy with the results. What I have noticed though is that when you pick a bmp file to upload the automatic resizing does not take place. My objective here is to figure out who else might have noticed this issue while attempting to find a solution for this problem. I need to ensure that even when a large bmp file is uploaded that the code <code> the_post_thumbnail( array(50,50), 'class=alignleft' ); </code> will show the 50x50 pixel image. Just in case anyone is interested, I have confirmed this issue is specifically related to bmp image by taking the original bmp image and saving it as a jpg and png file through photoshop and then using the wordpress media manager to upload the same files converted by photoshop... In both cases I noticed that after uploading each converted file the exact same images WERE correctly being resized. I should also point out that when a bmp file image was uploaded the actual upload of that file DID take place however in the media manager only the original (full size) image was available to insert into posts and checking the media upload folder also only showed a single image. Any guidance, help or diagnosis is greatly appreciated!
No, wordpress can not resize BMP files. Beware that it does not make sense to use BMP files in a website because a broad number of webbrowsers is not able to display them. Filetypes that are supported by Wordpress and which are widely supported by internet browsers are: GIF, JPG and PNG. Those formats are optimized for internet use as they compress image data. BMP is a common image format but not in the internet because it has large file sizes.
Can Wordpress resize BMP files?
wordpress
Given the code below how would I account for the table prefix that can change from installation to installation? Is there a better way to write it than an SQL query? Is there a variable I've missed that provides the table prefix for times like this? <code> // setting posts with current date or older to draft if (!wp_next_scheduled('sfn_expire_hook')){ wp_schedule_event( time(), 'hourly', 'sfn_expire_hook'); } add_action( 'sfn_expire_hook', 'sfn_show_expire'); function sfn_show_expire(){ global $wpdb; $server_time = date('mdy'); $result = $wpdb-&gt;get_results("SELECT * FROM GrandDn4wP_posts WHERE post_type = 'show' AND post_status = 'publish'"); if( !empty($result)) foreach ($result as $a){ $show_time = get_the_time('mdy', $a-&gt;ID); if ( $server_time &gt; $show_time ){ $my_post = array(); $my_post['ID'] = $a-&gt;ID; $my_post['post_status'] = 'draft'; wp_update_post( $my_post ); } } // end foreach } </code>
You can rewrite the code like this: <code> // setting posts with current date or older to draft if (!wp_next_scheduled('sfn_expire_hook')){ wp_schedule_event( time(), 'hourly', 'sfn_expire_hook'); } add_action( 'sfn_expire_hook', 'sfn_show_expire'); function sfn_show_expire(){ global $wpdb; $server_time = date('mdy'); $result = $wpdb-&gt;get_results("SELECT * FROM $wpdb-&gt;posts WHERE post_type = 'show' AND post_status = 'publish'"); if( !empty($result)) foreach ($result as $a){ $show_time = get_the_time('mdy', $a-&gt;ID); if ( $server_time &gt; $show_time ){ $my_post = array(); $my_post['ID'] = $a-&gt;ID; $my_post['post_status'] = 'draft'; wp_update_post( $my_post ); } } // end foreach } </code> but a better way to write it would be to use the function get_posts: <code> // setting posts with current date or older to draft if (!wp_next_scheduled('sfn_expire_hook')){ wp_schedule_event( time(), 'hourly', 'sfn_expire_hook'); } add_action( 'sfn_expire_hook', 'sfn_show_expire'); function sfn_show_expire(){ $server_time = date('mdy'); $result = get_posts( array( post_type =&gt; 'show', post_status =&gt; 'publish' ) ); if( !empty($result)) foreach ($result as $a){ $show_time = get_the_time('mdy', $a-&gt;ID); if ( $server_time &gt; $show_time ){ $my_post = array(); $my_post['ID'] = $a-&gt;ID; $my_post['post_status'] = 'draft'; wp_update_post( $my_post ); } } // end foreach } </code>
Taking WordPress table prefixes into account
wordpress
I get 404 status when fetching images, and the http still contains that image. Image shows up in a browser, but the 404 code breaks some applications. calls to wp-content/uploads/ are redirected in .htaccess: <code> &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteRule (.*) /index.php?getfile=$1 [L] &lt;/IfModule&gt; </code> Why do I get a 404 status if the image is in there and is served?
Problem solved. The plugin "User Access Manager" was found guilty of inserting a .htaccess file into <code> wp-content/uploads/ </code> and not handling calls properly afterwards. I don't know how UAM plugin could be fixed, but It's ok to remove the .htaccess file. Nothing else depends on it. (at least in my case)
404 when fetching image from wp-content/uploads/
wordpress
I'm trying out the SharDB plugin, but it doesn't seem to be respecting my CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE declarations -- it is querying <code> $shardb_prefix.users </code> instead of my custom table name. Anyone know if this plugin is supposed to support the CUSTOM_USER_TABLE definitions? Thanks!
Ok, looking into this, I found a little bug in the tables function (beginning on line 1088) in the db.php script file that comes with SharDB. It was this bit of code that was the problem (starting on line 1114 of db.php): <code> if ( isset( $tables['users'] ) ) { if( defined( 'CUSTOM_USER_TABLE' ) ) $pre_tables['users'] = CUSTOM_USER_TABLE; if ( defined( 'CUSTOM_USER_META_TABLE' ) ) $pre_tables['usermeta'] = CUSTOM_USER_META_TABLE; } </code> See, it does check before it returns the tables list to see if CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE are defined, and overwrites the default values if they are. However the check was not running in the first place because of the <code> isset( $tables['users'] ) </code> check on line 114. $tables is an array of table names, 'users' is one of the values in the array, so $tables['users'] is never set. So change line 114 to: <code> if ( isset( $pre_tables['users'] ) ) </code> and voila. You're all set (I'm gonna go find the plugin author now and report the bug!)
custom user tables supported in SharDB plugin?
wordpress
I was wondering if anyone could give me some suggestions on how best I could streamline the following; I have a WordPress blog (privately hosted) which I update daily (well, I normally schedule a load of updates at once) with pictures which I upload, tag and write a very brief comment on. I was originally considering a folder on the server I could FTP images into and then I would write something that would look there daily and create a post based on the picture, but then I wasn't sure about the meta data that I want along with it. Any help would be greatly appreciated. P.S I would make this a community wiki (as I am not sure there is even one answer let alone one stand out correct answer!) but I don't have enough the right privileges yet!
Hi @Toby : There are lots of ways to accomplish a daily picture blog so I'll just give you how I'd approach it. If I wanted to set up a photoblog on WordPress I'd start with a Flickr account and leverage it (or if you don't like Flickr for some reason you can also look at PhotoBucket, SmugMug, Picasa or one of the other Flickr alternatives.) Using Flickr With Flickr there are bulk uploading tools to make it easy for your to upload lots of photos including lots of tools for managing a large number of photos . Flickr itself has built-in tools to support photo-blogging including email-to-blog . And if the existing tools don't give you enough control with Flickr you can always write some PHP scripts to integrate and automate . There are lots of blog posts to show you how (and I'll show you how to write one as well, below): Search for photos using PHP and the flickr API Flickr API Fun Serialized PHP Response Format How to Create a Photo Gallery using the Flickr API Integrating Flickr Photo Streams with PHP 5 Lessons in Getting Started with the Flickr API and PHP And at least a few PHP libraries to simplify access to the Flickr API: phpFlickr Laughing Meme Flickr API Library for PHP Exploring the Flickr API So let's say you want to do a little simple photo blogging to WordPress using files that have been uploaded to Flickr? The first step is to get an API Key : The Flickr App Garden - Create an App While you are at it you might want to just scan the API docs: Flickr API Documentation Now there are a bunch of different ways to query Flickr via their API. I'll show how by Querying a Photo Set but you could also consider Searching by Tags . For the first example I'll use my Flickr photo set entitled "Barber Motorcycle Museum - Oct 21-22 2006" (I'm using it because people seem to like it; it gets lots of traffic.) You'll need to get the <code> photoset_id </code> which you can find in the URL: Next you need to call the <code> flickr.photosets.getPhotos </code> method of the Flickr API with a URL of the following format: <code> http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&amp;api_key={YOUR_API_KEY_GOES_HERE}&amp;photoset_id=72157594340403773&amp;media=photos&amp;format=json&amp;nojsoncallback=1 </code> Note that once you replace <code> {YOUR_API_KEY_GOES_HERE} </code> with your own API key you can actually call it from your browser and it will look something like this: Also note that I request JSON back using the <code> format=json&amp;nojsoncallback=1 </code> URL parameters because I find it much easier to handle JSON than XML, and the <code> nojsoncallback </code> omits the callback on would need if working in Javascript. What you'll get back is a nested data structure containing a list of photos , and for each photos you'll get an object with the following attributes (what I'm showing below it the output of the first element of the array of photos as generated by the standard PHP <code> print_r() </code> function): <code> [0] =&gt; stdClass Object ( [id] =&gt; 276672853 [secret] =&gt; 099eaa1af2 [server] =&gt; 107 [farm] =&gt; 1 [title] =&gt; Barber Motorcycle Museum - Oct 22 2006 (500) [isprimary] =&gt; 0 ) </code> Flickr's Photo URL Formats Now that we have our list of recent photos you next need to understand Flickr's Photo URL format which you can read more about here: Flickr's Photo Source URLs In general Flickr's photo URLs go like this: 500px Wide or High "Standard" Photo: <code> http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg </code> This version will be 500 pixels on its longest side. The Original Image: <code> http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{o-secret}_o.(jpg|gif|png) </code> This can be whatever was uploaded, a .JPG, a .GIF or a .PNG. Specific Sized Versions: These are always .JPG: <code> http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[size].jpg </code> Where <code> [size] </code> is one of: s - small square 75x75 t - thumbnail, 100 on its longest side m - small, 240 on its longest side z - medium, 640 on its longest side b - large, 1024 on its longest side (only exists for very large original images) So the following URL taken from the example results returned above pulls the photo that follows (note how the <code> z </code> before the <code> .jpg </code> indicates a photo 640 pixels wide on the longest size:) http://farm1.static.flickr.com/107/276672853_099eaa1af2_z.jpg Armed with all of the above information we can now create a PHP script using WordPress' <code> WP_Http </code> class to retrieve the photos from our set. I wrote a simple script which you can copy into the root of your website being sure to replace with your own <code> api_key </code> and <code> photoset_id </code> before running it: <code> include "wp-load.php"; define('FLICKR_API_KEY','{YOUR_API_KEY_GOES_HERE}'); define('FLICKR_GET_URL','http://api.flickr.com/services/rest/'); define('PHOTO_SIZE_CHAR', 's'); // s = 75x75 pixels on longest side $result = flickr_get(array( 'method' =&gt; 'flickr.photosets.getPhotos', 'photoset_id' =&gt; '{YOUR_PHOTOSET_ID_GOES_HERE}', 'media' =&gt; 'photos' )); if (isset($result['body']-&gt;photoset-&gt;photo)) { $size = PHOTO_SIZE_CHAR; foreach($result['body']-&gt;photoset-&gt;photo as $photo) { extract((array)$photo); $url = "http://farm{$farm}.static.flickr.com/{$server}/{$id}_{$secret}_{$size}.jpg"; echo "&lt;img src=\"{$url}\" alt=\"{$title}\" /&gt;\n"; } } function flickr_get($params,$args=array()) { $http = new WP_Http(); $params['api_key'] = FLICKR_API_KEY; $params['format'] = 'json'; $params['nojsoncallback'] = 1; $params = http_build_query($params); $url = FLICKR_GET_URL . "?{$params}"; $result = $http-&gt;get($url,$args); if (isset($result['response']['code']) &amp;&amp; $result['response']['code'] == 200) $result['body'] = json_decode($result['body']); else $result = false; return $result; } </code> Using the above with my API key and my Photoset ID I get the following: PHP Script for Posting of a Flickr Photoset Photo to your Blog Based on all that I've written a page called <code> blog-from-flickr.php </code> that you can put in the root of your website and call to get the following simple form: Enter a valid Photoset ID and then click that button and you'll get be redirected to a blog post that looks something like this! To get it all working was a bit more involved than the simple code above and more than I have time left to fully document but I'll post it below for your review (and you can also download it from here ). Of special note are the following aspects in the code: The script pulls the twenty five (25) most recent photos from the photoset and blog the earliest one of those. I assumed you'd want to upload in bulk and then post chronologically. If you upload more than 25 then you need to change the value of the constant <code> FLICKR_PHOTO_COUNT </code> to something larger, up to 500 (500 is the limit specified by Flickr.) Increasing it will only slightly increase how long it takes the script to run; it might not even be noticeable. The script stores Flickr's photo ID as a hidden custom field in <code> wp_postmeta </code> using the key <code> '_flickr_photo_id' </code> . That's how I can tell if it's been blogged before or not. The script uses an HTTP <code> POST </code> method (i.e. using an HTML <code> &lt;form&gt; </code> ) vs an HTTP <code> GET </code> method (calling a URL directly) to avoid accidentally triggering the posting process and to allow posting from a different Photoset . The script uses <code> current_user_can('publish_posts') </code> to ensure only a logged-in user with posting rights can trigger the posting logic. The script grabs the photo's description from Flickr and use it as a prefix to the <code> &lt;img&gt; </code> tag for the post content (note my example screenshot didn't have a description hence you see only the photo.) The script calls PHP's <code> getimagesize() </code> with a URL of the photo to get the height and width for the <code> &lt;img&gt; </code> tag; if your server is not configured for that you won't get size and width tags on your images (actually the code might crash; mine works so I couldn't test. If it crashes, you'll know. :) I didn't go to the effort to bring the tags over from Flickr and add them as tags, but that would be a worthwhile exercise for someone else. And that's about it. On to the code... The Flickr Photo Blogging Code: <code> &lt;?php /* blog-from-flickr.php Allows the WordPress blog owner to blog a recent photo from a Flickr Photoset just by clicking a button. Author: Mike Schinkel (http://mikeschinkel.com) Just drop this example into the root of your website and call directly to see it work. Use the class in your plugins or themes. In Answer To: stackexchange-url "wp-load.php"; define('FLICKR_API_KEY','{YOUR_FLICKR_API_KEY_GOES_HERE}'); define('DEFAULT_PHOTOSET_ID','{YOUR DEFAULT_PHOTOSET_GOES_HERE'); define('FLICKR_PHOTO_COUNT',25); define('FLICKR_GET_URL','http://api.flickr.com/services/rest/'); $photoset_id = DEFAULT_PHOTOSET_ID; if (count($_POST)==0) echo &lt;&lt;&lt;HTML &lt;html&gt; &lt;body&gt; &lt;form method="post"&gt; Enter Flickr Photoset ID: &lt;input type="text" name="photoset_id" value="{$photoset_id}" size="25" /&gt; &amp;nbsp;&lt;input type="submit" value="Blog Recent Photo from Flickr!" /&gt; &lt;input type="hidden" name="go" value="go!" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; HTML; else BlogFlickrPhotoSetPhoto::blog_photoset_photo($_POST['photoset_id']); class BlogFlickrPhotoSetPhoto { static function blog_photoset_photo($photoset_id) { if (current_user_can('publish_posts')) { $photoset = self::get_photoset_photos($photoset_id); if (!$photoset) { echo 'Not a valid Photoset ID. &lt;a href="#"&gt;Try again&lt;/a&gt;.'; } else { $photo = self::get_photo_to_blog($photoset); if (!$photo) { echo 'Unexpected Error. Photo Retrieval Failed.'; } else { $permalink = self::blog_photo($photo); wp_safe_redirect($permalink); } } } } static function blog_photo($photo) { $img = self::get_photo_html($photo); $photo_info = self::get_photo_info($photo-&gt;id); $description = ($photo_info ? "{$photo_info['body']-&gt;photo-&gt;description-&gt;_content}&lt;br/&gt;" : ''); $url = self::get_photo_url($photo); $post_id = wp_insert_post(array( 'post_title' =&gt; $photo-&gt;title, 'post_type' =&gt; 'post', 'post_author' =&gt; 1, 'post_content' =&gt; "{$description}{$img}", 'post_status' =&gt; 'publish', 'comment_status' =&gt; 'open', 'ping_status' =&gt; 'open', 'post_parent' =&gt; 0, )); if ($post_id) { update_post_meta($post_id,'_flickr_photo_id',$photo-&gt;id); $url = get_permalink($post_id); } else { $url = false; } return $url; } static function get_photo_to_blog($photoset) { global $wpdb; $photo = false; if (isset($photoset['body']-&gt;photoset-&gt;photo)) { //Collect the list of Flickr Photo_ids from our "N" most resent photoset photos $photos = $photoset['body']-&gt;photoset-&gt;photo; foreach($photos as $index =&gt; $photo) { $photo_ids[$index] = $photo-&gt;id; } $photo_id_list = "'" . implode("','",$photo_ids) . "'"; //Get a list of all photos we've already blogged $posts = $wpdb-&gt;get_results("SELECT post_id,meta_value FROM wp_postmeta WHERE meta_key='_flickr_photo_id' &amp;&amp; meta_value IN ({$photo_id_list})"); //Remove any photos from the list we've already blogged $photo_ids = array_flip($photo_ids); foreach($posts as $post) { if (isset($photo_ids[$post-&gt;meta_value])) { unset($photo_ids[$post-&gt;meta_value]); } } //Grab the earliest photo we've not blogged if (count($photo_ids)==0) { $photo = false; } else { krsort($photo_ids); $photo = $photos[reset($photo_ids)]; } } return $photo; } static function get_photoset_photos($photoset_id) { $photoset = self::flickr_get(array( 'method' =&gt; 'flickr.photosets.getPhotos', 'photoset_id' =&gt; $photoset_id, 'media' =&gt; 'photos', 'per_page' =&gt; FLICKR_PHOTO_COUNT, )); return $photoset; } static function get_photo_info($photo_id) { $photo_info = self::flickr_get(array( 'method' =&gt; 'flickr.photos.getInfo', 'photo_id' =&gt; $photo_id, )); return $photo_info; } static function get_photo_html($photo,$size='') { $url = self::get_photo_url($photo,$size); list($width, $height) = getimagesize($url); $hwstring = image_hwstring($width, $height); return "&lt;img src=\"{$url}\" alt=\"{$title}\" {$hwstring} /&gt;\n"; } static function get_photo_url($photo,$size='') { extract((array)$photo); $size = (!empty($size) ? "_{$size}" : ''); // If empty the 500px version will be returned. return "http://farm{$farm}.static.flickr.com/{$server}/{$id}_{$secret}{$size}.jpg"; } static function flickr_get($params,$args=array()) { $http = new WP_Http(); $params['api_key'] = FLICKR_API_KEY; $params['format'] = 'json'; $params['nojsoncallback'] = 1; $params = http_build_query($params); $url = FLICKR_GET_URL . "?{$params}"; $result = $http-&gt;get($url,$args); if (isset($result['response']['code']) &amp;&amp; $result['response']['code'] == 200) $result['body'] = json_decode($result['body']); else $result = false; return $result; } } </code> Fully Automatic Flickr Photo Blogging If you need to go even farther, you can recode the above to use a pseudo-cron instead of triggering on an HTTP <code> POST </code> . Here's a link to a few articles that can help with that: Timing is everything: scheduling in WordPress Pseudo Cron Jobs with WordPress Experiments with WP Cron Cron Developers Demo Plugin And if pseudo-cron isn't good enough, you can alway rename the script to an obscure name and use real cron to retrieve that obscurely-named URL. If you need to go that route, check Google to learn how to set up a cron task. . In either case with cron you'll probably have to remove the <code> current_user_can() </code> code because you won't be logged in. -Mike P.S. Getting your Flickr NSID (User ID) Beyond the above you may find you need to get your Flickr NSID (aka your user ID) for some of the methods, you can find it here: flickr.people.getInfo P.P.S. Authenticating a PHP Script with Flickr is Harder You may note that none of my examples used required the caller to be authenticated. It's a good bit more involved to authenticate so if you need that be sure to look into the Flickr PHP libraries mentioned as I think they handle that.
Automating a Daily Picture Blog?
wordpress
What is a good plugin to do surveys for wordpress. I can think of creating a custom contact form 7 - but i was having problem in the formatting and separating it from the body of the post visually. and it doesn't store survey result in some document or spreadsheet, so eventually i'll have to track everything manually. so - i am on the hunt for a survey specific plugin. the questions are simple, i need option buttons, check boxes, text boxes - and like 10 questions max - nothing fancy. Thanks in advance for the help Suggestions other than poll-daddy are welcomed :)
Have you try google docs ? you can embed their form as iframe which is easiest solution.
Survey plugin recommendations
wordpress
Sorry for this complete newbie question, but I googled it and cannot find this simple information. I just installed Wordpress today. Right now all text on my Wordpress Blog is in English: "Home", "About", "Comments", etc. How can I change the language? Update: I am actually not out of the woods yet with this one. I have: located the fr_FR.mo file and copied it into a new directory '/wp-content/languages/' Modified the wp-config.php file to have the following line into it: define ('WPLANG', 'fr_FR'); Unfortunately I still get the interface in English. Any help would be much appreciated. Ok, I found the problem: I was adding the line: define ('WPLANG', 'fr_FR'); when in fact there was already another line of code: define ('WPLANG', ); which was probably overriding my bit of code. Thank you for your help.
See Installing WordPress in Your Language in the codex.
How to change language?
wordpress
Hay, the example on the wp_get_archives documentation page shows how to show a list of all the posts, by months. However if there is no posts for a month, the month doesnt get displayed. So an example list could look like this <code> Janauary (5) March (1) April (1) ... </code> Is there a way to force the list to display a month, even if no posts exist? Thanks
I've looked over code and it doesn't seem possible with this function. Months and their post counts are fetched with raw SQL query, for months without posts there are simply no records in database. It doesn't make effort to skip empty month, it simply doesn't get those from database.
wp_get_archives() display months even if there is no posts
wordpress
So I wanted to play with some Linux-only PHP performance tools and installed Ubuntu Server 10.10 in VirtualBox (for the record I have little clue about Linux, never used it extensively). Turned out Ubuntu (Debian) has WordPress package that does some things differently then I am used to. I was especially puzzled with this instead of usual <code> wp-config.php </code> : <code> $debian_server = preg_replace('/:.*/', "", $_SERVER['HTTP_HOST']); $debian_server = preg_replace("/[^a-zA-Z0-9.\-]/", "", $debian_server); $debian_file = '/etc/wordpress/config-'.strtolower($debian_server).'.php'; if (!file_exists($debian_file)) { header("HTTP/1.0 404 Not Found"); echo "&lt;b&gt;$debian_file&lt;/b&gt; could not be found. The file is either not readable by this process or does not exist. &lt;br&gt; Please check if &lt;b&gt;$debian_file&lt;/b&gt; exists and contains the right password/username."; exit(1); } require_once($debian_file); define('ABSPATH', '/usr/share/wordpress/'); define('WP_CORE_UPDATE', false); define('WP_ALLOW_MULTISITE', true); require_once(ABSPATH.'wp-settings.php'); </code> Why does it do stuff this way? Does it play well with multisite and WordPress in general? Do I understand right that I won't be able to update WordPress core of such install, other than by updating package?
The code you posted is to have multiple wp-config.php-style wordpress configuration files with one codebase. the configuration is then based on the domain name. imagine the localserver is listening on <code> http://localhost.localdomain/ </code> (no idea which one is the default with ubuntu), then the configuration file would be: <code> /etc/wordpress/config-localhost.localdomain.php </code> . This is made so that the wordpress package can be upgraded w/o overwriting your own configuration. So the reason why this is done is to have an easy upgrade path with the ubuntu package manager. I assume this does not play well with multisite, but I have no clue. It should work flawlessly with normal wordpress usage. As Thomas MacDonald already suggested, you can always go with a manual install. I would recommend that as well because you wrote that you run performance and analyse tools and I think you want to do this on the original package. So I assume that there is no need for you to rely on the pre-made ubuntu wordpress package. That's mainly for those who want to install it the "ubuntu way". Good start for you with linux, it really rocks for development. I'm sure you will enjoy it once you figured all the new things out.
WordPress package configuration in Ubuntu Server?
wordpress
I have the following line to change my wp query slightly. The posts are by this ordered by the value in the custom field "wpfp_favorites". The value is allways an integer. Posts with value 0-9 is sorted correctly, but when a post has value 10 (or more i guess) its not listed above posts with 9. <code> query_posts('meta_key=wpfp_favorites&amp;orderby=meta_value'); </code> What is wrong? You can see the problem in "action" here: http://hverdagskupp.no/
take a look here: http://codex.wordpress.org/Function_Reference/query_posts you need to change orderby=meta_value to orderby=meta_value_num -> than you value gets treated as an integer not a string! <code> query_posts('meta_key=wpfp_favorites&amp;orderby=meta_value_num'); </code> i would pass an array instead of a string like <code> query_posts( array( 'meta_key'=&gt;'wpfp_favorites', 'orderby'=&gt;'meta_value_num' ); </code> you dont have to but its easier to read and WordPress converts that string to an array anyway....
orderby in query_posts
wordpress
All tutorials I have found say to add your shortcodes to functions.php in your theme. I would like to break that away from my theme and put that in a plugin so I can share these shortcodes between my network of blogs. Is there a reference or tutorial on creating these shortcodes in a plugin?
Code in <code> functions.php </code> and plugins works in almost exactly same way (except than stage at which it is loaded and some plugin-specific hooks). Basically you just take your code out of <code> functions.php </code> , place it in plugin and it still works. It is good practice to use naming conventions and checking for functions definitions so it doesn't explode if you accidentally load both copies. But there will be no difference in how code actually works. See Writing a Plugin for a starting point.
How would I create a plugin for my shortcodes?
wordpress
I've got a dashboard widget that pulls from an RSS feed on my central server and allows anyone using my theme to see newly available skins. Using the dashboard widget, I'm currently presenting a thumbnail image of the skin along with a description and a link to download. I'd like to enable the thumbnail so that when clicked, it will open the full size image in a lightbox over the wordpress dashboard. I want to install as little extras as possible to make this possible. My theme is already including jquery-1.4.2.min.js and I'd like to build off that if possible. Any ideas much appreciated.
WordPress already ships with both jQuery and jQuery UI. Rather than including them manually, you can call them by using <code> wp_enqueue_script </code> . I'm personally a big fan of the jQuery UI Dialog setup (which also ships with WordPress) ... it should be easy enough to attach a click handler to your thumbnail such that clicking launches a jQuery dialog.
Easy lightbox effect inside of dashboard widget
wordpress
How can I change the Maximum upload file size? I would like to be able to upload 10Mb at a time.
This is due to the PHP limitations on file size uploads. If you have access to your php.ini file, you can modify the following lines: <code> upload_max_filesize = 10M post_max_size = 10M max_execution_time = 300 </code> If you don't have access to the php.ini file (such as a hosting situation), you may need to contact your webhost and see if they will increase it for you. I have also seen users create a php.ini file with just these values and place it in the file where WordPress is installed. If your PHP instance allows for "inherited configurations" it will allow these local settings to override the global. The other solution would be to add the code dynamically into WordPress to make this change for you. This article has a nice way of doing it through a "plugin". I've seen dubious results from this approach (some report success, some report no success) so I can't say for sure if it will work for you.
How to increase the file size limit for media uploads?
wordpress
I wish to create a feed of my blog which is a feed of two categories OR the feed of some tag and not the feed of some other category I know how to do "have a feed of this1 + this2 categories", but how do you do "OR" in a feed URL? (and in general, is more complex operators on the URL possible, and how?) Links that don't answer the question (but help define it): http://lorelle.wordpress.com/2006/03/27/customizing-rss-feed-links-for-wordpresscom-and-wordpress-sidebar-widgets/ http://dailycupoftech.com/2007/07/25/creating-custom-wordpress-feeds/
Feeds are essentially WordPress Loop with customized template. So it will take regular <code> query_posts() </code> arguments in URL. For example see <code> /wp-includes/feed-rss2.php </code> template. Since <code> query_posts() </code> doesn't handle OR logic you describe it isn't possible with URL alone. You will have to write your own feed template that runs and concatenates two sets of post. I think it will work simply as page template, but can also be hooked into existing feed mechanics, see <code> do_feed() </code> .
Custom WordPress Feeds operators?
wordpress
Although I am very thankful to the wordpress core team that they have finally integrated native menu management capabilities I get frustrated with some key elements which I would like to change. I need a way of showing pages which is hierarchical in the same way hierarchical categories are displayed instead of being in a list and I need a way of manually including links which can be added to a menu. How can this be done? Thanks in advance UPDATED So, here are the two things I am trying to do. Currently if you go to the default wordpress "menu management" admin screen you can select to display the "pages" metabox on the left. The problem here is that when you click on the "view all" tab NONE of the pages are ordered correctly and they are not indented if applicable. CURRENT DEFAULT LAYOUT: DESIRED LAYOUT: (please note that I just indented them to show the parent relationship, the items should also be sorted based on their sort order). Additionally, within this list (or if easier then within its own metabox) I need some way of hard coding links which should be presented in the form of a checkbox list so one can click elements and include them within the menu. The reason for this is that instead of having to manually add these elements using the "custom links" I would prefer to select them from a list.
I succeeded in this, but it is a mess. Basically, the walker should have the following parameters: <code> $this-&gt;db_fields['parent'] = 'post_parent'; $this-&gt;db_fields['id'] = 'ID'; </code> But, to get that in place, you need to rip out the existing metabox callback, copy it, change one line so you get an extra filter, and place it back. Then you can pass your own walker that has these parameters set. <code> add_filter( 'admin_head-nav-menus.php', 'wpse2770_admin_head_nav_menus' ); function wpse2770_admin_head_nav_menus() { // Hijack "Pages" meta box callback with one that has an extra filter for the walker class $GLOBALS['wp_meta_boxes']['nav-menus']['side']['default']['add-page']['callback'] = 'wpse2770_wp_nav_menu_item_post_type_meta_box'; // Since Walker_Nav_Menu_Checklist is not always available, we create this class in this function (didn't even know that was possible...) class WPSE2770_Walker_Nav_Menu_Checklist extends Walker_Nav_Menu_Checklist { public function __construct() { $this-&gt;db_fields['parent'] = 'post_parent'; $this-&gt;db_fields['id'] = 'ID'; } } } add_filter( 'wp_nav_menu_item_post_type_meta_box_walker', 'wpse2770_wp_nav_menu_item_post_type_meta_box_walker', 10, 3 ); function wpse2770_wp_nav_menu_item_post_type_meta_box_walker( $walker, $post_type, $context ) { if ( 'page' == $post_type &amp;&amp; 'view-all' == $context ) { $walker = 'WPSE2770_Walker_Nav_Menu_Checklist'; } return $walker; } function wpse2770_wp_nav_menu_item_post_type_meta_box( $object, $post_type ) { global $_nav_menu_placeholder, $nav_menu_selected_id; $post_type_name = $post_type['args']-&gt;name; // paginate browsing for large numbers of post objects $per_page = 50; $pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) &amp;&amp; isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; $offset = 0 &lt; $pagenum ? $per_page * ( $pagenum - 1 ) : 0; $args = array( 'offset' =&gt; $offset, 'order' =&gt; 'ASC', 'orderby' =&gt; 'title', 'posts_per_page' =&gt; $per_page, 'post_type' =&gt; $post_type_name, 'suppress_filters' =&gt; true, 'update_post_term_cache' =&gt; false, 'update_post_meta_cache' =&gt; false ); if ( isset( $post_type['args']-&gt;_default_query ) ) $args = array_merge($args, (array) $post_type['args']-&gt;_default_query ); // @todo transient caching of these results with proper invalidation on updating of a post of this type $get_posts = new WP_Query; $posts = $get_posts-&gt;query( $args ); if ( ! $get_posts-&gt;post_count ) { echo '&lt;p&gt;' . __( 'No items.' ) . '&lt;/p&gt;'; return; } $post_type_object = get_post_type_object($post_type_name); $num_pages = $get_posts-&gt;max_num_pages; $page_links = paginate_links( array( 'base' =&gt; add_query_arg( array( $post_type_name . '-tab' =&gt; 'all', 'paged' =&gt; '%#%', 'item-type' =&gt; 'post_type', 'item-object' =&gt; $post_type_name, ) ), 'format' =&gt; '', 'prev_text' =&gt; __('&amp;laquo;'), 'next_text' =&gt; __('&amp;raquo;'), 'total' =&gt; $num_pages, 'current' =&gt; $pagenum )); if ( !$posts ) $error = '&lt;li id="error"&gt;'. $post_type['args']-&gt;labels-&gt;not_found .'&lt;/li&gt;'; $walker = 'Walker_Nav_Menu_Checklist'; $current_tab = 'most-recent'; if ( isset( $_REQUEST[$post_type_name . '-tab'] ) &amp;&amp; in_array( $_REQUEST[$post_type_name . '-tab'], array('all', 'search') ) ) { $current_tab = $_REQUEST[$post_type_name . '-tab']; } if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { $current_tab = 'search'; } $removed_args = array( 'action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce', ); ?&gt; &lt;div id="posttype-&lt;?php echo $post_type_name; ?&gt;" class="posttypediv"&gt; &lt;ul id="posttype-&lt;?php echo $post_type_name; ?&gt;-tabs" class="posttype-tabs add-menu-item-tabs"&gt; &lt;li &lt;?php echo ( 'most-recent' == $current_tab ? ' class="tabs"' : '' ); ?&gt;&gt;&lt;a class="nav-tab-link" href="&lt;?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'most-recent', remove_query_arg($removed_args))); ?&gt;#tabs-panel-posttype-&lt;?php echo $post_type_name; ?&gt;-most-recent"&gt;&lt;?php _e('Most Recent'); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;li &lt;?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?&gt;&gt;&lt;a class="nav-tab-link" href="&lt;?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args))); ?&gt;#&lt;?php echo $post_type_name; ?&gt;-all"&gt;&lt;?php _e('View All'); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;li &lt;?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?&gt;&gt;&lt;a class="nav-tab-link" href="&lt;?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'search', remove_query_arg($removed_args))); ?&gt;#tabs-panel-posttype-&lt;?php echo $post_type_name; ?&gt;-search"&gt;&lt;?php _e('Search'); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="tabs-panel-posttype-&lt;?php echo $post_type_name; ?&gt;-most-recent" class="tabs-panel &lt;?php echo ( 'most-recent' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?&gt;"&gt; &lt;ul id="&lt;?php echo $post_type_name; ?&gt;checklist-most-recent" class="categorychecklist form-no-clear"&gt; &lt;?php $recent_args = array_merge( $args, array( 'orderby' =&gt; 'post_date', 'order' =&gt; 'DESC', 'posts_per_page' =&gt; 15 ) ); $most_recent = $get_posts-&gt;query( $recent_args ); $args['walker'] = new $walker; echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $most_recent), 0, (object) $args ); ?&gt; &lt;/ul&gt; &lt;/div&gt;&lt;!-- /.tabs-panel --&gt; &lt;div class="tabs-panel &lt;?php echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?&gt;" id="tabs-panel-posttype-&lt;?php echo $post_type_name; ?&gt;-search"&gt; &lt;?php if ( isset( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { $searched = esc_attr( $_REQUEST['quick-search-posttype-' . $post_type_name] ); $search_results = get_posts( array( 's' =&gt; $searched, 'post_type' =&gt; $post_type_name, 'fields' =&gt; 'all', 'order' =&gt; 'DESC', ) ); } else { $searched = ''; $search_results = array(); } ?&gt; &lt;p class="quick-search-wrap"&gt; &lt;input type="text" class="quick-search input-with-default-title" title="&lt;?php esc_attr_e('Search'); ?&gt;" value="&lt;?php echo $searched; ?&gt;" name="quick-search-posttype-&lt;?php echo $post_type_name; ?&gt;" /&gt; &lt;img class="waiting" src="&lt;?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?&gt;" alt="" /&gt; &lt;?php submit_button( __( 'Search' ), 'quick-search-submit button-secondary hide-if-js', 'submit', false ); ?&gt; &lt;/p&gt; &lt;ul id="&lt;?php echo $post_type_name; ?&gt;-search-checklist" class="list:&lt;?php echo $post_type_name?&gt; categorychecklist form-no-clear"&gt; &lt;?php if ( ! empty( $search_results ) &amp;&amp; ! is_wp_error( $search_results ) ) : ?&gt; &lt;?php $args['walker'] = new $walker; echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args ); ?&gt; &lt;?php elseif ( is_wp_error( $search_results ) ) : ?&gt; &lt;li&gt;&lt;?php echo $search_results-&gt;get_error_message(); ?&gt;&lt;/li&gt; &lt;?php elseif ( ! empty( $searched ) ) : ?&gt; &lt;li&gt;&lt;?php _e('No results found.'); ?&gt;&lt;/li&gt; &lt;?php endif; ?&gt; &lt;/ul&gt; &lt;/div&gt;&lt;!-- /.tabs-panel --&gt; &lt;div id="&lt;?php echo $post_type_name; ?&gt;-all" class="tabs-panel tabs-panel-view-all &lt;?php echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?&gt;"&gt; &lt;?php if ( ! empty( $page_links ) ) : ?&gt; &lt;div class="add-menu-item-pagelinks"&gt; &lt;?php echo $page_links; ?&gt; &lt;/div&gt; &lt;?php endif; ?&gt; &lt;ul id="&lt;?php echo $post_type_name; ?&gt;checklist" class="list:&lt;?php echo $post_type_name?&gt; categorychecklist form-no-clear"&gt; &lt;?php // WPSE 2770: And this is the filter we want to add! $walker = apply_filters( 'wp_nav_menu_item_post_type_meta_box_walker', $walker, $post_type_name, 'view-all' ); $args['walker'] = new $walker; // if we're dealing with pages, let's put a checkbox for the front page at the top of the list if ( 'page' == $post_type_name ) { $front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0; if ( ! empty( $front_page ) ) { $front_page_obj = get_post( $front_page ); $front_page_obj-&gt;_add_to_top = true; $front_page_obj-&gt;label = sprintf( _x('Home: %s', 'nav menu front page title'), $front_page_obj-&gt;post_title ); array_unshift( $posts, $front_page_obj ); } else { $_nav_menu_placeholder = ( 0 &gt; $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; array_unshift( $posts, (object) array( '_add_to_top' =&gt; true, 'ID' =&gt; 0, 'object_id' =&gt; $_nav_menu_placeholder, 'post_content' =&gt; '', 'post_excerpt' =&gt; '', 'post_title' =&gt; _x('Home', 'nav menu home label'), 'post_type' =&gt; 'nav_menu_item', 'type' =&gt; 'custom', 'url' =&gt; home_url('/'), ) ); } } $args['walker']-&gt;db_fields['parent'] = 'post_parent'; $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args ); if ( 'all' == $current_tab &amp;&amp; ! empty( $_REQUEST['selectall'] ) ) { $checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items); } echo $checkbox_items; ?&gt; &lt;/ul&gt; &lt;?php if ( ! empty( $page_links ) ) : ?&gt; &lt;div class="add-menu-item-pagelinks"&gt; &lt;?php echo $page_links; ?&gt; &lt;/div&gt; &lt;?php endif; ?&gt; &lt;/div&gt;&lt;!-- /.tabs-panel --&gt; &lt;p class="button-controls"&gt; &lt;span class="list-controls"&gt; &lt;a href="&lt;?php echo esc_url(add_query_arg( array( $post_type_name . '-tab' =&gt; 'all', 'selectall' =&gt; 1, ), remove_query_arg($removed_args) )); ?&gt;#posttype-&lt;?php echo $post_type_name; ?&gt;" class="select-all"&gt;&lt;?php _e('Select All'); ?&gt;&lt;/a&gt; &lt;/span&gt; &lt;span class="add-to-menu"&gt; &lt;img class="waiting" src="&lt;?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?&gt;" alt="" /&gt; &lt;input type="submit"&lt;?php disabled( $nav_menu_selected_id, 0 ); ?&gt; class="button-secondary submit-add-to-menu" value="&lt;?php esc_attr_e('Add to Menu'); ?&gt;" name="add-post-type-menu-item" id="submit-posttype-&lt;?php echo $post_type_name; ?&gt;" /&gt; &lt;/span&gt; &lt;/p&gt; &lt;/div&gt;&lt;!-- /.posttypediv --&gt; &lt;?php } </code>
How to add a custom metabox to the Menu Management admin screen?
wordpress
I am utilizing the following code which transforms any hierarchical page or custom post type with the ability to reorder the the pages through simple drag/drop. (also this code also adds a new display filter to hierarchical pages to make things simpler). The problem I need help with which currently does not work is being able to drag one page tree into another page tree or out of an existing page tree. Could someone please provide the code modifications required to extend this capability? If you know of a better way to achieve the same objectives with different code instead of extending the code provided below please also post it. UPDATED: I have also posted the code here: https://gist.github.com/812204 NOTE: for all those individuals who would like to test this out just do the follow. 1st Copy/past the code below in your themes functions.php" file. <code> /////////////////////////////////////////////////////////////////////////////////////////// // CODE TO ADD POST PER PAGE FILTER /////////////////////////////////////////////////////////////////////////////////////////// add_filter( 'edit_posts_per_page', 'reorder_edit_posts_per_page', 10, 2 ); function reorder_edit_posts_per_page( $per_page, $post_type ) { // CHECK USER PERMISSIONS if ( !current_user_can('edit_others_pages') ) return; $post_type_object = get_post_type_object( $post_type ); // ONLY APPLY TO HIERARCHICAL POST TYPE if ( !$post_type_object-&gt;hierarchical ) return; // ADD POST PER PAGE DROP DOWN UI add_action( 'restrict_manage_posts', 'reorder_posts_per_page_filter' ); // ADD SPECIAL STYLES (MOVE CURSOR &amp; SPINNING LOADER AFTER REORDER) wp_enqueue_script( 'page-ordering', get_bloginfo('stylesheet_directory') . '/custom/js/page-resorting.js', array('jquery-ui-sortable'), '0.8.4', true ); add_action( 'admin_print_styles', 'reorder_admin_styles' ); if ( isset( $_GET['spo'] ) &amp;&amp; is_numeric( $_GET['spo'] ) &amp;&amp; ( $_GET['spo'] == -1 || ($_GET['spo']%10) == 0 ) ) : global $edit_per_page, $user_ID; $per_page = $_GET['spo']; if ( $per_page == -1 ) $per_page = 99999; update_user_option( $user_ID, $edit_per_page, $per_page ); endif; return $per_page; } // STYLING CSS FOR THE AJAX function reorder_admin_styles() { echo '&lt;style type="text/css"&gt;table.widefat tbody th, table.widefat tbody td { cursor: move; }&lt;/style&gt;'; } // FUNCTION TO CREATE THE NUMBER OF POSTS PER PAGE DROPDOWN UI function reorder_posts_per_page_filter() { global $per_page; $spo = isset($_GET['spo']) ? (int)$_GET['spo'] : $per_page; ?&gt; Display:&lt;select name="spo" style="width: 100px;"&gt; &lt;option&lt;?php selected( $spo, -1 ); ?&gt; value="-1"&gt;&lt;?php _e('All Results'); ?&gt;&lt;/option&gt; &lt;?php for( $i=10;$i&lt;=100;$i+=10 ) : ?&gt; &lt;option&lt;?php selected( $spo, $i ); ?&gt; value="&lt;?php echo $i ?&gt;"&gt;&lt;?php echo $i; ?&gt; &lt;?php _e('Results'); ?&gt;&lt;/option&gt; &lt;?php endfor; ?&gt; &lt;/select&gt; &lt;?php } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ACTUAL AJAX REQUEST FOR SORTING PAGES /////////////////////////////////////////////////////////////////////////////////////////////////////////////// add_action( 'wp_ajax_simple_page_ordering', 'reorder_do_page_ordering' ); function reorder_do_page_ordering() { // RECHECK PERMISSIONS if ( !current_user_can('edit_others_pages') || !isset($_POST['id']) || empty($_POST['id']) || ( !isset($_POST['previd']) &amp;&amp; !isset($_POST['nextid']) ) ) die(-1); // IS IT A REAL POST? if ( !$post = get_post( $_POST['id'] ) ) die(-1); $previd = isset($_POST['previd']) ? $_POST['previd'] : false; $nextid = isset($_POST['nextid']) ? $_POST['nextid'] : false; if ( $previd ) { // FETCH ALL THE SIBLINGS (RELATIVE ORDERING) $siblings = get_posts(array( 'depth' =&gt; 1, 'numberposts' =&gt; -1, 'post_type' =&gt; $post-&gt;post_type, 'post_status' =&gt; 'publish,pending,draft,future,private', 'post_parent' =&gt; $post-&gt;post_parent, 'orderby' =&gt; 'menu_order', 'order' =&gt; 'ASC', 'exclude' =&gt; $post-&gt;ID )); foreach( $siblings as $sibling ) : // BEGIN UPDATING MENU ORDERS if ( $sibling-&gt;ID == $previd ) { $menu_order = $sibling-&gt;menu_order + 1; // UPDATE THE ACTUAL MOVED POST TO 1 AFTER PREV wp_update_post(array( 'ID' =&gt; $post-&gt;ID, 'menu_order' =&gt; $menu_order )); continue; } // NOTHING LEFT TO DO - NUMBERS CORRECTLY PADDED if ( isset($menu_order) &amp;&amp; $menu_order &lt; $sibling-&gt;menu_order ) break; // NEED TO UPDATE THE SIBLINGS MENU ORDER AS WELL if ( isset($menu_order) ) { $menu_order++; // UPDATE THE ACTUAL MOVED POST TO 1 AFTER PREV wp_update_post(array( 'ID' =&gt; $sibling-&gt;ID, 'menu_order' =&gt; $menu_order )); } endforeach; } if ( !isset($menu_order) &amp;&amp; $nextid ) { // FETCH ALL THE SIBLINGS (RELATIVE ORDERING) $siblings = get_posts(array( 'depth' =&gt; 1, 'numberposts' =&gt; -1, 'post_type' =&gt; $post-&gt;post_type, 'post_status' =&gt; 'publish,pending,draft,future,private', 'post_parent' =&gt; $post-&gt;post_parent, 'orderby' =&gt; 'menu_order', 'order' =&gt; 'DESC', 'exclude' =&gt; $post-&gt;ID )); foreach( $siblings as $sibling ) : // START UPDATING MENU ORDERS if ( $sibling-&gt;ID == $nextid ) { $menu_order = $sibling-&gt;menu_order - 1; // UPDATE THE ACTUAL MOVED POST TO 1 AFTER PREV wp_update_post(array( 'ID' =&gt; $post-&gt;ID, 'menu_order' =&gt; $menu_order )); continue; } // NOTHING LEFT TO DO - NUMBER ALREADY PADDED if ( isset($menu_order) &amp;&amp; $menu_order &gt; $sibling-&gt;menu_order ) break; // NEED TO UPDATE THE SIBLING MENU ORDER if ( isset($menu_order) ) { $menu_order--; // UPDATE THE ACTUAL MOVED POST TO 1 AFTER PREV wp_update_post(array( 'ID' =&gt; $sibling-&gt;ID, 'menu_order' =&gt; $menu_order )); } endforeach; } // FETCH ALL THE SIBLINGS WITH RELATIVE ORDERING AND IF THE MOVED POST HAS CHILDREN REFRESH THE PAGE $children = get_posts(array( 'depth' =&gt; 1, 'numberposts' =&gt; 1, 'post_type' =&gt; $post-&gt;post_type, 'post_status' =&gt; 'publish,pending,draft,future,private', 'post_parent' =&gt; $post-&gt;ID )); if ( !empty($children) ) die('children'); die(); } </code> 2nd Steps Because we the script below calls a custom js file we need to crate and include this file as well. If you don't want to modify the script above then go and create a folder in the root directory of your theme folder and call it "custom". Next, within this folder create another folder called "js". Next create a new file within this folder called "page-resorting.js" and past the following code into that file. After this is done you should be able to reorder through drag/drop all pages in the admin area. <code> ///////////////////////////////////////////////////////////////////////////////////////////////////// // THIS SCRIPT APPLIES TO THE CUSTOM SCRIPT MODIFICATION ALLOWING HIERARCHICAL PAGES TO BE REORDERED ///////////////////////////////////////////////////////////////////////////////////////////////////// jQuery("table.widefat tbody").sortable({ cursor: 'move', axis: 'y', containment: 'table.widefat', scrollSensitivity: 40, helper: function(e, ui) { ui.children().each(function() { jQuery(this).width(jQuery(this).width()); }); return ui; }, start: function(event, ui) { if ( ! ui.item.hasClass('alternate') ) ui.item.css( 'background-color', '#ffffff' ); ui.item.children('td, th').css('border','none'); ui.item.css( 'outline', '1px solid #dfdfdf' ); }, stop: function(event, ui) { ui.item.removeAttr('style'); ui.item.children('td, th').removeAttr('style'); }, update: function(event, ui) { if ( ui.item.hasClass('inline-editor') ) { jQuery("table.widefat tbody").sortable('cancel'); alert( 'Please close the quick editor before reordering this item.' ); return; } var postid = ui.item.find('.check-column input').val(); // THIS POST ID var postparent = ui.item.find('.post_parent').html(); // POST PARENT var prevpostid = ui.item.prev().find('.check-column input').val(); var nextpostid = ui.item.next().find('.check-column input').val(); // can only sort in same tree var prevpostparent = undefined; if ( prevpostid != undefined ) { var prevpostparent = ui.item.prev().find('.post_parent').html() if ( prevpostparent != postparent) prevpostid = undefined; } var nextpostparent = undefined; if ( nextpostid != undefined ) { nextpostparent = ui.item.next().find('.post_parent').html(); if ( nextpostparent != postparent) nextpostid = undefined; } // DISPLAY AN ALERT MESSAGE IF ANY OF THE FOLLOWING TAKES PLACE // IF PREVIOUS AND NEXT ARE NOT AT THE SAME TREE LEVEL OR NOT AT THE SAME TREE LEVEL AND THE PREVIOUS PAGE IS THE PARENT OF THE NEXT OR JUST MOVED BENEATH ITS OWN CHILDREN if ( ( prevpostid == undefined &amp;&amp; nextpostid == undefined ) || ( nextpostid == undefined &amp;&amp; nextpostparent == prevpostid ) || ( nextpostid != undefined &amp;&amp; prevpostparent == postid ) ) { jQuery("table.widefat tbody").sortable('cancel'); alert( "SORRY, THIS ACTION IS NOT POSSIBLE!\n\n&gt;&gt;&gt; WHY THIS DOES NOT WORK:\nDrag-and-Drop capabilities only work for items within their current tree.\n\n&gt;&gt;&gt; HERE IS HOW YOU CAN MOVE IT:\nIn order to move this item to the location you specified you simply need to use the \"Quick Edit\" link and modify the associated \"Parent\" page.\n\n&gt;&gt;&gt; LOCATING THE QUICK EDIT LINK:\nOn the post you want to move, just hover over the post title and click on the \"Quick Edit\" link which appears below the title." ); return; } // SHOW AJAX SPINNING SAVE ELEMENT ui.item.find('.check-column input').hide().after('&lt;img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" /&gt;'); // EXECUTE THE SORTING VIA AJAX jQuery.post( ajaxurl, { action: 'simple_page_ordering', id: postid, previd: prevpostid, nextid: nextpostid }, function(response){ if ( response == 'children' ) window.location.reload(); else ui.item.find('.check-column input').show().siblings('img').remove(); }); // FIX CELL COLORS jQuery( 'table.widefat tbody tr' ).each(function(){ var i = jQuery('table.widefat tbody tr').index(this); if ( i%2 == 0 ) jQuery(this).addClass('alternate'); else jQuery(this).removeClass('alternate'); }); } }).disableSelection(); </code>
Not really an answer, but perhaps the answer lies within this somewhere. I unpacked the navmenu js script, and stripped out what appeared to be the code which makes the drag/drop sortable nested nav items possible. It's not pretty. I don't think jQuery UI's dragable/sortable modules support nesting elements, and that's most likely the thing that will make or break whether you make it work that way. The navmenu script has a rather indepth and hard to decipher set of objects and functions that are used to calculate the inner and outer width, or depth's. I would try to figure it out, but I have my own issue with my ajax post attachments uploading dynamic metabox plugin and making that work correctly still. Maybe looking at this though will give you some insight to what you need to do in your code, if you are even able to using jqUI. Here's the entire nav-menu.js file unpacked, https://gist.github.com/820633 There are pieces you may need to see which tie this stuff together in order to make sense of it, which I didn't include. <code> depthToPx: function (c) { return c * a.options.menuItemDepthPerLevel }, pxToDepth: function (c) { return Math.floor(c / a.options.menuItemDepthPerLevel) } menuItemDepth: function () { var c = a.isRTL ? this.eq(0).css("margin-right") : this.eq(0).css("margin-left"); return a.pxToDepth(c &amp;&amp; -1 != c.indexOf("px") ? c.slice(0, -2) : 0) }, updateDepthClass: function (d, c) { return this.each(function () { var e = b(this); c = c || e.menuItemDepth(); b(this).removeClass("menu-item-depth-" + c).addClass("menu-item-depth-" + d) }) }, shiftDepthClass: function (c) { return this.each(function () { var d = b(this), e = d.menuItemDepth(); b(this).removeClass("menu-item-depth-" + e).addClass("menu-item-depth-" + (e + c)) }) }, childMenuItems: function () { var c = b(); this.each(function () { var d = b(this), f = d.menuItemDepth(), e = d.next(); while (e.length &amp;&amp; e.menuItemDepth() &gt; f) { c = c.add(e); e = e.next() } }); return c }, updateParentMenuItemDBId: function () { return this.each(function () { var e = b(this), c = e.find(".menu-item-data-parent-id"), f = e.menuItemDepth(), d = e.prev(); if (f == 0) { c.val(0) } else { while (!d[0] || !d[0].className || -1 == d[0].className.indexOf("menu-item") || (d.menuItemDepth() != f - 1)) { d = d.prev() } c.val(d.find(".menu-item-data-db-id").val()) } }) } </code> This is the sortables init method, which does some crazy algebraic E=Mc2 looking stuff lol <code> initSortables: function () { var p = 0, e, t, d, l, o, f, c, i, s, m = a.menuList.offset().left, h = b("body"), q, n = r(); m += a.isRTL ? a.menuList.width() : 0; a.menuList.sortable({ handle: ".menu-item-handle", placeholder: "sortable-placeholder", start: function (A, z) { var u, x, w, v, y; if (a.isRTL) { z.item[0].style.right = "auto" } s = z.item.children(".menu-item-transport"); e = z.item.menuItemDepth(); j(z, e); w = (z.item.next()[0] == z.placeholder[0]) ? z.item.next() : z.item; v = w.childMenuItems(); s.append(v); u = s.outerHeight(); u += (u &gt; 0) ? (z.placeholder.css("margin-top").slice(0, -2) * 1) : 0; u += z.helper.outerHeight(); i = u; u -= 2; z.placeholder.height(u); q = e; v.each(function () { var B = b(this).menuItemDepth(); q = (B &gt; q) ? B : q }); x = z.helper.find(".menu-item-handle").outerWidth(); x += a.depthToPx(q - e); x -= 2; z.placeholder.width(x); y = z.placeholder.next(); y.css("margin-top", i + "px"); z.placeholder.detach(); b(this).sortable("refresh"); z.item.after(z.placeholder); y.css("margin-top", 0); k(z) }, stop: function (x, w) { var v, u = p - e; v = s.children().insertAfter(w.item); if (u != 0) { w.item.updateDepthClass(p); v.shiftDepthClass(u); g(u) } a.registerChange(); w.item.updateParentMenuItemDBId(); w.item[0].style.top = 0; if (a.isRTL) { w.item[0].style.left = "auto"; w.item[0].style.right = 0 } a.refreshMenuTabs(true) }, change: function (v, u) { if (!u.placeholder.parent().hasClass("menu")) { (l.length) ? l.after(u.placeholder) : a.menuList.prepend(u.placeholder) } k(u) }, sort: function (w, v) { var y = v.helper.offset(), u = a.isRTL ? y.left + v.helper.width() : y.left, x = a.negateIfRTL * a.pxToDepth(u - m); if (x &gt; d || y.top &lt; f) { x = d } else { if (x &lt; t) { x = t } } if (x != p) { j(v, x) } if (c &amp;&amp; y.top + i &gt; c) { o.after(v.placeholder); k(v); b(this).sortable("refreshPositions") } } }); function k(u) { var v; l = u.placeholder.prev(); o = u.placeholder.next(); if (l[0] == u.item[0]) { l = l.prev() } if (o[0] == u.item[0]) { o = o.next() } f = (l.length) ? l.offset().top + l.height() : 0; c = (o.length) ? o.offset().top + o.height() / 3 : 0; t = (o.length) ? o.menuItemDepth() : 0; if (l.length) { d = ((v = l.menuItemDepth() + 1) &gt; a.options.globalMaxDepth) ? a.options.globalMaxDepth : v } else { d = 0 } } function j(u, v) { u.placeholder.updateDepthClass(v, p); p = v } function r() { if (!h[0].className) { return 0 } var u = h[0].className.match(/menu-max-depth-(\d+)/); return u &amp;&amp; u[1] ? parseInt(u[1]) : 0 } function g(u) { var v, w = n; if (u === 0) { return } else { if (u &gt; 0) { v = q + u; if (v &gt; n) { w = v } } else { if (u &lt; 0 &amp;&amp; q == n) { while (!b(".menu-item-depth-" + w, a.menuList).length &amp;&amp; w &gt; 0) { w-- } } } } h.removeClass("menu-max-depth-" + n).addClass("menu-max-depth-" + w); n = w } } </code> Would be nice if they had a dev version of this file, like they do with other scripts in WP. The minified single letter vars are too much to handle for me right now. It's just Alphabet soup.
Help extending custom drag-drop page ordering on admin page list screen
wordpress
hi i have wordpress and buddypress installed and i wanted to be able to search through forum posts, blog posts and other info all over the site. i found Search Engine (Wordpress Plugin) and installed it. after a brief indexing process i was able to perform all of my search requests but the problem is that when this plugin is enabled and i try to search for something inside the wp-admin, there are no results. when i turn the plguin off the wp-admin search runs. i also tried google search plugin but the outcome was the same. how can i keep my search plugin and the normal plugin work together? thanks
I've solved it by using this tutorial: Creating The sitewide global/unified search Page for your Buddypress Theme (28 Apr 2010; Buddy Dev)
How to override normal Wordpress search in Buddypress?
wordpress
I'd like to create a custom post type and add this as a child post of some but not all existing standard posts (which are not pages). Is this possible? Can I, for example, create a custom post type and then include this in other posts using a shortcode? Is there a better way to do this using custom taxonomies?
Is there a better way to do this using custom taxonomies? You're right on the money there. Rather than try to make a custom post into the child of a standard post (because you can't), I'd recommend using a custom taxonomy to order things. Essentially, you could build a custom hierarchical taxonomy and use it to "categorize" both standard posts and custom posts. You'd mark your standard posts as the parent in the taxonomy and your custom posts as the child. A second option Another option would be to use a custom field for parental inheritance. This might be a bit faster to code and more intuitive to use (plus it will give you some added control). Add a custom meta field to your custom post type called "parents." This can then be a list of post IDs the child post should be nested under. When you need to call up the list, you can do a quick query to <code> SELECT </code> all of your custom posts that have the parent ID in question in their "parents" list.
How can I combine posts of different types in one hierarchy?
wordpress
I would like to add a button under my theme manager which shows a thumbnail listing of available skins (that did not ship with the theme when it was installed). I'd like to feed this listing from a file on a central server that I maintain. Looking for some advice on how to best implement this within WordPress. I will periodically add new skins to the available listing and would like for users of my theme to be able to view them and perhaps even see a "new" icon when a new skin is first launched. I'm also interested in the merits of hosting and serving the file from Amazon s3 vs my own server
Your best bet here would be a specialized RSS feed set up on your server. You could bundle a dashboard widget with your theme that automatically pulls this RSS feed and displays the thumbnails and a description of the new skins that are listed on your site. Step 1: RSS Feed First, decide what information you want to display in the widget. I recommend a skin title, the thumbnail, a short description, and a link to further information. Store this information as XML on your server. Step 2: Dashboard Widget Create a dashboard widget that routinely checks this feed and displays updated items on the dashboard. You can use just about any existing RSS reader widget as a model here... updates to your server-hosted XML file will automatically appear on remote WordPress dashboards in this section.
Displaying Remote Data inside of Theme admin
wordpress
I have a menu defined in WP Admin that looks like this: I want to be able to display all the child links on the sidebar whenever I am at a parent page. For example, if the user is on my "About Us" page, I want a list of the 4 links highlighted in green to appear on the sidebar. I looked at the documentation for wp_nav_menu() and it doesn't appear to have any built-in way to specify a particular node of a given menu to use as the starting point when generating the links. I created a solution for stackexchange-url ("a similar situation") which relied on the relationships created by the page parent, but I am looking for one which uses the menu system specifically. Any help would be appreciated.
This was still on my mind so I revisited it and put together this solution, that does not rely on context that much: <code> add_filter( 'wp_nav_menu_objects', 'submenu_limit', 10, 2 ); function submenu_limit( $items, $args ) { if ( empty( $args-&gt;submenu ) ) { return $items; } $ids = wp_filter_object_list( $items, array( 'title' =&gt; $args-&gt;submenu ), 'and', 'ID' ); $parent_id = array_pop( $ids ); $children = submenu_get_children_ids( $parent_id, $items ); foreach ( $items as $key =&gt; $item ) { if ( ! in_array( $item-&gt;ID, $children ) ) { unset( $items[$key] ); } } return $items; } function submenu_get_children_ids( $id, $items ) { $ids = wp_filter_object_list( $items, array( 'menu_item_parent' =&gt; $id ), 'and', 'ID' ); foreach ( $ids as $id ) { $ids = array_merge( $ids, submenu_get_children_ids( $id, $items ) ); } return $ids; } </code> Usage <code> $args = array( 'menu' =&gt; 'Menu Name', 'submenu' =&gt; 'About Us', ); wp_nav_menu( $args ); </code>
Display a portion/ branch of the menu tree using wp_nav_menu()
wordpress
I'm successfully using fetch_feed() to display an RSS feed inside a dashboard widget. However, I'm unable to load the thumbnail image from the items in the feed. I'm attempting to do it with the get_image_url() method, however, WordPress errors out on that method as an undefined method. Code is below... <code> function example_dashboard_widget_function() { // Display whatever it is you want to show $rss = fetch_feed( "http://localhost/testsite/wp-content/test.rss" ); if ( is_wp_error($rss) ) { if ( is_admin() || current_user_can('manage_options') ) { echo '&lt;p&gt;'; printf(__('&lt;strong&gt;RSS Error&lt;/strong&gt;: %s'), $rss-&gt;get_error_message()); echo '&lt;/p&gt;'; } return; } if ( !$rss-&gt;get_item_quantity() ) { echo '&lt;p&gt;No RSS items to show!&lt;/p&gt;'; $rss-&gt;__destruct(); unset($rss); return; } echo "&lt;ul&gt;\n"; if ( !isset($items) ) $items = 10; foreach ( $rss-&gt;get_items(0, $items) as $item ) { $publisher = ''; $site_link = ''; $link = ''; $content = ''; $date = ''; $image = ''; $image = $item-&gt;get_image_url(); // $image = esc_url( strip_tags( $item-&gt;get_thumbnail() ) ); $link = esc_url( strip_tags( $item-&gt;get_link() ) ); $content = $item-&gt;get_content(); $content = wp_html_excerpt($content, 250) . ' ...'; echo "&lt;li&gt;&lt;img src='$image' /&gt;&lt;a href='$link'&gt;$link&lt;/a&gt; - $content&lt;/li&gt;\n"; } echo "&lt;/ul&gt;\n"; $rss-&gt;__destruct(); unset($rss); } </code>
It's a method for completely different thing. RSS 2.0, Atom 1.0, and feeds with iTunes RSS tags are allowed to have a “feed logo”, which is a single image to represent the feed. This method returns the notated URL for that image/logo file. <code> get_image_url() </code> And it complains about undefined because it is method of feed object and you are iterating through feed item objects. Overall it depends on how your feed works with images. If they are simply included in content - mine them from there (with regex or something simpler if not much text). If images are included in media enclosure try <code> get_enclosures() </code> method.
How to enable thumbnails in RSS dashboard widget
wordpress
I have been running a blog for a friend and over the last months she has been adding insane amounts of images taken directly from a DSLR. Each takes up around 5-6 MB so the site is now slow to load and is consuming large amounts of bandwidth and disk size. I was looking on the smush.it plugin, but it doesn't seem to do it ad-hock and also, doesn't do bulk resize. Is there some easy way to fix this on the server with a plugin? Would prefer that instead of download all images and do bulk resize. Big thanks.
You need the bulk image resize utility: http://wordpress.org/extend/plugins/bulk-image-resize-utility/ I have used that numerous times and it does a fantastic job!
Resizing Uploading Images in Bulk?
wordpress
I have built a query to select posts within a category. Works fine. But when I choose to add a secondary filter to exclude a category, the query return the same result set, as if the secondary category filter is being ignored. In the following the query should select all posts in category 7 and exclude those in category 10: <code> $querystr = "SELECT * FROM $wpdb-&gt;posts LEFT JOIN $wpdb-&gt;term_relationships ON($wpdb-&gt;posts.ID = $wpdb-&gt;term_relationships.object_id) LEFT JOIN $wpdb-&gt;term_taxonomy ON($wpdb-&gt;term_relationships.term_taxonomy_id = $wpdb-&gt;term_taxonomy.term_taxonomy_id) WHERE ($wpdb-&gt;term_taxonomy.term_id = 7 AND $wpdb-&gt;term_taxonomy.term_id &lt;&gt; 10 AND $wpdb-&gt;term_taxonomy.taxonomy = 'category' AND $wpdb-&gt;posts.post_type = 'post' AND $wpdb-&gt;posts.post_status = 'publish')"; </code> Can someone help?
I would use the built in API like Rarst mentioned. You could do something like this: <code> $just_seven = new WP_Query( array( 'category__in' =&gt; array( 7 ), 'category__not_in' =&gt; array( 10 ) ) ); </code> You would then have those items in <code> $just_seven-&gt;posts </code> . However, if you MUST use a direct SQL statement, I'd suggest using <code> INNER JOIN </code> instead of <code> LEFT JOIN </code> .
SQL query to select posts from multiple categories
wordpress
I would like to add a custom write panel to a custom post type. I'm looking at the the code here: http://wefunction.com/2009/10/revisited-creating-custom-write-panels-in-wordpress/ I can get the custom write panel to appear on a standard post edit page but not for my registered custom post type. <code> add_meta_box( 'int_parent_meta', ucfirst( $key ) . 'Options', 'display_meta_box', 'name-of-custom-post-type', 'normal', 'high' ); </code> If I replace 'name-of-custom-post-type' with 'post' in the above line, the panel appears on the post edit screen. Anyone know what I'm missing here? Wordpress version is 3.0.1
the fourth argument should be the name of the custom post type, as defined when you created the post type. see http://codex.wordpress.org/Function_Reference/add_meta_box For a clearer explanation of how to successfully create metaboxes, see this tutorial the second argument should be the callback function, you can create the drop down HTML in a function, and place the function name in this argument and you'll have your pull down menu.
How can I display a drop-down select of Post Names
wordpress
How to get multiple menus in TwentyTen theme?
Hi @Himanshu Vyas : There are several steps to creating additional menus using the new menu system in WordPress in the TwentyTen theme or any WordPress theme (of which some of these steps can be done out of order) . In addition, I'm going to highly recommend you create a child theme based on TwentyTen instead of modifying it directly: Create a Child Theme based on the Twenty Ten theme. Register a Theme Location in your theme's <code> functions.php </code> file. Create a New Menu using the admin console of your website. Associate the New Menu and the Theme Location using your admin console. Call <code> wp_nav_menu() </code> in the Template File of your theme where you want the menu to appear. Style your Menu so that it integrates visually with your site. So let's be on with it! 1. Create a Child Theme Creating a child theme is extremely simple and gives you the benefit of being able to upgrade TwentyTen if a new version comes out without haven't to worry about loosing your changes. Yes, there's a small chance your changes will be incompatible with the new version, and if you make copies of TwentyTen files and modify them for your child theme you'll need to reapply those changes, but that's much better than loosing your changes when the theme is upgraded. But rather than duplicate my answer from another question where I suggested child themes I'll just point you there: <a href="stackexchange-url Customizing a WordPress theme without changing it? (Use Child Themes) For the examples in the rest of this answer I'm going to call the child theme "Himanshu" . 2. Register a Theme Location Registering a theme location is very straightforward using the <code> register_nav_menus() </code> function (yes, it would have been really nice if they had called that function <code> register_nav_menu_locations() </code> , but I digress...) I'll create a "Footer" menu for this example. In my example notice how I reference <code> 'primary' </code> in a comment; I do that so you'll see what the default nav menu location is named and that you don't have to define it yourself. Also note that I used to <code> __() </code> translation function and specified the name of the child theme as the translation domain. If you are using a child theme you need to create a <code> functions.php </code> file in your theme to house this function but if you are modifying a theme them just find <code> functions.php </code> and add it to the end: <code> register_nav_menus(array( //'primary' =&gt; __('Primary Menu Area','himanshu'), ==&gt; Primary defined by default 'footer' =&gt; __('Footer Menu Area','himanshu'), )); </code> If you are writing code for your own theme and don't need to distribute it to others or worry about translations you can just do this: <code> register_nav_menus(array('footer'=&gt;'Footer Menu Area')); </code> 3. Create a New Menu Next let's create your footer menu located by navigating to the Menus option of the Appearance menu in the admin console. Click the "+" to add a menu, type the name of your menu and then click "Create Menu" : Note that you'll often name your menu the same as the name of your menu location but that's not required and WordPress treats menus and their menu locations them as separate entities . Be sure to add some options to your menu or it will be of little use. Select the options you need using the admin console, add them to your menu and then save (in my screenshot I only show selecting "Pages" for menu options but you can mix and match what ever types of menu options WordPress provides) : 4. Associate the New Menu and the Theme Location Associating your new menu with your desired theme location is easy, just use WordPress' admin console: 5. Call <code> wp_nav_menu() </code> in the Template File Now we need to head back to code. I made a copy of <code> footer.php </code> from the TwentyTen theme and copied it to the "Himanshu" theme directory. Here's what the first 18 lines look like: <code> &lt;?php /** * The template for displaying the footer. * * Contains the closing of the id=main div and all content * after. Calls sidebar-footer.php for bottom widgets. * * @package WordPress * @subpackage Himanshu (based on Twenty Ten) * @since Twenty Ten 1.0 */ ?&gt; &lt;/div&gt;&lt;!-- #main --&gt; &lt;div id="footer" role="contentinfo"&gt; &lt;div id="colophon"&gt; </code> I inserted the call to <code> wp_nav_menu() </code> along with wrapper HTML right after <code> &lt;div id="colophon"&gt; </code> on line 18 so lines 13 thru 24 now look like the following: <code> &lt;/div&gt;&lt;!-- #main --&gt; &lt;div id="footer" role="contentinfo"&gt; &lt;div id="colophon"&gt; &lt;div id="footernav" role="navigation"&gt; &lt;?php wp_nav_menu(array( 'container_class' =&gt; 'menu-footer', 'theme_location' =&gt; 'footer' )); ?&gt; &lt;/div&gt; </code> Note I chose to call the wrapper <code> footernav </code> and the inner container <code> menu-footer </code> and I followed TwentyTen's lead and set <code> role="navigation" </code> . However, the most important aspect of the code is <code> 'theme_location' =&gt; 'footer' </code> which matches up to our named theme location in step #2. All these steps gives us a Footer menu that looks like the following: 6. Style your Menu Finally we just need to add CSS to our theme's <code> style.css </code> file and we can get a footer menu that looks like so: The styling is very basic so please don't hold my awful design skills against me as I'm not a designer nor have I ever threatened to be one! I've included comments in the CSS code explain why I used each selector and CSS property that I did: <code> #colophon { padding-top:6px; /* Move menu closer to thick black line (TwentyTen has 18px) */ } #footernav { /* Use same font-family as TwentyTen does for menus */ font-family: 'Helvetica Neue', Arial, Helvetica, 'Nimbus Sans L', sans-serif; font-size:1.1em; /* Make a little bigger than default */ padding-bottom:6px; /* Put some breathing room under the menu */ } #footernav .menu-footer { text-align:center; /* Needed to center the menu */ } #footernav ul { margin:0 auto; /* Also needed to center the menu */ width:auto; /* Make menu only as wide as needs to be */ display:inline; /* Also needed to keep width to a minumum */ } #footernav li { display:inline; /* Make menu horizontal instead of veritcal */ } #footernav a { text-decoration:none; /* Remove underlines from links */ background-color:#ddd; /* Create a light grey background for each option */ color:black; /* Make the items easy to see with text in black */ padding:0.25em 0.5em; /* Add space around the items for the background to display*/ margin:0 0.5em; /* Add space between the items */ } #footernav a:hover { background-color:black; /* Surround the menu item under the mouse pointer in black */ color:white; /* Make the text for the same menu item be white */ } </code> That's about it! Do note that this is a tool for a designer to use so you or whomever your designer is can implement menus using this in practically whatever way you like from a theme perspective; just call the <code> wp_nav_menu() </code> function referencing your menus and menu locations and you're good to go!
Creating Multiple Menus when using the TwentyTen Theme?
wordpress
I've got a site ( this one ) with too many links in the blogroll. I want to keep them there, but to maybe have them "fold" in the menu (after some of them showing without the unfolding of the menu) Any solutions for that? Update: When I wrote "folding" I meant that, for (a rough) example, there would be a shuffling of the links showing and that at some point there would be a "press here for more links" button - that will poll down more of the links.
there is a plugin called "better blogroll" I guess it would help you do what you want . I had it installed on one of my sites, but site currently down , so can't really test - but as far as i remember it does the work u asking for http://www.dyers.org/blog/better-blogroll-widget-for-wordpress/ give it a look anyway and when my site is back up , i will re-confirm this
"Folding" links in the blogroll
wordpress
Let's assume that I have the following posts with the following titles: PostA (is assigned to the 'category 1') PostX ( category 2 ) PostB (category 1) PostC ( category 1 ) PostD (category 1) PostY ( category 2 ) PostE (category 1) ... When a visitor will read the PostC, how can I display in the sidebar: Previous Posts: 'PostA' (these are links here, of course) 'PostB' Next Posts: 'PostD' 'PostE' IOW the previous and the next 2 posts from the same category. (If a post has more categories we will choose the 1st one or the last one - it doesn't matter very much). Also, if it is impossible to display the prev &amp; next two posts it is acceptable also only one previous and next post. (I know that there are some WP functions for this but we prefer if it's possible two posts). Also, of course, we want to display the first 'n' characters from the title (let's say 22). We don't want to display a static text like 'Next Post' or similar. TIA
The existing WordPress functions are only for displaying one previous or next post. I quickly wrote functions to display any number of posts. Paste the following in your theme functions.php file: <code> function custom_get_adjacent_posts( $in_same_cat = false, $previous = true, $limit = 2 ) { global $post, $wpdb; $op = $previous ? '&lt;' : '&gt;'; if ( $in_same_cat ) { $cat_array = wp_get_object_terms($post-&gt;ID, 'category', array('fields' =&gt; 'ids')); $join = " INNER JOIN $wpdb-&gt;term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb-&gt;term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; } $posts = $wpdb-&gt;get_results( $wpdb-&gt;prepare( "SELECT p.* FROM wp_posts AS p $join WHERE p.post_date $op '%s' AND p.post_type = 'post' AND p.post_status = 'publish' ORDER BY p.post_date DESC LIMIT $limit", $post-&gt;post_date, $post-&gt;post_type ) ); return $posts; } function custom_adjacent_posts_links( $in_same_cat = false, $previous = true, $limit = 2 ) { $prev_posts = custom_get_adjacent_posts( $in_same_cat, $previous, $limit ); if( !empty($prev_posts) ) { echo ($previous) ? '&lt;h3&gt;Previous Posts:&lt;/h3&gt;' : '&lt;h3&gt;Next Posts:&lt;/h3&gt;'; echo '&lt;ul&gt;'; foreach( $prev_posts as $prev_post ) { $title = apply_filters('the_title', $prev_post-&gt;post_title, $prev_post-&gt;ID); echo '&lt;li&gt;&lt;a href="' . get_permalink( $prev_post ) . '"&gt;' .$title . '&lt;/a&gt;&lt;/li&gt;'; } echo '&lt;/ul&gt;'; } } </code> In your sidebar file, where you want to display the posts, use <code> custom_adjacent_posts_links( true ); </code> to display the two previous posts in the same category and <code> custom_adjacent_posts_links( true, false ); </code> to display the next two posts in the same category.
Getting the Next and Previous Posts Titles in the Sidebar?
wordpress
I knew about Atom-based dedicated servers, but these plug-class servers take it to whole new level of low-end extreme. Most of WordPress optimization talk is about surviving on shared hosting or scaling up. I got curious - how viable is it to run WordPress on such low-end, but dedicated hardware? At which point will CPU or slow storage become bottleneck? How will it compare to generic shared hosting (even lower resources, but no neighbors and freedom to optimize).
I think it really breaks down to your traffic. The slower the hardware, the slower (the already slow) page generation. It's not specific to WP, it's the same for all large php scripts. If you get a server hit every now and then, as on a dev box or a family blog, it's no big deal. It'll just spit out pages more slowly. If you get concurrent hits on a regular basis, your site will get knocked off of the web quite easily. Also note that many a low end shared host stuffs multiple sites on low end hardware. It's obviously not as low end as what you linked to, but I wouldn't expect that much of a difference in performance as compared to an overstuffed shared server.
Running WordPress on low-end hardware/resources?
wordpress
( Moderators note: Title was originally "How can I add the "Page Attributes" and/or "Page Attributes > Template" selector to POSTS editor") WP currently only allows the assignment of a "template" to Pages (i.e. <code> post_type=='page' </code> .) I'd like to extend this functionality to Posts as well (i.e. <code> post_type=='post' </code> .) How can I add the "Page Attributes" meta box and more specifically, the template switcher to the posts editor? I'm assuming this is code I will place in my <code> functions.php </code> for my theme. UPDATE: I've managed to add the hardcoded templates pulldown menu to my post editor, by simply adding the select box html to my existing custom meta options box. Here's the code I'm using for that... <code> add_meta_box('categorydiv2', __('Post Options'), 'post_categories_meta_box_modified', 'post', 'side', 'high'); </code> And here's the function that writes out the options and the template select box... <code> //adds the custom categories box function post_categories_meta_box_modified() { global $post; if( get_post_meta($post-&gt;ID, '_noindex', true) ) $noindexChecked = " checked='checked'"; if( get_post_meta($post-&gt;ID, '_nofollow', true) ) $nofollowChecked = " checked='checked'"; ?&gt; &lt;div id="categories-all" class="ui-tabs-panel"&gt; &lt;ul id="categorychecklist" class="list:category categorychecklist form-no-clear"&gt; &lt;li id='noIndex' class="popular-category"&gt;&lt;label class="selectit"&gt;&lt;input value="noIndex" type="checkbox" name="chk_noIndex" id="chk_noIndex"&lt;?php echo $noindexChecked ?&gt; /&gt; noindex&lt;/label&gt;&lt;/li&gt; &lt;li id='noFollow' class="popular-category"&gt;&lt;label class="selectit"&gt;&lt;input value="noFollow" type="checkbox" name="chk_noFollow" id="chk_noFollow"&lt;?php echo $nofollowChecked ?&gt; /&gt; nofollow&lt;/label&gt;&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;&lt;strong&gt;Template&lt;/strong&gt;&lt;/p&gt; &lt;label class="screen-reader-text" for="page_template"&gt;Post Template&lt;/label&gt;&lt;select name="page_template" id="page_template"&gt; &lt;option value='default'&gt;Default Template&lt;/option&gt; &lt;option value='template-wide.php' &gt;No Sidebar&lt;/option&gt; &lt;option value='template-salespage.php' &gt;Salespage&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;?php } </code> And finally, the code to capture the selected values on save... <code> function save_post_categories_meta($post_id) { if ( defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE ) return $post_id; $noIndex = $_POST['chk_noIndex']; $noFollow = $_POST['chk_noFollow']; update_post_meta( $post_id, '_noindex', $noIndex ); update_post_meta( $post_id, '_nofollow', $noFollow ); return $post_id; } </code> Now, I believe all that's left is (1) capturing the selected template and adding it to the post meta for this post and (2) modifying index.php and single.php so that it uses the chosen template.
Hi Scott B: Hate to be the bearer of bad news but WordPress hardcodes the Page Template functionality to the "page" post type , at least in v3.0 (that might change in future versions but there's not a specific initiative I'm aware of to change it yet. So this is one of the very few times I'm struggling to figure out how to get around something without hacking core.) The solution I've come up with is to basically copy the relevant code from WordPress core and modify it to our needs. Here are the steps (the line numbers are from v3.0.1): Copy the <code> page_attributes_meta_box() </code> function from line 535 of <code> /wp-admin/includes/meta-boxes.php </code> and modify to suit. Code an <code> add_meta_boxes </code> hook to add the metabox created in #1. Copy the <code> get_page_templates() </code> function from line 166 of <code> /wp-admin/includes/theme.php </code> and modify to suit. Copy the <code> page_template_dropdown() </code> function from line 2550 of <code> /wp-admin/includes/template.php </code> and modify to suit. Add a Post Template to your theme. Code a <code> save_post </code> hook to enable storing of the post template file name upon save. Code a <code> single_template </code> hook to enable loading of the post template for the associated posts. Now on with it! 1. Copy the <code> page_attributes_meta_box() </code> function As our first step you need to copy the <code> page_attributes_meta_box() </code> function from line 535 of <code> /wp-admin/includes/meta-boxes.php </code> and I've chosen to rename it <code> post_template_meta_box() </code> . Since you only asked for page templates I omitted the code for specifying a parent post and for specifying the order which makes the code much simpler. I also chose to use postmeta for this rather than try to reuse the <code> page_template </code> object property in order to avoid and potential incompatibilities caused by unintentional coupling. So here's the code: <code> function post_template_meta_box($post) { if ( 'post' == $post-&gt;post_type &amp;&amp; 0 != count( get_post_templates() ) ) { $template = get_post_meta($post-&gt;ID,'_post_template',true); ?&gt; &lt;label class="screen-reader-text" for="post_template"&gt;&lt;?php _e('Post Template') ?&gt;&lt;/label&gt;&lt;select name="post_template" id="post_template"&gt; &lt;option value='default'&gt;&lt;?php _e('Default Template'); ?&gt;&lt;/option&gt; &lt;?php post_template_dropdown($template); ?&gt; &lt;/select&gt; &lt;?php } ?&gt; &lt;?php } </code> 2. Code an <code> add_meta_boxes </code> hook Next step is to add the metabox using the <code> add_meta_boxes </code> hook: <code> add_action('add_meta_boxes','add_post_template_metabox'); function add_post_template_metabox() { add_meta_box('postparentdiv', __('Post Template'), 'post_template_meta_box', 'post', 'side', 'core'); } </code> 3. Copy the <code> get_page_templates() </code> function I assumed it would only make sense to differentiate between page templates and post template thus the need for a <code> get_post_templates() </code> function based on <code> get_page_templates() </code> from line 166 of <code> /wp-admin/includes/theme.php </code> . But instead of using the <code> Template Name: </code> marker which page templates use this function uses a <code> Post Template: </code> marker instead which you can see below. I also filtered out inspection of <code> functions.php </code> (not sure how <code> get_page_templates() </code> ever worked correctly without that, but whatever!) And the only thing left is to change references to the word <code> page </code> to <code> post </code> for maintenance readability down the road: <code> function get_post_templates() { $themes = get_themes(); $theme = get_current_theme(); $templates = $themes[$theme]['Template Files']; $post_templates = array(); if ( is_array( $templates ) ) { $base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) ); foreach ( $templates as $template ) { $basename = str_replace($base, '', $template); if ($basename != 'functions.php') { // don't allow template files in subdirectories if ( false !== strpos($basename, '/') ) continue; $template_data = implode( '', file( $template )); $name = ''; if ( preg_match( '|Post Template:(.*)$|mi', $template_data, $name ) ) $name = _cleanup_header_comment($name[1]); if ( !empty( $name ) ) { $post_templates[trim( $name )] = $basename; } } } } return $post_templates; } </code> 4. Copy the <code> page_template_dropdown() </code> function Similarly copy <code> page_template_dropdown() </code> from line 2550 of <code> /wp-admin/includes/template.php </code> to create <code> post_template_dropdown() </code> and simply change it to call <code> get_post_templates() </code> instead: <code> function post_template_dropdown( $default = '' ) { $templates = get_post_templates(); ksort( $templates ); foreach (array_keys( $templates ) as $template ) : if ( $default == $templates[$template] ) $selected = " selected='selected'"; else $selected = ''; echo "\n\t&lt;option value='".$templates[$template]."' $selected&gt;$template&lt;/option&gt;"; endforeach; } </code> 5. Add a Post Template Next step is to add a post template for testing. Using the <code> Post Template: </code> marker mentioned in step #3 copy <code> single.php </code> from your theme to <code> single-test.php </code> and add the following comment header ( be sure to modify something in <code> single-test.php </code> so you can tell it is loading instead of <code> single.php </code> ) : <code> /** * Post Template: My Test Template */ </code> Once you've done steps #1 thru #5 you can see your "Post Templates" metabox appear on your post editor page: 6. Code a <code> save_post </code> hook Now that you have the editor squared away you need to actually save your page template file name to postmeta when the user clicks "Publish". Here's the code for that: <code> add_action('save_post','save_post_template',10,2); function save_post_template($post_id,$post) { if ($post-&gt;post_type=='post' &amp;&amp; !empty($_POST['post_template'])) update_post_meta($post-&gt;ID,'_post_template',$_POST['post_template']); } </code> 7. Code a <code> single_template </code> hook And lastly you need to actually get WordPress to use your new post templates. You do that by hooking <code> single_template </code> and returning your desired template name for those posts that have had one assigned: <code> add_filter('single_template','get_post_template_for_template_loader'); function get_post_template_for_template_loader($template) { global $wp_query; $post = $wp_query-&gt;get_queried_object(); if ($post) { $post_template = get_post_meta($post-&gt;ID,'_post_template',true); if (!empty($post_template) &amp;&amp; $post_template!='default') $template = get_stylesheet_directory() . "/{$post_template}"; } return $template; } </code> And that's about it! NOTE that I did not take into consideration Custom Post Types , only <code> post_type=='post' </code> . In my opinion addressing custom post types would require differentiating between the different post types and, while not overly difficult, I didn't attempt that here.
Adding Page Attributes Metabox and Page Templates to the Posts Edit Page?
wordpress
For all the folders and files. Please give some explained answer.
All files should be writable only by your user account. So the correct permissions for files and directories are: Directories: 755 Files: 644 You may want to secure some files: wp-config.php: for maximum security, this file should be made writable by your user only or its group. This means 400 or 440 permission .htaccess: 666 permission, so that WordPress can automatically generate rewrite rules for you wp-content/: some plugins and themes may require write access to this directory. you will be prompted when necessary. wp-content/themes/: 664 permission if you want to use the theme editor References: Changing File Permissions Hardening WordPress
What is true chmod for WordPress?
wordpress
I have started a new site ( here ), I want to add the theme a RSS icon/logo on the top right of the theme (like in this theme ). What is the best way for doing that? (PHP/CSS wise)
You want some code to be added to the <code> #title </code> element. You can do this, stackexchange-url ("as Sorich said"), by copying the <code> header.php </code> file and just adding it there, but you could also try to add it in the footer and then using Javascript move it to the correct element. This might survive theme upgrades better, but is maybe not so user-friendly (the image appears just after the page has been loaded, giving a strange flash). The code you need is simple, let's take the example you gave: <code> &lt;p&gt; &lt;a href="&lt;?php echo bloginfo('rss2_url'); ?&gt;"&gt; &lt;img style="vertical-align:middle" src="http://www.r-bloggers.com/wp-content/themes/black-lucas/images/rss.png" alt="Subscribe to R-bloggers"&gt; RSS Feed &lt;/a&gt; &lt;/p&gt; </code> Of course, you would copy the image to your own server and change the path. You can check the styles used on the page, using a good web inspector/debugging tool (like Firebug ).
How to add an RSS logo to my blogs header?
wordpress
( Moderator's note: post was originally entitled "Taxonomy.php title") How can I display the "Posts classified under:" title for the <code> taxonomy.php </code> page? For example, this code is used in <code> tag.php </code> : <code> printf( __( 'Tag Archives: %s', 'twentyten' ), '&lt;span&gt;' . single_tag_title( '', false ) . '&lt;/span&gt;' ); </code>
Use: <code> $tax = $wp_query-&gt;get_queried_object(); printf( __( 'Posts classified under: %s', 'textdomain' ), '&lt;span&gt;' . $tax-&gt;name . '&lt;/span&gt;' ); </code>
Displaying the Name of the Queried Taxonomy Term on a Term Archive Page?
wordpress
We currently use wordpress to manage our website under our main domain. We also have a few subdomain under which different applications run. <code> www.example.com // our main website, running wordpress extranet.example.com // a custom-made LAMP application forum.example.com // another LAMP application *.example.com // anything can happen in there. </code> We would like to use the Network feature to create subdomains in which each team can have its own communication tool based on wordpress + buddypress. Question: can i convert our main wordpress installation to Network with subdomain, without removing access to extranet.* and forum.* ? I read the manual , but it doesn't address the specific case where subdomains already exist and i'm afraid to break things up.
This seems possible to me. Most of this is related to server management and not only WordPress, so probably Server Fault also has interesting info on this. On the DNS side, you would create a wildcard to the server with WordPress, and define your other subdomains to the servers that host those (some or all of them can be the same as the WordPress server). Wildcards always have the least priority. For the server side it is useful to know that if a request reaches Apache but it finds no matching <code> ServerName </code> or <code> ServerAlias </code> in a <code> &lt;VirtualHost&gt; </code> , the first virtual host is returned. So you configure the WordPress setup as the first host and the others running on that server after it.
convert from single site to multisite (network) with existing subdomains
wordpress
I have my WordPress site being hosted on a Windows provider and I am moving to another Windows provider. Any gotchas or instructions on how i can smoothly transition from one to another without losing any info?
Hi @ooo : Assuming you want to keep the same domain, it's really quite simple. Basically you copy the files using an FTP client by downloading from the old host and uploading to the new one, and then you copy the MySQL database by doing a database dump to a SQL script (this is your "export" ) and then running the script (and this is your "import" .) The rest are just details: 1.) Use FTP to download all the files from the web root and all its subdirectories of your old hosted web server. 2.) Upload all those same files to the web root of the new hosted web server in the exact same named directories. 3.) Do a full database dump (i.e. export) of your MySQL database as a SQL script. 4.) Create a new MySQL database at your new web host. 5.) Create a user for your MySQL database and set it to have all permissions. Be sure to record the name of the database, of the user and of the password. 6.) Import your MySQL database by running the MySQL script in context of your new database. 7.) Next edit your <code> /wp-config.php </code> file on your new server and give set <code> DB_NAME </code> , <code> DB_USER </code> and <code> DB_PASSWORD </code> to your new database name, new database user name and new database user password. 7.) Finally, be sure to change your domain's DNS settings so it uses the name servers from your new web host. You;ll need to wait the timeout for the DNS cache to clear and the addresses to propagate (typically it only takes a few hours but it can take up to 48 before your new site is accessible.) Thats about it. If you need more specifics be sure to give a lot more details about your new host including minimally the name and website of your new host and if possible what type of control panel they offer for you to administer your site (i.e. CPanel or something else?)
Migrating a WordPress site from One Hosting Provider to Another?
wordpress
I have defined several page templates on my site http://178.21.128.82/ . When I set my pages to use one of these page templates, wordpress seems to stop treating it as a page: It is not accepted in the is_page() conditional tag The body class "page" is not present (instead its showing "home"). Only when I use the default page template for my pages they are truly treated as a page by wordpress. Anyone got a clue what´s going on? Thanks! Added: <code> query_posts('meta_key=wpfp_favorites&amp;orderby=meta_value'); if ( have_posts() ) : while ( have_posts() ) : the_post(); $start = get_post_meta($post-&gt;ID, '5Start', true); $stop = get_post_meta($post-&gt;ID, '6Slutt', true); if(is_active($start, $stop)) { $offer = print_offer($post-&gt;ID, $start, $stop); echo $offer; } endwhile; endif; </code>
Thought so... You are using <code> query_posts() </code> and this nukes native page's loop and replaces all relevant data with your query. Since your query isn't for page - your page is no longer treated as such. Always use <code> get_posts() </code> or new <code> WP_Query </code> object for secondary loops. See stackexchange-url ("When should you use WP_Query vs query_posts() vs get_posts()?")
Custom page template, not acting as page
wordpress
I am using Contact Form 7 on my website and would like to integrate Salesforce lead tracking with it. I was able to add a hidden field with my oid as suggested on this site But when I submit the contact form after adding this, it just gets stuck and never actually returns. As soon as I remove the hidden field, it starts working fine. Has anyone been able to integrate the lead tracking system with Wordpress Contact Form plugins? I also tried using cform with the instructions provided here . But this gives a warning that fopen failed. I assume thats because fopen does not allow write operations with HTTP wrappers. Not sure how the author managed to get it working! Would appreciate any help on this! I do not want to use the salesforce Web-to-lead form. Thanks.
I've used the Gravity Forms plugin and its post form-submission hook to fire off a server-side web2lead curl request in wordpress before now. Wasn't too difficult. Essentially your web2lead form submission is purely server-side so the regular gravity forms entry logging (including IP etc...) just carries on working. You get your data in both WP and SF.
Salesforce lead tracking with contact forms plugins
wordpress
Have this function : <code> class my_walker extends Walker_Nav_Menu { function start_el(&amp;$output, $item, $depth, $args) { global $wp_query; $indent = ( $depth ) ? str_repeat("\t", $depth) : ''; $class_names = $value = ''; $classes = empty($item-&gt;classes) ? array() : (array) $item-&gt;classes; $classes[] = 'menu-item-' . $item-&gt;ID; $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item)); $class_names = ' class="' . esc_attr($class_names) . '"'; $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item-&gt;ID, $item, $args); $id = strlen($id) ? ' id="' . esc_attr($id) . '"' : ''; $output .= $indent . '&lt;li' . $id . $value . $class_names . '&gt;'; $attributes = !empty($item-&gt;attr_title) ? ' title="' . esc_attr($item-&gt;attr_title) . '"' : ''; $attributes .= ! empty($item-&gt;target) ? ' target="' . esc_attr($item-&gt;target) . '"' : ''; $attributes .= ! empty($item-&gt;xfn) ? ' rel="' . esc_attr($item-&gt;xfn) . '"' : ''; $attributes .= ! empty($item-&gt;url) ? ' href="' . esc_attr($item-&gt;url) . '"' : ''; $item_output = $args-&gt;before; $item_output .= '&lt;a' . $attributes . '&gt;'; $item_output .= $args-&gt;link_before . apply_filters('the_title', $item-&gt;title, $item-&gt;ID) . $args-&gt;link_after; $item_output .= '&lt;/a&gt;'; $item_output .= $args-&gt;after; $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); } } </code> I need to add my own counter instead of item-> ID to add $myCounter(that will increment). This : <code> $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item-&gt;ID, $item, $args); </code> To this : <code> $id = apply_filters('nav_menu_item_id', 'menu-item-' . $myCounter, $item, $args); </code> I want to adjust to crazy css menu.How can I do this? Thanks in advance.
Do you need to modify walker or hook into it unmodified? Since there is filter provided for that id, it is easy to hook into. Try this: <code> add_filter( 'nav_menu_item_id', 'modify_menu_item_id' ); function modify_menu_item_id( $text ) { static $myCounter; if( !isset( $myCounter ) ) $myCounter = 0; return 'menu-item-' . ++$myCounter; } </code> Update Changing walker <code> // add to start of start_el method static $myCounter; if( !isset( $myCounter ) ) $myCounter = 0; </code> and <code> // change id lines to this $id = $args-&gt;depth ? 'menu-item-' . $item-&gt;ID : 'menu-item-' . ++$myCounter; $id = apply_filters('nav_menu_item_id', $id, $item, $args); $id = strlen($id) ? ' id="' . esc_attr($id) . '"' : ''; </code> I tried to exclude sub-menus by checking for current depth and I think it should work properly with multiple menus because each will get new instance of walker object.
Applying my own css classes in wp_menus 3?
wordpress
I'm looking for a solution that would enable me to publish a presentation inside WordPress. I do not want to attach a PPT file or embed a Flash plugin for that, I'm looking for a HTML solution. I would be preferable to be able to use PowerPoint to create the presentation but this is not a hard requirement, more important is to output a nice presentation for the users, one with auto-play.
I've run into this problem before with both PPT files and PDF documents. The solution, actually, was quite simple ... There's a plug-in called PDF and PPT Viewer that will uses Google Docs to render your presentation inside the page. Each slide/page is rendered as a image using Google's API rather than Flash or a native file viewer. I'm using this extensively on my portfolio to show PDF files without requiring a file download or browser plug-in. Here's a specific, live example of a press release I did in January: http://work.eamann.com/2010/02/publicity-release/ . Note how the plug-in embeds the Google viewer in an iFrame on the page. The file itself is hosted on my own site (I used the WordPress media gallery uploader). Important: The plug-in download page claims the system is only tested through WP 2.8.4, however the site I've referenced above is using 3.0.1 ... it is compatible with the latest release of WordPress, the author just hasn't updated the documentation yet!
Publishing presentations in WordPress?
wordpress
Is there a way to force SSL for all requests? Much like the option to use admin ssl, but for all requests, including the ones who are not logged in.
Here is a complete guide - Enable Complete support for SSL on Wordpress
Howto force SSL for all requests?
wordpress
I want to have the authors listed like usual from <code> wp_list_authors() </code> but I know there are a couple of ones I would like to exclude from the list as well. Is there a way to do that? Thanks
It seems <code> wp_list_authors </code> does not have any filters , nor does <code> get_users_of_blog </code> , the function it uses to get the user list. So you either have to regex-and-replace the output yourself, or create a similar function with an extra parameter to specify authors to exclude. It's not too big, and most of the code is spent handling options, so it isn't that much duplication. You could always vote for the existing Trac ticket to get an <code> exclude </code> parameter added in a future version!
How can I exclude specific authors from wp_list_authors
wordpress
currently, I use CSS specificity to override plugin styles. I prefer this to editing the plugin as it makes for less headaches when you update. What would be nice is if my style sheet loaded after the plugins, so that I only have to be as specific, not more. This would make my stylesheets much prettier.
As you suggest, the most elegant approach is when your CSS overrides are loaded after the CSS injected by the plugins. This is quite easy to achieve - you just need to make sure that your <code> header.php </code> calls <code> wp_head() </code> before it references your style sheet: <code> &lt;head&gt; &lt;!-- all the usual preamble stuff goes here --&gt; &lt;?php wp_head(); ?&gt; &lt;link rel="stylesheet" href="&lt;?php bloginfo('stylesheet_url'); ?&gt;" type="text/css" /&gt; &lt;/head&gt; </code>
best way to overide plugin CSS?
wordpress
There is plenty of information on how to make the Read More function display different text in the Codex but what kind of filter would need to be used to make it display <code> &lt;button class="readmorebtn" onclick(permalink)&gt;Read More&lt;/button&gt; </code> ?
The "(more...)" link gets filtered through <code> the_content_more_link </code> in <code> get_the_content() </code> . You can hook into this function and let it return whatever you want. <code> add_filter('the_content_more_link', 'more_button'); function more_button($more_link) { return '&lt;button class="readmorebtn" onclick="' . esc_attr('window.location="' . get_permalink() . '"') . '"&gt;Read more&lt;/button&gt;'; } </code>
How to make a button?
wordpress
Hey, there. I just got this site up and going. http://www.paledogstudios.com It works fine except for the fact I can't seem to see past comments (this blog was imported from blogger) or add comments. I know it's the code not the settings since someone else told me but he didn't help me further. He said it was probably on the index.php Help?
It appears that your posts titles do not link to the single post pages, they link to the archive page. By example, the lastest article "It really is that small" links to "http://www.paledogstudios.com/2010/10/04/". The error should be in your theme index.php file.
I can't view or add comments
wordpress
I have a client that wants to use a particular theme without modification, but will likely want to have more widgets than are available with a given theme. Is there a way to add widgets to the list of those available without modifying the theme? Thanks.
Yes, you can add widgets through plug-ins the same way you add them through themes. So move the widget code from your <code> functions.php </code> file and drop it inside a custom plug-in. You'll get the same functionality without the need to modify your theme.
Add widgets to available widgets section without changing the theme?
wordpress
I'm looking for a plugin which will allow me to count how many times a file has been downloaded. I don't need neither a fancy download page nor showing the download count on the page itself, I want it just for me. I'm aware that GA can track them but if the user right-click the link it might not detect it.
You want a plugin (or another piece of software) that tracks the actual server logs. If you don't need WordPress integration there are many options, AWStats is a classic for Apache and other server log formats. I don't know whether there are plugins that integrate nicely with WordPress (normalizing URLs to posts and stuff like that). WP-Alp seems to only display bandwidth usage.
Plugin to count file download
wordpress
I'm trying to create a custom post type that I can associate with parent posts (they are posts not pages). Wordpress is version 3.0.1. I was hoping to see a list of posts in a parent post drop-down under Page-Attributes but all I get its an 'Order' field. Have I missed something vital? <code> register_post_type( 'mytest_post_type', array( 'labels' =&gt; array( 'name' =&gt; __( 'mytest Interviews' ), 'singular_name' =&gt; __( 'mytest Interview' ), 'add_new' =&gt; __( 'Add New' ), 'add_new_item' =&gt; __( 'Add New mytest Interview' ), 'edit' =&gt; __( 'Edit' ), 'edit_item' =&gt; __( 'Edit mytest Interview' ), 'new_item' =&gt; __( 'New mytest Int.' ), 'view' =&gt; __( 'View mytest Inteview' ), 'view_item' =&gt; __( 'View mytest Int.' ), 'search_items' =&gt; __( 'Search mytest Interviews' ), 'not_found' =&gt; __( 'No mytest Interviews found' ), 'not_found_in_trash' =&gt; __( 'No mytest Interviews found in Trash' ), 'parent' =&gt; __( 'Parent mytest Interview' ), ), 'public' =&gt; true, 'show_ui' =&gt; true, 'hierarchical' =&gt; true, 'query_var' =&gt; true, 'supports' =&gt; array('title', 'editor', 'author','custom-fields','page-attributes'), ) ); </code> Or is it not possible to create a new custom post type and have those new posts be children of existing posts? thanks!
This works for me. Looking at the code , the dropdown only appears if the post type is hierarchical (which is true in your case), and if there are other posts of the same type in the database. So a post can not be a child of another post type (a regular post or page for example), and the first new post of a type will not show the dropdown menu.
Parent drop-down not appearing for custom post type
wordpress
I am using the menus API, and I want to switch to a different menu, but it is holding the first one for some reason Here is my code in functions.php <code> add_action( 'init', 'register_my_menus',10 ); function register_my_menus() { register_nav_menu('main-navigation', 'Main Navigation'); } </code> Here is the code in my theme file (header.php) <code> &lt;?php $args = array( 'menu' =&gt; 'main-navigation', 'container_id' =&gt; 'navigation', 'fallback_cb' =&gt; 'wp_page_menu' ); wp_nav_menu($args); ?&gt; </code>
_Menus are somewhat confusing around there. Try this: <code> $args = array( 'theme_location' =&gt; 'main-navigation', 'container_id' =&gt; 'navigation', 'fallback_cb' =&gt; 'wp_page_menu' ); wp_nav_menu($args); </code> <code> theme_location </code> tries to display menu that is attached to this location. <code> menu </code> tries to display menu by slug/id (not location of menu, but actual menu that you create in admin area). So you are mixing up location with menu slug, it gets confused and just serves first menu it can. See <code> wp_nav_menu() </code> documentation for full description of logic behind it.
Menu API not switching menus?
wordpress
My pagination is only linking to the same posts that are on my front page. I have 3 posts on my front page, when I press next it goes to /page/2 but only shows the same 3 posts, with no previous button. The next button is still there, but still goes to page/1 Here is the full query. <code> &lt;?php query_posts('post_type=post&amp;posts_per_page=3'); if ( have_posts() ) : while ( have_posts() ) : the_post(); $category = choose_one_category(get_the_category()); switch ($category){ case "Festival News": $left[] = $post; break; case "Industry News": $centre[] = $post; break; case "Other": $right[] = $post; break; } endwhile; ?&gt; &lt;div class="custom-pagination"&gt; &lt;div &gt;&lt;?php previous_posts_link('&amp;laquo; Previous') ?&gt;&lt;/div&gt; &lt;div &gt;&lt;?php next_posts_link('Next &amp;raquo;') ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php endif; ?&gt; </code>
Building off of what Rarst has said, I'm pretty sure the query string will retain 'paged' queries even if <code> WP_Query </code> strips it out as irrelevant. You could try replacing your query posts line with this: <code> global $query_string; parse_str( $query_string, $my_query_array ); $paged = ( isset( $my_query_array['paged'] ) &amp;&amp; !empty( $my_query_array['paged'] ) ) ? $my_query_array['paged'] : 1; query_posts('post_type=post&amp;posts_per_page=3&amp;paged='.$paged); </code>
Pagination resolving to first page only
wordpress
Hay, i have a custom post type "Events", however this is basically a post type, so it inherits the post.php template page. Is there anyway to use a different template (i.e events.php) if the content type is an 'event'?
Try <code> single-events.php </code> . See Template Hierarchy in Codex for full scheme of templates.
display different template based on post type
wordpress
I have a hierarchical taxonomy called 'tarefa' I have to display all posts from a child taxonomy. I used get_term_children function function to verify if the taxonomy parent has children. If the taxonomy parent has children I will query posts by taxonomy children. The problem is: I have to query posts by taxonomy slug but the function get_term_children return an array of taxonomy IDS. The question is: How can I return a taxonomy slug by a taxonomy ID?
I have bit of trouble understanding your question. Taxonomy (like <code> category </code> ) slug or term (like <code> uncategorized </code> ) slug? <code> get_term_children() </code> works with terms so I will stick with that. Try this: <code> $term = get_term( $id, $taxonomy ); $slug = $term-&gt;slug; </code>
Get term SLUG by term ID
wordpress
We're in the process of migrating a site from an existing CMS system into WordPress. The existing CMS system has no direct integration tools with WordPress. I'm looking into the option of creating my own script/application that will migrate the content between the two systems. Would it be better to migrate directly into the database (inserting the rows myself) or to generate a WXR file (or multiple) and let the WordPress import module handle things for me?
If this is a standard CMS (not something you came up with yourself), I would say that a WXR solution is the way to go. It might take some extra work, but it will be a good learning experience and a nice way to build up your Wordpress skills. The WXR route will be an automated solution that's reliable and repeatable. You might want to consider doing this as an open source project, soliciting help from the community to get it done. The end result will be a useful tool from which others can utilize, improve, and extend. Open source contributions are always nice to list on the resume, too.
Is a direct or import approach safer for migration into WordPress?
wordpress
Is anyone aware of any way to show statistics on your WP blog to show android market place downloads? For example, I create an application and host it on the android market place, it gets downloaded/installed 10 times. Is there any plugin I can use to display these figures/links etc on the sidebar in WP?
This plugin will display information from the Android Market, it may be able to be modified to include statistics, but I'm not sure. Otherwise, there are no existing plugins that do what you are asking.
Plugin for Android Marketplace downloads?
wordpress
I have created a custom WP_Query as seen below. The query works well except for when $favorites is empty. When $favorites is empty, the query still outputs posts, which I don´t want. It could seem like it defaults back to the standard WP_Query to output all published posts. Anyone knows what´s going on? <code> $favorites = wpfp_get_users_favorites($user = ''); $favorites_query = new WP_Query(array('post__in' =&gt; $favorites)); while ($favorites_query-&gt;have_posts() ) : $favorites_query-&gt;the_post(); </code> Thanks!
Empty argument here does not equal logical in nothing . It equals no value to process and so WP ignores it and goes further as usual. Just wrap your query in <code> if( !empty( $favorites) ) </code> condition.
Custom WP_Query with no posts to output
wordpress
I have two custom taxonomies applied to two custom post types. the terms list on the sidebar just fine and will list all posts associated with it. However, if you search one of the terms in specific, it doesn't bring up a post with that term. Example: http://dev.andrewnorcross.com/das/all-case-studies/ Search for term "PQRI" I get nothing. Any ideas? I've tried using various search plugins but they either break my custom search parameters or just don't work.
I would recommend the Search Everything plugin too, but if you want to implement this using WP's search function, here's the code I'm using in my Atom theme: <code> // search all taxonomies, based on: http://projects.jesseheap.com/all-projects/wordpress-plugin-tag-search-in-wordpress-23 function atom_search_where($where){ global $wpdb; if (is_search()) $where .= "OR (t.name LIKE '%".get_search_query()."%' AND {$wpdb-&gt;posts}.post_status = 'publish')"; return $where; } function atom_search_join($join){ global $wpdb; if (is_search()) $join .= "LEFT JOIN {$wpdb-&gt;term_relationships} tr ON {$wpdb-&gt;posts}.ID = tr.object_id INNER JOIN {$wpdb-&gt;term_taxonomy} tt ON tt.term_taxonomy_id=tr.term_taxonomy_id INNER JOIN {$wpdb-&gt;terms} t ON t.term_id = tt.term_id"; return $join; } function atom_search_groupby($groupby){ global $wpdb; // we need to group on post ID $groupby_id = "{$wpdb-&gt;posts}.ID"; if(!is_search() || strpos($groupby, $groupby_id) !== false) return $groupby; // groupby was empty, use ours if(!strlen(trim($groupby))) return $groupby_id; // wasn't empty, append ours return $groupby.", ".$groupby_id; } add_filter('posts_where','atom_search_where'); add_filter('posts_join', 'atom_search_join'); add_filter('posts_groupby', 'atom_search_groupby'); </code> It's based on the Tag-Search plugin: http://projects.jesseheap.com/all-projects/wordpress-plugin-tag-search-in-wordpress-23
Include custom taxonomy term in search
wordpress
Does anybody know of any good publicly-available Wordpress training materials (videos, manuals, etc.) that could be used to give content editors a basic overview of Wordpress. We have a a handful of blogs on a Wordpress server and I'd really like to be able to automate training some more.
Interconnect/Spectacula folks manage free WordPress User Guide for training users.
User Training Materials
wordpress