question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I have an interesting problem which I hope someone can quickly answer. I have created my own metabox which, based on "MY METABOX CODE" (list below) is correctly displaying a dropdown list of all my terms within the "event_types" taxonomy I created. Where I am running into an issue is being able to SAVE/UPDATE the term associated with a post when a different term is selected from the dropdown and the post is updated. After tinkering around with various code bits I was able to figure out that by MANUALLY entering the term_ID number(s) [separated by commas] into the array area I am getting the results I am looking for. For example if on saving the post a function were to call this code <code> wp_set_post_terms( $post_id, array(5,7), 'event_types', FALSE); </code> then my post WILL UPDATE and associate the term_ID 5 &amp; 7 to it which as you can see I am passing in the array. The problem is that this is hard coded into my functions.php file and not based on a user selected dropdown value (note: I am actually only trying to pass one ID but I did two for testing as explained below). I have also been able to figure out that if I add the following code to my metabox file then I am able to echo a list of assigned term IDs but the last item has a comma. <code> &lt;?php $event_types = wp_get_object_terms($post-&gt;ID, 'event_types'); foreach ($event_types as $event_type) { echo $event_type-&gt;term_id . ','; } ?&gt; </code> So... it seems I have 85% of my problem solved. The Remaining 15% of my problem remains as follows: What do I need to add to my functions.php file code (listed below) so that when I create/update a post the NEW VALUE selected from my taxonomy dropdown list is passed into the array? Although in this example I am looking to ensure that only a SINGLE taxonomy can be associated with a post, there are other situations where I would like to create a checkbox list which would require me to pass more than one value into the array. As such, what would I need to change so that a comma separated list of term IDs is passed into the array? If your answer involves using some or part of the example code I listed above where I echo the IDs then how do I ensure the last ID which is printed does not have a comma at the end? (Is there a different/better way to do it? I saw hints which might relate to adding a filter but I am not sure how this is done...) Thank you guys very much in advance - below is the code I am currently using in each file. CODE IN MY FUNCTIONS.PHP FILE <code> function save_event_taxonomy_terms($meta, $post_id) { $event_types = wp_get_object_terms($post-&gt;ID, 'event_types'); wp_set_post_terms( $post_id, array($names), 'event_types', FALSE); } </code> MY METABOX CODE <code> &lt;select name='post_event_types' id='post_event-types'&gt; // DISPLAY TERMS AS DROP DOWN OPTIONS &lt;?php $names = wp_get_object_terms($post-&gt;ID, 'event_types'); $event_types = get_terms('event_types', 'hide_empty=0'); ?&gt; &lt;option class='event_type-option' value='' &lt;?php if (!count($names)) echo "selected";?&gt;&gt;Not Assigned&lt;/option&gt; &lt;?php foreach ($event_types as $event_type) { if (!is_wp_error($names) &amp;&amp; !empty($names) &amp;&amp; !strcmp($event_type-&gt;slug, $names[0]-&gt;slug)) echo "&lt;option class='event_type-option' value='" . $event_type-&gt;slug . "' selected&gt;" . $event_type-&gt;name . "&lt;/option&gt;\n"; else echo "&lt;option class='event_type-option' value='" . $event_type-&gt;slug . "'&gt;" . $event_type-&gt;name . "&lt;/option&gt;\n"; } ?&gt; &lt;/select&gt; </code>
I figured I would post the answer to this after Dimas was able to assist me. Utilizing his WPAlchemey Class I added a save_action var which looked like this (note that I am using the taxonomy for "category" which of course you can change to whatever your custom taxonomy might be): <code> 'save_action' =&gt; 'save_taxonomy_terms', </code> I then add the following function for this as follows: <code> function save_taxonomy_terms($meta, $post_id) { wp_set_post_terms($post_id, array($meta['my_terms']), 'category', FALSE); } </code> An my metabox code which displays the dropdown list of taxonomies looks like this: <code> &lt;label&gt;Event Category:&lt;/label&gt; &lt;?php $terms = get_terms('category', 'hide_empty=0'); ?&gt; &lt;?php $mb-&gt;the_field('my_terms'); ?&gt; &lt;select name="&lt;?php $mb-&gt;the_name(); ?&gt;"&gt; &lt;option value='' &lt;?php if (!count($terms)) echo "selected";?&gt;&gt;Not Assigned&lt;/option&gt; &lt;?php foreach ($terms as $term): ?&gt; &lt;option value="&lt;?php echo $term-&gt;term_id; ?&gt;"&lt;?php $mb-&gt;the_select_state($term-&gt;term_id); ?&gt;&lt;?php echo '&gt;' . $term-&gt;name; ?&gt;&lt;/option&gt; &lt;?php endforeach; ?&gt; &lt;/select&gt; </code>
Saving Taxonomy Terms
wordpress
I need to create a custom post meta box(es) for my custom post type "Slideshow" (this post type is already created). Each metabox will hold the content in each slide slide and save it to corresponding custom fields. Each metabox should contain the following fields: Title (Text Field) Image (Either a Text Field for the img URL or ideally a Dropdown List showing thumbnails of the images attached attached to the post) Embed Code (Text Area) Description (wysiwyg) Hide the Slide (Checkbox to use to temporarily hide a slide without deleting it) Delete Slide (button that deletes the contents of the post meta fields that were filled in by this slide) I would also like a button somewhere that allows me to "Add a slide" so when it is clicked, it adds another "Slide" Custom Meta Box which is a duplicate of the first but adds an incremental number to each custom post meta field. I currently just have 15 metaboxes and the Slideshow template is set up in a way that if only 5 of the metaboxes are filled in then only 5 slides display. Finally, I'd like to be able to re-order the slides, whether by "Drag and Drop" or by another Text Field that I can type the order number in. I have gotten it almost where I need it with the "More Fields" plugin and some code help from Rarst. With the "More Fields" plugin I have the following fields in each metabox: Title (Text Field) Image (A dropdown list of the images attached to the post) Embed Code (Text Area) Description (wysiwyg) Hide the Slide (Checkbox to use to temporarily hide a slide without deleting it) Here is a screenshot of how I have it setup through the "More Fields" plugin: The problem with this is that there is no way to delete a slide once it is made because "More Fields" doesn't use <code> &lt;?php delete_post_meta($post_id, $key, $value); ?&gt; </code> anywhere. The other problem with the plugin is that it is too unreliable and breaks frequently with updates. I have been able to implement a similar solution with my own custom metaboxes that includes: Title (Text Field) Image (Text Field for the img URL) Embed Code (Text Area) Description (Text Area) Hide the Slide (Checkbox to use to temporarily hide a slide without deleting it) With this implementation I can't seem to get the multiple TinyMCE fields to work or the image dropdown box. The TinyMCE code seems to work until I add the code that create incremental copies of the first metabox at which point I get this error right above the field where the TinyMCE buttons should be: <code> Warning: array_push() [function.array-push]: First argument should be an array... </code> . Also, right now I am relying on my writers to know to put in EITHER a video or an image for each slide and that's ok but it may be better to have a radio button that lets them choose which one the slide is (probably default to image) which is tied to a conditional display statement in the slideshow template. I am handling image uploads via the built-in "Featured Image" box in the sidebar although I wouldn't mind a custom metabox that simply said "Upload Images" at the top of the write panel. Ultimately I am looking for a slideshow similar to this: http://www.nytimes.com/slideshow/2010/08/10/science/20100810angier-1.html. I want mine to also be able to have a video as the content in the slide instead of a picture. I need an intuative and easy to use Admin panel for my writers (they are not very tech savvy and not reliable using html and/or shortcodes). Just in case it's not clear from the example, every slide should generate a new pageview. The Drag'n'Drop reordering isn't a high priority but it would be cool. I found a plugin that handles this really well: SlideDeck. Unfortunately the plugin doesn't suit my needs but the way they handle ordering of the slides is pretty slick. It's a seperate metabox in the sidebar that lets you drag the slides around into the order you like. This is also how you add slides, by clicking on an "Add Slide" button which adds another Slide Metabox to the write panel. Here is a screenshot: You can also see more screenshots of it in action in the wordpress repository. Here is all my code: The functions setting up my Slideshow Post Type and Slideshow Pagination: http://loak.pastebin.com/g63Gf186 The original code from DeluxeBloggingTips.com (DBT) that I based my Metaboxes off of: http://loak.pastebin.com/u9YTQrxf The version of the DBT code that I modified to give me incremental versions of the same metabox: http://loak.pastebin.com/WtxGdPrN A modified version of the DBT code that Chris Burbridge created to allow for multiple instances of TinyMCE: http://loak.pastebin.com/Mqb3pKhx With this code the TinyMCEs do work. My modification of Burbridge's code that tries to incorporate my incrementation and a field that lets you choose the image from a dropdown list of all the images attached to the post: http://loak.pastebin.com/xSuenJTK In this attempt, the TinyMCE is broken and the dropdown doesn't work. This probably doesn't matter but just in case you are wondering, here is the code I use to pull the embed code from the custom post meta, resize it, and insert it in the post: http://loak.pastebin.com/n7pAzEAw This is an edited version of the original question to reflect the current status of the project and answers the questions posted in the comments. Thanks to stackexchange-url ("Chris_O") for putting the bounty on this. Also, thanks to stackexchange-url ("Rarst") and Justin for helping me out with a lot of this in the ThemeHybrid.com forum. I have spent hours and hours on this and am stuck (I spent a couple hours alone on this Question). Any help would be greatly appreciated.
From the looks of things, your safest bet and easiest route would be to fork the More Fields plugin specifically for your use. The two biggest features I can see your fork needing are a field "factory" and a drag-and-drop interface. Multiple Fields My suggestion would be to look at the WordPress Widget class and use it as a model for your field factory - basically, borrow the ability to create multiple instances of a field once you have the framework built for it. This is the core of how multiple widgets work in a sidebar: You define the code for each widget once by extending the <code> WP_Widget </code> class. Then, you can create as many copies of the widget as you want The specifics of each widget are stored as serialized data in the options table You can customize each widget, remove them with a simple <code> delete </code> command, and set their positioning explicitly through the Appearance drag-and-drop interface Drag-and-drop Once again, I suggest looking to the WordPress widget system for inspiration. We've already got a fairly intuitive drag-and-drop interface set up there, so it would be fairly easy to re-purpose much of the same code elsewhere. Or, if you want to get really fancy, you can implement your own drag-and-drop system inside a separate custom meta field. So each slide would be defined by a custom meta box that's linked to the post. The order of the slides would be set by a separate custom meta box that's also linked to the post. I'd recommend submitting slide updates via AJAX so you can dynamically update the slide order meta box based on the information (this prevents having to manually hit "update" and wait for the page to reload before moving things around). jQuery UI has a great "draggable" interface that you could easily manipulate for your purposes within this custom meta box. The hard part isn't building the interface, it's getting consistent, accurate communication between the meta box and the collection of slide meta boxes elsewhere on the page. In Summary What I gathered from your post is that you have a somewhat workable solution: You've added 15 custom fields to your custom post type via the More Fields widget but want to dynamically add/remove fields rather than work with a set number You want a way to adjust the order of these custom fields so that the slides load in order The way I'd approach this is to abstract the custom meta creation process to a class I can use over and again to create new custom meta fields. Then I'd extend the class to initialize two types of meta boxes: one for slides, one for slide structure. I'd also build into the slide structure meta box the ability to dynamically create new slide meta boxes (the slide meta boxes would house their own "delete" action). The entire slideshow would be stored not by the slide meta boxes, but by the slide structure meta box into a custom meta field for the post - the custom meta would be a jagged array, with each of the slides represented as arrays within it - in order . Customizing the order of the slideshow in the structure meta box would reorganize the array and re-save the post meta. This way I only have 1 meta value to read back out when I want access to the slideshow. Between SlideDeck, More Fields, and the custom code you've put together so far, you've already got most of your solution in hand ... you just need to get it all working together at the same time. I'd focus on getting the root implementation down first before adding the JavaScript embellishments - dynamically creating, modifying, saving, and deleting slides is more important than a rich text editor, IMO. Get that cracked out first. Then get the ordering system down. Then you can focus on getting multiple instances of TinyMCE working on the page.
Help Creating a Slideshow Custom Post Type with Custom Meta Boxes?
wordpress
Some links on my site take the user to a specific post in context on a category page . On non-WP sites, this is easily accomplished by including <code> #example-div-id </code> in the url like this: <code> http://www.example.com#example-div-id </code> But in a WP environment, this url isn't working : <code> http://www.example.com/?cat=15#post-170 </code> This (incorrectly) jumps the browser window to the end of the page. But this does work ...manually removing the trailing slash after page load and reloading the page. The browser window jumps to the appropriate div, or post. <code> http://www.example.com?cat=15#post-170 </code> . Does anyone know why this is? Or how to get WP to eliminate the trailing slash? Is it safe to eliminate the trailing slash? Update I tried using EAMann's solution below, implementing pretty permalinks to facilitate the anchor jump. The results achieved completely break my post order and exclusion of child categories. My navigation is category based. I don't use pages, but use category names in the navigation. Each 'page' is really a category archive showing posts from the category. What I've read about permalinks starting with %category% leads me to avoiding permalinks all together. I certainly don't want to start the permalink with the year or post id either. It doesn't make sense on my site. <code> http://www.example.com/category/my-category </code> looks more professional and "normal" than <code> http://www.example.com/2009/my-category </code> when the intended illusion is that the category names are really pages on this business site. So I'd appreciate any other explanations why the anchor jumping isn't working. Update #2 (in response to EAMann's comment directly on the OP) My site is a business website that for the most part displays static content. A few areas have featured portfolio work and there is blog section. The site uses a category based navigation. All the site content is written as posts. Each post is associated with a category that determines where the post is displayed. The site navigation menu is created with <code> wp_list_categories() </code> . Clicking on a category opens a category archive that presents all the posts from the category. I'm currently using the default permalink structure. <code> http://www.example.com/?cat=15 </code> shows a category page. Update #3 After more investigation, it appears that the jQuery plugin "innerfade" that I'm using to display a slideshow at the top of the page is the culprit. It has nothing to do with the trailing slash. Sorry to go down the wrong path. If I comment out the php that includes the plugin js file, and the anchor jump works just fine. I would guess that some javascript manipulation of the page content is screwing up the jump. I've worked around the problem using <code> $(window).scrollTo(); </code> . I appreciate everyone's time.
As I've stated in updates to my question...other javascript working on the page conflicts with the anchor jump. I implimented more js to work around the conflict. The url almost looks the same as before, but with a parameter name inserted before the pound symbol, <code> http://www.example.com/?cat=15&amp;hi=#post-170 </code> but I use jQuery-Howto's 'plugin' to get url parameters. <code> $.extend({ getUrlVars: function(){ var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&amp;'); for(var i = 0; i &lt; hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; }, getUrlVar: function(name){ return $.getUrlVars()[name]; } }); </code> I retrieve the post number assigned to the 'hi' url parameter and scroll to 20px above the post with the same id. <code> //'hi' var used to jump to anchor var hi = $.getUrlVar('hi'); if ( hi ) { //scroll to link or search results if url var 'hi' is present $(window).scrollTop($(hi).position().top-20); </code> the jquery plugin code and my custom code above go in my javascript file which is included in header.php
How to use div -ids in url to jump to specific post...Is trailing slash the culprit?
wordpress
In my current theme version, I'm registering sidebars with names. However, in previous versions, I only had one sidebar and registered it without a name like so... <code> if ( function_exists('register_sidebar') ) register_sidebar(array( 'before_widget' =&gt; '&lt;div class="menu side %2$s"&gt;', 'after_widget' =&gt; '&lt;/div&gt;', 'before_title' =&gt; '&lt;h4&gt;', 'after_title' =&gt; '&lt;/h4&gt;', )); </code> But now in my updated theme, I register several sidebars and give them all a name. However, when I update the old theme to the latest version, the sidebar widget that was registered without a name is seemingly getting arbitrarily assigned to one of the new "named" sidebars, but not the one I need it to. I need that unmamed sidebar widget to be reassigned to the one named "Sidebar" in the updated theme. Here are my new sidebar registrations... <code> if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' =&gt; 'Featured_Home', 'before_widget' =&gt; '&lt;div class="featured-home"&gt;', 'after_widget' =&gt; '&lt;/div&gt;', 'before_title' =&gt; '&lt;h2&gt;', 'after_title' =&gt; '&lt;/h2&gt;', )); if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' =&gt; 'Featured_Inside', 'before_widget' =&gt; '&lt;div class="featured-inside"&gt;', 'after_widget' =&gt; '&lt;/div&gt;', 'before_title' =&gt; '&lt;h2&gt;', 'after_title' =&gt; '&lt;/h2&gt;', )); if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' =&gt; 'Featured_Category', 'before_widget' =&gt; '&lt;div class="featured-category"&gt;', 'after_widget' =&gt; '&lt;/div&gt;', 'before_title' =&gt; '&lt;h4&gt;', 'after_title' =&gt; '&lt;/h4&gt;', )); if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' =&gt; 'Sidebar', 'before_widget' =&gt; '&lt;div class="menu side %2$s"&gt;', 'after_widget' =&gt; '&lt;/div&gt;', 'before_title' =&gt; '&lt;h4&gt;', 'after_title' =&gt; '&lt;/h4&gt;', )); if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' =&gt; 'Home_PreFooter', 'before_widget' =&gt; '&lt;div class="footer-pre-home"&gt;', 'after_widget' =&gt; '&lt;/div&gt;', 'before_title' =&gt; '&lt;h4&gt;', 'after_title' =&gt; '&lt;/h4&gt;', )); if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' =&gt; 'Inside_PreFooter', 'before_widget' =&gt; '&lt;div class="footer-pre-inside"&gt;', 'after_widget' =&gt; '&lt;/div&gt;', 'before_title' =&gt; '&lt;h4&gt;', 'after_title' =&gt; '&lt;/h4&gt;', )); </code>
Try moving registration of <code> Sidebar </code> sidebar to be first. I had an impressions that widget should move to that special "unassigned" area in this situation, but maybe that only works between themes, not changes in same theme.
Sidebar Widget Registration without a name, how is it assigned to new named sidebar widget?
wordpress
Is it possible to write a virus in a form of a WordPress plugin/theme? Is it possible to: steal user data? damage existing WordPress installation? (optionally) self-spread the virus? Are there any existing cases of this kind of viruses?
When you write PHP code, you can do just about anything. So when you run the code of a plugin it can do just about anything as well. It can query the database and get whatever info is there (which is why it's a good idea to store passwords as hashes.) Since it can query the database, it can also delete anything in the database, ruining settings, turning off plugins etc. Plugins can send out info the normal way, mail, http, so spreading a virus will be hard if the receiver has good protection. Depending on your server setup, a plugin can take over your server. If you allow it, to download files that it can execute, it would be able to download any code, that it would be able to run in your server. If the user running the code has enough privileges, it can do stuff like changing the password effectively shutting you out of the server. But all of this, will be easy to spot, so if a lot of people are using it, you should be safe to download and use it, since expert PHP developers, would have found out about it. So short answer is, yes almost anything is possible, but the dangers are not that great. If you use popular pluings . I think a bigger danger, would be that the plugin is poorly written, and will accidentally create a security risk, like not validating user provided data etc.
Can a WordPress plugin or theme contain a virus?
wordpress
How do we edit and remove link backs to theme Developers from theme settings page ? Some themes which we install on site has link backs .How do you edit them from multisites? Does any body have Idea on removing these links? I want to edit the Links Like "Mystique 2.4.2 by digitalnature " .
Basic idea is to search theme files for text of the link and remove code that inserts it. Best case scenario it would be single line to remove. Worst case scenario - link would be added by highly obfuscated code and rigged to break theme if link is removed. Since theme you referenced is in official theme repository it would be unlikely to have obfuscated code.
How do you remove Link backs on Theme settings page?
wordpress
I have a post here: http://www.food101.co.il/?p=5993 Where the image is overlapping the sidebar. I wish to shrink the image, but I want something that will do this without me editing the post (why? because the author is not me - and I want an automated system) Is there a plugin or a CSS solution that can do this? (as cross browser as possible?)
Quick fix via CSS would be using max-width property to style images inside posts. Unfortunately it is very unreliable in Internet Explorer. <code> .entry img { max-width:500px !important; } </code> Also in your specific case image has size defined with inline style and it interferes. Plugin method would involve scanning and changing posts content on the fly, which would probably bring in performance issues, etc. In my opinion it is better to fix such things consistently on content level. If you have no authority to edit posts show the issue to person who has.
How to limit image size for the entire website ? But without editing the post (css/plugin?!)
wordpress
I use the get_page_children() function to create a sub_nav for a designer client I do work for. She uses the Spry Assets flyout JS that DreamWeaver creates, so I have to manually do the menus like this rather than use the new menus functionality in WordPress. I had them all set up and working perfectly, and then my client upgraded to 3.0.1 and somehow she says that broke them. I'm not sure if it happened then or if it was something else that caused the break. I've narrowed down the problem. The Codex says you need to get a list of all page objects to use for this function. You use a "query" function I've never seen before. http://codex.wordpress.org/Function_Reference/get_page_children <code> $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query-&gt;query(array('post_type' =&gt; 'page')); </code> Those 2 lines should generate an array of all of your page objects that is usable by get_page_children() later. However, it's not working anymore because $all_wp_pages ISN'T all of my pages. I have 38 pages on this site, and when I do an output of the $all_wp_pages array, I only get 10 pages. Anyone have any idea why that would be happening? The 10 pages that do show up all happen to be ONE page and its children. But they show up no matter what page you're on. It's really bizarre. Thanks!
I don't have enough pages to test, but I have an idea that 10 is default pagination number. <code> $all_wp_pages = $my_wp_query-&gt;query(array( 'post_type' =&gt; 'page', 'posts_per_page' =&gt; -1 )); </code> If this doesn't work I will try to find some time to generate bunch of pages and test.
I'm having a lot of trouble since upgrade to 3.0.1 with get_page_children() function
wordpress
I want to disable shortcode captions for posts in one of my themes, and display the content elsewhere, such as in a sidebar. The images aren't uploaded to wordpress, but they're linked-to using the post editor's add an image -> from URL functionality resulting in the following shortcode: <code> [caption id="" align="alignnone" width="300" caption="Leonard Nimoy has done far more thing than just play Mr. Spock"]&lt;a href="http://example.com/nimoy"&gt;&lt;img src="http://example.com/uploads/nimoy.jpg" alt="Leonard Nimoy in a black suit" title="Leonard Nimoy" width="300" height="228" /&gt;&lt;/a&gt;[/caption] </code> Any thoughts? I'm assuming using a filter on <code> img_caption_shortcode </code> somehow, but I don't know if that's the way to approach this.
Try this: <code> $caption_info = array(); add_filter( 'img_caption_shortcode', 'capture_caption', 10, 3 ); function capture_caption( $blank = '', $attr, $content ) { global $caption_info; $caption_info[] = array('attr' =&gt; $attr, 'content' =&gt; $content ); return ' '; } </code> It will save info from all captions into global <code> $caption_info </code> variable and suppress their display in content (space is returned because filter result is ignored if empty).
How to display a shortcode caption somewhere other than the_content
wordpress
In regards to my previous stackexchange-url ("question about shortcode captions"), it doesn't appear to me that the actual text of a caption is stored anywhere other than in the post content within the shortcode itself. I would have thought that <code> wp_get_attachment_metadata </code> would store the info for an attachment, but it doesn't. Am I wrong? Or does WordPress not store the actual caption anywhere?
Yes, it stores the caption in it's own place in the DB. I can't quote the exact location but in Wordpress, "Attachments" are a post type and it stores each attachment just like a post. For an attachment post type, it treats the Image Caption as <code> the_excerpt </code> the Image Description as <code> the_content </code> and the Image Title as... <code> the_title </code> .
Are captions stored anywhere?
wordpress
is that possible, without javascript hacks? like this: <code> &lt;ul class="my_menu"&gt; &lt;li class="first"&gt; ... &lt;/li&gt; &lt;li&gt; ... &lt;/li&gt; &lt;li&gt; ... &lt;/li&gt; &lt;li class"with_sub"&gt; ... &lt;ul class="my_menu_sub"&gt; &lt;li class="first"&gt; ... &lt;/li&gt; &lt;li&gt; ... &lt;/li&gt; &lt;li&gt; ... &lt;/li&gt; &lt;li class="last"&gt; ... &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt; ... &lt;/li&gt; &lt;li&gt; ... &lt;/li&gt; &lt;li class="last"&gt; ... &lt;/li&gt; &lt;/ul&gt; </code>
A better and simpler approach: <code> function add_first_and_last($items) { $items[1]-&gt;classes[] = 'first-menu-item'; $items[count($items)]-&gt;classes[] = 'last-menu-item'; return $items; } add_filter('wp_nav_menu_objects', 'add_first_and_last'); </code>
Adding first / last CSS classes to menus
wordpress
I am getting an error message When uploading some themes . <code> Warning: fopen(/home/..../public_html/...../wp-content/themes/creativeart/style.css) [function.fopen]: failed to open stream: No such file or directory in /home/...../public_html/...../wp-includes/functions.php on line 4165 Warning: fread(): supplied argument is not a valid stream resource in /home/...../public_html/...../wp-includes/functions.php on line 4168 Warning: fclose(): supplied argument is not a valid stream resource in /home/...../public_html/...../wp-includes/functions.php on line 4171 </code> What does it mean ?I don't understand if the problem in themes or Am I missing some thing in my Wordpress Installation? I have tried the same themes in two wordpress installations and got the same error . I am listing some of themes here . mysticgrunge creativeart Does any one have idea on such error?
From the looks of things, it's a server issue. The WordPress theme uploader uses <code> fopen() </code> to transfer files from one location to the server. It looks like there's a timeout or access error because a) <code> fopen </code> can't find the file that it's supposed to be transferring and b) the <code> fread </code> and <code> fclose </code> functions can't find the data stream to read the file and close it. I would recommend manually uploading the themes instead to bypass this error. Instead of uploading the <code> .zip </code> file via WordPress, do the following: Unzip the theme folder somewhere on your local machine Log in to your site's FTP system Navigate to <code> /wp-content/themes/ </code> Use FTP to transfer the entire theme folder from your local machine to the server This will entirely bypass any kind of <code> fopen </code> / <code> fread </code> / <code> fclose </code> errors you're getting. If there's still a problem, then it's an issue with either your server, your WordPress installation itself, or the actual theme and will require some more in-depth troubleshooting.
I am getting an error some times when uploading themes
wordpress
Our passwords are handled by an external LDAP server and the plugin we're using to therefore removes all references to the ability to change passwords. What I'd like to do then, is add a link to the users profile editing page (where they get taken after clicking on their name) which points to our password change page. How do I add a link here?
I assume you mean <code> /wp-admin/profile.php </code> page and want to hide native password fields. Try this (just test if form works ok with it): <code> add_filter( 'show_password_fields', 'modify_profile_password' ); function modify_profile_password( $show ) { ?&gt; &lt;tr id="password"&gt; &lt;th&gt;Change your password at&lt;/th&gt; &lt;td&gt;&lt;a href=""&gt;password change page&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php return false; } </code>
How would I add a link to the profile editing page of the dashboard?
wordpress
i have <code> add_options_page('Post Products Settings', 'Post Products Settings', 'administrator', 'pp_settings', 'pp_settings_page'); </code> anyway i can get whats specified in the 1st parameter for use in my page header? i know i can hard code it tho, but just curious
There are a few ways you can do this. My preferred way of doing this is using Object Oriented Programming (OOP) to structure the plugin. For example, I might do this: <code> class JPBTitle { var $page_title = "Post Products Settings"; function __construct(){ add_action( 'admin_menu', array( $this, 'admin_menu' ) ); } function admin_menu(){ add_options_page( $this-&gt;page_title, $this-&gt;page_title, 'administrator', 'pp_settings', array( $this, 'pp_settings' ) ); } function pp_settings(){ echo "&lt;div class='wrap'&gt;\n\t&lt;h2&gt;$this-&gt;page_title&lt;/h2&gt;&lt;/div&gt;"; } } $JPBTitle = new JPBTitle(); </code> There are many many advantages to using object oriented programming in plugins; however, if you don't want to use OOP, I would suggest either setting a global variable or defining a constant with the value you want to use for that string.
How can i get the title i specified in add_options_page for my header
wordpress
I am about to have to write a script to take a fresh install of WordPress 3.0.1 and add-in all the initial features for a website . This is for a company that installs lots of similar websites and they need a standard starting point in configuration and data. I'm wondering if anyone else has already done this and if so if they can share their code? I envision we will tweak this script each time they create a new site so hard-coding is fine although eventually (after enough experience) I'd like to convert into a plugin. Here's the basic list of tasks I think we'll need (these assume I've started with WordPress 3.0.1 already installed and my custom plugins and custom theme copied into the appropriate directories) : <code> // Create users for the current site // Delete Hello Dolly Plugin // Download, Install and Activate repository plugins // Activate Custom Plugins (assume the plugins are already there) // Activate Custom Theme // Delete Hello Post // Delete Comment on Hello Post // Create Pages with Starter Content // Create Initial Custom Post Types with Starter Content // Create Multiple Menus // Create Menu Items for those Menus linking to Pages and wp-login.php // Create Initial Taxonomy Terms // Set Desired Permalinks Setting // Set Static Front Page Setting </code> That's about it (though I may identify more as I get into it.) Again, I'm looking for code that I can just copy and modify so I don't have don't have to figure out all these details myself (which is not hard, just tedious and time consuming) . Oh one more thing, I have to start on this now so the sooner the better! :-)
As I mentioned I was going to be start working on this need immediately so I'm making headway. Given that I'm knocking these down I figured it's best to start posting them. Still, if someone else can/will post (some of) the parts I haven't done I'll be happy to let you copy whatever I'd done you haven't and select your answer as the best answer. Until then I'm going to start posting the code. First Thing: Include <code> wp-load.php </code> : Since we're creating a standalone file in the root of the website to run initialization that will only be used to "bootstrap" a site (I called mine <code> /my-init.php </code> ) we start by including <code> /wp-load.php </code> to load the WordPress API functions: <code> &lt;?php include "wp-load.php"; </code> Creating Users for the Site We'll use the <code> wp_insert_user() </code> function located in <code> /wp-includes/registration.php </code> to create our users. This file is not loaded by default so we'll have to load it ourselves with a call to <code> require_once() </code> . We'll also use the <code> get_user_by() </code> function to first see if the user has already been created; no need to run the code twice if they haven't. NOTE: This is a pattern will follow; e.g. our script should not duplicate or overwrite anything if called multiple times, especially after users have added or changed data for any of the items we plan to initialize. <code> require_once( ABSPATH . WPINC . '/registration.php'); $user = get_user_by('slug','johnsmith'); if (!is_object($user)) { wp_insert_user(array( 'user_login' =&gt; 'johnsmith', 'role' =&gt; 'administrator', 'user_email' =&gt; 'johnsmith@example.com', 'user_url' =&gt; 'http://example.com', 'first_name' =&gt; 'John', 'last_name' =&gt; 'Smith', 'comment_shortcuts' =&gt; '', 'use_ssl' =&gt; '0', 'user_pass' =&gt; '12345', )); } </code> Deleting the "Hello Dolly" Plugin To delete the "Hello Dolly" plugin (sorry Matt) we'll use the <code> delete_plugins() </code> function. <code> delete_plugins() </code> expects an array of file paths that are relative to the <code> /wp-content/includes/ </code> directory. For the Hello Dolly plugin the file path is simply <code> hello.php </code> since the Hello Dolly plugin isn't stored in it's own directory but for most plugins it will be in the form of <code> {$subdir}\{$filename}.php </code> ; i.e. the file path for Akismet is <code> akismet/akismet.php </code> . However, <code> delete_plugins() </code> is not available until we've included <code> /wp-admin/includes/plugin.php </code> and there's also a dependency with <code> wp-admin/includes/file.php </code> so we <code> require_once() </code> both of those before we call <code> delete_plugins() </code> . Finally we use <code> WP_PLUGIN_DIR </code> constant combined with <code> file_exists() </code> to see if the main plugin file exists before we attempt to delete it (not that is would matter if we tried to delete a missing file, but it's more elegant to actually check first and you might need to know how for some other reason) : <code> require_once(ABSPATH . 'wp-admin/includes/plugin.php'); require_once(ABSPATH . 'wp-admin/includes/file.php'); if (file_exists(WP_PLUGIN_DIR . '/hello.php')) delete_plugins(array('hello.php')); </code> Note that sometimes <code> delete_plugins() </code> will fail because of file permissions or maybe the fact a plugin is currently activated or some other reason that you'll first need to resolve but for our use-case Hello Dolly goes away without a fight. Downloading, Installing and Activating Repository Plugins I don't actually need to download plugins from the repository right now (I was thinking it would just be a nice to have) we're going to let this requirement slide and revisit it later. Activating Your Plugins Next up is activating our own custom plugins. We are assuming we have already uploaded them to the plugin directory and all we need to do it activate them for WordPress. ( Note : This technique will work for activating repository plugins too, it just won't download and install them first.) We'll use the <code> activate_plugin() </code> function which like <code> delete_plugins() </code> requires <code> /wp-admin/includes/plugin.php </code> to be included but does not need <code> /wp-admin/includes/file.php </code> in case you are only needing to automate activation and not deletion. We'll again test for existence (not need to activate if not there, eh?) and we'll also verify using the <code> is_plugin_active() </code> function that the plugin has not already been activated. Note I used a few variables this time ( <code> $plugin_filepath </code> and <code> $plugin_dir </code> ) to keep from duplicating the plugin identifier numerous times. Our example that follows activates the plugin <code> my-custom-plugin.php </code> which is located in the <code> my-custom-plugin </code> subdirectory: <code> require_once(ABSPATH . 'wp-admin/includes/plugin.php'); $plugin_filepath = 'my-custom-plugin/my-custom-plugin.php'; $plugin_dir = WP_PLUGIN_DIR . "/{$plugin_filepath}"; if (file_exists($plugin_dir) &amp;&amp; !is_plugin_active($plugin_filepath)) activate_plugin($plugin_filepath); </code> Activating Your Preferred Theme Activating a theme is a bit easier than deleting or activating a plugin, comparatively speaking; one function call is all that is required: <code> switch_theme() </code> . The <code> switch_theme() </code> function accepts two (2) parameters: the template and the stylesheet . Well, at least that's what the parameters are named. You might be more familiar with the terms <a href="stackexchange-url Parent Theme and Child Theme . Assuming you've created a Child Theme with the default TwentyTen theme that comes with WordPress being the Parent Theme and you called it "My Custom Theme" and placed it into the <code> /wp-content/themes/my-custom-theme </code> directory, you'd activate your theme using this call: <code> switch_theme('twentyten', 'my-custom-theme'); </code> But what if it is not a child theme? That's easy, just pass the directory slug/theme identifier (i.e. the name of subdirectory off of <code> /wp-content/themes </code> that contains your theme) as both parameters. Assuming you want to activate the Thematic theme by Ian D Stewart you've call <code> switch_theme() </code> like so: <code> switch_theme('thematic', 'thematic'); </code> Personally I think it's a bit whacky to have to keep track of both details here so I wrote a function called <code> activate_my_theme() </code> that first checks to make sure the the <code> get_current_theme() </code> function and if not activates it. You just need to tell it the child theme (aka the "stylesheet") and it figures out the parent theme for you (aka the "template") by grabbing the details from the <code> get_theme() </code> function. <code> activate_my_theme('My Current Theme'); function activate_my_theme($theme_name) { if ($theme_name!=get_current_theme()) { $theme = get_theme($theme_name); switch_theme( $theme['Template'], $theme['Stylesheet'] ); } } </code> One key point to be aware of ; the <code> get_theme() </code> function expects to be passed the name of the Child Theme, NOT it's directory slug/theme identifier. (The name comes from the "Theme Name:" section in the header of the theme's <code> style.css </code> file. Fortunately the <code> get_current_theme() </code> function returns the name too.) Inspecting the header in the <code> style.css </code> file of the WordPress default theme Twenty Ten we see it's name is in fact <code> 'Twenty Ten' </code> : <code> /* Theme Name: Twenty Ten Theme URI: http://wordpress.org/ Description: The 2010 theme for WordPress is stylish, customizable, simple, and readable -- make it yours with a custom menu, header image, and background. Twenty Ten supports six widgetized areas (two in the sidebar, four in the footer) and featured images (thumbnails for gallery posts and custom header images for posts and pages). It includes stylesheets for print and the admin Visual Editor, special styles for posts in the "Asides" and "Gallery" categories, and has an optional one-column page template that removes the sidebar. Author: the WordPress team Version: 1.1 Tags: black, blue, white, two-columns, fixed-width, custom-header, custom-background, threaded-comments, sticky-post, translation-ready, microformats, rtl-language-support, editor-style */ </code> Deleting the "Hello World" Post Next we want to delete the "Hello World" post. You may have seen that @Rarst has shown us how to use the <code> wp_delete_post() </code> function which is exactly what we need. As he explained the second parameter will fully delete the post as opposed to moving it to the trash and the first parameter is the <code> $post-&gt;ID </code> . Of course it would be nice to be able to specify the slug instead of the <code> $post-&gt;ID </code> and so I decide to find a way to do that. After some spelunking I found that WordPress has an unfortunately named function called <code> get_page_by_path() </code> which actually allows us to look up any post type by its slug (it is unfortunately named because you might overlook it when trying to find something that works with post types other than <code> 'page' </code> .) Since we passing <code> get_page_by_path() </code> the WordPress-defined constant <code> OBJECT </code> it will return to us a post in the form of an post object. For the third parameter we passed <code> 'post' </code> to indicate we wanted it to lookup post types of <code> 'post' </code> . Since <code> get_page_by_path() </code> will return the post object we need or return <code> null </code> if no post matches the slug we can check for existence and do a lookup at the same time: <code> $post = get_page_by_path('hello-world',OBJECT,'post'); if ($post) wp_delete_post($post-&gt;ID,true); </code> Note: We could have run code to delete every post in the database but if we had we would not be able to run this code again once we've added the posts we want to keep and that was one of our design constraints. Next... I'll keep adding to this as I figure it out until I'm done or until someone else helps out.
Initialization Script for "Standard" Aspects of a WordPress Website?
wordpress
in the book professional wordpress, they use something like <code> $options = array( 'classname' =&gt; 'pp_widget', 'description' =&gt; '...' ); $this-&gt;WP_Widget('pp_widget', ..., $options); </code> but in most tutorials <code> $this-&gt;WP_Widget(false, ... </code> is used. i wonder is there a reason to specify the <code> $id_base </code> param? i see that if i dont, an <code> id </code> will be generated. also, is there any need to specify the <code> classname </code> option? on a side note, i asked a related question on stack overflow: parent::somefunction </code> or <code> $this-&gt;somefunction </code> if someone got an answer let me know :)
The reason is simply customization (these values end up in widget's HTML markup). If someone needs to change this stuff (for example to be compatible with some script without adding wrapper layers) the option is there. As for methods calling - <code> parent:: </code> explicitly calls method from parent class, <code> $this-&gt; </code> calls method from current class. Since widgets do not redefine WP_Widget method there is no practical difference.
Widget constructor: about $id_base and $options
wordpress
I'm looking to build a member directory for one of my WordPress sites that hooks into the Facebook API. Site users would be able to browse through the directory of members and view their Facebook profile and information such as e-mail address, phone number, website, etc. Basically, I'm thinking that members will need to login to facebook from the site and "allow access." Then, WordPress can pull member data from Facebook such as e-mail address, phone number, website, etc. and store it as custom meta in WordPress. One problem with this approach would be when a user updated their facebook profile, the WordPress site wouldn't get updated until they log back into the site and the "update" process kicks off again. Am I way off base? Is there an easier way to do it? Is there anything that would get me started with this, or would it need to be built entirely from scratch?
Hi @Nate Dudek , I think you'll likely want to start with BuddyPress as it is essentially a "Facebook-in-a-Box" , albeit a much more limited version of Facebook. It'll have more of the data structures you need to integrate with Facebook in the manner you describe. Beyond that you might find these articles helpful: How To Integrate Facebook With WordPress 12 Useful Facebook Wordpress Plugins For Bloggers 6 Best Facebook WordPress Plugins 10 Must Have Facebook Plugins For WordPress WP-FacebookConnect Plugin Plugins on WordPress.org tagged with "Facebook" Hope this helps!
Building a Member Directory Site on WordPress with Facebook API Integration?
wordpress
What do you all use for live blogging? I've found Live Blogging by Chris Northwood (more than I need) and Twitter LiveBlog by Mashuqur Rahman (I want it to stay within WordPress). Are these really the only two games in town?
I wrote my own Liveblogging platform, which turned out to be very simple to do indeed. Sadly, it's not ready for release yet. In practice, all you need is a page with a form which writes to a database. Now; liveblogs tend to get hammered, so I created a page which used my templates as a flat file (so no database calls). Whenever I updated the liveblog with another entry, it wrote it to a flat file, and it showed the flat file to the user. Rather simple, but brutally fast. Stood up to very high traffic on a small tech site you may have heard of .
Live blogging plugins?
wordpress
I am having a doubt about using "Cron Job" . I have installed a Plugin named FeedWordpress which lets us to publish RSS feeds .It has given me an option to publish automatically or to publish by setting cron Jobs . Could any one guide me to set these Cron Job? I have no Idea on it .This is the message it given for that configuration . If you want to use a cron job, you can perform scheduled updates by sending regularly-scheduled requests to http://......?update_feedwordpress=1 For example, inserting the following line in your crontab: */10 * * * * /usr/bin/curl --silent http://......?update_feedwordpress=1 will check in every 10 minutes and check for updates on any feeds that are ready to be polled for updates. I have another doubt .Is there any possibility to slow down and affects the load (It is of shared hosting ) ,if I turn on the Automatic Updates of feeds?How does it helps me If I use cron Job and put a cetain limit? So that it affects the server load only when It updates the feeds . Is there any chance to suspend my hosting account by Host If I Make my Blog as Aggregator because of high loads?
Cron is job scheduling mechanism in Unix-based operating systems. It depends on your hosting if you have access to it. Since WordPress needs to run some tasks periodically it has own PHP-based mechanism called WP-Cron that is both used by core and accessible to plugins. Basically OS cron is more reliable, WP-Cron is more compatible. <code> Automatic updates </code> most likely refers to plugin using WP-Cron. How much this might be issue with hosting depends on: hosting policy for background processes hosting CPU quotas (and bandwidth quotas if they are low enough and you poll often enough) amount and rate of updates you perform
Help needed to make my site as Aggregator
wordpress
How do you add Read more ...link to a particular post or to all posts in a blog ?
<code> Read more </code> links usually appear under following conditions: Template uses <code> the_content() </code> function for display. Post has <code> &lt;--more--&gt; </code> tag in content, which creates <code> teaser </code> . Result is <code> teaser </code> , followed by <code> read more </code> link. Sometimes such links are created artificially by appending them to output of <code> the_excerpt() </code> function in template. So to precisely answer your question - it depends on your template tags and how you use <code> excerpts </code> and/or <code> teasers </code> . See post (by me) for writeup on excerpt/teaser differences and mechanics.
How do you add Read more ... link to posts?
wordpress
Is there a way to let my users define the crop area of a post thumbnail? The thumbnails always are existing post attachments, I would rather not create an extra attachment per thumbnail. The post thumbnails should be 200x100 pixels, and come from one of the images used in the post. So in my ideal world, when you click the "Set Featured Image" link, you get an overview of the already included images, and when you click one of these, you can define the crop area yourself (moving or resizing it, but keeping the 2x1 aspect ratio). When you click "OK", the new post thumbnail is saved with the original attachment (in the <code> _wp_attachment_metadata['sizes']['post-thumbnail'] </code> metadata field for example), not as a new attachment. Using an image that is already used as a post thumbnail for another post should not be allowed, or at least give a warning. I believe the included image editor will not suit my needs, since you can choose to edit all versions of the image, or the regular thumbnail, but not only the post thumbnail. I also find it a bit confusing to know what versions I am editing, so I think my users will have even more trouble with it. Is there a plugin that does what I want, or that I can easily extend to my needs? Update: Example UI I really like the interface of the Mac OS X Address Book image picker: you select an image, and resize a fixed ratio thumbnail cropper via a slider. You can also drag the base image around. You can expand this idea to multiple image sizes (I have a <code> post-thumbnail </code> and <code> post-thumbnail-1/2 </code> that's half that size, for example). Let the user select the sizes (s)he is editing now with checkboxes, and draw the appropriate crop rectangles on the screen.
The code is still a mess, but it seems to work, even on IE 8. I plan to release it in the repository, but in the meantime you can play with my current version. To access it you click the "Edit Image" when adding or editing an image, it replaces the usual image editor (they are very hard to combine). Since most of the admin area uses the regular thumbnail and my current version edits the post thumbnail, it might seem the code has no effect, but try it by showing a post thumbnail and you should see it change. This plugin requires my On-Demand Image Resizer, which is also still a mess, to do the actual resizing.
User-friendly cropping of post thumbnails?
wordpress
One of the things that attracted me to the WordPress platform was the plugin API and large selection, but more recently I have been self developing before looking for plugins, only using plugins for things that I don't feel I would be able to complete on time and in budget. So what do you do when you need functionality? Do you first think how you can do it yourself, or do you dive into the plugin repo straight away, the 'never reinvent the wheel' mentality? I think both have valid arguments.
There are several things I consider when making such choice (in no particular order): does task involve general functionality (plugin) or processing my specific content (develop) is there the plugin for the task from known developer and well-maintained (plugin) or there is fractured field of numerous plugins (develop) do I want full range of related functionality (plugin) or single specific tweak (develop) In general I will always do at least quick search through plugins to assess how likely it is to get task done with them. There is no rule of a thumb here. I both use plugins for tasks that can be easily coded (for example page titles) and coded from scratch some really beaten things (for example anti-spam protection).
Self Develop or Plugin as first option?
wordpress
is there a list of plugins that are in use on WordPress.com somewhere? It would be very interesting to see how they have implemented specific widgets and functionality.
Not an easy question to answer. That stuff is mostly private and they seem to use greatly modified versions of some public plugins. wordpresscom tag in repository has several. Also see this topic for more ideas and places to check List of plugins used on WordPress.com
What plugins are in use on wordpress.com
wordpress
We use wordpress like a CMS and would very much like to allow users to have a "homepage". Ideally they'd be prevented from mucking up the whole site. Is there a simple way to limit users editing rights to a single page? I'm currently using the Members plugin to do other permission-based stuff, so it'd be great if a solution could either neatly augment this, or replace it entirely. Bonus points for automatic creation of a homepage when a new user is created. UPDATES: I should clarify that these pages need to be confined to a specific area of the site (i.e. all children of the same page). Also, after speaking to some users it seems that they'd find it useful to create sub-pages branching from their home page.
Sorry to do this, but I stumbled across the answer in the wordpress forums . It turns out that Role Scoper does this really well. The author of that forum post said it best: To enable a user to edit one particular page, but not anything else: Give them a WordPress role of Subscriber Manage > Pages > Edit their page Expand the "Editors" tab under "Advanced Options" Check the non-braced checkbox to the left of your user's name (if child pages will be created, also check the braced checkbox {[]}, which assigns the role for all current or future child pages) Save the Page
Is there a way (plugin?) to restrict a user to being able to edit just one page?
wordpress
It seems like half the tutorials in the Codex and around the blogosphere use <code> query_posts() </code> and half use <code> WP_Query </code> . What's the deal?
<code> query_posts() </code> is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with posts pagination). Any modern WP code should use more reliable methods, like making use of pre_get_posts </code> hook, for this purpose. TL;DR don't use query_posts() ever ; <code> get_posts() </code> is very similar in usage and accepts same arguments (with some nuances, like different defaults), but returns array of posts, doesn't modify global variables and is safe to use anywhere; <code> WP_Query </code> class powers both behind the scenes, but you can also create and work with own object of it. Bit more complex, less restrictions, also safe to use anywhere.
When should you use WP_Query vs query_posts() vs get_posts()?
wordpress
i am trying to install plugin tumblrize and got the error Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in D:\Projects\Websites\jiewmeng\wp-content\plugins\tumblrize\tumblrize.php on line 636 Call Stack: 0.0005 332520 1. {main}() D:\Projects\Websites\jiewmeng\wp-admin\plugins.php:0 0.2249 3035904 2. plugin_sandbox_scrape() D:\Projects\Websites\jiewmeng\wp-admin\plugins.php:160 on line 636 is <code> register_activation_hook(__FILE__, 'tumblrize_activate'); </code> i dont see anything wrong with that, just learnt to develop plugins and that line looks ok? there is the function on line 611 <code> function tumblrize_activate () { ... </code> i am using wordpress 3.0.1 + PHP 5.3.2 btw
Now this one was really really hard to notice bug. I basically brutforced it by cutting/pasting blocks of code. Long story short - line 462 has wrong code opening tag <code> &lt;? </code> instead of <code> &lt;?php </code> . Which causes some kind of cascading tag mismatch, which seems to go unnoticed by any kind of syntax checker, but wreaks havoc on execution.
Problem installing plugin: unexpected T_STRING, expecting T_FUNCTION
wordpress
What is the use of map_meta_cap filter? This filter is not documented anywhere. I have an unclear idea of what it could be: Used to map the permissions of the user to operations on posts. What exactly is it meant for? If possible please give some sample code example of its right usage.
This filter allows you to extend the <code> map_meta_cap() </code> function . This function is called by <code> WP_User-&gt;has_cap() </code> to convert a meta capability to one or more primitive capabilities . For example, you want to know whether the current user should be allowed to edit the current post, the <code> edit_post </code> meta capability . This depends on some factors: is the user the author of the post? Is the post already published? Is the post marked as private? The primitive capabilities are <code> edit_posts </code> , <code> edit_published_posts </code> , <code> edit_others_posts </code> and <code> edit_private_posts </code> : you can assign these to user roles. <code> map_meta_cap() </code> checks the author and status of the post and returns the correct set of primitive capabilities this user must have to allow editing of the post (if the post is written by someone else and published, it would return <code> array('edit_others_posts', 'edit_published_posts') </code> , so the user must have both capabilities to continue). Adding this idea of meta capabilities and primitive capabilities allows you to keep the base <code> WP_User </code> class free from knowledge of posts and post statuses and whatever, and just focus on capabilities. The actual conversion is in an external function, <code> map_meta_cap() </code> . The filter <code> map_meta_cap </code> allows you to extend the functionality, for example when using custom posts. I believe basic support is provided if you set the <code> capabilities </code> argument of <code> register_post_type </code> , but the mentioned article by Justin Tadlock and Prospress plugin provide complete examples of this. But you can customize it to completely turn the capabilities system over, if you desire.
What Is The Use Of map_meta_cap Filter?
wordpress
I want to create a new database user for my WordPress installation. Usually on localhost, i can just use root, but it is good practice to use a user with as little rights as possible. What are those rights? I was wondering if WordPress needed to have installed plugins etc. It may require <code> CREATE </code> &amp; <code> DROP </code> privileges as well.
If your database is set up to deny remote connections (i.e. only applications on the same server can interact with the database) then there's no danger in giving your WordPress user full access. As a matter of fact, most automated installation scripts used by web hosts grant full access to their WordPress user by default. Keep in mind that your database "user" is not actually a site user ... and unless you're manually administering your database via phpMyAdmin, the login credentials will never be used by anything but WordPress. That said, there's no guarantee that future versions of WordPress won't need the features you're disabling. If you use your WordPress user to manually administer the database, you might need these features as well. My recommendation would be to grant full access to your WordPress user, but use a highly complex password for the user.
What specific database privileges does WordPress need?
wordpress
I have a widget like this: <code> class test_widget extends WP_Widget{ function test_widget(){ $widget_ops = array('description' =&gt; 'test widget'); $this-&gt;WP_Widget(false, 'Test', $widget_ops); add_action('init', array(&amp;$this, 'ajax'), 99); // include in jQuery(document).ready() add_action('jquery_init', array(&amp;$this, 'js')); } function js(){ // get settings from all widget instances $widget_settings = get_option($this-&gt;option_name); // identify this instance foreach($widget_settings as $instance =&gt; $options): $id = $this-&gt;id_base.'-'.$instance; $block_id = 'instance-'.$id; if (is_active_widget(false, $id, $this-&gt;id_base)): ?&gt; $("#&lt;?php echo $block_id; ?&gt; .button").click(function(){ $.ajax({ type: "GET", url: "&lt;?php echo get_bloginfo('url'); ?&gt;", data: { id: "&lt;?php echo $block_id; ?&gt;", some_data: "&lt;?php echo $options['some_widget_option']; ?&gt;", my_widget_ajax: 1 }, success: function(response){ alert(response); // yey } }); return false; }); &lt;?php endif; endforeach; } function ajax(){ if(isset($_GET['my_widget_ajax'])): $some_data = esc_attr($_GET['some_data']); echo $some_data; exit(); endif; } function widget($args, $instance){ // the widget front-end } function update($new_instance, $old_instance){ // update form return $instance; } function form($instance){ // the form } } </code> Basically there's a button in it which triggers a ajax request that retrieves some info... As you can see the only way I could add the ajax function was by hooking it to the init tag, and the js to a theme function that handles the javascript. The problem is that this only works when the widget is present in a sidebar. And I also need it to work when I call this widget with the_widget() function, for eg. inside a page. I don't know how could I retrieve the widget options to pass them in the javascript code... Any ideas?
The problem is that this only works when the widget is present in a sidebar. If you need some code to run independently from widget, I reason it makes sense to add that code separately from widget class. And I also need it to work when I call this widget with the_widget() function, for eg. inside a page. I don't know how could I retrieve the widget options to pass them in the javascript code... That function takes instance array with widget data. I am not sure about your specifics, but I thinks you can pass whatever you need in there. Directly called widget has no data, other than passed in instance (or retrieved by itself).
Widget Javascript code (ajax)
wordpress
I am installing on a local machine using <code> localhost </code> . I have a "learning" version of WordPress @ <code> http://localhost/wordpress </code> and I want to create another version of WordPress (@ <code> http://localhost/jiewmeng </code> ) I want to test and maybe move to a real server later. I found that when I extracted a fresh copy of WordPress into <code> localhost/jiewmeng </code> , it probably detects the WordPress database and uses that? All the data I get is from the "learning" version of WordPress. How do i set this up so that the 2 installations of WordPress are separate?
The database connection constants are defined in the wp-config.php file. Whether the 2 wp-config.php files in the jiewmeng directory and the WordPress directory are the same? You need to create 2 different databases and set their constants in the respective wp-config.php files.
How do I install two versions of WordPress on 1 server?
wordpress
Something which I have never seen covered is the best way to validate that specific form fields are filled out correctly for custom post type meta boxes. I am looking to get expert opinions on how best to validate custom fields for any metaboxes that one might create. My interest are to: ensure field validation takes place before the post is published/updated utilizing a class/code which does not conflict with other wordpress javascript allows you to define specific fields as required while others could be optional validate fields based on customizable rules including regex for things like email format control the visual display of any errors/notices Thanks in advance!
The easiest way is to add Javascript validation via the jQuery Validate plugin. Here's the most basic walkthrough: Near your add_meta_box call, enqueue the jQuery Validate plugin as well as a JS file for your simple script: <code> add_action('admin_enqueue_scripts', 'add_my_js'); function add_my_js(){ wp_enqueue_script('my_validate', 'path/to/jquery.validate.min.js', array('jquery')); wp_enqueue_script('my_script_js', 'path/to/my_script.js'); } </code> Then in my_script.js include the following: <code> jQuery().ready(function() { jQuery("#post").validate(); }); </code> This will enable validation on the post form. Then in the add_meta_box callback where you define the custom fields, you'd add a "required" class for each field you wish to validate, like so: <code> &lt;input type="text" name="my_custom_text_field" class="required"/&gt; </code> All fields with "required" in their class will be validated when the post is saved/published/updated. All of the other validation options (rules, error styling, etc) can be set in the document.ready function in my_script.js; check the jQuery Validate docs for all the options.
Validating Custom Meta Box Values & Required Fields
wordpress
I have a blog that gets the usual spam, which Akismet is pretty good with. Not good enough for me to turn off moderation just yet. I am wondering is there a way to "whitelist" a list of readers so their comments can skip moderation and just get posted?
In <code> Settings </code> > <code> Discussion </code> Uncheck <code> An administrator must always approve the comment </code> Check <code> Comment author must have a previously approved comment </code> This way comments from people (identified by combination of name, email and site) who have previously approved comments will not require moderation. Rest of comments will.
Whitelisting Commenters
wordpress
I'm looking for a method/plugin/hack to auto-insert an outline when I start a new post in Wordpress. I've searched online for ideas as well as the WP Plugin repo with no luck. Essentially, many of my posts have a similar structure, and it would be nice not to have to paste it in each time, but to have it embedded in the body of the "Add New Post" page. Of course, it should be editable.
Hi @KJH : Your question is very similar to this question: <a href="stackexchange-url Creating a Custom Post Type for Inserting Preset Content into Post &amp; Pages? You might find the solution to be what you need; I extended my WP Boilerplate Shortcode plugin to meet the needs of the person asking the question; you might find the solution fits your needs as well.
Method/Plugin/Hack to Start a Post with an Writing Outline?
wordpress
I've been trying to set up a way to write posts in a series on my site. The idea is that each post can belong to a different series in a custom taxonomy. I've gotten just about everything set up the way I want it ... with one exception. Registering the Taxonomy This part is working. I've dropped the following code into a plug-in: <code> function jdm_build_series_taxonomy() { $labels = array( 'name' =&gt; _x('Series Labels', 'taxonomy general name'), 'singular_name' =&gt; _x('Series Label', 'taxonomy singular name'), 'search_items' =&gt; __('Search Series Labels'), 'popular_items' =&gt; __('Popular Series Labels'), 'all_items' =&gt; __('All Series Labels'), 'parent_item' =&gt; __('Parent Series Label'), 'parent_item_colon' =&gt; __('Parent Series Label:'), 'edit_item' =&gt; __('Edit Series Label'), 'update_item' =&gt; __('Update Series Label'), 'add_new_item' =&gt; __('Add New Series Label'), 'new_item_name' =&gt; __('New Series Label Name') ); register_taxonomy( 'series', 'post', array( 'hierarchical' =&gt; true, 'label' =&gt; __('Series'), 'labels' =&gt; $labels, 'query_var' =&gt; true, 'rewrite' =&gt; true ) ); } add_action( 'init', 'jdm_build_series_taxonomy', 0 ); </code> This adds "Series Labels" to the Posts dropdown menu and gives me a "Series Labels" box on the post edit screen. Everything's working, and I can mark posts as a part of a series perfectly. The problem lies in the next section ... Listing items in the Taxonomy My goal is to allow readers to walk through a series one post at a time, starting with the oldest post and moving forwards chronologically. This is different than a typical archive page, because I have 10 posts per page for my archives, but I obviously want only one post per page for my series archive. I've created a <code> taxonomy-series.php </code> file inside my template. And it half works. The first page will work just fine - <code> http://localhost/wp/series/my-test-series/ </code> displays the first article in the series with the "Next Entry &raquo;" link on the bottom of the page. So far, so good ... But when you click "Next Entry &raquo;" and go to the next page ( <code> http://localhost/wp/series/my-test-series/page/2/ </code> ) it's a) the wrong article and b) the wrong template! However, if I set "Blog pages show at most:" to "1" on the Reading page (it's normally set to 10) then things work just fine. Page 2 displays the second article, page 3 displays the third, etc. So ... what do I need to double check to force the taxonomy archive page to display only one post on each page? I've tried the following: <code> $new_query = wp_parse_args( $query_string, array( 'posts_per_page' =&gt; 1, 'paged' =&gt; $paged ) ); query_posts($new_query); </code> and <code> query_posts($query_string.'&amp;posts_per_page=1&amp;paged='.$paged); </code> to no avail ... ideas? Tips? Suggestions?
Hi @EAMann : I cringe anytime I need to do something creative with URLs in WordPress as the URL system is in my opinion by far the most inelegant aspect of WordPress. I always feel like I'm having to fight WordPress to get it to do what I want, and that WordPress is actively fighting me back related to URLs. So with that opener... Thinking through your issue I'm going to make a suggestion which isn't exactly what you asked for. If you don't find it to be what you are looking for that's okay just please don't anyone down-vote because I'm just trying to help. Taxonomy Isn't Single Increment and Has No Meta One of the problems with what you are trying to do is the taxonomy system doesn't a single increment ordering and it doesn't have meta . For example in a 3 post series you might find terms with <code> ID </code> s of <code> 373 </code> , <code> 411 </code> and <code> 492 </code> ; you can figure that <code> 373 = #1 </code> , <code> 411 = #2 </code> and <code> 492 = #3 </code> but that's all happenstance and relative to each other. It's like trying to location the root of your WordPress site in plugin code but you don't know how many levels deep your code will be stored. Of course can write code to figure it all out and map them but that gets tricky and I'm not sure you'd get much value out of trying to figure it out instead of using a different approach. Explicitly Assign Your Page Numbers So the first thing I would suggest is that you explicitly assign your page numbers for each post in your series using post meta/custom fields (I picked the term <code> installment </code> instead of <code> page </code> because it made more sense to me but clearly you could use any term that fits for your use-case.) Assigning page/installment numbers has the benefit of you being in complete control and that way you'll know what to fix when somethings out of whack and if you want to reorder you can do so just by changing the numbers. I'm assuming you'll have a edit metabox for a custom field name <code> _installment </code> for selecting the installment numbers (and it could even manage/juggle installment numbers via AJAX if you want to get creative so that you never have pages out of sync.) Use <code> $wp_rewrite-&gt;add_rule() </code> to Explicitly Assign Your URL I won't go in depth since I know you've generally got mad WordPress skilz so I'll just point out that <code> $wp_rewrite-&gt;add_rule() </code> is the cruz of getting this all to work. Everything else is just providing support around that function's result. Use the <code> init </code> hook assign your URL rule: <code> &lt;?php add_action('init', 'add_series_installment_url'); function add_series_installment_url() { global $wp,$wp_rewrite; $wp-&gt;add_query_var('series'); $wp-&gt;add_query_var('installment'); $wp_rewrite-&gt;add_rule('series/([^/]+)/(installment-\d+)','index.php?series=$matches[1]&amp;installment=$matches[2]','top'); $wp_rewrite-&gt;flush_rules(false); // This should really be done in a plugin activation } </code> Use <code> parse_query </code> hook to Translate URL to Query Vars The 2nd half of this solution uses the <code> parse_query </code> hook which I know you much be familiar with. In general we capture the <code> query_vars </code> defined in <code> init </code> and captured via the URL rule and convert them into what we need to query WordPress posts with <code> taxonomy </code> + <code> term </code> handling your <code> series </code> and <code> meta_key </code> + <code> meta_value </code> handling the explicitly assigned installment/page: <code> &lt;?php add_action('parse_query', 'apply_series_installment_to_query'); function apply_series_installment_to_query(&amp;$query) { if (isset($query-&gt;query['series']) &amp;&amp; isset($query-&gt;query['installment']) &amp;&amp; preg_match('#^installment-(\d+)$#',$query-&gt;query['installment'],$match)) { $query-&gt;query_vars['post_type'] = 'post'; $query-&gt;query_vars['taxonomy'] = 'series'; $query-&gt;query_vars['term'] = $query-&gt;query['series']; $query-&gt;query_vars['meta_key'] = '_installment'; $query-&gt;query_vars['meta_value'] = $match[1]; unset($query-&gt;query_vars['series']); // You don't need this unset($query-&gt;query_vars['installment']); // or this unset($query-&gt;query_vars['name']); // or this } } </code> Summary Normally I would have gone into a lot more depth explaining an answer but it's late, I've had too little sleep in the past 48 hours, and most importantly I know you can figure it out, you probably just needed one thing I mentioned here. So I hope you like this solution. Even if you don't the two parts with <code> init </code> and <code> parse_query </code> and the <code> $wp_rewrite-&gt;add_rule() </code> and the <code> $query-&gt;query_vars[] </code> respectively are what you need even if you want to stick with your original architecture. Good luck and looking forward to seeing it when you have it done and online! Anyway, Hope this helps.
Fixing Pagination with Custom Taxonomy Archive
wordpress
My site has a blog page at <code> /blog/ </code> , with links to blog posts. A post will have a URL starting at the root of the site, which is a bit jarring. I'd like to have the posts URLs appear as if they are within the blog section of the site. My site currently has a permalink structure like the following: <code> /2010/09/11/sample-post/ </code> I'd like to modify it to include a <code> blog </code> prefix: <code> /blog/2010/09/11/sample-post/ </code> As I understand, WordPress should be able to handle the appropriate redirects. My issue is the fact that I have the blog page at <code> /blog/ </code> If I change my post permalink structure, is there going to be any conflict with a page having a similar URL?
I just tested it (briefly) on local test install and having static page at <code> /page/ </code> and pretty permalinks starting with <code> /page/ </code> doesn't seem to cause any issues.
Changing my permalink structure - will new layout conflict with existing page?
wordpress
When writing WordPress plugins there is often a need to set up options for which roles on the site have access to certain functionality or content. To do this a plugin dev needs to fetch the list of roles that exist on the site to use in the option. Because custom roles can be created we cannot assume the default roles are the only ones available. What is the best way to fetch the list?
Roles are stored in the global variable <code> $wp_roles </code> . The ideal function is <code> get_editable_roles() </code> from <code> /wp-admin/includes/user.php </code> <code> function get_editable_roles() { global $wp_roles; $all_roles = $wp_roles-&gt;roles; $editable_roles = apply_filters('editable_roles', $all_roles); return $editable_roles; } </code> The "editable" part is because it offers other plugins a chance to filter the list in case someone other than admin has <code> 'edit_users' </code> privilege (and thus 'admin' needs to be removed from the list, else that user could make themselves admin). Role management plugins used to create custom roles are the ones that would be using that filter. Otherwise this function is essentially <code> get_roles() </code> (which doesn't exist) . Presumably your plugin will only offer the settings page in question to someone who has admin-level capabilities like <code> 'manage_options' </code> and is basically an admin with access to all roles, so the filter shouldn't affect you. There is also <code> wp_dropdown_roles() </code> which gives you the roles as <code> &lt;option&gt; </code> fields for a <code> &lt;select&gt; </code> list (though checkboxes are likely to work better in many scenarios where you're choosing who has access to something) .
Getting a List of Currently Available Roles on a WordPress Site?
wordpress
I wish to use the following RSS in my widget, but it seems to not pick it up: http://www.tapuz.co.il/blog/rssBlog.asp?FolderName=TickTack I imagine there is a problem in the feed. So: What is it? And can it be fixed? Thanks.
Maybe you can test with the plugin RSSImport, this has two different parser and more flexibility and also an debug-function for locate problems. The feed ist valid and I think, you must use this with a widget.
Why can't I add this feed to the RSS widget?
wordpress
i dont really understand why the check if the nonce function exists before running it ... <code> if ( function_exists('wp_nonce_field') ) wp_nonce_field('gmp_nonce_check'); </code> i understand its for backwards compatibility ... Also notice how you are verifying that the <code> wp_nonce_field </code> function exists before trying to call it for backward compatibility but wont it break anyway if on post back i check <code> if ( isset($_POST['submit']) ) { check_admin_referer('gmp_nonce_check'); </code>
The answer is that you should not check if wp_nonce_field() exists before using it! The recommendation to perform the check assumes that you want to be compatible with versions of WordPress from before the function existed. If Rarst is right that it was introduced in 2.0.4 then you should NOT be supporting earlier versions, as they are all absolutely insecure and anyone using them needs to upgrade RIGHT NOW. Usually you should not have to check for existence of functions from inside WP, unlike functions from plugins that might not be activated. Where did you see that comment you quoted? It should be removed.
Why do I need to check if wp_nonce_field() exists before using it
wordpress
I've read Professional WordPress and it says: <code> esc_html </code> function is used for scrubbing data that contains HTML. This function encodes special characters into their HTML entities <code> esc_attr </code> function is used for escaping HTML attributes <code> esc_url </code> . This function should be used to scrub the URL for illegal characters. Even though the href is technically an HTML attribute What's the difference between these? If I have <code> &lt;script&gt;alert('hello world!');&lt;/script&gt;this is some content </code> Would all <code> &lt; &gt; </code> be converted to <code> &amp;lt; &amp;gt; </code> ? Will the URL be something like <code> %xxx </code> ?
<code> esc_html </code> and <code> esc_attr </code> are near-identical, the only difference is that output gets passed through differently named filters ( <code> esc_html </code> and <code> attribute_escape </code> respectively). <code> esc_url </code> is more complex and specific, it deals with characters that can't be in URLs and allowed protocols (list of which can be passed as second argument). It will also prepend input with <code> http:// </code> protocol if it's not present (and link is not relative).
What's the difference between esc_* functions?
wordpress
i am reading professional wordpress. their code for uninstalling a plugin is <code> //build our query to delete our custom table $sql = "DROP TABLE " . $table_name . ";"; //execute the query deleting the table $wpdb-&gt;query($sql); require_once(ABSPATH .’wp-admin/includes/upgrade.php’); dbDelta($sql); </code> my question is why run <code> dbDelta </code> after <code> $wpdb-&gt;query($sql); </code>
This is indeed bizarre. I think they first tried it with <code> dbDelta </code> , found it doesn't work with <code> DROP </code> queries, and went with a straight <code> $wpdb </code> query instead. They then just forgot to take out the <code> dbDelta </code> stuff. It appears <code> dbDelta </code> collects creation queries in <code> $cqueries </code> and insert queries in <code> $iqueries </code> , but silently ignores the rest . What a lovely function... To be sure, you could ask this question on the book forum , hopefully the authors hang around there. Don't forget to mention you first asked it here, so we get some publicity!
Plugin uninstall: why run dbDelta after $wpdb-> query($drop_sql)
wordpress
reading a book about wordpress ... sorry if i ask the too many questions at 1 go but i am new and confused why does the author always not save data in the metadata box when its a revision. just in case its not clear, what i refer to by metadata box is the one added by <code> add_meta_box </code> . <code> //save meta box data function pp_save_meta_box($post_id,$post) { // if post is a revision skip saving our meta box data if($post-&gt;post_type == ‘revision’) { return; } // process form data if $_POST is set if(isset($_POST[’pp_sku’]) &amp;&amp; $_POST[’pp_sku’] != ‘’) { // save the meta box data as post meta using the post ID as a unique prefix update_post_meta($post_id,’pp_sku’, esc_attr($_POST[’pp_sku’])); update_post_meta($post_id,’pp_price’, esc_attr($_POST[’pp_price’])); update_post_meta($post_id,’pp_weight’, esc_attr($_POST[’pp_weight’])); update_post_meta($post_id,’pp_color’, esc_attr($_POST[’pp_color’])); update_post_meta($post_id,’pp_inventory’,esc_attr($_POST[’pp_inventory’])); } } </code>
You omitted how is this function called. I assume it is added to <code> save_post </code> action. This action passes current post id as argument. In case of revision that would be revision id and not parent post id. So, as I see it, there is no reason to save additional data for revision (creating duplicate set of it). Update. Scratch that. I looked through source code. Apparently <code> *_post_meta </code> functions will automatically change to parent post id if passed revision post id. So you might modify original post, thinking you are modifying revision.
why shouldn't i save metadata when its a revision
wordpress
I use thickbox in the WP backend for preview or other content. On own pages in the backend works my script very fine and a can use custom width and height for the thickbox. below my code: <code> &lt;script type="text/javascript"&gt; &lt;!-- var viewportwidth; var viewportheight; if (typeof window.innerWidth != 'undefined') { viewportwidth = window.innerWidth-80, viewportheight = window.innerHeight-100 } else if (typeof document.documentElement != 'undefined' &amp;&amp; typeof document.documentElement.clientWidth != 'undefined' &amp;&amp; document.documentElement.clientWidth != 0) { viewportwidth = document.documentElement.clientWidth, viewportheight = document.documentElement.clientHeight } else { // older versions of IE viewportwidth = document.getElementsByTagName('body')[0].clientWidth, viewportheight = document.getElementsByTagName('body')[0].clientHeight } //document.write('&lt;p class="textright"&gt;Your viewport width is '+viewportwidth+'x'+viewportheight+'&lt;/p&gt;'); document.write('&lt;a onclick="return false;" href="&lt;?php echo WP_PLUGIN_URL . '/' . FB_ADM_BASEDIR; ?&gt;/inc/index.php?username=&lt;?php echo DB_USER; ?&gt;&amp;?KeepThis=true&amp;amp;TB_iframe=true&amp;amp;height='+viewportheight+'&amp;width='+viewportwidth+'" class="thickbox button"&gt;&lt;?php _e( 'Start Adminer', FB_ADM_TEXTDOMAIN ); ?&gt;&lt;/a&gt;'); //--&gt; &lt;/script&gt; </code> Now to my problem and question. I will use a thickbox on the page wp-admin/plugins.php and here dont work the script. WP set the height and width always to the core-values and this is to small for my request. Maybe other readers have an idea or a solution. Many thanks!
<code> plugins.php </code> page calls <code> add_thickbox() </code> function that enqueues WP native thickbox script and style. It has this in documentation: If any of the settings need to be changed, this can be done with another js file similar to media-upload.js and theme-preview.js. That file should require array('thickbox') to ensure it is loaded after. So there are different possible ways to approach this: As WP suggest create and queue .js file that will add settings you need to defaults. Re-register or disable native thickbox completely and replace with your own code.
Custom height/width for thickbox in WP Backend
wordpress
I want to connect <code> wpdb </code> to another database. How do I create the instance and pass it the database name/username/password? Thanks
Yes it's possible. The wpdb object can be used to access any database and query any table. Absolutely no need to be Wordpress related, which is very interesting. The benefit is the ability to use all the wpdb classes and functions like <code> get_results </code> , etc so that there's no need to re-invent the wheel. Here's how: <code> $mydb = new wpdb('username','password','database','localhost'); $rows = $mydb-&gt;get_results("select Name from my_table"); echo "&lt;ul&gt;"; foreach ($rows as $obj) : echo "&lt;li&gt;".$obj-&gt;Name."&lt;/li&gt;"; endforeach; echo "&lt;/ul&gt;"; </code>
Using wpdb to connect to a separate database
wordpress
I want to backup my WP flies but the FTP is really slow. Is there a better solution ? (assume CRON and SSH in a managed VPS)
(assuming that FTP is slow due to amount of files) I use SSH to remotely give command to compress WP directory in single archive and then fetch that file. On Windows this is relatively easily scriptable with WinSCP ( scripting documentation ). This method greatly speeds up transfer, makes it secure, requires no plugins server-side, timestamps backups and is easy to schedule or launch with single click. (assuming FTP is slow in general) I would suggest to research backup plugins that can email backups (although size can get restrictive) or upload them to file storage service.
What is a better way to backup files then FTP?
wordpress
I've got a CMS style setup. The blog part is not on the home page. I'm trying to add certain things to the side-bar according to which template the page is using. That all works fine, except for the blog page, which does not even reveal its template name. <code> echo get_post_meta($post-&gt;ID,'_wp_page_template',true); // produces nothing for blog template blog-page.php, but does show standard-page.php if ( is_page_template('blog-page.php')) { // show blog sidebar stuff.... never gets called } if ( is_page_template('standard-page.php')) { // show blog sidebar stuff.. this works } </code> What else can I use to check if the page is a blog page rather than then template? UPDATE Doesn't seem to be actually using blog-page.php, but index.php instead... what if statement can i use to check if its a blog-style page?
You probably want one of the conditional tags . Possibly <code> is_single() </code> , or maybe <code> get_post_type() == 'post' </code> depending on how complex your setup is.
Why does blog page not reveal it's template?
wordpress
I'm aware that there are posts discussing this issue already (e.g. stackexchange-url ("stackexchange-url but I have a specific set of requirements according to my wordpress site structure, namely: 6 pages A small number of posts (~ 3 at launch, maybe 1 new one per month) I'd like to include the post name in the URL (for both SEO and easier stats analysis), but I've seen references to 'problems' arising from using just the post name. Would this be the case, even on such a small site? Would <code> /%post_id%/%$postname%/ </code> be a 'better' alternative? I notice that, even with this configuration, the Pages don't use the post_id in their URL.
Hi * @Bobby Jack :* You'll have absolutely zero problem given your number of pages and posts. If you were looking at 5000, 10k, 25k pages or more, then start to worry. And the real problem is with categories as the URL base in the current implementation of WordPress' URL routing (which I hope to see changed in v3.2 or v3.3): Category in Permalinks Considered Harmful In Summary, nothing to worry about.
Minimal custom permalink structure
wordpress
I'm just getting my feet wet with templates and have a few questions. First, Ideally, my templates use the same structure as my main theme, however, they simply use a different stylesheet and images. Currently, the way I allow changing the look of the site is with stylesheet switching. I simply have a folder under my main theme called "styles", then under that I have a single folder for each of my "skins". Inside each skin folder is a style.css along with some images. The way it works is that I've placed some code in my main theme's header.php file, so that it reads the value of the currently active skin from the options database, then loads the stylesheet for that skin like so... In the above example, the active skin is "skin1" so I'm always loading... "...mytheme/styles/". get_option('active_skin') ."style.css" This works exceedingly well, and allows me to place a simple skin switcher widget (a pulldown menu with thumbnail display) inside my function.php file to allow the admin user to easily switch between several skins that completely change the look and feel of the site. The beauty of this approach is that the selected theme and underlying markup remains unchanged, so I'm able to create a variety of styles using predictable markup. Sort of like CSS zen garden. Same markup, thousands of designs. All that changes is the stylesheet and images. However, the one downside to this approach (at least with WordPress) is that the selected skin applied to the whole site. I'm unable to apply one skin to the home page and one skin to a special page that might need a completely different look and feel. If there was a way to add some code to each skin folder so that it would appear in the "templates" drop down menu in the page editor, I'd be able to do exactly what I want. Is this possible?
Sure it's possible. The quick way would be to add a custom field to the postmeta (in the "Custom Fields" area of the Edit Post/Edit Page page) and in your theme get the value using get_post_meta() . The slightly-less-quick way would be to add a wrapper to this Custom Field value by putting your theme selector in a post meta box .
How do you apply multiple skins to a site via the "templates" selector using stylesheet switching?
wordpress
I want to add a field to the general settings page, but I can not save the field because I can't find a hook for the pages save. Any ideas?
You just need to <code> register_setting() </code> on your setting and it will be saved automatically. See the Settings API for more info. Here's a complete example: <code> function spw_cb() { if( !($value = get_option('sprockets_per_widget')) ) { $value = 7; } ?&gt; &lt;input type="text" size="3" name="sprockets_per_widget" value="&lt;?php echo $value; ?&gt;" /&gt; Numeric only! &lt;?php } function spw_init() { add_settings_field('sprockets_per_widget', 'Sprockets per Widget', 'spw_cb', 'general'); register_setting('general', 'sprockets_per_widget', 'intval'); } add_action('admin_init', 'spw_init'); </code>
Is there a hook attached to general settings save?
wordpress
On my CMS-style setup, I have the standard search box which searches everything. However, on my blog page, I would like to also have another search box which searches just the blog... is this possible, and how would I go about it? EDIT I used this code within a text widget which goes on my blog page: <code> &lt;form id='searchform' method='get'&gt; &lt;input style='margin-top:5px;' type='text' name='s' id='s' placeholder='Search (blog only)'&gt; &lt;input type='hidden' name='post_type' value='post' /&gt; &lt;/form&gt; </code> This has the advantage that the results page is styled like the blog, and not the standard search page. (though I don't know how to indicate that the page is showing search results.. how to show this?)
Hi @cannyboy : There's a plugin called Search Unleashed that gives lots of different functionality. One of my clients was using it and I was impressed with the control it gave. Not 100% sure it will give you what you need but it's worth checking out. If your blog only has post_types of "post" and you don't use them for the rest of the site you could use @TerryMatula 's suggestion but with <code> $post_type </code> => <code> 'post' </code> instead, i.e.: <code> &lt;input type="hidden" name="post_type" value="post" /&gt; </code>
Searching Only Blog Posts From a WordPress Site's Main Posts Page?
wordpress
I have a website I am starting to build on Wordpress, but I want a placeholder theme to put up while I develop the theme. I had some links to some good "Coming Soon" themes for 2.X, but I lost them. Any good "Coming Soon" themes for Wordpress 3.0? I would prefer it to have a place for the visitors to sign up for updates via email.
@Martin There are a few "Coming Soon" themes available on The WordPress.org theme repository. One of them is Ready to Launch . My recommendation is to use one of the "Coming Soon" plugins instead. Why Use a Plugin? The advantage to using a plugin is that it allows you to work on the site while the public sees the coming soon page. Anyone who is logged in will be able to see the progress on the theme. I use CSS Jockey's Custom Coming Soon Page because it allows complete control over the coming soon landing page and includes a simple email sign up and jQuery countdown timer. This allows my client to add content and see the progress of the site while it's being built. Here are a few more plugin choices Simple Coming Soon and Under Construction Under Construction
Are there any 'Coming Soon' themes for Wordpress 3.0?
wordpress
I would like to keep my main theme as the active theme, but allow users to select a slightly different layout via the "Page/Post Attributes" panel. Ideally, I'd like to store this layout under my main theme's "styles" directory, in its own folder. MyTheme > styles > My-special-Layout > style.css So that in the "Page Attributes" panel, I see a template there called "My-special-layout" ... However, I have two issues... I can't seem to get the "child" theme to appear in the "Page Attributes" panel. (I'm simply adding a folder under my main theme directory and placing a <code> style.css </code> file there that has the value " <code> Template: my_main_theme_directory </code> "). But I never see any templates appear in the "page attributes" panel. I can't get the "Page Attributes" panel on the POST editor. I'd like to allow the template to be applied to Posts as well as Pages . How to get this panel on the post editor?
You're not doing child themes right. A child theme is a separate theme altogether that everyone must use, but relies on another theme for all template parts it doesn't provide. What you want is templates: http://codex.wordpress.org/Theme_Development#Defining_Custom_Templates Basically, just create a new theme file in the theme's root directory (e.g. <code> foobar.php </code> ) write this at the top: <code> /* Template Name: Foobar */ </code> That will give you a new template called Foobar (obviously, change Foobar to whatever you want. That's the name that will appear in the dropdown menu on the editor page). As of now, WordPress only supports templates for pages and custom post types, not posts. There are ways to hack this, like checking for a post meta on posts and pulling it on template include: <code> function my_post_templater($template){ if( !is_single() ) return $template; global $wp_query; $c_template = get_post_meta( $wp_query-&gt;post-&gt;ID, '_wp_page_template', true ); return empty( $c_template ) ? $template : $c_template; } add_filter( 'template_include', 'my_post_templater' ); function give_my_posts_templates(){ add_post_type_support( 'post', 'page-attributes' ); } add_action( 'init', 'give_my_posts_templates' ); </code> If you put that code in your theme's <code> functions.php </code> file, that should work (as long as you actually have custom templates in your theme folder). For more information about child themes, read here: http://codex.wordpress.org/Child_Themes
Adding a Template to the Page Attributes Panel for both Posts and Pages?
wordpress
I've got a CMS-style wordpress setup where the homepage is not the main blog posts page. However, I would like to display the first paragraph of the latest blog post on the homepage, with a link to the post. How would I do that? I'd also like to display, above this excerpt, the first image within the post, but I'm guessing that might be harder... or I'll have to use the 'featured image' or a custom field...?
To show the excerpt from the latest post you can use query_posts. Example Query Posts Showing the Latest Post with the Featured Image: <code> &lt;?php query_posts('showposts=1'); ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;h3 class="home link"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt; &lt;?php the_post_thumbnail(); ?&gt; &lt;?php the_excerpt(); ?&gt; &lt;?php endwhile; ?&gt; </code> You will need to reset the query if you want to show content entered into your home page's post editor. <code> &lt;?php wp_reset_query(); ?&gt; </code>
how to display an excerpt of the latest post on the homepage?
wordpress
I don't want to edit core files in order to change the page where a user enters new posts, so is there a way to do it within a theme, perhaps within functions.php ..? Specifically, I'm trying to change the wording of the 'Set featured image' text to something like 'Set featured image - 50 pixels by 50 pixels'
You can use the filter <code> admin_post_thumbnail_html </code> : <code> function custom_admin_post_thumbnail_html( $content ) { return $content = str_replace( __( 'Set featured image' ), __( 'Set featured image - 50 pixels by 50 pixels' ), $content ); } add_filter( 'admin_post_thumbnail_html', 'custom_admin_post_thumbnail_html' ); </code>
How to change the wording in wp-admin back-end?
wordpress
As part of my efforts to speed up my themes for my clients I am delivering my CSS via a dynamic PHP file. At the end of the called for example <code> my_theme_css.php </code> : This allows me to add Expiry headers to my CSS and JavaScript like so: <code> &lt;?php header("Expires: Thu, 31 Dec 2020 20:00:00 GMT"); header('Content-type: text/css'); ?&gt; </code> I then want to allow the user to add thir own custom CSS so I have set the following up: <code> &lt;?php header("Expires: Thu, 31 Dec 2020 20:00:00 GMT"); header('Content-type: text/css'); ?&gt; p{color:blue;} /** Custom CSS **/ &lt;?php if(get_theme_mod('my_custom_css') != '') { $my_custom_css = get_theme_mod('my_custom_css'); echo $my_custom_css; } ?&gt; </code> I have then added the applicable theme options. But what I am finding is that <code> get_theme_mod() </code> doesn't work due to scope issue (I imagine.) Any suggestions on how to get around this? I could add the following code: <code> &lt;?php if(get_theme_mod('my_custom_css') != '') { $my_custom_css = get_theme_mod('my_custom_css'); echo $my_custom_css; } ?&gt; </code> Within <code> &lt;style&gt;&lt;/style&gt; </code> tags in the header and that would work fine, expect I don't want the CSS inline, I want it on the main CSS file with the expiry header.
Hi @Ash G: I didn't follow 100% where you were specifically having problems so I'm not sure I really can answer your issues point-by-point but I can explain how to do this from ground up . And unless what you are doing is a good bit more involved then you mentioned it's a little bit more work than I think you were anticipating but it is still completely doable. And even if I'm covering lots of ground that you already know there's a good chance other's with less knowledge or experience will find this via Google and be helped by it too. Bootstrap WordPress with <code> /wp-load.php </code> The first thing we need to do in your <code> my_theme_css.php </code> file is bootstrap WordPress' core library functions. The following line of code loads <code> /wp-load.php </code> . It uses <code> $_SERVER['DOCUMENT_ROOT'] </code> to locate the website's root so you don't have to worry about where you store this file on your server; assuming <code> DOCUMENT_ROOT </code> is set correctly as it always should be for WordPress then this will bootstrap WordPress: <code> &lt;?php include_once("{$_SERVER['DOCUMENT_ROOT']}/wp-load.php"); </code> So that's the easy part. Next comes the tricky part... PHP Scripts Must Handle All Caching Logic Here's where I'll bet you might have stumbled because I sure did as I was trying to figure out how to answer your question. We are so used to the caching details being handled by the Apache web server that we forget or even don't realize we have to do all the heavy lifting ourselves when we load CSS or JS with PHP. Sure the expiry header may be all we need when we have a proxy in the middle but if the request makes it to the web server and the PHP script just willy-nilly returns content and the "Ok" status code well in essence you'll have no caching. Returning "200 Ok" or "304 Not Modified" More specifically our PHP file that returns CSS needs to respond correctly to the request headers sent by the browser. Our PHP script needs to return the proper status code based upon what those headers contain. If the content needs to be served because it's a first time request or because the content has expired the PHP script should generate all the CSS content and return with a "200 Ok" . On the other hand if we determine based on the cache-related request headers that the client browser already has the latest CSS we should not return any CSS and instead return with a "304 Not Modified" . The too lines of code for this are respectively (of course you'd never use them both one line after another, I'm only showing that way here for convenience) : <code> &lt;?php header('HTTP/1.1 200 Ok'); header('HTTP/1.1 304 Not Modified'); </code> Four Flavors of HTTP Caching Next we need to look at the different ways HTTP can handle caching. The first is what you mention; <code> Expires </code> : Expires : This <code> Expires </code> header expectz a date in the ( PHP <code> gmdate() </code> function ) format of <code> 'D, d M Y H:i:s' </code> with a <code> ' GMT' </code> appended ( GMT stands for Greenwich Mean Time .) Theoretically if this header is served the browser and downstream proxies will cache until the specified time passes after which it will start requesting the page again. This is probably the best known of caching headers but evidently not the preferred one to use; Cache-Control being the better one . Interestingly in my testing on <code> localhost </code> with Safari 5.0 on Mac OS X I was never able to get the browser to respect the <code> Expires </code> header; it always requested the file again (if someone can explain this I'd be grateful.) Here's the example you gave from above: <code> header("Expires: Thu, 31 Dec 2020 20:00:00 GMT"); </code> Cache-Control : The <code> Cache-Control </code> header is easier to work with than the <code> Expires </code> header because you only need to specify the number of time in seconds as <code> max-age </code> meaning you don't have to come up with an exact date format in string form that is easy to get wrong. Additionally <code> Cache-Control </code> allows several other options such as being able to tell the client to always re-validated the cache using the <code> mustrevalidate </code> option and <code> public </code> when you want to force caching for normally non-cachable requests (i.e requests via <code> HTTPS </code> ) and even not cache if that's what you need (i.e. you might want to force a a 1x1 pixel ad tracking .GIF not to be cached.) Like <code> Expires </code> I was also unable to get this to work in testing ( any help? ) The following example caches for a 24 hour period (60 seconds by 60 minutes by 24 hours): <code> header("Cache-Control: max-age=".60*60*24.", public, must-revalidate"); </code> Last-Modified / If-Modified-Since : Then there is the <code> Last-Modified </code> response header and If- <code> Modified-Since </code> request header pair. These also use the same GMT date format that the <code> Expires </code> header use but they do a handshake between client and server. The PHP script needs to send a <code> Last-Modified </code> header (which, by the way, you should update only when your user last updates their custom CSS) after which the browser will continue to send the same value back as an <code> If-Modified-Since </code> header and it's the PHP script's responsibility to compare the saved value with the one sent by the browser. Here is where the PHP script needs to make the decision between serving a <code> 200 Ok </code> or a <code> 304 Not Modified </code> . Here's an example of serving the <code> Last-Modified </code> header using the current time (which is not what we want to do; see the later example for what we actually need): <code> header("Last-Modified: " . gmdate('D, d M Y H:i:s', time()).'GMT'); </code> And here is how you'd read the <code> Last-Modified </code> returned by the browser via the <code> If-Modified-Since </code> header: <code> $last_modified_to_compare = $_SERVER['HTTP_IF_MODIFIED_SINCE']; </code> ETag / If-None-Match : And lastly there's the <code> ETag </code> response header and the <code> If-None-Match </code> request header pair. The <code> ETag </code> which is really just a token that our PHP sets it to a unique value (typically based on the current date) and sends to the browser and the browser returns it. It the current value is different from what the browser returns your PHP script should regenerate the content an server <code> 200 Ok </code> otherwise generate nothing and serve a <code> 304 Not Modified </code> . Here's an example of setting an <code> ETag </code> using the current time: <code> header("ETag: " . md5(gmdate('D, d M Y H:i:s', time()).'GMT')); </code> And here is how you'd read the <code> ETag </code> returned by the browser via the <code> If-None-Match </code> header: <code> $etag_to_match = $_SERVER['HTTP_IF_NONE_MATCH']; </code> Now that we've covered all that let's look at the actual code we need: Serving the CSS file via <code> init </code> and <code> wp_enqueue_style() </code> You didn't show this but I figured I would show it for the benefit of others. Here's the function call that tells WordPress to use <code> my_theme_css.php </code> for it's CSS. This can be stored in the theme's <code> functions.php </code> file or even in a plugin if desired: <code> &lt;?php add_action('init','add_php_powered_css'); function add_php_powered_css() { if (!is_admin()) { $version = get_theme_mod('my_custom_css_version',"1.00"); $ss_dir = get_stylesheet_directory_uri(); wp_enqueue_style('php-powered-css', "{$ss_dir}/my_theme_css.php",array(),$version); } } </code> There are several points to note: Use of <code> is_admin() </code> to avoid loading the CSS while in the admin (unless you want that...), Use of <code> get_theme_mod() </code> to load the CSS with a default version of <code> 1.00 </code> (more on that in a bit), Use of <code> get_stylesheet_directory_uri() </code> to grab the correct directory for the current theme, even if the current theme is a child theme, Use of <code> wp_enqueue_style() </code> to queue the CSS to allow WordPress to load it at the proper time where <code> 'php-powered-css' </code> is an arbitrary name to reference as a dependency later ( if needed ), and the empty <code> array() </code> means this CSS has no dependencies ( although in real world it would often have one or more ), and Use of <code> $version </code> ; Probably the most important one, we are telling <code> wp_enqueue_style() </code> to add a <code> ?ver=1.00 </code> parameter to the <code> /my_theme_css.php </code> URL so that if the version changes the browser will view it as a completely different URL (Much more on that in a bit.) Setting <code> $version </code> and <code> Last-Modified </code> when User Updates CSS So here's the trick. Every time the user updates their CSS you want to serve the content and not wait until <code> 2020 </code> for everyone's browser cache to timeout, right? Here's a function that combined with my other code will accomplish that. Every time you store CSS updated by the user, use this function or functionality similar to what's contained within: <code> &lt;?php function set_my_custom_css($custom_css) { $new_version = round(get_theme_mod('my_custom_css_version','1.00',2))+0.01; set_theme_mod('my_custom_css_version',$new_version); set_theme_mod('my_custom_css_last_modified',gmdate('D, d M Y H:i:s',time()).' GMT'); set_theme_mod('my_custom_css',$custom_css); } </code> The <code> set_my_custom_css() </code> function automatically increments the current version by 0.01 (which was just an arbitrary increment value I picked) and it also sets the last modified date to right now and finally stores the new custom CSS. To call this function it might be as simple as this (where <code> new_custom_css </code> would likely get assigned via a user submitted <code> $_POST </code> instead of by hardcoding as you see here) : <code> &lt;?php $new_custom_css = 'body {background-color:orange;}'; set_my_custom_css($new_custom_css); </code> Which brings us to the final albeit significant step: Generating the CSS from the PHP Script Finally we get to see the meat, the actual <code> my_theme_css.php </code> file. At a high level it tests both the <code> If-Modifed-Since </code> against the saved <code> Last-Modified </code> value and the <code> If-None-Match </code> against the <code> ETag </code> which was derived from the saved <code> Last-Modified </code> value and if neither have changed just sets the header to <code> 304 Not Modifed </code> and branches to the end. If however either of those have changed it generates the <code> Expires </code> , <code> Cache-Control </code> . <code> Last-Modified </code> and <code> Etag </code> headers as well as a <code> 200 Ok </code> and indicating that the content type is <code> text/css </code> . We probably don't need all those but given how finicky caching can be with different browsers and proxies I figure it doesn't hurt to cover all bases. (And anyone with more experience with HTTP caching and WordPress please do chime in if I got any nuances wrong.) There are a few more details in the following code but I think you can probably work them out on your own: <code> &lt;?php $s = $_SERVER; include_once("{$s['DOCUMENT_ROOT']}/wp-load.php"); $max_age = 60*60*24; // 24 hours $now = gmdate('D, d M Y H:i:s', time()).'GMT'; $last_modified = get_theme_mod('my_custom_css_last_modified',$now); $etag = md5($last_modified); if (strtotime($s['HTTP_IF_MODIFIED_SINCE']) &gt;= strtotime($last_modified) || $s['HTTP_IF_NONE_MATCH']==$etag) { header('HTTP/1.1 304 Not Modified'); } else { header('HTTP/1.1 200 Ok'); header("Expires: " . gmdate('D, d M Y H:i:s', time()+$max_age.'GMT')); header("Cache-Control: max-age={$mag_age}, public, must-revalidate"); header("Last-Modified: {$last_modified}"); header("ETag: {$etag}"); header('Content-type: text/css'); echo_default_css(); echo_custom_css(); } exit; function echo_custom_css() { $custom_css = get_theme_mod('my_custom_css'); if (!empty($custom_css)) echo "\n{$custom_css}"; } function echo_default_css() { $default_css =&lt;&lt;&lt;CSS body {background-color:yellow;} CSS; echo $default_css; } </code> So with these three major bits of code; 1.) the <code> add_php_powered_css() </code> function called by the <code> init </code> hook, 2.) the <code> set_my_custom_css() </code> function called by whatever code allows the user to update their custom CSS, and lastly 3.) the <code> my_theme_css.php </code> you should pretty much have this licked. Further Reading Aside from those already linked I came across a few other articles that I thought were really useful on the subject so I figured I should link them here: Cache it! Solve PHP Performance Problems - A typical SitePoint Uber-Article; five (5) long pages of all things caching and PHP, covering HTTP and other forms of caching. CSS Caching Hack - This is what I did with <code> $version </code> but he explains more in-depth than I did. php: howto control page caching - Good details on using HTTP headers with PHP. Epilogue: But I would be remiss to leave the topic without making a closing comments. Expires in <code> 2020 </code> ? Probably Too Extreme. First, I don't really think you want to set <code> Expires </code> to the year 2020. Any browsers or proxies that respect <code> Expires </code> won't re-request even after you've made many CSS changes. Better to set something reasonable like 24 hours (like I did in my code) but even that will frustrate users for the day during which you make changes in the hardcoded CSS but forget to but the served version number. Moderation in all things? This Might All Be Overkill Anyway! As I was reading various articles to help me answer your question I came across the following from Mr. Cache Tutorial himself, Mark Nottingham: The best way to make a script cache-friendly (as well as perform better) is to dump its content to a plain file whenever it changes. The Web server can then treat it like any other Web page, generating and using validators, which makes your life easier. Remember to only write files that have changed, so the Last-Modified times are preserved. While all this code I wrote it cool and was fun to write (yes, I actually admitted that), maybe it's better just to generate a static CSS file every time the user updates their custom CSS instead, and let Apache do all the heavy lifting like it was born to do? I'm just sayin... Hope this helps!
Generating CSS Files Dynamically Using PHP Scripts?
wordpress
I'm using add_settings_field to add some more details to a settings menu, but not sure how I save the settings, or call them back in my theme. Here is the code thus far <code> add_action('admin_init','vimeo_setup'); function vimeo_setup(){ add_settings_field('vimeo_id','Vimeo ID','display_vimeo','general'); } function display_vimeo(){ echo '&lt;input type="text" name="vimeo_id" id="vimeo_id" value="" size="30" style="width:85%" /&gt;'; echo '&lt;p&gt;&lt;small&gt; Enter your Vimeo ID here.&lt;/small&gt;&lt;/p&gt;'; } </code>
Documentation for add_settings_field() Says following: You MUST register any options used by this function with register_setting() or they won't be saved and updated automatically.
use add_settings_field properly?
wordpress
Why? Sometimes an easy fix to altering the behavior of WordPress itself or a plugin could be to alter the files of the plugin or WordPress directly. When coming up with such an idea, the usual response is: Don't hack core. Why is it generally a bad idea to change core files? Consider? Sometimes, however, things that can be critical for a site is simply impossible to do, in a nice way without altering core files. When in such a situation, what do you need to be aware of, before you go ahead and starting hacking core? How? You have considered all the options, but the only solution is hacking core files. How should you go about doing this? How will having an altered core, influence workflows, like updating?
If you must hack core, consider doing so in a way that makes it extensible for others. Add an Action Hook Nine times out of ten, you could do what it is you wanted if only there was an extra <code> do_action </code> call in a specific file. In that case, add the action, document it, and submit a patch via Trac . If there's a good reason for your patch (i.e. you're not the only one who would ever use it) then you can probably get it added to core. Next, build a custom plug-in (you don't have to release/distribute it!) that ties in to this new hook and performs whatever function you need it to do. Refactor a core file Other times, you might just need a piece of code to behave differently. Pass a variable by reference, for example, or return a value rather than echo it. Take some time to sit down and refactor the code so it does what you need it to do ... then submit a patch via Trac so the rest of us can benefit from your work. Do you see a theme developing here? Hacking core isn't necessarily a no-no ... just something most developers will highly discourage for new users or novice programmers (if you're asking us how to do something, we'll suggest a plug-in every time before even considering to suggest you hack core). Hacking core is the way WordPress develops and evolves, but it's dangerous for someone just learning PHP or with no experience working with WP files. Please start with a plug-in before touching core - if you break a plug-in you can uninstall it quickly (removing via FTP if necessary) ... but if you break core, bad things can happen to your site and potentially to your database as well. But if you are in a situation where a core hack is unavoidable, then make the change. Also, publish your change in a prominent location (if your blog is highly visible, that might be sufficient ... but I suggest Trac because that's how community changes get pulled into the next release). Your change might be the magic bullet that could fix problems in a hundred different sites ... so contribute back to the community that helped you build your site. If the change gets committed, then your hack becomes part of core and you won't need to worry about it in the future. If it doesn't, at least you have detailed documentation on how to re-implement the hack after you upgrade WP in 3 months.
Modifying WordPress core files
wordpress
I am having a strange issue with the built in wordpress image editor. I have no problem uploading files or preforming any other media functions. The only thing I seem to be unable to do is utilize the image "edit" capabilities (the area where you can crop, resize, rotate...) When I click on "edit" for an image I see the editor and I see the thumbnail on the right, wordpress just won't show me the actual image in the main area and thus I can't utilizing any of the editing capabilities. I am assuming this must be some type of JavaScript conflict however I not sure the best way to diagnose this other than what I have already done (disabling all plugins and ensuring no functions.php file is modifying a setting or including other javascript). How can I diagnose this issue to see what might be going wrong?
I have actually managed to resolve my own problem. For anyone else that might ever read this the problem which caused this was that my <code> functions.php </code> file had a closing <code> ?&gt; </code> at the very end. For whatever reason this is what cause the issue and by removing this last line it was working again.
Wordpress Image Editor not working - conflict?
wordpress
Does anyone happen to know how I can automatically turn: http://www.domain-name.com/wp-content/themes/theme-name/css/stylesheeet.css into http://www.domain-name.com/css/stylesheet.css Naturally I could just create the applicable folder within the root of the website, place the files there and just reference them but that is now what I am after. I am looking for a way to keep all css &amp; javascript files within the theme folder but I would like for wordpress to show the above outlined url path if you view the source of the page. In an ideal situation I am looking for a piece of code which can be added that automatically does this for all files referenced within my theme folder including any images. Thank you in advance
Offhand I think you'd need two things: First, a rewrite rule in your .htaccess file like so: <code> RewriteEngine On RewriteBase / RewriteRule ^css/(.*) /wp-content/themes/theme-name/css/$1 [L] RewriteRule ^js/(.*) /wp-content/themes/theme-name/js/$1 [L] </code> Second, add a filter to your theme's functions.php like so: <code> function change_css_js_url($content) { $current_path = '/wp-content/themes/theme-name/'; $new_path = '/'; // No need to add /css or /js here since you're mapping the subdirectories 1-to-1 $content = str_replace($current_path, $new_path, $content); return $content; } add_filter('bloginfo_url', 'change_css_js_url'); add_filter('bloginfo', 'change_css_js_url'); </code> A couple caveats: - if a plugin or something doesn't use bloginfo() or get_bloginfo() it will not trigger the filter. You can get around this by hooking your function into other filters as needed. - some plugins/themes/etc use a hard-coded paths. There's not much you can do about this except modify the code to use one of WP's functions to get the path. Here's the same example using the twentyten theme (no css/js subdirectories, but the idea is the same.) .htaccess <code> # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^twentyten/(.*) /wp-content/themes/twentyten/$1 [L] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt; # END WordPress </code> functions.php <code> function change_css_js_url($content) { $current_path = '/wp-content/themes/'; $new_path = '/'; // No need to add /css or /js here since you're mapping the subdirectories 1-to-1 $content = str_replace($current_path, $new_path, $content); return $content; } add_filter('bloginfo_url', 'change_css_js_url'); add_filter('bloginfo', 'change_css_js_url'); </code>
Changing the visible url path to css & js files
wordpress
I have a website for which we are trying to be discreet about the fact that we are using WordPress. What steps can we take to make it less obvious?
The biggest WordPress giveaways are between the <code> &lt;head&gt; &lt;/head&gt; </code> tags. Example WordPress head content output by The Twentyten Theme and how to remove: <code> &lt;link rel="profile" href="http://gmpg.org/xfn/11" /&gt; </code> Remove directly from header.php <code> &lt;link rel="stylesheet" type="text/css" media="all" href="http://example.com/wp-content/themes/twentyten/style.css" /&gt; </code> Hide WordPress by calling your stylesheet from another location and change the wp-content directory. WordPress requires your theme to include some basic information at the top of style.css (style.css must be in the themes root directory). You will need to create an alternate CSS and call it from your head. WordPress does not require you to use the themes style.css it only requires it to be in the themes directory. Remove directly from header.php <code> &lt;link rel="alternate" type="application/rss+xml" title="Example Blog &amp;raquo; Feed" href="http://example.com/feed/" /&gt; &lt;link rel="alternate" type="application/rss+xml" title="Example Blog &amp;raquo; Comments Feed" href="http://example.com/comments/feed/" /&gt; &lt;link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://example.com/xmlrpc.php?rsd" /&gt; &lt;link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://example.com/wp-includes/wlwmanifest.xml" /&gt; &lt;link rel='index' title='Example Blog' href='http://example.com/' /&gt; &lt;meta name="generator" content="WordPress 3.1-alpha" /&gt; </code> To remove these extra links you can add a filter to functions.php <code> // remove junk from head remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'feed_links', 2); remove_action('wp_head', 'index_rel_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'start_post_rel_link', 10, 0); remove_action('wp_head', 'parent_post_rel_link', 10, 0); remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); </code> You can change your plugin directory and your wp-content directory in your wp-config.php file but you could have some problems if your theme or any plugins do not use the proper method to call files. <code> define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/new-wp-content' ); </code> Set WP_CONTENT_URL to the full URI of this directory (no trailing slash), e.g. <code> define( 'WP_CONTENT_URL', 'http://example/new-wp-content'); </code> Optional Set WP_PLUGIN_DIR to the full local path of this directory (no trailing slash), e.g. <code> define( 'WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/new-wp-content/new-plugins' ); </code> Set WP_PLUGIN_URL to the full URI of this directory (no trailing slash), e.g. <code> define( 'WP_PLUGIN_URL', 'http://example/new-wp-content/new-plugins'); </code> PLUGINS Be aware that some plugins like Akismat, All in One SEO, W3-Total-Cache, Super Cache, and many others add comments to the HTML output. Most are easy to modify to remove the comments but your changes will be overwritten anytime the plugins get updated. wp-includes The wp-includes directory holds jquery and various other js files that themes or plugins will call using wp_enqueue_script(). To change this you will need to deregister the default WordPress scripts and register the new location. Add to functions.php: <code> function my_init() { if (!is_admin()) { // comment out the next two lines to load the local copy of jQuery wp_deregister_script('jquery'); wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', false, '1.3.2'); wp_enqueue_script('jquery'); } } add_action('init', 'my_init'); </code> This will need to be done with each script used by your theme or plugins.
Steps to Take to Hide the Fact a Site is Using WordPress?
wordpress
Let's say we create an IMDB like website. So (for example) we can have two types of custom post types: movies actors We would like to see in each movie page all of it's actors. And in each actors page all of the movies he played in. Can this cross linking be done using custom post types? If not, is it expected to be possible in the future? If not, is there an alternative (in WP) for doing this? Thanks
Checkout scribu's post2post plugin , it should fill your needs.
Linking between custom post types as if they where taxonomies?
wordpress
I've had a few non-technical clients have a tough time with WordPress' admin UI. One of them asked me today if there were any books that could help someone like him - someone who is only concerned with writing content. All of the WordPress books I've seen are either targeted toward developers, or have a lot of technical content. What may work best for him is a book that explains terms such as "categories" , "pages vs posts" , "widgets" , etc. On a side note, it would seem to me that as tools like WordPress get adopted by a larger audience - including non-web-savvy people - there's a great opportunity for a set of guides aimed specifically at content creators and not developers. Do you know of any books that can help a non-technical, non-web-savvy person write, edit &amp; manage the content of their WordPress-powered site?
It's not a book but I wrote a "25 Steps to Understand WordPress and it's Terms" about a month ago in response to a question on the LinkedIn WordPress group and maybe copying it here will help? (Maybe I could every take these and turn them into a book for managers complete with screenshots; what do you think?) 25 Steps to Understanding WordPress and it's Terms Here's a very high-level overview of terms ( Note: I'm stating things that are not 100% true early in the list and leaving out some details in earlier points. Rest assured I know that some of these earlier points are not 100% correct but clarification too soon will just overwhelm the reader ): 1: A "CMS" WordPress is a "Content Management System" aka a "CMS." In other words it is a system to manage (and present) content. 2: "posts" WordPress stores each of it's major content items in what they call "posts" (lowercase "posts" that is.) There is subsidary content not stored in a "post" but major content is stored in a "post." How do you tell if it's major or not? The person who configures the site makes that decision. 3: "Posts" &amp; "Pages" Out of the box WordPress has two types of "posts" : "Posts" and "Pages" (Note they are Proper case. Yes this can be confusing. Just pay attention to the capitalization and realize that a "post" is like a generic "car" and a "Post" is like a "Ford Mustang." ) 4: "Posts" A "Post" is a content type that is used to store "blog-like" content. Blog-like content typically has the following unique attributes: an Author, a Date/time published, Optional Commenting. 5: "Pages" A "Page" on the other hand is a content type used to store what appear to be "static" web pages on your site like your "About" page, your "Services" page, maybe your "Products" page, your "Contact Page" and so on. 6: "web pages" Don't get a WordPress "Page" confused with a "web page" ; practically every URL that you visit on a WordPress website generates a web page; a "Page" in WordPress on the other hand is a type of content as defined by WordPress. 7: "main menu items" Many (most?) of the main menu items in a WordPress website typically link to a "Page" and rarely to a "Post." To access Posts via a main menu item would typically link to list of posts. 8: Lists of Posts Your main list of Posts is typically either your home web page or your "Blog" web page. 9: "Categories" &amp; "Tags" You can also find website that will display a web page containing a list of Posts based on those assigned to a given "Category" or a given "Tag" (more on Categories and Tags later.) 10: "Pages" , redux A "Page" typically has the following unique attributes: An optional "Parent" Page which enables streamlined URLs like: <code> http://example.com/parent-page/child-page/ </code> An optional "Page Template" (more on those in a bit.) And an optional "order" which in older versions before WordPress 3.0 was used to determine the order in menu this page's menu. 11: Shared Attributes of Posts &amp; Pages Both Posts and Pages share the following attributes: A Title A Content Body A Status ( Published , Pending Review , Draft , etc.) A Visibility ( Public , Private , Password Protected , etc.) Custom Fields (ability to associate any set of name-value pairs of information that you want to any Post or Page) A Featured Image (aka a Thumbnail ) Probably more... 12: Differences between Posts and Pages Revisited Actually, the "unique" things I mentioned for Posts and for Pages are actually shared meaning you can get (practically) everything with either post type but most of the time people use Posts as described and Pages as described and there is not a whole lot of reason not to. 13: Components of a WordPress site Every WordPress site is comprised of (two or) three components: WordPress *"Core" -- That's what everyone who uses WordPress has. One (1) "Theme" at a time -- This is what provides a sites look and might include functionality (like a home page image rotator or a sidebar video player.) Zero (0) or more "Plugins" -- These can do almost anything but typically they add some kind of functionality somewhere such as your latest Tweets from Twitter in a sidebar or even the ability to edit specialty types. 14: "Themes" A "Theme" in WordPress is a collection of programming scripts in the PHP language that generate HTML web pages when used, CSS files for "styling" the layout, colors, and fonts, Images used to create the site design, and probably some other files. 15: "Theme template files" A Theme has "template files" in PHP that are used to generate the HTML web pages for the site. They are named using a naming convention and most of them are optional. 16: "single.php" The "single.php" file it used by WordPress to generate the HTML required to display a single Post content item. 17: "page.php" The "page.php" file is the default "Page Template" (more on them in a bit) used by WordPress to display a single Page content item. 18: "index.php" The "index.php" is the default file WordPress uses to generate HTML if no other more specialize template file is not available. This file can generate both lists of Posts and/or it can display specific Posts Pages or Pages based on the URL that a browser uses to request a web page from the site. 19: "header.php" and "footer.php" The files "header.php" and "footer.php" respectively generate the beginning and ending HTML for (practically) every page on a WordPress site. The HTML they generate "wraps" around the HTML generated by the other PHP files. 20: "Page Templates" (finally) A "Page Template" is a file that is part of a Theme and it is also a special type of "template file." A Page Template allows WordPress to display different Pages with different web page layouts. For example a Theme could have two (2) different Page Templates: The Default Two-Column Page Template and A One-Column Page Template. 21: Classifying Posts &amp; Pages: Taxonomy WordPress provides a flexible system called the "Taxonomy" system to enable site owners and authors to classify their Posts and/or Pages (aka "posts." ) You can classify posts using "Categories" or "Tags" ; collectively they comprise the Taxonomy system. 22: "Categories" A "Category" is a name that can be applied to a post to classify it. The list of Categories on a web site is typically a short list of pre-defined terms that collectively help define the focus of the site. Examples might be: "Automobiles" , "Social Media" , "Politics" , etc. 23: "Tags" A "Tag" is also a term that can be applied to a page to classify but Tags are typically free-form entry and are typically used to match up with the details of the post. it. Given the list of Categories from above Tags might be: "Ford Mustang" , "BMW 5 Series" or "Shelby Cobra" "Twitter" , "Facebook" or "FourSquare" ; and "Obama" , "Congress" , "Tea Party." 24: List of "posts" Using Categories and Tags you can generate HTML web pages which are list of posts using URLs like these: For Categories: http://example.com/category/automobiles http://example.com/category/social-media http://example.com/category/politics For Tags: http://example.com/tag/ford-mustang http://example.com/tag/bmw-5-series http://example.com/tag/shelby-cobra http://example.com/tag/twitter http://example.com/tag/facebook http://example.com/tag/foursquare http://example.com/tag/obama http://example.com/tag/congress http://example.com/tag/tea-party 25: "Parent Themes" &amp; "Child Themes" While WordPress can have a standalone Theme a relatively new development is what they call a "Child Theme." It sits in a side-by-side directory and references the "Parent Theme." Anything the Child Theme doesn't do explicitly WordPress delegates to the Parent Theme. This way you can "modify" a Theme provided by someone else without completely modifying it (i.e. you can often seemlessly upgrade to a newer version of the Parent Theme. Note that anytime a Child Theme is created the Theme it references becomes a "Parent Theme" by default.) Parent/Child Themes also make it much easier to create reusable Themes and also much easier for someone new to get started; they just need to create a Child Theme of an existing Theme. Epilogue: Whew! Whew! I think that's about it for the basics. There is a ton more to learn about WordPress, of course, but I think this might help you better understand the terminology of the WordPress world. Once you've digested all that, let me and the others know how else we can help you.
Recommended Books on WordPress for Management and non-Developers?
wordpress
A client asked for a blog that will have localized content (i.e. en.blogname.com for English content, fr.blogname.com for French content, etc). Being new to building such a blog, we recently discovered WPML and qTranslate, which look perfect for our needs. Do you have any best / recommended practices for setting up a multilingual blog? At this point, we don't envision the need to have the WordPress software translated, but if you've found that to be a good idea, we would love to know. The authors will all be multilingual (English + one other language), but it's conceivable that non-English speakers may be hired later.
The best way is without plugin - i set WP3.0 with multisite; the first blog is a dummy to rewrite the uesers to right blog with his language, a small script in the theme to rewirte ro the right language; i see in the browser-language of the users and rewrite; the second is the default blog, the third blog is another blog and so on - olso it is possible to swich the blog from post tot post with core function of WPMU and you can add own functions to post draft in other blogs from published post in a blog update for your question: Sorry, my english is bad I install wp3.0 or MU and the first blog, the admin-blog has an small theme, one template with a small function. The function read the browser-language of the users on the frontend of the domain and sitch then to the other blog of this install, she have this language as default. All other blogs are for different languages and one blog is for one language. So it is possible to has great tables for the different posts and all works with WP core methods. WPMU has enough function to switch from post to post in different language. Give it a post in blog english and link to post in blog german, than i write this with an own plugin in the postmeta of the post. So it is possible for the users, he can switch on the frontend from a post in other language. Also you can use <code> wp_insert_post() </code> to add an draft in blog german maybe, when you publish in blog english. I hope you understand my way - works great and i have many customer with this solution. Update, pulled from the comments 12/22/2012 We have created a free plugin to do this: wordpress.org/extend/plugins/multilingual-press bueltge Dec 22 '11 Update 10/29/2012 Pro Variant of the created plugin solution with many more functions for more comfort.
Best practices for localizing WordPress content?
wordpress
The standard search for Wordpress works, but doesn't seem too clever. If I search for 'tomato' and I have a page whose title is 'Tomato' I would expect that to come first in the results. However the results seem to be ordered by date published. So if a page/post mentions 'tomato' somewhere in the text, it will be first in the results if it was just published. How would I make Wordpress prioritise page titles in the search? (I'm using the Starkers theme)
You can replace the default Wordpress search with something more useful. As you have pointed out, the build-in search is very limited. So you're not the first one with this problem. I suggest the following two plugins: Search API (Wordpress Plugin) WordPress Sphinx Search Plugin (Wordpress Plugin) The last one allows to weight between parts of a post. But keep in mind that it needs you to configure and make use of Sphinx , a free open-source SQL full-text search engine.
How to make Wordpress search prioritise page titles?
wordpress
Wordpress has <code> wp_enqueue_script() </code> but not a <code> wp_dequeue_script() </code> function, so what would be the best way to dequeue a script? I'm using LAB.js to load all of my scripts rather than enqueueing them server side, so I don't want plugins running around adding jQuery 10 times when I'm already loading it. Would using <code> wp_deregister_script( 'jquery' ) </code> accomplish the same purpose?
There is a <code> dequeue </code> method available ... I'm just not sure why it isn't wrapped in a <code> wp_dequeue_script() </code> method. (I might create a ticket for this issue, actually) But yes, using <code> wp_deregister_script </code> will accomplish what you're trying to do. Just remember, if you ever do want to use WP's built-in jQuery later you'll need to re-queue it first.
How to dequeue a script?
wordpress
I've created a Contact Us page (my-site.com/contact-us/) using contact-form-7 which works fine on my local WordPress install. However, when I try the same form on the online version of the site, it simply hangs. I checked the http headers using Fiddler and saw that the url being used by the ajax submit is /contact-us/#wpcf7-f1-p15-o1 . The error shown by Fiddler is HTTP 400 "Bad Request". There's no server information, so I'm assuming the request doesn't even make it to the server. Local setup: XAMPP on Windows XP Online setup: IIS 6.0 on Windows 2003 WordPress version: 2.9.2 Browser: Opera 10.61 Update: I'm using gmail as my smtp server via the WP-Mail-SMTP plugin.
I've had this problem before. There's an easy way and a hard way to fix it. The easy solution: use a Linux server. The hard solution: write your own contact form. IIS 6 doesn't play nice with anything WordPress uses or does. It works on XAMPP because that's a LAMP stack running PHP, MySQL, Apache, and (usually, for Windows) Tomcat. When IIS runs those scripts, it's all going through Windows. Think of your site as fuel, and Windows and Linux as different kinds of engines (diesel and regular. You can decide which you think is which). What works for one doesn't necessarily work for the other.
Contact Form 7 form is working on local wordpress install but fails on production server
wordpress
I'm doing a custom query using WP_query to get posts from a specific category, but for some reason navigation links for the list don't appear. Is there a way to get the newer/older links to show up and work using a custom WP_query? This is what I'm doing: <code> &lt;?php $mainList_query = new WP_Query('cat=4,352,731,754,49,44,54,17&amp;showposts=200&amp;order=DESC'); ?&gt; &lt;?php if($mainList_query-&gt;have_posts()) : while($mainList_query-&gt;have_posts()) : $mainList_query-&gt;the_post(); ?&gt; &lt;div class="articleSection"&gt; &lt;h2 class="headlinelist"&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;div class="byline2"&gt;&lt;?php the_time('F jS, Y') ?&gt; by &lt;?php the_author() ?&gt; at &lt;?php the_time() ?&gt; &lt;/div&gt; &lt;?php if ( in_category( array(754,49,44,54,17) ) ) { ?&gt; &lt;img src="&lt;?php bloginfo('template_url'); ?&gt;/images/360btn.jpg" width="67" height="16" alt="" /&gt; &lt;?php } ?&gt; &lt;?php if ( in_category(4) ) { ?&gt; &lt;img src="&lt;?php bloginfo('template_url'); ?&gt;/images/ps3btn.jpg" /&gt; &lt;?php } ?&gt; &lt;p class="postmetadata"&gt;&lt;?php the_tags('Tags: ', ', ', '&lt;br /&gt;'); ?&gt; Posted in &lt;?php the_category(', ') ?&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('&amp;laquo; Older Entries') ?&gt;&lt;/div&gt; &lt;div class="alignright"&gt;&lt;?php previous_posts_link('Newer Entries &amp;raquo;') ?&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; ?&gt; </code>
try adding '&amp;paged='.$paged to your query string <code> &lt;?php $mainList_query = new WP_Query('cat=4,352,731,754,49,44,54,17&amp;showposts=200&amp;order=DESC&amp;paged='.$paged); ?&gt; </code>
WP_Query older new links navigation?
wordpress
I have an issue with the new custom menu in WP3. Suddenly the nesting of categories stopped working and even though it's possible to nest them in the UI, when I press Save, then they all go back flat. Any chance someone has experienced this and know a way to fix it? Thanks.
First, try disabling all of your plugins . If that fixes it, re-enable them one by one until you find the culprit.
Unable to nest categories in menu
wordpress
I'm seeking to customize my categories listing (archive.php) so that it shows a thumbnail image of the first image attached to each post However, apparently the archive.php file is one of those that does not natively support the attachment object. For example, the code below will do most of what I want (though if no attachment is found, I get a blank image, I need to fix that). However, I'm afraid having a SELECT in a loop like this is perhaps way too expensive for what I'm trying to do. Any ideas? <code> &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;?php global $wpdb; $attachment_id = $wpdb-&gt;get_var("SELECT ID FROM $wpdb-&gt;posts WHERE post_parent = '$post-&gt;ID' AND post_status = 'inherit' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1"); ?&gt; &lt;div class="searchItem" style="clear:both;"&gt; &lt;h3 id="post-&lt;?php the_ID(); ?&gt;"&gt;&lt;img src="&lt;?php echo wp_get_attachment_url($attachment_id); ?&gt;" class="post-attachment" /&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;/h3&gt; &lt;small&gt;&lt;?php the_time('l, F jS, Y') ?&gt;&lt;/small&gt; &lt;div class="excerpt"&gt;&lt;?php echo $post-&gt;post_excerpt; ?&gt;&lt;/div&gt; &lt;div class="postmetadata"&gt;Posted in &lt;?php the_category(', ') ?&gt; | &lt;?php comments_popup_link('No Comments &amp;#187;', '1 Comment &amp;#187;', '% Comments &amp;#187;'); ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; </code>
You could use the WordPress function get_children. Although I don't think it makes a difference, performance-wise. <code> &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;?php $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 ) ) ); ?&gt; &lt;div class="searchItem" style="clear:both;"&gt; &lt;h3 id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;?php if( $attachment ) echo '&lt;img src="' . wp_get_attachment_url($attachment[0]-&gt;ID) . '" class="post-attachment" /&gt;'; ?&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;/h3&gt; &lt;small&gt;&lt;?php the_time('l, F jS, Y') ?&gt;&lt;/small&gt; &lt;div class="excerpt"&gt;&lt;?php echo $post-&gt;post_excerpt; ?&gt;&lt;/div&gt; &lt;div class="postmetadata"&gt;Posted in &lt;?php the_category(', ') ?&gt; | &lt;?php comments_popup_link('No Comments &amp;#187;', '1 Comment &amp;#187;', '% Comments &amp;#187;'); ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; </code>
Showing post thumbnail (attachment) on the archive.php category listing
wordpress
A number of the sites I'm migrating to a WordPress Multisite instance have embedded videos and iframes within posts. Rather than convert each post to the kosher way of doing video embeds, I'd rather disable the WordPress functionality which strips out the embeds on import. Disabling the stripping when editing a post was as simple as disabling the kses filter . Unfortunately, I can't figure out what I need to disable for importing posts. At the moment I suspect the wp_insert_post() method but haven't narrowed down the filter. Any ideas? Update: This is specific to WordPress Multisite. Importing into a single WordPress site works just fine.
http://core.trac.wordpress.org/ticket/14818
Disabling HTML Filtering When Importing Into WordPress Multisite
wordpress
In response to stackexchange-url ("Mike Schinkel")'s comment (see below) on stackexchange-url ("my post about how to pre-populate content") (essentially using a content template)... @Scott B I mean why did you support a file on disk rather than an place in the admin? For multiple, have you considering created a "Sales Letter" custom post type? No, but it sounds like a better solution. How would you do it and where would you store the choices for the content? (I assume you might have a few different types of content templates to offer.)
Hi @Scott B : Your question got me thinking about extending your use-case to a plugin I published earlier called WP Boilerplate Shortcode . I know your question isn't about shortcodes but the name is only legacy for your use-case; indeed my extension I just added because of your question will do (almost) exactly what you are asking for (I'll explain the "almost" part below). I'm going to have to come back and document this more in-depth but I figured I've give you first access to it sooner than later (note the <code> instructions.txt </code> file does not address the new features yet): Download the WP Boilerplate Shortcode Plugin - v1.0.5 The easy part of doing what you ask was the back-end coding; the harder part was figuring out a good UI. If there are multiple content items to choose from the user needs a way to select which one to use and there's not one obvious way to do that. One approach I could have used would have been to intercept when the user clicked "Add Post" and ask them which pre-populated content item they want to start with but that seemed kludgy and not in line with how the WordPress admin normally works. So instead I added a "Insert Boilerplate" metabox with a dropdown containing the list of available boilerplate text items. To use this plugin download, copy to a subdirectory in your <code> /wp-content/plugins/ </code> directory and then activate it. After activation look for the "Boilerplate" menu and start adding your sales Letters as Boilerplates being careful to selecting the "Associated Post Types" for which you want each Boilerplate to be active. Then in the "Add {post type}" window in the admin look to the top right; you'll find the content from the boilerplate to the end of whatever is currently in the content editor: Note that upon activation the plugin will add any post types you might have into the "Associated Post Type" taxonomy but if you add new post types later you'll have to add them manually; just make sure to match exactly the plural name of the post type (i.e. "Products" or "Featured Posts" or whatever.) This isn't exactly what you asked for but given the need for a way to select content I think it's a really workable solution. I'd love to get your feedback on what you think of it.
Creating a Custom Post Type for Inserting Preset Content into Post & Pages?
wordpress
After creating a new WordPress site, how can I edit the default links like "Site Admin" found in the sidebar "meta" section?
I assume you're talking about the "Meta" box you see in the sidebar. These links can't be edited, they're part of the sidebar widget itself. Your safest bet would be to replace the Meta widget with your own Text widget that lists out whatever links you do want displayed.
Editing the Default Links like "Site Admin" in the Sidebar Meta Section?
wordpress
One of the best blogging practices is that of writing "pillar posts" - featured content that's longer than a typical post and will likely generate a high volume of traffic to your site. Extensive tutorials, comprehensive user guides, and in-depth product reviews mostly fall into this category. They're the 1500-word behemoths that sit alongside your daily 300-word "update" articles. Most of the times, pillar posts can be thrown to the top of your site with stickies. This makes them visible, directs the user's attention, and keeps timeless content relevant. After a while, though, you might want to promote these posts to static pages - still searchable and useful, but with their own special spot on the blog. I have a series of articles I plan to write over the next month or so regarding the XML-RPC API built in to WordPress . It's a great system, but scantily documented ... so I'm going to put together some comprehensive method documentation. The thing is, my docs will cover roughly 5-6 different pillar posts. I want this content to be featured on my blog when it's published (once per week), but I'd also like the entire series to be repeated as a static page on the site. The static page would be broken up into individual pages (using <code> &lt;!--nextpage--&gt; </code> to divide sections) so that each post is contained in a different section. How can I have my featured content be both individual posts on the blog and a separate static page? I'm looking at both usability and SEO here ... having the content duplicated is a huge negative, so a simple copy-paste job with both versions on the site isn't my goal. My first inkling would be to develop a custom post type for features like this with its own custom taxonomy. Each "post" would be an individual feature (custom post type) and would be owned by a series (custom taxonomy). Then each post could be included in the loop when published but also on the archive page for the series. So my question (and the reason I'm marking this as a wiki), is how would you approach this situation?
As I was reading your post I was envisioning almost exactly what you prescribed at the end: My first inkling would be to develop a custom post type for features like this with its own custom taxonomy. Each "post" would be an individual feature (custom post type) and would be owned by a series (custom taxonomy). Then each post could be included in the loop when published but also on the archive page for the series. The only difference was I was thinking "Pages" instead of "Features" mostly because you referred to Pages in your question but Features is probably even better. So your instincts are already spot-on , IMO anyway.
Implementing Pillar Posts; Long Posts yet with Some Page-Like Handling?
wordpress
Here is a question I have spent over 3 hours attempting to solve but each approach I take ends up not working out for me. All I am attempting to do is utilize this opensource ajax calendar script: FullCalendar and have the entries display all posts within a specific post type. For each of the posts within this event post type I have a custom metabox with the following custom fields: event category event start date event start time event end date event end time At the most basic level I just need each post to show up within the applicable calendar box based on the "event start date" and "event start time" and link to the applicable event post details page. In an ideal situation I was looking to have each event category with its own color and have each event span multiple days if the applicable event has an <code> "event_end_date" </code> that is different than the start date. Has anyone done this before and can past the applicable code to get either of these in place. I feel this would be highly valuable to the WordPress community as well.
Hi @NetConstructor: FullCalendar is a nice find. Looks to me like you'll need to write a shortcode (which I show how to do here): <a href="stackexchange-url Adding an Archive of Posts to the Navigation Menu in WordPress 3.0 And then generate the code to call the FullCalendar within the shortcode . After that you'll need to write code to generate a Javascript array or have it references a JSON feed: Full Calendar Events (as an array) Full Calendar Events (as an json feed) Here's code you can put into a standalone <code> .PHP </code> file which you could call <code> /fullcalendar-json-feed.php </code> or whatever you like. The code queries a custom post types called <code> event </code> which will run in the root directory of your website and will generate a JSON feed and it assumes you've got some custom fields needed to populate the array/feed. (I'm going to leave the rest of the query and custom field details to you. Note I didn't actually test this with FullCalendar so it might take a bit of tweaking) : <code> &lt;?php /* * See: stackexchange-url "wp-load.php"; global $wpdb; header('Content-Type:application/json'); $events = array(); $result = new WP_Query('post_type=event&amp;posts_per_page=-1'); foreach($result-&gt;posts as $post) { $events[] = array( 'title' =&gt; $post-&gt;post_title, 'start' =&gt; get_post_meta($post-&gt;ID,'_start_datetime',true), 'end' =&gt; get_post_meta($post-&gt;ID,'_end_datetime',true), 'allDay' =&gt; (get_post_meta($post-&gt;ID,'_all_day',true) ? 'true' : 'false'), ); } echo json_encode($events); exit; </code> You can generate the array option with very similar code to that above. Still, this is going to take a bit of coding for you to get right. Maybe you just want to use a solution that's already built? Here's a Q&amp;A discussion about calendars for WordPress: <a href="stackexchange-url Recommendation for a WordPress Calendar Plugin with Recurring Events?
Loading Custom Post Type Events into jQuery-based FullCalendar?
wordpress
I recently released a plugin, WP Coda Slider, that uses shortcodes to add a jQuery slider to any post or page. I am adding an options page in the next version and I would like to include some CSS options but I don't want the plugin to add the style choices as inline CSS. I want the choices to be dynamically added to the CSS file when it's called. I would also like to avoid using fopen or writing to a file for security issues. Is something like this easy to accomplish or would I be better off just adding the style choices directly to the page?
Use <code> wp_register_style </code> and <code> wp_enqueue_style </code> to add the stylesheet. DO NOT simply add a stylesheet link to <code> wp_head </code> . Queuing styles allows other plugins or themes to modify the stylesheet if necessary. Your stylesheet can be a .php file: <code> wp_register_style('myStyleSheet', 'my-stylesheet.php'); wp_enqueue_style( 'myStyleSheet'); </code> my-stylesheet.php would look like this: <code> &lt;?php // We'll be outputting CSS header('Content-type: text/css'); include('my-plugin-data.php'); ?&gt; body { background: &lt;?php echo $my_background_variable; ?&gt;; font-size: &lt;?php echo $my_font_size; ?&gt;; } </code>
How do I add CSS options to my plugin without using inline styles?
wordpress
What is the difference between the suppress_errors() function and the hide_errors() functionin wpdb class? What is the use of each function?
<code> suppress_errors() </code> hides errors during the database bootstrapping <code> hide_errors() </code> hides SQL errors
What Is The Difference Between suppress_errors() And hide_errors() in $wpdb?
wordpress
My goal was simple --- to create a custom post type with a custom metabox with a simple drop down list of taxonomy terms instead of utilizing the tags or checkboxes. The reason was to ensure that the editor can only select a single term from the taxonomy list. After trial and error I finally managed to figure out a way to utilize the excellent metabox creation tools I am using from WP-Alchemy (http://farinspace.com/wpalchemy-metabox/) to create my metabox and have it display the applicable terms in a dropdown list. The problem I am having is that I can't seem to get a new selection from the dropdown menu to save the selected value. To be clear... its important that only a single term be associated with each post in this custom post type meaning that whenever a different value is select from the dropdown menu and the post is saved it needs to ensure the previous selection is unregistered. As mentioned I currently have it displaying the list of terms in a dropdown and I also have it correctly displaying whatever term might be associated. Just the saving of the new values is where i am having issues. From extensive research it "seems" like the solution involves using the wordpress "wp_set_post_terms" functions which is further explained here: http://codex.wordpress.org/Function_Reference/wp_set_post_terms However I am unsure how to utilize it correctly to achieve my desired result. Below I have include the code I am utilizing. It's very possible there is a better way of doing this and I would appreciate whatever suggestions you guys might have might also ensure that the applicable "checks" are being done to ensure data can't be inserted by users that are not authorized. FUNCTIONS.PHP FILE (SHOWS THE CREATION OF THE CUSTOM POST TYPE AND TAXONOMY BELOW. <code> ////////////////////////////////////////////////////////////////////////////// // CUSTOM POSTTYPE FOR -- SERVICES ////////////////////////////////////////////////////////////////////////////// add_action('init', 'services'); function services() { register_post_type('services', array( 'labels' =&gt; array( 'name' =&gt; __('Services'), 'singular_label' =&gt; __('Service'), 'new_item' =&gt; __('Add a Service'), 'add_new' =&gt; __('Add a Service'), 'add_new_item' =&gt; __('Add a Service'), 'edit' =&gt; __('Edit Service'), 'edit_item' =&gt; __('Edit Service'), 'view' =&gt; __('View Service'), 'view_item' =&gt; __('View Service'), 'search_items' =&gt; __('Search Services'), 'not_found' =&gt; __('No Services Found'), 'not_found_in_trash' =&gt; __('No Services Found in Trash'), 'parent_item' =&gt; __('Parent Service'), 'parent_item_colon' =&gt; __('Parent Service:') ), 'can_export' =&gt; true, 'menu_position' =&gt; 7, 'public' =&gt; false, 'show_ui' =&gt; true, 'publicly_queryable' =&gt; true, 'hierarchical' =&gt; true, 'query_var' =&gt; true, 'capability_type' =&gt; 'post', 'exclude_from_search' =&gt; false, 'supports' =&gt; array( 'title', 'editor', 'revisions', 'page-attributes' ), 'rewrite' =&gt; array( 'slug' =&gt; 'disability-services', 'with_front' =&gt; false ) )); } </code> HERE IS WHERE I AM REGISTERING THE TAXONOMY I AM TRYING TO WORK WITH <code> // CUSTOM TAXONOMY METABOX POSTTYPE - AGE GROUPS register_taxonomy('theme', array('services'), array( 'hierarchical' =&gt; false, 'singular_label' =&gt; 'Age Group', 'query_var' =&gt; 'theme', 'public' =&gt; true, 'show_ui' =&gt; true, 'show_tagcloud' =&gt; false, 'show_in_nav_menus' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'age-groups', 'with_front' =&gt; false ), 'labels' =&gt; array( 'name' =&gt; __( 'Age Groups' ), 'singular_name' =&gt; __( 'Age Groups' ), 'search_items' =&gt; __( 'Search Age Groups' ), 'all_items' =&gt; __( 'All Age Groups' ), 'parent_item' =&gt; __( 'Parent Age Group' ), 'parent_item_colon' =&gt; __( 'Parent Age Group:' ), 'edit_item' =&gt; __( 'Edit Age Group' ), 'update_item' =&gt; __( 'Update Age Group' ), 'add_new_item' =&gt; __( 'Add Age Group' ), 'new_item_name' =&gt; __( 'New Name of Age Group' ), 'popular_items' =&gt; __( 'Popular Age Groups' ), 'separate_items_with_commas'=&gt; __( 'Separate Age Groups with commas' ), 'add_or_remove_items' =&gt; __( 'Add or remove Age Groups' ), 'choose_from_most_used' =&gt; __( 'Select Popular Age Groups' ), ), )); wp_insert_term('Kids', 'theme'); wp_insert_term('Teens', 'theme'); wp_insert_term('Adults', 'theme'); </code> THIS IS THE REMAINDER OF THE CODE I AM USING IN THE FUNCTIONS FILE AND THE CODE TO CREATE THE METABOX BASED OFF WPALECHEMY. In this attempt I tried to include 'save_filter' => "wp_set_post_terms( $post-> ID, 'theme' )", with the hope this would save the applicable data but it did not. <code> // CUSTOM METABOX POSTTYPE - SERVICE DETAILS $custom_metabox_service_details = new WPAlchemy_MetaBox(array ( 'id' =&gt; '_service_details-metaboxes', // underscore prefix hides fields from the custom fields area 'title' =&gt; 'Age Groups', // title added automatically to the custom metabox 'types' =&gt; array('services'), // added only for custom post type "name-of-post-type" can also be "page" or "post" 'context' =&gt; 'normal', // same as above, defaults to "normal" but can use "advanced" or "side" 'priority' =&gt; 'high', // same as above, defaults to "high" but can use "low" as well 'mode' =&gt; WPALCHEMY_MODE_EXTRACT, 'save_filter' =&gt; "wp_set_post_terms( $post-&gt;ID, 'theme' )", 'template' =&gt; TEMPLATEPATH . '/admin-metabox/service_details-metaboxes.php' // contents for the meta box )); </code> I SHOULD ALSO NOTE THAT DIMAS OVER AT WPALECHMEY JUST ADDED SOME NEW CODE INTO HIS 1.3.2 VERSION OF GITHUB WHICH ALLOWS THE ABOVE CODE TO INCLUDE A <code> 'save_filter' =&gt; "custom-function", </code> This code allows you to create a custom function or I guess call a custom function which gets executed upon hitting the publish button so maybe that is the best way to save the data? In any case, I am utilizing the following code for the custom metabox to display the actual dropdown list displaying the taxonomy terms. <code> &lt;?php // This function gets called in edit-form-advanced.php echo '&lt;input type="hidden" name="taxonomy_noncename" id="taxonomy_noncename" value="' . wp_create_nonce( 'taxonomy_theme' ) . '" /&gt;'; // Get all theme taxonomy terms $themes = get_terms('theme', 'hide_empty=0'); ?&gt; &lt;select name='post_theme' id='post_theme'&gt; // DISPLAY TERMS AS DROP DOWN OPTIONS &lt;?php $names = wp_get_object_terms($post-&gt;ID, 'theme'); ?&gt; &lt;option class='theme-option' value='' &lt;?php if (!count($names)) echo "selected";?&gt;&gt;None&lt;/option&gt; &lt;?php foreach ($themes as $theme) { if (!is_wp_error($names) &amp;&amp; !empty($names) &amp;&amp; !strcmp($theme-&gt;slug, $names[0]-&gt;slug)) echo "&lt;option class='theme-option' value='" . $theme-&gt;slug . "' selected&gt;" . $theme-&gt;name . "&lt;/option&gt;\n"; else echo "&lt;option class='theme-option' value='" . $theme-&gt;slug . "'&gt;" . $theme-&gt;name . "&lt;/option&gt;\n"; } ?&gt; &lt;/select&gt; </code> I am assuming saving the data should be simple as pie but I guess I am confusing myself on how to accomplish this. As mentioned I would appreciate if you could also provide suggestions on the code to ensure any necessary checks are done to ensure data is saved correctly and only be the correctly authorized people. Must thanks in advance!
For anyone who is interested, I answered this question on a different post: stackexchange-url ("stackexchange-url
Custom Metabox with Taxonomy Dropdown - Saving Issue
wordpress
I am playing around with wordpress and a few plugins. Say I have something called "Shopping Cart" and I delete the page. Then I recreate it, I can't have the old URL back. I get domain.com/shopping-cart-2 and I want the old one back. How can I do this?
You are asking about the slug of a page . To change the URL part (also referred to as "slug") containing the name of your Page, use the "Edit" (or "Change Permalinks" in older WordPress versions) button under the Page title on the Edit screen of the particular Page, accessible from Pages tab of WordPress Administration Panel. Please check the trash and remove the previous page from trash as well. Afterwards you should be able to re-use the previously used slug.
Editing the Number at the end of Page URLs / Editing Page Slugs
wordpress
Hay, does anyone know a way to display the featured image url within the RSS feed?
<code> function add_featured_image_url($output) { global $post; if ( has_post_thumbnail( $post-&gt;ID ) ){ $output = wp_get_attachment_url( get_post_thumbnail_id( $post-&gt;ID ) ) . ' ' . $output; } return $output; } add_filter('the_excerpt_rss', 'add_featured_image_url'); add_filter('the_content_feed', 'add_featured_image_url'); </code>
display featured image in RSS feed
wordpress
Posts may be published either immediately or in the future. Suppose a plug-in wants to do something at the moment when the post becomes published and visible on the blog (I don't mean when the post is saved as published in the admin panel with whatever date). Is there a hook like "post_visible" or something similar.
Every time a post changes status, <code> wp_transition_post_status </code> function will be called. This triggers the actions <code> ${old_status}_to_${new_status} </code> and <code> ${new_status}_${post-&gt;post_type} </code> , so for example <code> publish_post </code> will be triggered here. A post with a date in the future will have the status <code> future </code> until it is actually published, so this should work for you.
Any Hook Called When Post Becomes Published?
wordpress
Is there a way to resize images to the actual size they will be shown in the post? I have users that import a large image and then resize it in the visual editor. This is easy, since they can just drag the image until it is the size they want, without first opening an image editor, resizing the image, saving it, and uploading it as a separate attachment. Of course, this sometimes results in an image that is 100px wide in the post, but 1500px in reality. Is there a plugin that does this when a new post is saved? I would like to keep the existing full-size image (for linking, or later resizes), but just add an extra size (and save it in the <code> _wp_attachment_metadata </code> object), so this post has the image in the correct size, and a reference to the full-size attachment. Of course, all existing posts should also be handled once. <code> &lt;img&gt; </code> tags there might have just a <code> width </code> , just a <code> height </code> , or none of them: this should all be cleaned up, so they all have the correct <code> width </code> , <code> height </code> and an image of that size.
I created two plugins that together should solve my needs. They are currently in an early alpha stage, and all comments are welcome. The base plugin is an On-Demand Resizer . This plugins monitors requests for non-existing files in the uploads dir, and creates images of the requested size if needed. For example, <code> image-200x100.jpg </code> will create and return <code> image.jpg </code> , but resized to 200 by 100 pixels. The image is saved by that name in the directory, so further requests are handled straight by the server. The second plugin, Resize img tags , modifies <code> &lt;img&gt; </code> tags so their <code> src </code> attributes include width and/or height data. This allows the first plugin to serve the correct images. Together they do what I want, and I only need to create a run-once function to convert all existing posts, but that should be easy (I don't want to hook into <code> the_content </code> for something that should run only once). A third "bonus" plugin, Virtual intermediate images , intercepts the creation of the intermediate images when uploading a new image in WordPress. Since they are still created by the first plugin if requested, this allows you to specify multiple image sizes without taking up disk space unless they are actually used. This is not needed for the two first to work, but it was an easy addition, and it highlights the fact that I still need to work around the WordPress image editor, but I will do that when I create stackexchange-url ("my thumbnail editor"), which will also use the first plugin.
Resizing images to the actual size used in the editor?
wordpress
Okay I know the title is pretty vague but I didn't know how to articulate it. Basically, I want a plugin that sends email notifications to users who opted-in only if they specifically got replied to. WordPress has its built-in functionality for comment threading/replying, so instead of bombarding the user with emails each time a new comment is posted on a post they've subscribed to, I'd like to give them the option to only be notified when they specifically get replied to. I can develop this myself if need be, in fact, a preliminary search yielding no results seems to point at this. My question is, what hooks would I take a look at? Looking at other notifier plugins, I see they make use of <code> comment_post </code> and others which I can come up with myself. More specifically, how would I go about knowing if user x got a direct reply? I understand how the subscription system and all of that would work, my only concern is how to tell if a subscribed user received a direct reply through the built-in commenting system.
I figured it out. Each comment row in the <code> wp_comments </code> table has a field named <code> comment_parent </code> which stores the <code> comment_ID </code> of the parent comment. If the comment has no parent, then the default is 0. So I guess on each comment post I would check the database for the posted comment's parent, and if it matched the comment of a subscriber, notify him or her. Sounds like a plan.
Hook to See if Comment got a Reply?
wordpress
Post and page guids include the full absolute URL of my site (e.g. http://www.example.com/wordpress/?p=1). This causes a problem if the domain, or wordpress path changes, or if I'm viewing the site via its IP address rather its domain, etc. Problem 1: there are some internal links on my site that are using the guid. I'm guessing this is wrong and I should rewrite the template code to remove references to the guid - correct? Problem 2: images are inserted into a post using their absolute URL, rather than a relative one. This seems short-sighted, but I'm wondering if there's a reasonable reason for that. Is there a way to change that behaviour?
1) The GUID is exactly that -- a GUID. It's used to uniquely identify the post. If you need to link to a post, then use <code> get_permalink( $post_ID ) </code> ( <code> $post_ID </code> is optional) (link: get_permalink ). 2) Not without a plugin, no. There's talk of using an image shortcode for 3.1 though, or maybe 3.2. In the meantime, you can try using an alpha version of my Regenerate Thumbnails plugin: http://viper007bond.pastebin.com/XprbYtg2 It'll go through all of your posts and update all image tags. Make sure you back up your database first though. The code is alpha and not guaranteed to work, although I have tested it quite a bit.
Problem with guids and absolute links
wordpress
I want a multi site WordPress website to make a wedding website in which the users can make their accounts for their websites, how will this actually be done in WordPress?
As you probably already know. Since WordPress 3.0 Multi-Site functionality has been included by default as the WordPress MU project has been merged into the WordPress 3.0 core. In regards to the initial setup, it might take a little bit of work if you are not familiar with php coding but what I can tell you is that once its setup your essentially good to go. The process of actually being able to offer or add additional subdomains off your root domain take less than 30 seconds to complete by a user. Let me know if you are looking for anything in specific in regards to this or if you have any follow-up questions. UPDATED: Before You Begin - Admin Requirements If you want to run a network of blogs you should at least have a basic understanding of UNIX/Linux administration. A basic knowledge of WordPress development, PHP, HTML and CSS is recommended as well. Setting up and running a multi-site installation is more complex than a single-site install . Reading this page should help you to decide if you really need a multi-site install, and what might be involved with creating one. If the instructions on this page make no sense to you, be sure to test things on a development site first, rather than your live site. Server Requirements Since this feature requires extra server setup and more technical ability, please check with your webhost and ask if they support the use of this feature. It is not recommended to try this on shared hosting. You are given the choice between sub-domains or sub-directories in Step 4: Installing a Network . This means each additional site in your network will be created as a new virtual subdomain or subdirectory. Sub-directories -- like <code> example.com/site1 </code> and <code> example.com/site2 </code> Sub-domains -- like <code> site1.example.com </code> and <code> site2.example.com </code> Sub-directory sites It works with the use of the mod_rewrite feature on the server having the ability to read the .htaccess file, which will create the link structure. If you are using pretty permalinks in your blog already, then subdirectory sites will work as well. Sub-domain sites It works using wildcard subdomains. You must have this enabled in Apache, and you must also add a wildcard subdomain to your DNS records. (See Step 2 how to set up.) Some hosts have already set up the wildcard on the server side, which means all you need to add is the DNS record. Some shared webhosts may not support this, so you may need to check your webhost before enabling this feature. WordPress Settings Requirements Giving WordPress its own directory will not work in WordPress 3.0 with multisite enabled. It interferes with the member blog lookup. You cannot create a network in the following cases: "WordPress address (URL)" is different from "Site address (URL)". "WordPress address (URL)" uses a port number other than ':80', ':443'. You cannot choose Sub-domain Install in the following cases: WordPress install is in a directory (not in document root). "WordPress address (URL)" is localhost. "WordPress address (URL)" is IP address such as 127.0.0.1. You cannot choose Sub-directory Install in the following cases: If your existing WordPress installation has been set up for more than a month, due to issues with existing permalinks. (This problem will be fixed in a future version.) (See your <code> /wp-admin/network.php </code> for more detail) Step 1: Backup Your WordPress Your WordPress will be updated when creating a Network. Please backup your database and files. Step 2: Setting Wildcard Subdomains (If this is a Sub-directories Install, skip this step.) Sub-domain sites work with the use of wildcard subdomains. This is a two-step process: Apache must be configured to accept wildcards. Open up the httpd.conf file or the include file containing the VHOST entry for your web account. Add this line: <code> ServerAlias *.example.com </code> In the DNS records on your server, add a wildcard subdomain that points to the main installation. It should look like: <code> A *.example.com </code> External links: Wildcard DNS record (Wikipedia) Apache Virtual Host (Apache HTTP Server documentation) Step 3: Allow Multisite To enable the Network menu item, you must first define multisite in the <code> /wp-config.php file </code> . Open up <code> /wp-config.php </code> and where it says this: <code> /* That's all, stop editing! Happy blogging. */ </code> Add this line above it: <code> define('WP_ALLOW_MULTISITE', true); </code> Step 4: Installing a Network This will enable the Network menu item to appear in the Tools menu. Visit <code> Administration </code> > <code> Tools </code> > <code> Network </code> to see the screen where you will configure certain aspects of our network. Tools Network SubPanel Addresses of Sites in your Network You are given the choice between sub-domains or sub-directories (if none of the above applies). This means each additional site in your network will be created as a new virtual subdomain or subdirectory. you have to pick one or the other, and you cannot change this unless you reconfigure your install. See also "Before you Begin" . Sub-domains -- like <code> site1.example.com </code> and <code> site2.example.com </code> Sub-directories -- like <code> example.com/site1 </code> and <code> example.com/site2 </code> Network Details These are filled in automatically: Server Address - The Internet address of your network will be example.com. Network Title - What would you like to call your network? Admin E-mail Address - Your email address. Double-check they are correct and click the Install button. You may receive a warning about wildcard subdomains. Check Setting Wildcard Subdomains. Warning! Wildcard DNS may not be configured correctly! The installer attempted to contact a random hostname ( <code> 13cc09.example.com </code> ) on your domain. To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a <code> * hostname </code> record pointing at your web server in your DNS configuration tool. You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message. Step 5: Enabling the Network The rest of the steps are ones you must complete in order to finish. Tools Network Created. First, back up your existing <code> /wp-config.php </code> and <code> /.htaccess </code> files . Create a <code> blogs.dir </code> directory under <code> /wp-content/ </code> - This directory is used to stored uploaded media for your additional sites and must be writable by the web server. They should be CHOWNed and CHMODed the same as your wp-content directory. Add the extra lines your WordPress installation generates into your <code> /wp-config.php </code> file. - These lines are dynamically generated for you based on your configuration. Edit the <code> /wp-config.php </code> file while you are logged in to your sites admin panel. Paste the generated lines immediately above <code> /* That's all, stop editing! Happy blogging. */ </code> . Remove the earlier placed <code> define('WP_ALLOW_MULTISITE', true); </code> line only if you wish to remove the Network menu in the admin area. You may choose to leave this to be able to access the <code> /.htaccess </code> rules again.. Add the generated mod_rewrite rules to your <code> /.htaccess </code> file, replacing other WordPress rules. - These lines are dynamically generated for you based on your configuration. (If there isn't one, then create it.) Log in again. - Once the above steps are completed and the new <code> /wp-config.php </code> &amp; <code> /.htaccess </code> files are saved, your network is enabled and configured. You will have to log in again. click "Log In" to refresh your Adminstration Panel. If you have problems logging back in, please clear your browser's cache and cookies. Step 6: Super Admin Settings You will now see a new menu section called Super Admin. The menus contained in there are for adding and managing additional sites in your network. Your base WordPress install is now the main site in your network. Go <code> Super Admin </code> > <code> Options </code> panel to configure network options, and then create sites and users. Things You Need To Know Here are some additional things you might need to know about advanced administration of the blog network. WordPress Plugins - WordPress Plugins now have additional flexibility, depending upon their implementation across the network. Site Specific Plugins - WordPress Plugins to be activated or deactivated by an individual blog owner are stored in the plugins directory. You need to enable the Plugins page for individual site administrators from <code> Network </code> > <code> Options </code> . Network Plugins - WordPress Plugins stored in the plugins directory can be activated across the network by the super admin. Must-Use Plugins - Plugins to be used by all sites on the entire network may also be installed in the mu-plugins directory as single files, or a file to include a subfolder. Any files within a folder will not be read. These files are not activated or deactivated; if they exist, they are used. Categories and Tags - Global terms are disabled in WordPress 3.0 by default. You can use the Sitewide Tags WordPress Plugin or other similar Plugins to incorporate global tags on the portal/front page of the site or on specific pages or blogs within the network to increase navigation based upon micro-categorized content.
Setting up a Multisite WordPress for Wedding Websites?
wordpress
I've created a simple menu in wp-admin> appearance> menus called main-nav. Works fine. However, I'd like to add a custom element to the end of the menu... a search box like the search box in the apple.com menu bar. I can't work out where the menus get constructed in code. where can I can add this... any ideas? (I'm using the starkers theme) EDIT Thanks to tnorthcutt and hakre for pointing me in the right direction. The solution was to put this code in with the other 'add_filter' stuff in my theme's functions.php <code> add_filter('wp_nav_menu_items','search_box_function'); function search_box_function ($nav){ return $nav."&lt;li class='menu-header-search'&gt;&lt;form action='http://example.com/' id='searchform' method='get'&gt;&lt;input type='text' name='s' id='s' placeholder='Search'&gt;&lt;/form&gt;&lt;/li&gt;"; } </code> UPDATE @tnorthcutt's solution is great for when you have just one menu on your screen, but if you add second menu it appends the search box to that menu too. How would you target just one menu? i've registered my menu's like so: <code> register_nav_menus( array( 'primary' =&gt; __( 'Primary Navigation', 'twentyten' ), 'secondary'=&gt;__('Secondary Menu', 'twentyten' ), ) ); </code> ..and the secondary one gets shown like this: <code> wp_nav_menu( array( 'container_class' =&gt; 'menu-header', 'theme_location' =&gt; 'secondary' ) ); </code>
Try this: <code> add_filter('wp_nav_menu_items','search_box_function'); function search_box_function { search box code goes here } </code> For reference, check out Bill Erickson's excellent tutorial on accomplishing this with the Genesis framework.
Where do custom menus get constructed?
wordpress
I want users to be able to upload photos using <code> add_cap('upload_files') </code> but in their profile page, the Media Library shows every image that's been uploaded. How can I filter that so that they can only view the images they uploaded? Here's my solution for the moment… I'm doing a simple WP query, then a Loop on the user's "Profile" page <code> $querystr = " SELECT wposts.post_date,wposts.post_content,wposts.post_title, guid FROM $wpdb-&gt;posts wposts WHERE wposts.post_author = $author AND wposts.post_type = 'attachment' ORDER BY wposts.post_date DESC"; $pageposts = $wpdb-&gt;get_results($querystr, OBJECT); </code>
You could always filter the media list using a <code> pre_get_posts </code> filter that first determines the page, and the capabilities of the user, and sets the author parameter when certain conditions are met.. Example <code> add_action('pre_get_posts','users_own_attachments'); function users_own_attachments( $wp_query_obj ) { global $current_user, $pagenow; if( !is_a( $current_user, 'WP_User') ) return; if( 'upload.php' != $pagenow ) return; if( !current_user_can('delete_pages') ) $wp_query_obj-&gt;set('author', $current_user-&gt;id ); return; } </code> I used the delete pages cap as a condition so Admins and Editors still see the full media listing. There is one small side effect, which i can't see any hooks for, and that's with the attachment counts shown above the media list(which will still show the total count of media items, not that of the given user - i'd consider this a minor issue though). Thought i'd post it up all the same, might be useful.. ;)
Restricting Users to View Only Media Library Items They Have Uploaded?
wordpress
With the new wp_nav_menu system, it is possible to add a category as a menu item, so in my example I have a 'news' category, which is a submenu item of 'About'. <code> About (page) --news (category) --history (page) --contact us (page) </code> The menu highlighting CSS picks up from current-menu-parent and current-menu-ancestor, so that when I'm in a submenu section, the top level menu item (e.g. 'About') is highlighted when I visit 'news'. This works fine, apart from when I visit a post in the 'news' category, which matches is_single() and in_category('news'). As far as I can see in Firebug, the 'current-menu-parent' and 'current-menu-ancestor' is applied to the 'news' menu item, however it's not applied to the 'About' top level menu item. Is there something I'm missing in setting up my menu? I've tried using a custom walker, however it seems that the initial menu ancestors are not being set up properly? It seems my only solution (without resorting to a nasty JQuery hack) is to create a 'news' page which queries the news posts, rather than pointing to the news 'category'. Any ideas? Thanks, Dan Update with code sample 09/09/2010 The way it is currently, viewing a single page in the News category http://www.example.com/2010/09/top-news-did-you-know/ : <code> &lt;li id="menu-item-28" class="menu-item menu-item-type-post_type menu-item-28"&gt;&lt;a href="http://www.example.com/about/"&gt;About Us&lt;/a&gt; &lt;ul class="sub-menu"&gt; &lt;li id="menu-item-71" class="menu-item menu-item-type-taxonomy"&gt;&lt;a href="http://www.example.com/category/events/"&gt;Events&lt;/a&gt;&lt;/li&gt; &lt;li id="menu-item-70" class="menu-item menu-item-type-taxonomy current-post-ancestor current-menu-parent current-post-parent current-menu-parent"&gt;&lt;a href="http://www.example.com/category/news/"&gt;News &amp;#038; views&lt;/a&gt;&lt;/li&gt; &lt;li id="menu-item-88" class="menu-item menu-item-type-post_type"&gt;&lt;a href="http://www.example.com/contact-us/"&gt;Contact Us&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;&lt;/li&gt; </code> So you see that "About Us" doesn't have any CSS class to indicate it is a parent of the currently viewed page. How I think it should work (and to be honest, if it doesn't do this, then it's a bug due to lack of implementation): <code> &lt;li id="menu-item-28" class="menu-item menu-item-type-post_type current-menu-ancestor current-menu-parent current_page_parent current_page_ancestor menu-item-28"&gt;&lt;a href="http://www.example.com/about/"&gt;About Us&lt;/a&gt; &lt;ul class="sub-menu"&gt; &lt;li id="menu-item-71" class="menu-item menu-item-type-taxonomy"&gt;&lt;a href="http://www.example.com/category/events/"&gt;Events&lt;/a&gt;&lt;/li&gt; &lt;li id="menu-item-70" class="menu-item menu-item-type-taxonomy current-post-ancestor current-menu-parent current-post-parent current-menu-parent"&gt;&lt;a href="http://www.example.com/category/news/"&gt;News &amp;#038; views&lt;/a&gt;&lt;/li&gt; &lt;li id="menu-item-88" class="menu-item menu-item-type-post_type"&gt;&lt;a href="http://www.example.com/contact-us/"&gt;Contact Us&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;&lt;/li&gt; </code> This has the <code> current-menu-ancestor current-menu-parent current_page_parent current_page_ancestor </code> CSS classes attached to the Top level menu item. It works this way for every other page, or even when viewing the category itself, just not a single page in a category.
Currently this is not possible if a page menu item is a parent to a category menu item. In your example if About was a category and News was child category then the About (category) menu item would be assigned: current-post-ancestor current-menu-parent current-post-parent
How do I get my wp_nav_menu single category page to highlight the parent?
wordpress
In a previous question I needed to set a future dated post (custom post type) as published on save instead of scheduling it. On the date it's 'scheduled' for I'd like to set it as a draft again. I've been trying to hook into init and wrap it in an if checking for post type. I figured it would compare to server time and then set status to draft if it was older than server time. As a rough outline: <code> if custom post type get_the_time of post get the server time if post time is older than server time set status to draft endif </code> Here and update with some code I'm working with. <code> function sfn_show_expire(){ global $wpdb; $server_time = date('mdy'); $result = $wpdb-&gt;get_results("SELECT * FROM wp_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 } add_action( 'init', 'sfn_show_expire' ); </code> It's getting the posts I need and is giving me the server time but isn't doing anything past that as far as I can tell.
Your query isn't giving you a post ID, it's giving you an entire post. The <code> SELECT * </code> returns all columns, <code> ID </code> , <code> post_status </code> , etc. So setting <code> $my_post['ID'] = $a </code> doesn't do anything for you in this case. Try using: <code> $my_post['id'] = $a-&gt;ID; </code> instead. That should accurately set your ID before you call <code> wp_update_post() </code> and you should be in business. Aside from that, I see no problems with what you're doing ... except that querying the database every time the site is loaded might eventually create performance issues. I'd set up an hourly chron job instead to automate the process ... then it doesn't depend on or slow down user traffic.
How to Set Post Status to Draft if older than today
wordpress
What I mean by series is like writing a book. A reader should be able to click on the book and then proceed to read the chapters. I can probably mimic it by creating a page and then linking it to a series of posts. I am looking for a more natural way to present and navigate.
I've used this plugin for a client site I did a while back...it might do what you need... Organize Series plugin
Is there a way I can write a series in WordPress?
wordpress
I have some query that brings around 50+ posts (I know it's not ideal but had to do that to build something the client asked..) and a set of loops to order them in a certain way and it looks like that this sequence is delaying parts of the rendering of the page. I'd like to cache in a transient this entire block of rendered HTML, is that possible?
Transients API documentation formulates suggested usage as: long/expensive database queries or complex processed data Your case seems like a perfect fit for this description. On technical side you will need to concatenate your output into variable and put into transient, instead of displaying it.
Is it possible to save an entire piece of rendered HTML in a transient?
wordpress
I've been browsing around a bit, but haven't been able to find any plugins for changing the default theme editor. Currently it's a text area with no syntax highlighting. I'd like something that at least gives syntax highlighting. There are all sorts of plugins for the post editor, but I've yet to find one for the theme editor. If all else fails, I'll make one myself, but I thought I would ask here before I did that. Thanks!
@Jack Slingerland, There are a few plugins that do this but the only one I that has been updated recently is Power Code Editor . At a recent WordCamp Matt mentioned that a new built in theme editor with a trash bin and revisions is on the road map but I have not heard it mentioned in any of the dev meetings.
Are there any Worpdress plugins to change the theme editor?
wordpress
I know that it is possible to restrict (or extend) the memory usage of the entire WP site using: <code> define('WP_MEMORY_LIMIT', '64M') </code> Is it possible to do the same for only one plugin that the website uses ?
No and even if you could, if the plugin ran out of available memory then the entire page generation would stop due to the fatal error. You're better off fixing the plugin itself to not use as much memory or to just further increase the total memory allocated to WordPress/PHP.
Can you limit the memory usage of a particular plugin?
wordpress
Hay, I've installed WordPress 3 on my server, and duplicated the stock theme and made some amends to it. However, when i add a post, i don't see an option to add a 'featured image'. Has this featured been removed? How do i reactivate it? Thanks
Your theme must indicate that it supports post thumbnails : <code> if ( function_exists('add_theme_support') ) { add_theme_support('post-thumbnails'); // If not the standard size, state your size too set_post_thumbnail_size( 200, 200, false ); } </code>
No option to add a 'featured image' in my wordpress installation
wordpress
I've built a simple sales page theme and would like to enhance it a bit by allowing the input of default content (including headers, bullet points, testimonial blockquotes and the ubiquitous "add to cart" button). What are the options for adding html snippets to content pages and/or posts? Ideally, when I click "Add New" from the Post or Page menu, the content would already be pre-populated with the sales page default content. Or perhaps even better, I could add a menu below the "Add New" link like "Add New Salespage" and by clicking that, it would default the sales page content. I'd like to have a page in my theme folder called salespage.html (or salespage.txt, or salespage.php, whichever is easier to work with) and this would be the content that is used to prepopulate the editor. Any help much appreciated. UPDATE: Thanks to Chris_O's answer below, I was able to find the solution. I've augmented Chris suggested solution to load the content from an external file.... <code> if (get_option("cb2_theme") == "salespage") { //added to support salespage creation add_filter( 'default_content', 'my_editor_content' ); function my_editor_content( $content ) { if(file_exists(ABSPATH.'wp-content/themes/clickbump_wp3/styles/salespage/default-content.html')){$content = file_get_contents(ABSPATH.'wp-content/themes/mytheme/styles/salespage/default-content.html');}else{$content = "Enter your salespage content here. h1-h3 tags, blockquotes etc";} //$content = "This is some custom content I'm adding to the post editor because I hate re-typing it."; return $content; } } </code>
@Scott B, I just read a post on Justin Tadlocks Blog regarding this same issue. The Solution Use the <code> default_content </code> filter hook and it to the themes function.php file. Example: <code> &lt;?php add_filter( 'default_content', 'my_editor_content' ); function my_editor_content( $content ) { $content = "This is some custom content I'm adding to the post editor because I hate re-typing it."; return $content; } ?&gt; </code> You could add XHTML or anything you wanted to the $content string When you click "Add New Post" you get:
Pre-populating the Page/Post Content Editor with HTML Snippets?
wordpress
Is there anyway to create a special feed in WordPress that is on a delay that I can distribute to some of our content partners? I found some tutorials on how to delay your feed but it uses the conditional statement <code> is_feed </code> and I don't want to apply this to all feeds, just one particular feed. Any advice? Edit: To clarify, I want to provide one full feed that publishes in real time (the native WP feed) and another full feed that displays the same content but is on a delay so it doesn't update until after the time period that I specify.
This tutorial explains how to create a custom feed: http://yoast.com/custom-rss-feeds-wordpress/ . Put the add_filter (from the wpengineer tutorial) before the query_post, and a remove_filter('posts_where', 'publish_later_on_feed'); after it.
Delaying One RSS Feed in WordPress but Not the Others?
wordpress
I have a feeling this is a bug. When you create a new custom post type it does not seem possible to modify the first submenu item text. I am referring to the link which allows you to view the post list. For what I can tell it just seems to be duplicating the name name of the main post type menu which was created. Does anyone know how to modify this text so that I can have the main menu element says "Articles" and the post list submenu name to say "Manage Articles" ? I was under the impression that <code> "edit_item" </code> would control the text to be displayed in te submenu but for some reason this is not registering. Here is the code I am currently using: <code> ////////////////////////////////////////////////////////////////////////////// // CUSTOM POSTTYPE FOR -- ARTICLES ////////////////////////////////////////////////////////////////////////////// add_action('init', 'articles'); function articles() { register_post_type('articles', array( 'labels' =&gt; array( 'name' =&gt; __('Articles'), 'singular_label' =&gt; __('Article'), 'new_item' =&gt; __('Add Article'), 'add_new' =&gt; __('Add Article'), 'add_new_item' =&gt; __('Add Article'), 'edit' =&gt; __('Edit Article'), 'edit_item' =&gt; __('Edit Article'), 'view' =&gt; __('View Article'), 'view_item' =&gt; __('View Article'), 'search_items' =&gt; __('Search Articles'), 'not_found' =&gt; __('No Articles Found'), 'not_found_in_trash' =&gt; __('No Articles Found in Trash'), ), 'supports' =&gt; array( 'thumbnail', 'title', 'editor', 'author', 'revisions', ), 'rewrite' =&gt; array( 'slug' =&gt; 'articles', 'with_front' =&gt; false, ), 'rewrite' =&gt; true, 'can_export' =&gt; true, 'show_ui' =&gt; true, 'menu_position' =&gt; 3, 'public' =&gt; true, 'query_var' =&gt; true, 'publicly_queryable' =&gt; true, 'exclude_from_search' =&gt; false, 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, )); } add_filter('manage_edit-articles_columns', 'add_new_articles_columns'); function add_new_articles_columns($articles_columns) { $new_columns['cb'] = '&lt;input type="checkbox" /&gt;'; $new_columns['article_thumbnail'] = _x('Image', 'column name'); $new_columns['title'] = _x('Article Title', 'column name'); $new_columns['article_excerpt'] = _x('Article Excerpt', 'column name'); $new_columns['article_source'] = _x('Article Source', 'column name'); $new_columns['author'] = __('Created by'); $new_columns['date'] = _x('Last Action', 'column name'); return $new_columns; } add_action('manage_posts_custom_column', 'manage_articles_columns', 10, 2); function manage_articles_columns($column_name, $id) { global $wpdb; switch ($column_name) { case 'article_thumbnail': the_post_thumbnail( array(50,50) ); break; case 'article_excerpt': echo substr(get_the_excerpt(),0,500); break; case 'article_source': echo get_the_term_list($post-&gt;ID, 'content_sources', '', ', ',''); break; default: break; } } </code>
Hi @NetConstructor.com : I think you already asked about this and I gave you an answer that would address this question too: Changing the Order of Admin Menu Sections? In that answer I gave you a library you can use to make interacting with the admin menus super easy. Here's what you'd have to do to achieve your stated goal on this question: <code> &lt;?php require_once('wp-admin-menu-classes.php'); add_action('admin_menu','my_admin_menu'); function my_admin_menu() { rename_admin_menu_section('Articles','Manage Articles');` } </code> P.S. BTW, I noticed there were stackexchange-url ("4 answers provided on that question") which you asked almost a week ago, but you haven't gone back an selected any of the answers as the correct answer. Since you have been here asking a lot of questions I know it's not like you've not been around; please take time to select the best answer for your questions as soon as you have a viable answer otherwise people might become demotivated to keep answering. Something this consider...
Renaming Menu Item within Admin Menu Section for a Custom Post Type?
wordpress
I am looking to achieve something which I figured would be fairly simple to accomplish but it seems there are no real examples available to achieve my needs. Essentially I have a custom post type of "Articles" for this custom post type I have a new taxonomy which I have registered which was created so that source publications can be added. My goal was to be able to add an article through this custom post type and then select the applicable "source publication" from the term list so I could display where the article came from. Now, the problem I am having seems to be simple... All I am trying to do is add some additional fields to the page where you can enter each taxonomy term. In this case I would like to add a field for "URL" and include an image for each source so I can add a logo. So the question here is... how would I go about adding an additional field to each term? I am assuming if wordpress does not allow for this functionality naively that somehow the "description" field could be utilized as a type of custom fields area and thus that the data can be stored there. Then I am trying to of course extract the data out and display it. I was able to customize the taxonomy column titles in case anyone is interest in the same way that columns can be modified for custom post types like this: <code> // CUSTOM TAXONOMY COLUMNS FOR CONTENT SOURCES add_filter("manage_edit-content_sources_columns", 'content_sources_columns'); function content_sources_columns($content_sources_columns) { $new_columns = array( 'cb' =&gt; '&lt;input type="checkbox" /&gt;', 'name' =&gt; __('Name'), // 'source_image' =&gt; '', 'description' =&gt; __('URL'), 'slug' =&gt; __('Slug'), 'posts' =&gt; __('Posts') ); return $new_columns; } </code>
Hi @NetConstructor.com : I wrote this last month for somebody and it may address what you are looking for. It is an example you would modify, not a complete ready-to-use solution: <code> &lt;?php /* * Example code showing how to hook WordPress to add fields to the taxonomny term edit screen. * * This example is meant to show how, not to be a drop in example. * * This example was written in response to this question: * * http://lists.automattic.com/pipermail/wp-hackers/2010-August/033671.html * * By: * * Mike Schinkel (http://mikeschinkel.com/custom-wordpress-plugins/) * * NOTE: * * This could easily become a plugin if it were fleshed out. * A class with static methods was used to minimize the variables &amp; functions added to the global namespace. * wp_options was uses with one option be tax/term instead of via a serialize array because it aids in retrival * if there get to be a large number of tax/terms types. A taxonomy/term meta would be the prefered but WordPress * does not have one. * * This example is licensed GPLv2. * */ // These are helper functions you can use elsewhere to access this info function get_taxonomy_term_type($taxonomy,$term_id) { return get_option("_term_type_{$taxonomy}_{$term-&gt;term_id}"); } function update_taxonomy_term_type($taxonomy,$term_id,$value) { update_option("_term_type_{$taxonomy}_{$term_id}",$value); } //This initializes the class. TaxonomyTermTypes::on_load(); //This should be called in your own code. This example uses two taxonomies: 'region' &amp; 'opportunity' TaxonomyTermTypes::register_taxonomy(array('region','opportunity')); class TaxonomyTermTypes { //This initializes the hooks to allow saving of the static function on_load() { add_action('created_term',array(__CLASS__,'term_type_update'),10,3); add_action('edit_term',array(__CLASS__,'term_type_update'),10,3); } //This initializes the hooks to allow adding the dropdown to the form fields static function register_taxonomy($taxonomy) { if (!is_array($taxonomy)) $taxonomy = array($taxonomy); foreach($taxonomy as $tax_name) { add_action("{$tax_name}_add_form_fields",array(__CLASS__,"add_form_fields")); add_action("{$tax_name}_edit_form_fields",array(__CLASS__,"edit_form_fields"),10,2); } } // This displays the selections. Edit it to retrieve static function add_form_fields($taxonomy) { echo "Type " . self::get_select_html('text'); } // This displays the selections. Edit it to retrieve your own terms however you retrieve them. static function get_select_html($selected) { $selected_attr = array('text'=&gt;'','user'=&gt;'','date'=&gt;'','etc'=&gt;''); $selected_attr[$selected] = ' selected="selected"'; $html =&lt;&lt;&lt;HTML &lt;select id="tag-type" name="tag-type"&gt; &lt;option value="text"{$selected_attr['text']}&gt;Text&lt;/option&gt; &lt;option value="user"{$selected_attr['user']}&gt;User&lt;/option&gt; &lt;option value="date"{$selected_attr['date']}&gt;Date&lt;/option&gt; &lt;option value="etc" {$selected_attr['etc']}&gt;Etc.&lt;/option&gt; &lt;/select&gt; HTML; return $html; } // This a table row with the drop down for an edit screen static function edit_form_fields($term, $taxonomy) { $selected = get_option("_term_type_{$taxonomy}_{$term-&gt;term_id}"); $select = self::get_select_html($selected); $html =&lt;&lt;&lt;HTML &lt;tr class="form-field form-required"&gt; &lt;th scope="row" valign="top"&gt;&lt;label for="tag-type"&gt;Type&lt;/label&gt;&lt;/th&gt; &lt;td&gt;$select&lt;/td&gt; &lt;/tr&gt; HTML; echo $html; } // These hooks are called after adding and editing to save $_POST['tag-term'] static function term_type_update($term_id, $tt_id, $taxonomy) { if (isset($_POST['tag-type'])) { update_taxonomy_term_type($taxonomy,$term_id,$_POST['tag-type']); } } } </code> Hope it helps.
Adding Custom Field to Taxonomy Input :Panel
wordpress
I have seen code in an answer to this stackexchange-url ("question"), how to remove the promotional back link to WordPress.org in my theme. I have added this to my theme's CSS but there is no change. Am I missing see some thing? Apologies for my Ignorance . Code I have used: <code> #site-generator { display: none; } </code> How can you remove the widgets from dashboard and add new customized widgets ? Is there possibility to hide the date and time from posts ? Update :Could anybody tell me ,If I can remove the term 'wordpress' from displaying on title bar?
Here is the code I always use whenever I setup a new wordpress blog: CUSTOM ADMIN FOOTER TEXT <code> // CUSTOMIZE ADMIN FOOTER TEXT function custom_admin_footer() { echo '&lt;a href="http://www.netconstructor.com/"&gt;Website Design by NetConstructor, Inc.&lt;/a&gt;'; } add_filter('admin_footer_text', 'custom_admin_footer'); </code> REMOVE VERSION INFO FROM THE HEAD OF FEEDS <code> // REMOVE VERSION INFO FROM THE HEAD OF FEEDS function complete_version_removal() { return ''; } add_filter('the_generator', 'complete_version_removal'); </code> REMOVE JUNK FROM THE HEADER OF PUBLIC WEBSITE PAGES <code> // REMOVE JUNK FROM THE HEADER OF PUBLIC WEBSITE PAGES remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'feed_links', 2); remove_action('wp_head', 'index_rel_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'start_post_rel_link', 10, 0); remove_action('wp_head', 'parent_post_rel_link', 10, 0); remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); </code> REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN <code> // REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN global $user_login; get_currentuserinfo(); if ($user_login !== "sysadmin") { add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) ); } </code> CUSTOM ADMIN LOGOS: <code> // CUSTOM ADMIN LOGIN HEADER LOGO function my_custom_login_logo() { echo '&lt;style type="text/css"&gt; h1 a { background-image:url('.get_bloginfo('template_directory').'/images/excitesteps-login-logo.png) !important; } &lt;/style&gt;'; } add_action('login_head', 'my_custom_login_logo'); // CUSTOM ADMIN LOGIC HEADER LOGO add_action('admin_head', 'my_custom_logo'); function my_custom_logo() { echo '&lt;style type="text/css"&gt;#header-logo { background-image: url('.get_bloginfo('template_directory').'/images/excitesteps-icon.gif) !important; }&lt;/style&gt;'; } // CUSTOM ADMIN LOGIN HEADER LINK &amp; ALT TEXT function change_wp_login_url() { echo bloginfo('url'); } function change_wp_login_title() { echo get_option('blogname'); } add_filter('login_headerurl', 'change_wp_login_url'); add_filter('login_headertitle', 'change_wp_login_title'); </code>
How do I white label my self-hosted site created by wordpress?
wordpress
The more customization I make to WordPress the more I start thinking about if I should be organizing this file or splitting it up. More specifically, if I have a bunch of custom functions which only apply to the admin area and others which just apply to my public website is there any reason to possibly include all admin functions within their own file or group them together? Would splitting them up into separate files or grouping them together possibly speed up a WordPress website or does WordPress/PHP automatically skip over functions which have an is_admin code prefix? What's the best way to deal with a large functions file (mine is 1370 lines long).
If you are getting to the point where the code in your theme's <code> functions.php </code> is starting to overwhelm you I would definitely say you are ready to consider splitting it up into multiple files. I tend to do that almost by second nature at this point. Use Include Files in your Theme's <code> functions.php </code> File I create a subdirectory called "includes" under my theme directory and segment my code into include files organized by what makes sense to me at the time (which means I'm constantly refactoring and moving code around as a site evolves.) I also rarely put any real code in <code> functions.php </code> ; everything goes in the include files; just my preference. Just to give you an example here's my test install that I use to test my answers to questions here on WordPress Answers. Every time I answer a question I keep the code around in case I need it again. This isn't exactly what you'll do for a live site but it shows the mechanics of splitting up the code: <code> &lt;?php /* * functions.php * */ require_once('includes/null-meta-compare.php'); require_once('includes/older-examples.php'); require_once('includes/wp-admin-menu-classes.php'); require_once('includes/admin-menu-function-examples.php'); require_once('includes/cpt-filtering-in-admin.php'); // WA: Adding a Taxonomy Filter to Admin List for a Custom Post Type?stackexchange-url // stackexchange-url // stackexchange-url // http://lists.automattic.com/pipermail/wp-hackers/2010-August/034384.html require_once('includes/301-redirects.php'); // stackexchange-url </code> Or Create Plugins Another option it to start grouping your code by function and create your own plugins. For me I start coding in the theme's <code> functions.php </code> file and by the time I get the code fleshed out I've moved most of my code into plugins. However NO Significant Performance Gain From PHP Code Organization On the other hand structuring your PHP files is 99% about creating order and maintainability and 1% about performance, if that (organizing <code> .js </code> and <code> .css </code> files called by the browser via HTTP is a completely different case and has huge performance implications.) But how you organize your PHP code on the server pretty much doesn't matter from a performance perspective. And Code Organization is Personal Preference And last but not least code organization is personal preference. Some people would hate how I organize code just as I might hate how they do it too. Find something you like and stick with it, but allow your strategy to evolve over time as you learn more and get more comfortable with it.
Organizing Code in your WordPress Theme's functions.php File?
wordpress
I have just installed the Plugin " W3 Total Cache " .I have enabled permalinks too. Then it is showing a message Browser Cache feature is not operational. Your .htaccess rules could not be modified. Please verify /home/..../public_html/..../.htaccess has the following rules: SO I have pasted the code it has shown on with that message to my .htaccess file .But still it is showing the same error .Am I missing something? It is the code shown and I have added to .htaccess file <code> # BEGIN W3TC Browser Cache &lt;IfModule mod_deflate.c&gt; &lt;IfModule mod_setenvif.c&gt; BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html &lt;/IfModule&gt; &lt;IfModule mod_headers.c&gt; Header append Vary User-Agent env=!dont-vary &lt;/IfModule&gt; AddOutputFilterByType DEFLATE text/css application/x-javascript text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon &lt;/IfModule&gt; &lt;FilesMatch "\.(css|js)$"&gt; FileETag None &lt;IfModule mod_headers.c&gt; Header set X-Powered-By "W3 Total Cache/0.9.1.1" &lt;/IfModule&gt; &lt;/FilesMatch&gt; &lt;FilesMatch "\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$"&gt; FileETag None &lt;IfModule mod_headers.c&gt; Header set X-Powered-By "W3 Total Cache/0.9.1.1" &lt;/IfModule&gt; &lt;/FilesMatch&gt; &lt;FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$"&gt; FileETag None &lt;IfModule mod_headers.c&gt; Header set X-Powered-By "W3 Total Cache/0.9.1.1" &lt;/IfModule&gt; &lt;/FilesMatch&gt; # END W3TC Browser Cache </code> (I have added the same code here.Please let me know If adding such a long code is inappropriate here .I will remove it from this question)
From my experience with W3 Total Cache this error is triggered when the plugin cannot write to the .htaccess file. It also suggests chmod 777 to the file and has a button that says "try-again" that you can click after changing the permissions to .htaccess. I would suggest chmod 777 to .htaccess, click try again, then change the permissions back afterwards. If this is not possible then you will need to paste the code into the file above the WordPress rewrite rules making sure not to replace them. The plugin has a set of rules for each caching method that need to be added to various .htaccess files. To find the rules needed for each file go to performance - install: The code you posted above is missing the mime type rules that should be in the browser cache .htaccess.
Error Message from W3 Total Cache when .htaccess Rules Cannot Be Modified?
wordpress
I just added Contact Form 7 to my site . I'm using the default configuration (didn't change any setting). The mails are classified as spam in my Gmail inbox. Is there any way of making them go directly to the inbox?
@janoChen, The problem could be that your email server is not using Domain Keys or a valid spf record DomainKeys is an e-mail authentication system that allows for incoming mail to be checked against the server it was sent from to verify that the mail has not been modified. This ensures that messages are actually coming from the listed sender and allows abusive messages to be tracked with more ease. DomainKeys can be set up in Cpanel under Email Authentication SPF will specify which machines are authorized to send email from your domain(s). This means that only mail sent through this server will appear as valid mail from your domain(s) when the SPF records are checked. SPF records can be set in Cpanel or by adding the record to your DNS. A sample SPF record looks like this: v=spf1 a mx ip4:xxx.xxx.17.118 a:my.servername.com ?all This tells email servers that the specified ip address and host are permitted to send mail from my domain. The Configure SMTP plugin will set up WordPress to use SMTP authentication to send out mail. It also has an option to use Gmail or Google Apps to send WordPress mail. Check the email headers to find out why your messages are going to spam In Gmail you can view the headers which will tell you the problem with the message by clicking the drop down arrow under replay and selecting "show original". Here is a header example from some "Viagra" spam in my spam box: <code> Received-SPF: neutral (google.com: 123.238.77.28 is neither permitted nor denied by best guess record for domain of chris@buymmoaccounts.com) client-ip=123.238.77.28; Authentication-Results: mx.google.com; spf=neutral (google.com: 123.238.77.28 is neither permitted nor denied by best guess record for domain of chris@buymmoaccounts.com) smtp.mail=chris@buymmoaccounts.com </code>
Contact Form 7 Plugin send emails to my Gmail as spam
wordpress