question
stringlengths 0
34.8k
| answer
stringlengths 0
28.3k
| title
stringlengths 7
150
| forum_tag
stringclasses 12
values |
---|---|---|---|
I am involved in a large migration from another CMS to WordPress. We have a copy of the database and have worked out how to extract the content and programmatically create WordPress posts from it using an instantiation of the <code> wpdb </code> class. However, there are a couple of thousand images which we would like to pull across automatically, generate the various sizes, and then attach to the posts, to save about a week's work! Is there a way I can get an image from a remote site by URL and save it in my wp-uploads folder? I guess this uses <code> wp_http </code> but I'm unfamiliar with that. Once I've got the image and saved it I'm ok as I can then use <code> wp_generate_attachment_metadata </code> to create the various sizes and <code> wp_insert_attachment </code> to attach it to a post. Thanks Simon
|
There's actually a great function that will do all three of those things for you: <code> media_sideload_image( $url, $post_id, $description ); </code> The first argument is the remote url of the image you want to download. The second argument is the post id of the post to which you want to attach the image. The third argument is optional, but will be a description if included. I'd suggest finding a way to throttle the downloads so that you don't keep timing out, such as limiting the number of images it pulls in per load and setting the importer to refresh itself between downloads, or using AJAX to do them one at a time asynchronously.
|
Programmatically get images by URL and save in uploads folder
|
wordpress
|
I am wondering how can I write a conditional tag that affects a custom taxonomy slug and its children? Found this in Wordpress Codex: <code> is_tax( 'flavor', 'mild') </code> When the archive page for the flavor taxonomy with the slug of 'mild' is being displayed. However with this code only 'mild' slug archive page is affected and not it's children taxonomy terms. Thanks!
|
I have a handy little function that i based on post_is_in_descendant_category function it expends the is_tax to check if its the term or any of his children <code> function is_or_descendant_tax( $terms,$taxonomy){ if (is_tax($taxonomy, $terms)){ return true; } foreach ( (array) $terms as $term ) { // get_term_children() accepts integer ID only $descendants = get_term_children( (int) $term, $taxonomy); if ( $descendants && is_tax($taxonomy, $descendants) ) return true; } return false; } </code> and you use it just the same so instead of: <code> is_tax('flavor', 'mild'); </code> you put: <code> is_or_descendant_tax(get_term_by( 'name', 'mild', 'flavor' ), 'flavor'); </code> or if you are using term id instead of name then: <code> is_or_descendant_tax(12, 'flavor'); </code> and you are set.
|
Conditional tag affecting taxonomy term and its children?
|
wordpress
|
I've been looking into setting up a WordPress network install. Everything has been going pretty smoothly until I get to the point where my desired domain layout doesn't fit well. I would like to have a layout as follows: blog.*.stackexchange.com so for example, I would like to have multiple sites in a network that look like: blog.wordpress.stackexchange.com blog.apple.stackexchange.com blog.$site.stackexchange.com I think I could get this working with some creative re-write rules, and manual DNS intervention but I'd rather have a setup where I can hand off the creation of everything but the DNS to someone else (we already have a process for automatically creating all sub-domains needed in DNS) From my playing around and reading WP really wants the sites to be the next level domain, so in my above example, it wants the main WP blog to be at stackexchange.com and the network blogs to be at wordpress.stackexchange.com. Is there any way to achieve my desired effect or should I just go the route of doing blog.stackexchange.com/$site ?
|
You could use the Domain Mapper plugin for this. Drawback being that you'd have manually configure each subblog.
|
Setting up a wordpress network with third level domains
|
wordpress
|
I am using the MidMo Clean theme and for some reason the 404 error page isn't working. Parse error: syntax error, unexpected T_STRING in /home/wpversec/public_html/UXJobsLA.com/wp-content/themes/clean-home/404.php on line 14 http://uxjobsla.com/error Short of me disabling all my plugins and re-installing a out of the box version of the theme, anyone have any ideas please? Thanks!
|
So I think you're problem is the quotes in the href inside your function. Try escaping them like this and it should be fixed. <code> <p><?php _e("Sorry but, you are looking for something that isn't here. <br /><br /> Looking for more web developer jobs, please visit our sister site: <a href=\"http://LAMPjobsLA.com\">LAMPjobsLA.com</a>", 'cleanhome') ;?></p> </code>
|
How to fix 404 page error on theme
|
wordpress
|
I had some code in a template file. When I pasted it from the backend's post panel (HTML tab) as a post, and retrieved it as custom loop, the code didn't output well. Any suggestions? Adding them as posts: <code> <?php /** * Template Name: Lyrics Page * @package WordPress * @subpackage Prominent * @since Prominent 1.0 */ get_header(); ?> <div id="tagline"> <div class="container"> <?php // Run main loop (The Loop). ?> <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <div class="content0"> </div> <?php endwhile; ?> </div><!-- .container --> </div><!-- #content-bottom --> <div id="content"> <div class="container"> <div id="mainbar"> <div id="accordions-top"> <?php $custom_posts = new WP_Query(); ?> <?php $custom_posts->query('category_name=Lyrics'); ?> <?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?> <?php the_content(); ?> <?php endwhile; ?> </div> </div><!-- #mainbar --> <?php get_sidebar(); ?> </div><!-- .container --> </div><!-- #content-bottom --> <?php get_footer(); ?> </code> Directly on the file: <code> <?php /** * Template Name: Lyrics Page * @package WordPress * @subpackage Prominent * @since Prominent 1.0 */ get_header(); ?> <div id="tagline"> <div class="container"> <?php // Run main loop (The Loop). ?> <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <div class="content0"> <?php the_content(); ?> </div> <?php endwhile; ?> </div><!-- .container --> </div><!-- #content-bottom --> <div id="content"> <div class="container"> <div id="mainbar"> <div id="accordions-top"> <div class="basic" style="float:left; margin-left: 2em;" id="list1e"> <a>There is one obvious advantage:</a> <div> <p> You've seen it coming!<br/> Buy now and get nothing for free!<br/> Well, at least no free beer. Perhaps a bear,<br/> if you can afford it. </p> </div> <a>Now that you've got...</a> <div> <p> your bear, you have to admit it!<br/> No, we aren't selling bears. </p> </div> <a>Rent one bear, ...</a> <div> <p> get two for three beer. </p> <p> And now, for something completely different.<br/> And now, for something completely different.<br/> And now, for something completely different.<br/> And now, for something completely different.<br/> And now, for something completely different.<br/> And now, for something completely different.<br/> And now, for something completely different.<br/> And now, for something completely different.<br/> Period. </p> </div> </div> </div> </div><!-- #mainbar --> <?php get_sidebar(); ?> </div><!-- .container --> </div><!-- #content-bottom --> <?php get_footer(); ?> </code> Output of the post when I add via admin panel: <code> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="generator" content= "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" /> <title></title> </head> <body> <div id="content"> <div class="container"> <div id="mainbar"> <div id="accordions-top"> <div class="basic" style="float:left; margin-left: 2em;" id="list1e"> <a>There is one obvious advantage:</a> <div> <p>You&rsquo;ve seen it coming!<br /> <br /> Buy now and get nothing for free!<br /></p> <p>Well, at least no free beer. Perhaps a bear,<br /> <br /> if you can afford it.</p> </div> <p><a>Now that you&rsquo;ve got&hellip;</a></p> <div> <p>your bear, you have to admit it!<br /></p> <p>No, we aren&rsquo;t selling bears.</p> </div> <p><a>Rent one bear, &hellip;</a></p> <div> <p>get two for three beer.</p> <p>And now, for something completely different.<br /> <br /> And now, for something completely different.<br /> <br /> And now, for something completely different.<br /> <br /> And now, for something completely different.<br /> <br /> And now, for something completely different.<br /> <br /> And now, for something completely different.<br /></p> <p>And now, for something completely different.<br /> <br /> And now, for something completely different.<br /> <br /> Period.</p> </div> </div> </div> </div><!-- #mainbar ==ý--> </div> </div> </body> </html> </code>
|
Finally, figured out, I needed this: <code> remove_filter('the_content', 'wpautop'); </code>
|
Adding some HTMl code as posts doesn't work but it does if it is added directly in the file?
|
wordpress
|
Is there a way to limit how many pages a user can make inside a custom post type? This would be pretty effective for commercial WP plugins and I am making one, but have come across a little problem and I would need to figure out how to do this. Thanks.
|
Check out my plugin Bainternet Posts Creation Limits this plugin helps you to limit the number of posts/pages/custom post types each user can create on your site. Its just what you need. Update open up bapl.php and in bapl_limit_post_count function change on line 44: <code> if ( current_user_can('manage_options') ) {}else{ if (isset($postt[$curent_type])){ //$postt= bapl_getOptions('bapl'); foreach ($postt as $key => $option){ if ($key = $curent_type) { $ptname = $key; $limit = $option; break; } } //print_r($postt); $count_posts = count(get_posts(array('author'=>$current_user->ID,'post_type',$ptname))); if ($count_posts >= $limit){ //wp_die( __('You Can't Create any more pages of this type.') ); bapl_not_allowed(); exit; } } } </code> to: <code> if (isset($postt[$curent_type])){ foreach ($postt as $key => $option){ if ($key = $curent_type) { $ptname = $key; $limit = $option; break; } } $count_posts = count(get_posts(array('author'=>$current_user->ID,'post_type',$ptname))); if ($count_posts >= $limit){ bapl_not_allowed(); exit; } } </code> this way the admin is limited too. Next you will need to change bapl_getOptions function and set you defaults there. And last you will probably wont to remove the admin control panel of this plugin so comment out line 69 were it says : <code> add_action('admin_menu', 'bapl_menu'); </code>
|
Limit Amount of Pages users can create in Custom Post Types
|
wordpress
|
I've been looking for a chat support plugin for WP and I haven't been able to find one, does anyone know about one? Free or paid doesn't matter. Thanks in advance.
|
If you're looking for a "talk with a representative" type chat plugin I found that www.oggchat.com was a reasonable one, and they have a Wordpress plugin to go with it. It supports the rep chatting from either the Oggchat website or via Gtalk, so your rep could be anywhere at any time, with a smartphone and a Gtalk program. If it's a "users on the site can chat together", then Oggchat isn't what you're looking for.
|
Chat support plugin?
|
wordpress
|
I've been racking my brains for the best way to create a simple gallery in Wordpress without relying on a plugin like NextGen gallery, and was thinking a shortcode would be a good way combined with the in-built method of 'attaching' images to a post. That way, the user would 'attach' images they've uploaded and the description for the image could be used as a caption. That was, until I realised that there's no easy way to 'unattach' an image from a post unless you delete the image itself (meaning it disappears from other posts/pages you've inserted it into). Plus, it doesn't let you link the images to different parts of your site. So I'm now thinking Custom Fields or some other method involving a shortcode or hardcoding an area in my template might be a good way to do it, but the problem is how to associate the various parts of the gallery for each image: the image url the image dimensions the link wrapping the image the order of the images The HTML I'd need to output for each image would be this: <code> <a href="-LINK_TO_PAGE_HERE-" title="caption" alt="description"> <img src="-URL_TO_IMAGE-" width="x" height="y" /> </a> </code> And then I'd wrap that in a div like <code> <div id="osu-gallery">...</div> </code> so I could do what I wish with it in jQuery. Is that possible in Wordpress without the use of a plugin? I want to do this on a post-by-post basis and without going into the HTML editor and manually writing the code. My clients tend not to be too computer-savvy... Thanks for any pointers, Osu
|
You won't be able to do it purely with Javascript (with or without jQuery) as the images are hosted server-side, and there'd be no way for a Javascript function to scan to see what's available. What you could do is write a function to do it in functions.php and tie it to a shortcode, but then you're starting to get into the territory of where a plugin would be easier.
|
Making jQuery-based galleries with Wordpress without a plugin?
|
wordpress
|
It's possible that I'm just doing this wrong, so feel free to let me know how you would solve this problem. I have a mostly page-based site, but there are a few "pages" where my content is coming from a custom <code> query_posts() </code> call. In all of these pages I want to be able to use <code> wp_list_pages() </code> to generate sub-navigation. This works just fine when I'm in a normal page, but when I'm in a "page" with <code> query_posts() </code> content, this doesn't work at all. Here's an example of what I mean by a "page". This one is a theme file called <code> page-media.php </code> : <code> <?php get_header(); ?> <?php query_posts('category_name=in-the-media'); ?> <?php get_template_part('loop', 'index'); ?> <?php get_sidebar(); ?> <?php get_footer(); ?> </code> The sub-navigation happens in <code> sidebar.php </code> , so it's happening post-loop. Here's how I'm generating my menu: <code> if($post->post_parent) { $children = wp_list_pages('title_li=&child_of=' . $post->post_parent . '&echo=0'); } else { $children = wp_list_pages('title_li=&child_of=' . $post->ID . '&echo=0'); } </code> I then print <code> $children </code> later in a <code> <ul> </code> . This works perfectly in a page or its sub-page, but displays nothing in a page where I've called <code> query_posts() </code> . Am I approaching this correctly? Is there something I'm missing? Thanks!
|
This is for future askers, Whenever you use query_posts or custom wp_query you should add wp_reset_query(); after your loop or when you are done processing your posts. This little line of code will help in solving pagination issues or in your case rest the global $post the original as before your query.
|
Using wp_list_pages() after calling query_posts()
|
wordpress
|
If you use the <code> [gallery] </code> tag at all you know that permalinks for image attachments end up like <code> blog.com/2011/03/18/post-permalink/attachment-permalink </code> . The URL extension from the post permalink appears to be based on the attachment's title on first save. To my knowledge, however, this permalink does not update when the image title is edited in the media tools. I cannot find a way to do edit attachment permalinks at all, actually. Is there a user-facing interface I'm missing that will let users edit an attachment's permalink?
|
This'll add a slug field to the edit attachment page, which'll allow you to independently change it when and how you choose to. Drop it into a plugin or your theme's <code> functions.php </code> ; <code> function __edit_attachment_name( $fields, $post ) { $fields['post_name'] = array( 'label' => __('Slug'), 'value' => $post->post_name ); return $fields; } add_filter( 'attachment_fields_to_edit', '__edit_attachment_name', 10, 2 ); function __save_attachment_name( $attachment, $POST_data ) { if ( !empty( $POST_data['post_name'] ) ) $attachment['post_name'] = $POST_data['post_name']; return $attachment; } add_filter( 'attachment_fields_to_save', '__save_attachment_name', 10, 2); </code>
|
Is there a user-facing interface to edit an attachment's permalink?
|
wordpress
|
I'm working on a plugin to will retrieve data from a remote server and display it on the Dashboard. To do this, I'll be using the WordPress HTTP API but I'm not seeing any information on the HTTP API using any form of caching. As I don't want my plugin to cause problems for the admins of the remote server, I was wondering if I missed some documentation about the HTTP API doing caching or if I'll also need to use the Transients API to implement caching for my plugin?
|
It does not. Some functionality actively uses HTTP API and is cached - feed fetching, updates checking. But caching is always implemented at wrapper's level. Making HTTP request without context is too unspecific to make educated guess about caching needs (one minute or one hour).
|
Does WordPress's HTTP API use any caching?
|
wordpress
|
I'm deploying a multi-site network, using subfolders. I've found on the main site the permalinks for news posts can only be placed like so: <code> /blog/%year%/%monthnum%/%postname%/ </code> I understand that this prefix is needed to lessen the risk of conflict between the main site and sub-sites. Unfortunately this is a serious website, where the word 'blog' isn't really appropriate. Something like <code> /pressreleases </code> would be much more appropriate, and still avoid conflicts. I tried various of the 'tricks' people mention, such as editing the permalink structure from the network admin settings. I also tried using rewrite rules (both Apache and the Redirection plugin) without much luck. WordPress needs to believe the posts are at the location in the address bar, so rewriting results in a 404. I could redirect them back to <code> /blog </code> , but that still has the same problem. How can I change the permalinks?
|
Let see if I remember this correctly. Go to http://yoursite.com/wp-admin/options.php Find <code> permalink_structure </code> . By default, the value should be <code> /blog/%year%/%monthnum%/%postname%/ </code> Change the value manually to whatever value you like. e.g <code> /pressreleases/%year%/%monthnum%/%postname%/ </code> or just <code> /%year%/%monthnum%/%postname%/ </code> . Then Save Changes. Now visit http://yoursite.com/wp-admin/options-permalink.php and DON'T click Save Changes. It should flush the rules. If you click Save Changes it will revert back to the default. LOL
|
Multi-site: removing /blog from posts
|
wordpress
|
I recently started working with a client who has over 400 pages on their WP site (yes, pages, not posts). Their menu needs to be redone, so I decided to go the 'custom menus' route. However, not more than a third of the pages are available to select from the 'Pages' meta box on the Menus page. And 'search' does not seem to work (typing in the page title, even of pages that do show in the box, results in 'No results found' message. In short, some of the pages I need to add to the menu are not available for me to select. What's up with this? And how do I solve it? Also, if I select on-site pages as 'custom links', will WP still add classes to the links to indicate they are 'current page' or 'current page ancestor'?
|
Upgraded to 3.1 from 3.05 and both problems (inability to see all pages in 'pages' box, and inability to search) went away.
|
Is there a limit to number of pages displayed for selection in custom menu?
|
wordpress
|
I would really appreciate if you could help me :) I'm very stuck and don't know how to proceed. I have a custom post type called <code> event </code> and 2 custom taxonomies registered for it: <code> event_type </code> with tag-like functionality (ex. of event type: yoga, voice work) <code> event_location </code> with category-like functionality (ex of event location: uk-> brighton, london; europe-> paris). There are pages on the website like <code> Yoga -> Upcoming events </code> ; <code> Voice work -> Upcoming workshops </code> . Depending on which page we are on I'd like to display appropriate events. For example, if we're on page <code> Yoga -> Upcoming events </code> I'd like to display all <code> event </code> custom posts with <code> event_type </code> being yoga and then group the results by <code> event_location </code> taxonomy terms. For example, list all yoga events for UK, Brighton then UK, London and then Europe, Paris and so on. What I currently do in a template is the following: I get the slug of the current page and its ancestors. I get slugs of all terms in the <code> event_type </code> taxonomy, that have some events associated with them. I determine which event types to display, by intersecting previously gathered values. Then I construct a WP_Query to get <code> event </code> posts with determined <code> event_type </code> taxonomy terms. This seems to work. However, results came back unordered and I would like them to be ordered by <code> event_location </code> taxonomy terms. For example: UK Brighton Event 1 Event 2 London Event 3 Europe Paris Event 4 I would also like to display only non-expired <code> event </code> posts and order them by <code> event_date </code> . The <code> event_date </code> value is stored as meta value along with the rest of <code> event </code> post details under a single meta_key. Here is my code so far: <code> //pull in the appropriate events depending on the page type: yoga/voice work /* get the ancestors and current page slugs */ // collect ancestor pages $relations = get_post_ancestors($post->ID); // add current post to pages array_push($relations, $post->ID); // get pages slugs $relations_slugs = array(); foreach($relations as $page_ID){ $page = get_page($page_ID); array_push($relations_slugs, $page->post_name); } /* get the term slugs (non-empty) for event_type taxonomy */ //get the event_type taxonomy values $event_types = get_terms( 'event_type', 'hide_empty=true' ); $event_types_slugs = array(); foreach($event_types as $event_type){ array_push($event_types_slugs, $event_type->slug); } /* find what event_type to display on the current page */ $page_event_types = array_intersect($relations_slugs, $event_types_slugs); $page_event_types_string = implode(",",$page_event_types); /* find the events of the event_type to display on the current page */ $args = array( 'post_type' => 'event', 'tax_query' => array( array( 'taxonomy' => 'event_type', 'field' => 'slug', 'terms' => $page_event_types_string ) ) ); $temp = $wp_query; //assign orginal query to temp variable for later use $wp_query = null; $wp_query = new WP_Query($args); /* run the loop to output the event's details */ get_template_part( 'loop', 'event-details' ); </code> I'm not great at constructing SQL statements. I would really appreciate if you could help me. Thank you very much!!! EDIT I have significantly simplified the functionality (as I got quite confused and lost in the original one). Please see my answer. Thanks to @Bainternet for taking the time and trying to help me out!
|
I got a bit confused with this one. At the end I've decided not to group the events by <code> event_location </code> category and simplify the functionality. What I have done instead is the following: I detect what <code> event_type </code> events to display by looking at a URL. Then I display all the events of that <code> event_type </code> and order them by <code> event_date </code> ASC - the ones that coming soon appear first. Here the URL is of format <code> /events?type=event_type </code> I present a sidebar with all the <code> event_location </code> category terms. A user can see all events in a specific location by clicking on the links. The URL in this case has the following format: <code> /events?location=event_location </code> . Events of all types but for that specific location are displayed ordered ASC (the ones that coming soon appear first). Then in my custom query I include <code> 'tax_query' </code> . For example, for the <code> event_location </code> taxonomy something like: <code> $wp_query['tax_query'] = array('taxonomy' => 'event_location', 'field' => 'slug', 'terms' => $_GET['location'] ) </code> Hope that helps someone.
|
how to group custom post type posts by custom taxonomy terms
|
wordpress
|
I'm having a very hard time implementing post formats in my Thematic child theme. I am able to add post format theme support and add content via the big conditional statement, but the <code> .format-video </code> , etc. selectors do not appear in the post class so I can' use them to style the formats. According to some echoing tests, the selector appears as it should in <code> post_class() </code> but is nowhere to be found in <code> thematic_post_class() </code> . I tried removing <code> thematic_post_class() </code> to let <code> post_class() </code> function instead: <code> // remove thematic_post_class to include post format selector in post class function childtheme_override_post_class() { remove_action('thematic_post_class','thematic_access', 9); } add_action('init', 'childtheme_override_post_class'); </code> With this function, <code> thematic_post_class() </code> no longer echoes, but the theme is still not registering the format selectors. I saw in another post that the <code> after_setup_theme </code> action hook worked to enable formats in a Twenty-Ten child - tried this in my theme but it made no difference: <code> function wpfolio_add_format_support() { add_theme_support( 'post-formats', array( 'aside', 'gallery', 'video', 'link', 'image', 'quote') ); } add_action('after_setup_theme', 'wpfolio_add_format_support', 11);` </code> Any ideas? Thanks in advance
|
Okay, I'm going on the assumption that the real question is "how do I get Thematic to add the post-format to its body classes?" Try this in your functions.php: <code> function my_thematic_post_format_class( $classes = array() ) { $format = get_post_format(); if ( '' == $format ) $format = 'standard'; $classes[] = 'format-' . $format; return $classes; } add_filter( 'post_class', 'my_thematic_post_format_class' ); </code> Don't override the thematic post class functions. Just add that filter, and you should be good.
|
Post format selector in Thematic child theme post class
|
wordpress
|
After you have uploaded an attachment in Wordpress using the media upload screen, is there a hook or filter I can run after the image has been uploaded where I can get the path to the uploaded image so I can analyse it? I am building a plugin that will analyse an image after it has been uploaded and then tag the image with the average colour it finds in the image. The only problem is I don't know what hook I can use that will fire right after the image has uploaded and then a way I can get the path to the newly uploaded file. Any help would be gratefully appreciated.
|
Turns out I solved my own question with help from a colleague. The two filters that get called after media is uploaded or when media is being edited are; 'add_attachment' and 'edit_attachment'. Here is the code I am using, I then check to see if the attachment is an image (code omitted from example). <code> function analyse_attachment($attachment_ID) { $attachment = get_attached_file($attachment_ID); // Gets path to attachment update_post_meta($attachment_ID, "image_rgb", $the_colour); } add_action("add_attachment", 'analyse_attachment'); add_action("edit_attachment", 'analyse_attachment'); </code> Obviously I've omitted some stuff that isn't relevant to the question. But that code gets called right after you've uploaded or edited an attachment.
|
Getting Path To Uploaded Attachment Image After Upload
|
wordpress
|
I am looking into updating this template ( http://templatic.com/demos/answers/?ptype=ask-a-question ) which allows logged in subscribers to post (questions). I would like to add an option to upload a file and attach it to the post. I was thinking of using the media-upload functionality, but I do not want to give users full access to the media library. How could this be achieved?
|
You won't find much on the Codex or the net about this. Media can seem like a pretty dark art, but everything you're looking for is in /wp-admin/includes/media.php . The function you're looking for is <code> media_handle_sideload() </code> . You'll have to pass it a <code> $file_array </code> , which you'll have to read up on. Basically you just make sure your file information is all up to snuff, pass it into this function and it creates something that acts a lot like a regular post and can be manipulated via the media tools and custom post querie s with <code> post_type=attachment </code> argument.
|
How can I to add upload functionality outside of the admin area?
|
wordpress
|
What codex/query would I use to call a list of pages with a specific tag from within another page?
|
Probabbly the easest way to do it is use: Kalin's Post List Creates a shortcode or PHP snippet for inserting dynamic, highly customizable lists of posts or pages such as related posts or table of contents into your post content or theme. so you can either use a shortcode or edit your theme file.
|
Display list of posts with x tag within a page?
|
wordpress
|
Take a look at this post: http://mikewills.me/blog/links-for-2011-02-24/ My images are broke and CSS links are broke. I know the problem is with the permalink, but why would it be broke? I have the same problem with the Twenty Ten theme and the new Twenty Ten Five theme.
|
Viewing your pagesource and clicking on your first style sheet link brings up this error: <code> <html> <head> <title>Not Found</title> </head> <body> <h1>Apache server with mod_pagespeed</h1> OK <hr> NOT FOUND:http://mikewills.me/blog/links-for-2011-02-24/ wp-content/themes/richardshepherd-TwentyTenFive-a8f2860 /style.css.pagespeed.ce.pAcUzu9T3K.css </body> </html> </code> So it looks like your (cached?) stylesheet isn't where you think it is or your apache module isn't configured correctly.
|
Template messed up on viewing posts
|
wordpress
|
I have a script that loads jQuery when an element comes into the viewport, as discovered by Javascript (without a library), and it looks like this: viewport.js: <code> var height = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE height = window.innerHeight; } else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' height = document.documentElement.clientHeight; } else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible height = document.body.clientHeight; } function gingah_comments_onLoad() { var element = document.getElementById("comments"); var current = height+document.body.scrollTop; var target = element.offsetTop; console.log(current); console.log(target); if (current >= target) { if (typeof jQuery == 'undefined') { $.defer("http://localhost/wp/wp-includes/js/jquery/jquery.js", { }).done(console.log('loaded jQuery')); window.onscroll = null; } } } window.onscroll = gingah_comments_onLoad; </code> And the html used: <code> <head> <script src="DeferJS.min.js" type="text/javascript"></script> <script src="viewport.js" type="text/javascript"></script> </head> <body> <div style="height: 1000px; border: 1px solid #ff0000;">Top</div> <div class="comment_box" style="height: 1000px; border: 1px solid #ff0000;"> <div id="comments">Comment1</div> </div> </body> </code> The DeferJS.min.js refers to a minified version of the following: https://github.com/BorisMoore/DeferJS/raw/master/DeferJS.js However, when I try to implement this in Wordpress (3.1), having used wp_enqueue_script for both viewport.js and DeferJS.min.js, the scrollTop appears to not work at all. When the HTML and JS above is combined, it will log the values to the console, making it very clear when #comments came into the viewport. But when replicating the process in Wordpress, the current var does not count upwards when scrolling down, but stays static. And, according to Firebug, viewport.js, DeferJS.min.js and l10n.js (Wordpress 3.1 localization) are the only scripts loaded. Also, Quirksmode lists the scrollTop method as available in practically all browsers. What could be the cause of this malfunction in document.body.scrollTop?
|
It would seem that something in Wordpress causes a virtual revert to a standards that require cross-browser compatibility, making the same code not work inside and outside Wordpress. However, with some code to handle browser-differences (and still avoiding using libraries), the following is what viewport.js looks like now: <code> function height() { if( typeof( window.innerWidth ) == 'number' ) { //Non-IE return window.innerHeight; } else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' return document.documentElement.clientHeight; } else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible return document.body.clientHeight; } } function distance() { if(typeof pageYOffset!= 'undefined'){ //most browsers return pageYOffset; } else { var B= document.body; //IE 'quirks' var D= document.documentElement; //IE with doctype D= (D.clientHeight)? D: B; return D.scrollTop; } } function gingah_comments_onLoad() { var element = document.getElementById("comments"); var current = height()+distance(); var target = element.offsetTop; console.log(current); console.log(target); if (current >= target) { if (typeof jQuery == 'undefined') { $.defer("http://localhost/wp/wp-includes/js/jquery/jquery.js", { }).done(console.log('loaded jQuery')); window.onscroll = null; } } } window.onscroll = gingah_comments_onLoad; </code> Which then loads jQuery from the standard Wordpress-path when the #comments -element comes into view.
|
Document.body.scrollTop in Wordpress
|
wordpress
|
Let's say theme 1.0 is installed with 30 files in it. Then two weeks later theme is upgraded to theme 2.0 which contains only 10 files. Do those older 20 files get automatically deleted after upgrade? What I wanted to do is to place a file inside the theme directory, trough which the user can customize the theme. This file would be created after the theme is installed trough the theme settings. But if WP does delete files that do not exist in the official theme package, then this file would be deleted as well...
|
Yes. Find a theme that support Child Theme . Create a child theme so that your modification doesn't get deleted if you update the parent theme.
|
Does WP delete deprecated plugin/theme files on plugin/theme upgrade?
|
wordpress
|
I'm just doing some wordpress development and wondered for a brand new install, which code within core is generating the first value that get's filled into the <code> home </code> option? I'm looking for the code in core, e.g. the filename and the line where this happens. Does someone remembers from mind?
|
When the installer runs it calls <code> wp_install() </code> , that in turn calls <code> populate_options() </code> defined in <code> wp-admin/includes/schema.php </code> , which runs the following.. <code> if ( !__get_option('home') ) update_option('home', $guessurl); </code> Prior to that <code> $guessurl </code> is defined by.. <code> $guessurl = wp_guess_url(); </code> The guess URL function is defined in <code> wp-includes/functions.php </code> and looks like this. <code> function wp_guess_url() { if ( defined('WP_SITEURL') && '' != WP_SITEURL ) { $url = WP_SITEURL; } else { $schema = is_ssl() ? 'https://' : 'http://'; $url = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); } return rtrim($url, '/'); } </code> wp_install() http://core.trac.wordpress.org/browser/tags/3.1/wp-admin/includes/upgrade.php#L22 populate_options() http://core.trac.wordpress.org/browser/tags/3.1/wp-admin/includes/schema.php#L177 guess_url() http://core.trac.wordpress.org/browser/tags/3.1/wp-includes/functions.php#L3585 Hope that's the info you're looking for... :)
|
On Install, which code sets the 'home' option?
|
wordpress
|
I find it very unnecessary to have an "add image" button that brings me to yet another screen that will let me upload content to my post. Ideally I would like to have a meta box with the option to add images directly in a meta box. I managed to get some functionality by copy the source for the media-upload form and paste it in a meta box. The image I choose gets uploaded, however I doesn't show any progressbar, and I need to find a way to list attached images below for better overview. Anyone managed to do this? Code: <code> function add_image_test() { ?> <script type="text/javascript"> //<![CDATA[ addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; var userSettings = {'url':'/','uid':'2','time':'1300489693'}; var ajaxurl = 'http://xxx.com/wp-admin/admin-ajax.php', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup', isRtl = 0; //]]> </script> <script type='text/javascript'> /* <![CDATA[ */ var swfuploadL10n = { queue_limit_exceeded: "You have attempted to queue too many files.", file_exceeds_size_limit: "This file exceeds the maximum upload size for this site.", zero_byte_file: "This file is empty. Please try another.", invalid_filetype: "This file type is not allowed. Please try another.", default_error: "An error occurred in the upload. Please try again later.", missing_upload_url: "There was a configuration error. Please contact the server administrator.", upload_limit_exceeded: "You may only upload 1 file.", http_error: "HTTP error.", upload_failed: "Upload failed.", io_error: "IO error.", security_error: "Security error.", file_cancelled: "File canceled.", upload_stopped: "Upload stopped.", dismiss: "Dismiss", crunching: "Crunching&hellip;", deleted: "moved to the trash.", error_uploading: "&#8220;%s&#8221; has failed to upload due to an error" }; try{convertEntities(swfuploadL10n);}catch(e){}; /* ]]> */ </script> <script type='text/javascript' src='http://xxx.com/wp-admin/load-scripts.php?c=1&amp;load=jquery,utils,swfupload-all,swfupload-handlers,json2&amp;ver=2af6dbb1e89d69a2363895fac893188d'></script> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery('form#post').attr('enctype','multipart/form-data'); jQuery('form#post').attr('encoding','multipart/form-data'); }); </script> <form enctype="multipart/form-data" method="post" action="http://xxx.com/wp-admin/media-upload.php?type=image&amp;tab=type&amp;post_id=1622" class="media-upload-form type-form validate" id="image-form"> <input type="submit" name="save" id="save" class="hidden" value="Save Changes" /><input type="hidden" name="post_id" id="post_id" value="1622" /> <input type="hidden" id="_wpnonce" name="_wpnonce" value="2460ab002a" /><input type="hidden" name="_wp_http_referer" value="/wp-admin/media-upload.php?post_id=1622&amp;type=image&amp;" /> <script type="text/javascript"> //<![CDATA[ var uploaderMode = 0; jQuery(document).ready(function($){ uploaderMode = getUserSetting('uploader'); $('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;}); $('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;}); }); //]]> </script> <div id="media-upload-notice"> </div> <div id="media-upload-error"> </div> <script type="text/javascript"> var swfu; SWFUpload.onload = function() { var settings = { button_text: '<span class="button">Select Files<\/span>', button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; font-size: 11px; text-shadow: 0 1px 0 #FFFFFF; color:#464646; }', button_height: "23", button_width: "132", button_text_top_padding: 3, button_image_url: 'xxx.com/wp-includes/images/upload.png?ver=20100531', button_placeholder_id: "flash-browse-button", upload_url : "xxx.com/wp-admin/async-upload.php", flash_url : "http://xxx.com/wp-includes/js/swfupload/swfupload.swf", file_post_name: "async-upload", file_types: "*.*", post_params : { 'post_id' : '1622', 'auth_cookie' : 'admin|1301439526|5e5e63158e880597c782656a719f1738', 'logged_in_cookie' : 'admin|1301439526|e01206ec12b5cee4a605f9abff385cc0', '_wpnonce' : '2460ab002a', 'type' : 'image', 'tab' : 'type', 'short' : '1' }, file_size_limit : "4194304b", file_dialog_start_handler : fileDialogStart, file_queued_handler : fileQueued, upload_start_handler : uploadStart, upload_progress_handler : uploadProgress, upload_error_handler : uploadError, upload_success_handler : uploadSuccess, upload_complete_handler : uploadComplete, file_queue_error_handler : fileQueueError, file_dialog_complete_handler : fileDialogComplete, swfupload_pre_load_handler: swfuploadPreLoad, swfupload_load_failed_handler: swfuploadLoadFailed, custom_settings : { degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available }, debug: false }; swfu = new SWFUpload(settings); }; //]]> </script> <div id="flash-upload-ui" class="hide-if-no-js"> <div> Choose files to upload <div id="flash-browse-button"></div> <span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="Cancel Upload" class="button" /></span> </div> <p class="media-upload-size">Maximum upload file size: 4MB</p> </div> <div id="html-upload-ui"> <p id="async-upload-wrap"> <label class="screen-reader-text" for="async-upload">Upload</label> <input type="file" name="async-upload" id="async-upload" /> <input type="submit" name="html-upload" id="html-upload" class="button" value="Upload" /> <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;">Cancel</a> </p> <div class="clear"></div> <p class="media-upload-size">Maximum upload file size: 4MB</p> </div> <script type="text/javascript"> //<![CDATA[ jQuery(function($){ var preloaded = $(".media-item.preloaded"); if ( preloaded.length > 0 ) { preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); } updateMediaForm(); }); //]]> </script> <div id="media-items"> </div> <p class="savebutton ml-submit"> <input type="submit" name="save" id="save" class="button" value="Save all changes" /></p> </form> <script type='text/javascript'> /* <![CDATA[ */ var commonL10n = { warnDelete: "You are about to permanently delete the selected items.\n 'Cancel' to stop, 'OK' to delete." }; try{convertEntities(commonL10n);}catch(e){}; var setPostThumbnailL10n = { setThumbnail: "Use as featured image", saving: "Saving...", error: "Could not set that as the thumbnail image. Try a different attachment.", done: "Done" }; try{convertEntities(setPostThumbnailL10n);}catch(e){}; /* ]]> */ </script> <script type='text/javascript' src='http://xxx.com/wp-admin/load-scripts.php?c=1&amp;load=hoverIntent,common,jquery-color,imgareaselect,image-edit,set-post-thumbnail&amp;ver=6356b0bc2df931d1f1d78f0d91f6539d'></script> <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script> <?php } </code>
|
As Apple might've put it " There's a plugin for that " :) ( Faster Image Insert )
|
Put the media uploader in a metabox
|
wordpress
|
I've got problems getting pretty permalinks to work. When changing the permalinks (e.g. to month/name), my .htaccess (in the wordpress directory - there is another one one level up) is changed like this: <code> AddType x-mapp-php5 .php AddHandler x-mapp-php5 .php # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /wordpress/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wordpress/index.php [L] </IfModule> # END WordPress </code> But I still get 404s when trying to access an existing page. My blog is in the /wordpress/ subdirectory, not sure if that may be a problem. The URLs are both set to <code> http://<my domain>/wordpress </code> which is where my wordpress files are located. Any ideas what I can do, where I can see the results of the rewrite or anything else that would help me to track down the problem? Thanks in advance!
|
I've finally managed to track down the cause of the problem .. it was a Plugin that seems to have issues (Top Level Categories). I've looked into their documentation, but there is no indication that I would run into that problem. Hmmmm ... At least it's working now!
|
Problems redirecting to "pretty" permalinks (wordpress in Subdirectory)
|
wordpress
|
I will like to implement a few of the boilerplate template features in one of my instance WordPress. I am trying to figure out how to exchange the regular jquery calls below <code> <script type='text/javascript' src='http:/.../wp-includes/js/jquery/jquery.js?ver=1.4.4'></script> <script type='text/javascript' src='http://.../wp-includes/js/jquery/ui.core.js?ver=1.8.9'></script> </code> to this: <code> <!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script> <script>window.jQuery || document.write("<script src='js/libs/jquery-1.5.1.min.js'>\x3C/script>")</script> </code>
|
You should be loading jQuery with <code> wp_enqueue_script('jquery') </code> - that way, you won't end up with multiple instances if plugins try to load it too. To use Google CDN, place this in your <code> functions.php </code> ; <code> wp_deregister_script('jquery'); wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js', array(), '1.5.1'); </code> Update: Personally, and I know this sounds like a cop-out, but I wouldn't bother checking the CDN. Google is just so damn reliable, and it's more than likely it's already in the user's browser cache anyway (so many sites use Google's CDN). However , in my duty to answer, you have one of two options; Check server side with a remote get, and if it fails, serve the local copy (expensive and not recommended) Run a script client-side that checks for jQuery, and prints the fallback if necessary The trouble with 2) is that you need to inject this script right after jQuery, and before any other plugins that depend on it fire their scripts. The only way I know you can do this is to 'listen' for jQuery, then output the JavaScript on the next call. The magic? Drop this in your <code> functions.php </code> ; <code> if ( !is_admin() ) : /** * Hack to display fallback JavaScript *right* after jQuery loaded. */ function __jquery_fallback( $src, $handle = null ) { static $run_next = false; if ( $run_next ) { $local = '/js/libs/jquery-1.5.1.min.js'; echo <<<JS <script type="text/javascript">/*//<![CDATA[*/window.jQuery || document.write('<script type="text/javascript" src="$local"><\/script>');/*//]]>*/</script> JS; $run_next = false; } if ( $handle === 'jquery' ) $run_next = true; return $src; } add_filter( 'script_loader_src', '__jquery_fallback', 10, 2 ); add_action( 'wp_head', '__jquery_fallback', 2 ); endif; </code> For those in the know, this is also hooked to <code> wp_head </code> right after <code> wp_print_scripts </code> would have fired, in case there were no more scripts to print after <code> jquery </code> (the function does it's work on the next call, rather than the instance it is called with jQuery).
|
How to replace regular jquery calls with CDN calls from Google?
|
wordpress
|
Specifically, I'm talking about the following which gets added automatically: 1) <code> <script type='text/javascript' src='http://mysite.com/wp-includes/js/l10n.js?ver=20101110'></script> </code> 2) <code> <script type="text/javascript"> //<![CDATA[ var _wpcf7 = { cached: 1 }; //]]> </script> </code> 3) <code> <link rel="stylesheet" href="http://disqus.com/stylesheets/theme/disqus.css?v=2.0" type="text/css" media="screen" /> </code> 4) <code> <style type='text/css'> #wpadminbar .quicklinks li#wp-admin-bar-stats {height:28px} #wpadminbar .quicklinks li#wp-admin-bar-stats a {height:28px;padding:0} #wpadminbar .quicklinks li#wp-admin-bar-stats a img {padding:4px 11px} </style> </code> Not sure about #1, I know #2 is generated by the Contact Form 7 plugin, #3 is Disqus, and #4 is from the new admin bar in 3.1 and although I added <code> show_admin_bar( false ); </code> to my functions file, the styles still show up in my head section. Anyway to get rid of all or at least some of these?
|
1) Normally not (that's the translation mechanism offered for javscript strings), but you can probably de-register that l10n script. But be warned that some plugins and the site might not work as intended any longer. 2) Yes, by uninstalling the contact form 7 plugin. 3) Yes, by removing the disqus plugin. 4) If disabling the admin bar did not work, please report this as a bug in wordpress trac . I assume it left's over a registered hook to be removed, but that's just an assumption.
|
removing wordpress generated code from the head section?
|
wordpress
|
Is it possible to add a short description to a custom taxonomy's admin area? For example, I've added a taxonomy that determines what kind of banners are displayed on a post's page. In the meta box for this taxonomy on the Edit/Add Post page I'd like to add a little blurb explaining how it works.
|
I don't know of any hooks to add or filter the metabox so you can either create your own metabox to replace the custom taxonomy metabox or in this case just use JQuery <code> .append() </code> for example is your taxonomy is named banners and its none - hierarchical (like tags) then: <code> $('.tagsdiv-banners').append('<p>your short description here</p>'); </code> and if its hierarchical (like categories) <code> $('.bannersdiv').append('<p>your short description here</p>'); </code> the only difference is the name of the selector , for none hierarchical taxonomies you use tagsdiv-{$tax_name} and for hierarchical taxonomies you use {$tax_name}div.
|
Custom taxonomy admin description
|
wordpress
|
Hi is it possible to modify the login fields required to login into wp-admin? Say to use the email address instead of the username together with the password to gain access. How would I go about doing that? thanks
|
There are plugins which help to do this: With http://wordpress.org/extend/plugins/wp-email-login/ people can use their email address instead of their username to log into you WordPress install. Using http://wordpress.org/extend/plugins/theme-my-login/ you can have the WordPress login included in your design, and allow users to modify their account information without logging into the backend.
|
Modify WP-Admin login fields
|
wordpress
|
I spent almost an hour searching why my sidebar here: http://www.r-bloggers.com/ Is dropping to the bottom of the page. Could you please advise on how to fix it? Thanks.
|
Your <code> #leftcontent </code> div is not closed out with a closing <code> </div> </code> tag after your loop. Edit your index.php, find the Loop , and look for the end of the loop (usually it looks like <code> endwhile; endif; </code> . Add a closing <code> </div> </code> tag immediately after that (but outside of the <code> <?php ... ?> </code> tags).
|
CSS - why does my sidebar drops to the bottom of the page?
|
wordpress
|
I know the ultimate seo plugin for seo optimizing seo. But with more that 250 post, and no seo plugin installed, i like to know if there is a plugin that will 1) make the title of the page, the title of the post 2) make the description based on the first paragraph 3) make the keyword meta by parsing the whole post, retreive all the reveland word that are more that 3% occurence, and fill the meta with them any idea ?
|
take a look at WordPress SEO by Yoast it will cover : 1) make the title of the page, the title of the post 2) make the description based on the first paragraph as for your #3 make the keyword meta by parsing the whole post, retrieve all the relevant word that are more that 3% occurrence, and fill the meta with them I highly doubt you will find a plugin that does that for you, but there are a few like Keyword Density SEO-Tool - Keyword Density Checker which do chack that , so i guess you can use that to update your keywords.
|
Automatic SEO for wordpress
|
wordpress
|
I'm using the following to let the user login: <code> <form name='loginform' id='loginform' action='<?php echo get_settings('siteurl')?>/wp-login.php' method='post'> <label>User:</label><br /> <input type='text' name='log' id='user_login' class='input' tabindex='20' /><input type='submit' name='wp-submit' id='wp-submit' value='Login' tabindex='23' /><br /> <label>Pass:</label><br /> <input type='password' name='pwd' id='user_pass' class='input' tabindex='21' /> <span id="forgotText"><a href="<?php echo get_settings('siteurl')?>/wp-login.php?action=lostpassword"><?php _e('Forgot')?>?</a></span><br /> <?php //echo "<input name='rememberme' type='hidden' id='rememberme' value='forever' />";?> <?php echo wp_register('',''); ?> <input type='hidden' name='redirect_to' value='<?php echo htmlspecialchars($_SERVER['REQUEST_URI'])?>' /> </form> <?php global $opt_jfb_hide_button; if( !get_option($opt_jfb_hide_button) ) { jfb_output_facebook_btn(); //jfb_output_facebook_init(); This is output in wp_footer as of 1.5.4 jfb_output_facebook_callback(); } ?> </code> But it stays in the same page, how can I redirect the user to the home page?
|
I'm going to venture a guess here, and maybe someone more versed can back me up or set me straight But here: <code> <?php echo htmlspecialchars($_SERVER['REQUEST_URI'])?>' </code> Is the redirect value.... It is redirecting to the original url, wherever the user came from If you swap that out for your home url with something like: <code> <?php echo home_url( '/' ); ?> </code> I would think that would do it
|
Redirecting after login?
|
wordpress
|
I'm a relatively new Wordpress user, usually I just code my sites by hand though I'm trying to move to a CMS. I installed Wordpress onto a subforlder (http://www.iss.guild.uwa.edu.au/wordpress/) to test. Every now and again I would get warning messages like below, though starting today I started getting fatal errors. According to my server admin he has PHP 5.2.6 and MySQL 4.1.2 installed. Also it doesn't seem to help on whether I'm using Wordpress 3.1 or Wordpress 2.7 (which had been installed by someone else some time back and seemed to work)
|
The Health Check plugin is triggering the first error. Is this when you're running 2.7? <code> get_transient() </code> was only introduced in 2.8, which would explain it's absence. The second failure is merely a failed HTTP request. This can happen every now and then (mainly due to timeouts). It shouldn't interrupt the normal functioning of WordPress (the HTTP request was made by <code> wp-cron.php </code> , which is triggered as a separate request). The obvious advice is; Upgrade to 3.1 if you're not running it, now! Update any active plugins Ensure you are using a fairly regularly maintained theme (or if you built it yourself, make sure you're using best practices and have removed calls to any deprecated functions ).
|
Need help decrypting error and warning messages
|
wordpress
|
I am using the publish_post action to run some checks on a user after their post is published: <code> $author_ID = ???? add_action('publish_post', 'rhb_check_current_user', 10, $author_ID); </code> How can I get the original author's ID?
|
use <code> add_action('publish_post', 'rhb_check_current_user'); </code> and in your rhb_check_current_user function check using the global $post: <code> function rhb_check_current_user(){ global $post; $author_id = $post->post_author; ... ... } </code>
|
get author of published post
|
wordpress
|
I have a custom theme. There is no comments.php file, Wordpress is using whatever the default is. I need to modify the comments area, but I want to base my changes off of the default template. Where is the default template and how can I copy it into my own theme's comments.php? UPDATE Sorted it out for myself. The following directory contains default fallbacks if a file is not specified in your custom theme - <code> \wordpress\wp-includes\theme-compat\ </code> I copied the comments.php file from there over to my custom theme and am ready to rock. I was told in a WordPress forum that this file is deprecated though and I should really be building my own.
|
I got some help from Wordpress forum. As of Wordpress 3.1 a function called <code> comment_form() </code> creates the submit comment area. You can override default settings by creating an argument list and passing it in as a parameter. Here is a quick example where I change the default header Reply to Comment and then remove the acceptable tags section at bottom of form. <code> $comments_settings = array( 'title_reply' => 'Comment', 'comment_notes_after' => '' ); comment_form($comments_settings); </code>
|
Default comments file and how to copy it
|
wordpress
|
I've read about the WP enqueue_script() function, but if I wanted to use a newer version of jQuery than what my WP installation is using, can I load it through this & WP will use the latest version? or will it load both? or what will happen? Thanks!
|
To replace the default jQuery url, do: <code> wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', 'your custom url', ... ); </code> Then call <code> wp_enqueue_script( 'jquery' ); </code> as usual. Note that various pages in the WP admin might not be compatible with never versions of jQuery, not to mention plugin scripts.
|
Loading a newer version of jQuery within WordPress
|
wordpress
|
I'm tired of editing functions.php every time I want to add/remove a sidebar. I know there is Sidebar Generator plugin , but I wanted to develop something on my own that will work out of the box without plugins. Anyways, I already know how to list all sidebars, how to register them and remove, but I'm not sure how to do this automatically from options page (I have one already of course). I've analyzed the plugin's code but my PHP sucks so I don't understand half of it or even more. Maybe someone here developed own sidebar generator and can help me with basics like how to register new sidebar using $_POST etc.? I was thinking about fopen("functions.php", "r+"), but I'm not sure about this method, because it could even wipe out the whole functions.php file if used wrong, searching for already registered widgets could be painful too. I believe it'd be very useful to have something like that, and that's strange there's no in built sidebar generator in WP.
|
The code for this plugin is actually pretty simple. The init function loops through all the sidebars (stored in the wp_options table) and registers them in wordpress: <code> <?php function init(){ //go through each sidebar and register it $sidebars = sidebar_generator::get_sidebars(); if(is_array($sidebars)){ foreach($sidebars as $sidebar){ $sidebar_class = sidebar_generator::name_to_class($sidebar); register_sidebar(array( 'name'=>$sidebar, 'before_widget' => '<li id="%1$s" class="widget sbg_widget '.$sidebar_class.' %2$s">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle sbg_title">', 'after_title' => '</h2>', )); } } } ?> </code> The sidebars are added/removed with the add_sidebar() and remove_sidebar() methods respectively. The $_POST['sidebar_name'] gets stored in the $name variable as the sidebars name: <code> <?php function add_sidebar(){ $sidebars = sidebar_generator::get_sidebars(); $name = str_replace(array("\n","\r","\t"),'',$_POST['sidebar_name']); $id = sidebar_generator::name_to_class($name); if(isset($sidebars[$id])){ die("alert('Sidebar already exists, please use a different name.')"); } $sidebars[$id] = $name; sidebar_generator::update_sidebars($sidebars); $js = " var tbl = document.getElementById('sbg_table'); var lastRow = tbl.rows.length; // if there's no header row in the table, then iteration = lastRow + 1 var iteration = lastRow; var row = tbl.insertRow(lastRow); // left cell var cellLeft = row.insertCell(0); var textNode = document.createTextNode('$name'); cellLeft.appendChild(textNode); //middle cell var cellLeft = row.insertCell(1); var textNode = document.createTextNode('$id'); cellLeft.appendChild(textNode); //var cellLeft = row.insertCell(2); //var textNode = document.createTextNode('[<a href='javascript:void(0);' onclick='return remove_sidebar_link($name);'>Remove</a>]'); //cellLeft.appendChild(textNode) var cellLeft = row.insertCell(2); removeLink = document.createElement('a'); linkText = document.createTextNode('remove'); removeLink.setAttribute('onclick', 'remove_sidebar_link('$name')'); removeLink.setAttribute('href', 'javacript:void(0)'); removeLink.appendChild(linkText); cellLeft.appendChild(removeLink); "; die( "$js"); } function remove_sidebar(){ $sidebars = sidebar_generator::get_sidebars(); $name = str_replace(array("\n","\r","\t"),'',$_POST['sidebar_name']); $id = sidebar_generator::name_to_class($name); if(!isset($sidebars[$id])){ die("alert('Sidebar does not exist.')"); } $row_number = $_POST['row_number']; unset($sidebars[$id]); sidebar_generator::update_sidebars($sidebars); $js = " var tbl = document.getElementById('sbg_table'); tbl.deleteRow($row_number) "; die($js); } ?> </code> The sidebars are loaded and registered into the theme with the get_sidebar method <code> <?php function get_sidebar($name="0"){ if(!is_singular()){ if($name != "0"){ dynamic_sidebar($name); }else{ dynamic_sidebar(); } return;//dont do anything } global $wp_query; $post = $wp_query->get_queried_object(); $selected_sidebar = get_post_meta($post->ID, 'sbg_selected_sidebar', true); $selected_sidebar_replacement = get_post_meta($post->ID, 'sbg_selected_sidebar_replacement', true); $did_sidebar = false; //this page uses a generated sidebar if($selected_sidebar != '' && $selected_sidebar != "0"){ echo "\n\n<!-- begin generated sidebar -->\n"; if(is_array($selected_sidebar) && !empty($selected_sidebar)){ for($i=0;$i<sizeof($selected_sidebar);$i++){ if($name == "0" && $selected_sidebar[$i] == "0" && $selected_sidebar_replacement[$i] == "0"){ //echo "\n\n<!-- [called $name selected {$selected_sidebar[$i]} replacement {$selected_sidebar_replacement[$i]}] -->"; dynamic_sidebar();//default behavior $did_sidebar = true; break; }elseif($name == "0" && $selected_sidebar[$i] == "0"){ //we are replacing the default sidebar with something //echo "\n\n<!-- [called $name selected {$selected_sidebar[$i]} replacement {$selected_sidebar_replacement[$i]}] -->"; dynamic_sidebar($selected_sidebar_replacement[$i]);//default behavior $did_sidebar = true; break; }elseif($selected_sidebar[$i] == $name){ //we are replacing this $name //echo "\n\n<!-- [called $name selected {$selected_sidebar[$i]} replacement {$selected_sidebar_replacement[$i]}] -->"; $did_sidebar = true; dynamic_sidebar($selected_sidebar_replacement[$i]);//default behavior break; } //echo "<!-- called=$name selected={$selected_sidebar[$i]} replacement={$selected_sidebar_replacement[$i]} -->\n"; } } if($did_sidebar == true){ echo "\n<!-- end generated sidebar -->\n\n"; return; } //go through without finding any replacements, lets just send them what they asked for if($name != "0"){ dynamic_sidebar($name); }else{ dynamic_sidebar(); } echo "\n<!-- end generated sidebar -->\n\n"; return; }else{ if($name != "0"){ dynamic_sidebar($name); }else{ dynamic_sidebar(); } } } ?> </code> We actually load the sidebar array from the wp_options table with the following: <code> <?php function get_sidebars(){ $sidebars = get_option('sbg_sidebars'); return $sidebars; } ?> </code> This code is really pretty simple once you know PHP, so may I suggest taking a little time to become more familiar with it? It really is a great skill to have. Hopefully this helps point you in the right direction.
|
Sidebar Generator? :)
|
wordpress
|
I know, wp_head() is important, but it inject so much crap into the header, i like to get it out... and just add manually the 2-3 line of code i need.. BUT, and there is always a but, i need the wordpress auto-generated code for : <code> <meta name="description" content="" /> <meta name="keywords" content="" /> <link rel='canonical' href='http://jlecologia.com/cms/' /> (why not!) and <meta http-equiv="Content-Language" content="fr-FR" /> </code> How i can ask for the generation of that... ???? something like : bloginfo('name') will be fine for me Thanks
|
You can remove some of the header stuff with the following. <code> // remove unncessary header info function remove_header_info() { remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'start_post_rel_link'); remove_action('wp_head', 'index_rel_link'); remove_action('wp_head', 'adjacent_posts_rel_link'); } add_action('init', 'remove_header_info'); </code> The default installation does not include stuff like meta keywords, so that is either a theme or plugin that you are using.
|
Wordpress wp_head() crap
|
wordpress
|
I'm in the midst of building a Wordpress Plugin that adds a custom post type, for which I'd like to include a default template to display. Essentially, this is an event management plugin, and the custom post type is for the Events. There's a handful of custom meta fields, as well as a child post type (Performances), so without a default template to display them, using it would be pretty unfriendly. But I would like theme designers to be able to create their own templates for these post types if desired. Is there a way to use the the template provided with my plugin unless the theme provides its own template? What's the best practice for doing so? Edit: Following the advice of Peter Rowell, I caught the template_redirect action and, if the post type was one of mine and a template for it did not exist in the current theme, defaulted to the plugin's template: <code> class FestivityTemplates { public static function determineTemplate(){ global $post; $standard_type = strpos($post->post_type, 'fest_'); if(is_single() && $standard_type !== false) { FestivityTemplates::loadSingleTemplate($post); } } private static function loadSingleTemplate($post) { $template_name = 'single-'.$post->post_type.'.php'; $template = locate_template(array($template_name), true); if(empty($template)) { include(WP_PLUGIN_DIR . '/Festivity/lib/templates/' . $template_name); exit(); } } } add_action('template_redirect', array('FestivityTemplates', 'determineTemplate')); </code>
|
You might want to look at the routine that WP uses for this: <code> locate_template() </code> . It is in <code> wp-includes/theme.php </code> and is called from a number of functions in that file. Those functions are used by <code> wp-includes/template-loader.php </code> to select the correct type of template based on the current page and then walk up the theme hierarchy looking for a match.
|
Creating a default Custom Post Template that a Theme can override
|
wordpress
|
suppose you are viewing a single image from the gallery. You have both previous and next links there (for navigation). but is there a way to also show all the other images from the same gallery in the same page (for example i want to show other images from same gallery) if there is a way then can anyone please provide me the simplest code please.
|
At it's very simplest, add this to your theme's <code> attachment.php </code> <code> <?php do_shortcode('[gallery id="' . $post->post_parent . '"]'); ?> </code>
|
show other images from same gallery
|
wordpress
|
EDIT: I want to update one field (post_content) within a known record (id of 4) of a known table (wp_posts) in a new database (new_db). The update has to come from one field (post_content) within a known record (id of 5) of a known table (wp_posts) in the old database (old_db). Is this possible, or is something like this too atomic (?) for MySQL? Greetingz! When manipulating WordPress's database directly, I've seen stackexchange-url ("many examples here") where people replace a URL like so; <code> mysql> UPDATE wp_db.wp_post SET post_content=REPLACE(post_content, 'http://oldsite', 'http://newsite' ) ; </code> However, I have a .sql dump file from my old site, that I wish to import correctly. (I cannot create an XML export file, it's too late) I have created "dummy" posts on my new blog, and have imported the old database. Now I'm trying to do something like this; <code> UPDATE new_db.new SET post_content = REPLACE(post_content,(SELECT post_content FROM old_db.wp_posts WHERE id = oldpost#) WHERE id = newpost#; </code> I realize I'll have to do this for post_date, post_title, and post_content between old_db.wp_posts and new_db.posts, I'm just hoping this is actually possible somehow....
|
Seems like trying to put "field X" into db.table.record.fieldY is too atomic, or requires a better magic wand than google can find. I've gone a head and just ripped the posts out wholesale and injected them into the new DB. Here's how I did it. I hope it helps the next poor sod who finds himself in the same place I was... How to rip out and inject WordPress posts from an old database into a new one. 0) Make a backup first of the new DB. <code> mysqldump -u root -p new_db >> dump-new_db-datetime.sql </code> 1) first, find all your old published posts & pages; <code> SELECT id,post_date,post_title FROM old_db.old_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY id; </code> 2) Delete all your revisions with; <code> DELETE FROM old_posts WHERE post_type = "revision"; </code> 3) inject your old posts & pages into the new DB <code> INSERT INTO new_db.new_posts ( post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count ) SELECT old_posts.post_author, old_posts.post_date, old_posts.post_date_gmt, old_posts.post_content, old_posts.post_title, old_posts.post_excerpt, old_posts.post_status, old_posts.comment_status, old_posts.ping_status, old_posts.post_password, old_posts.post_name, old_posts.to_ping, old_posts.pinged, old_posts.post_modified, old_posts.post_modified_gmt, old_posts.post_content_filtered, old_posts.post_parent, old_posts.guid, old_posts.menu_order, old_posts.post_type, old_posts.post_mime_type, old_posts.comment_count FROM old_db.old_posts; </code>
|
MySQL: Possible to replace all of wp_posts.post_content(id#) via UPDATE + REPLACE + SELECT?
|
wordpress
|
I have installed the more fields plugin which gives me access to a custom field checkbox. When setting the field up through the plugin the caption says: Creates single checkbox, which key is either on/off. As you can see by the query I am looking for all the events whose event-archive = on. Is there a better way to do this? This doesn't return any posts anyways. Is there a better way to build a boolean field? <code> $archive_query = new WP_Query( array( 'post_type' => 'event', // only query events 'meta_key' => 'event-archive', // load up the event_date meta 'order' => 'desc', // ascending, so earlier events first 'posts_per_page' => '5', 'meta_query' => array( array( // restrict posts based on meta values 'key' => 'event-archive', // which meta to query 'value' => 'on', // value for comparison 'compare' => '=', // method of comparison 'type' => 'CHAR' // datatype, we don't want to compare the string values ) // meta_query is an array of query ites ) // end meta_query array ) // end array ); // close WP_Query constructor call </code>
|
Have you already looked at the output of WP_Query, if you don't submit the "meta_query" key? Do you get the posts for the event-posttype? If yes, then you could check what the "more fileds"-plugin puts in the "event-archive" custom field. Maybe you have to set the value to integer 1 or just submit a boolean true. e.g. <code> array( 'key' => 'event-archive', 'value' => 1 ) array( 'key' => 'event-archive', 'value' => true ) </code> EDIT I've just installed the plugin, created a new meta field "event-archive" of type "checkbox" and some posts with and without this meta value. If I use the following query, I get all posts from posttype "event" with the metavalue selected. <code> $args = array( 'post_type' => 'event', 'order' => 'desc', 'posts_per_page' => '5', 'numberposts' => -1, 'meta_query' => array( array( 'key' => 'event-archive', 'value' => 1, 'compare' => '=', 'type' => 'CHAR' ) ) $archive_posts = get_posts($args); print_r($archive_posts); </code> Note You can also use WP_Query if you like The "meta_query" parameter requires WordPress 3.1
|
custom field as a boolean with a checkbox?
|
wordpress
|
I'm returning a custom hierarchal taxonomy via wp_get_object_terms. The trouble is that the results are being ordered by name or count, neither of which are proving reliable. (I'm using a custom taxonomy for "Location" - City, State, Country - sometimes the State appears before the City) Is there a way I can order the resulting array by the custom taxonomy hierarchy? Is there, perhaps, another way I should be looking at this?
|
Just a rough sketch to get your idea: countries (hierarchical taxonomy) France (country - sub taxonomy) Champagne (state - sub sub taxonomy) Le Mans (city - term) Angers (city - term) Nantes (city - term) And you want to order: <code> $query_results = query( 'country' => 'france', 'orderby' => 'state city', 'order' => 'ASC' ); </code> Did i get this right? If not, feel free to edit my answer or update your Q.
|
wp_get_object_terms - How can I order the resulting array by hierarchy?
|
wordpress
|
Is it possible to filter the posts or categories that XML-RPC users see in their mobile application? I have a plugin that hooks into <code> pre_get_posts </code> and <code> list_terms_exclusions </code> to do what I need it to do. I've had requests to allow the same functionality on their mobile devices.
|
Okay, so I discovered the answer to my question. It is possible to filter the posts and categories that users see in their XML-RPC application. The <code> pre_get_posts </code> and <code> list_terms_exclusions </code> filters are called via the blogger.getRecentPosts XML-RPC method. Inside this function, it calls <code> wp_get_recent_posts </code> which uses <code> get_posts </code> . In other words, there's really nothing special you have to do if you are hooking into the above filters. My problem was that for my plugin, I was only filtering while in the admin: <code> if ( is_admin() </code> SOLUTION In order to make sure it only fires when requested through an XML-RPC application, all you have to do is check for the XMLRPC_REQUEST constant and hook into the <code> xmlrpc_call </code> action. <code> if ( defined ( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) { add_action( 'xmlrpc_call', array( &$this, 'posts' ) ); } </code> Inside your callback, hook into the <code> pre_get_posts </code> and <code> list_terms_exclusions </code> filters.
|
Possible to filter the posts or categories that XML-RPC users see in their mobile application?
|
wordpress
|
I want to convert a HTML/CSS layout i made into a WordPress Theme, But i don't know any PHP, I have a basic idea of the structure of a WordPress Theme, So i was wondering if i could just slice my HTML template into a header.php, footer.php, sidebar.php and index.php and just copy paste all the php code bits from the default twentyten theme? I've been going through the twentyten theme files and i have come across some bits of code where it says 'twentyten', for example: <code> // Add a page number if necessary: if ( $paged >= 2 || $page >= 2 ) echo ' | ' . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) ); </code> and <code> <div class="skip-link screen-reader-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentyten' ); ?>"><?php _e( 'Skip to content', 'twentyten' ); ?></a></div> </code> Can i just replace the text that says 'twentyten' with my theme's name? Or should i just leave it that way?
|
You have the basic idea. You can build up a theme using html and css as you see fit. That controls the look and feel basically. The php brings the content and function. I learned to make themes by picking at other themes until I figured out what the php did. You can look up each template tag in the codex to get an idea of what it does The 'twentyten' you refer to would do nothing in your theme unless you do it properly. Nor would changing it. that refers to the text domain...you can see this in twentyten's functions.php <code> // Make theme available for translation // Translations can be filed in the /languages/ directory load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' ); </code> it is the textdomain for being able to translate the theme. In your example code it is so that the word Page can be translated to the user language http://codex.wordpress.org/Function_Reference/load_theme_textdomain http://codex.wordpress.org/I18n_for_WordPress_Developers For personal themes you will never release, it's not necessarily so important. But it's great to learn how to use. And its necessary if you ever plan to release a theme
|
Making a Wordpress theme based on twentyten
|
wordpress
|
When a new blog is created in a WP Multisite instance I want to be able to set the default theme and configuration options create 2 menus (main and secondary) and associate them with the 2 slots provided by the theme set various theme options as defined on the theme option page What's the best way to go about achieving this? which hook should i use - I'm going to use this: ('WP_DEFAULT_THEME', 'theme-folder-name' in wp-config.php to set the default theme - unless this prevents a needed hook from firing. easiest way to programatically create menus and associate them with existing theme menu 'slots'
|
The best hook I can find is <code> wpmu_new_blog </code> (line 1086, <code> wp-includes/ms-functions.php </code> , <code> wpmu_create_blog() </code> ) - it passes 6 arguments like so; <code> do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta ); </code> <code> $meta </code> is an array of initial site options, not to be confused with the options generated by <code> populate_options() </code> . Programatically creating nav menus may prove to be a little tricky, as there is no 'API' as such - they're a mix of posts, post meta and <code> nav_menu </code> terms, coupled with a few available functions such as <code> is_nav_menu_item() </code> and <code> wp_setup_nav_menu_item() </code> . My best advice would be to check out <code> wp-admin/nav-menus.php </code> , as this is where all the core code lies for creating menus. Using <code> WP_DEFAULT_THEME </code> should be fine, and is probably the best approach too.
|
Multisite: setting theme and options when a new blog is created
|
wordpress
|
After using this code: <code> //Set custom featured image metabox function customposttype_image_box() { remove_meta_box('postimagediv', 'eezzyweb-webfolio', 'side'); add_meta_box('website_grid_view', __('Featured Image for grid view'), 'post_thumbnail_meta_box', 'eezzyweb-webfolio', 'side', 'low'); } add_action('do_meta_boxes', 'customposttype_image_box'); </code> and afterwards removing it, the Featured Image metabox is at the bottom, not on the right side anymore... Is there something I need to reset/unregister??? Thank you
|
The <code> add_meta_box </code> code you've posted does certainly register the metabox to the bottom of the side area. If the box is shown in the center then i imagine it's because you've(at some point) moved the metabox, as can be done with any of the metaboxes(all drag and drop). WordPress remembers where you move boxes to, and only adheres to the positioning inside the <code> add_meta_box </code> as a default view(when they've not yet been moved). The solution would be to drag and drop the box back to the side area, assuming this is just a case of re-positioning the metabox.
|
Featured Image meta box shows at the bottom?
|
wordpress
|
Setting up a WP multisite instance - the client has an existing ontology / set of categories that they want to classify all content across the set of blogs. Also the desire is that any new categories would be added at the 'network blog' level and synced to the other blogs. What's the best way of doing this?
|
<code> function __add_global_categories( $term_id ) { if ( get_current_blog_id() !== BLOG_ID_CURRENT_SITE || ( !$term = get_term( $term_id, 'category' ) ) ) return $term_id; // bail if ( !$term->parent || ( !$parent = get_term( $term->parent, 'category' ) ) ) $parent = null; global $wpdb; $blogs = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}'" ); foreach ( $blogs as $blog ) { $wpdb->set_blog_id( $blog ); if ( $parent && ( $_parent = get_term_by( 'slug', $parent->slug, 'category' ) ) ) $_parent_ID = $_parent->term_id; else $_parent_ID = 0; wp_insert_term( $term->name, 'category', array( 'slug' => $term->slug, 'parent' => $_parent_ID, 'description' => $term->description )); } $wpdb->set_blog_id( BLOG_ID_CURRENT_SITE ); } add_action( 'created_category', '__add_global_categories' ); </code> This will run whenever a category is added on the main site. A few caveats/points worth mentioning; If you have a lot of blogs, this function may get pretty intensive. On average, we are running anywhere between 5 to 8 queries (possibly more) per blog - depending on the speed of your database, this function may need to be chunked. Only newly added categories are 'synced'. Updating and deleting categories are not (code will need to be revised). If a newly added category has a parent, and the parent cannot be found within the multisite blog in question, the category will be created with no parent (this should only be the case if the parent category was created before this function was installed).
|
WordPress Multisite - global categories
|
wordpress
|
I'm writing a plugin and want to have a feature where, in the Admin area, the user will click on a link and it will download a theme to the /themes directory on their server. How would I do this? Thanks.
|
Ehm... You are writing the plugin or thinking about it? Could you show us some stuff that you already did? You should check the permissions on the server where you want to upload the files. Then - in case - change chmod, upload and then change chmod back for sec. reasons. Maybe the update class will help you a little further.
|
Create a Plugin to Download Files from Web to Server
|
wordpress
|
[box id='1' text="some texte"] the shortcode, at one point is outputting text the html result is : <code> </p> some text </p> </code> There is an extra closing paragraph in the start and and opening at the end... WHY ? where those come from ?.... any idea ?.. it screw my w3 validation ! ** note i have found that... but look all "patched" to me...any clean solution... wp is dirty ? reference
|
I discover that it's a know bug, and will be fix in future release Reference here So then, i used this code... not pretty, but do the magic !, thanks <code> $content = do_shortcode( shortcode_unautop( $content ) ); if ( '</p>' == substr( $content, 0, 4 ) and '<p>' == substr( $content, strlen( $content ) - 3 ) ) $content = substr( $content, 4, strlen( $content ) - 7 ); return '<div my stuff>' . $content . '</div>'; </code>
|
ShortCode and extra
|
wordpress
|
I tried asking the plugin author and while waiting for a response I figured I'd give this place a try too. This is what wordpress-popular-posts.php looks like: pastebin Is there something I can change in there to include custom post types? Maybe somewhere around line 132 since I'm calling the <code> wpp_get_mostpopular </code> function? I suppose I'd need to add custom post types to the list of arguments but I'm not sure where that would be.
|
Not sure if this is the right place... but line 496 <code> $nopages = "AND $wpdb->posts.post_type = 'post'"; </code> seems to be the only place I see any post selection limited to just post When I've messed around with other plugins, to add in CPTs, I'v elooked for similar selection criteria. And added in my own CPTs. So the first place I would mess around is here. I'm not a coder, so I'm not sure exactly how to add in the CPT here.... <code> $nopages = "AND $wpdb->posts.post_type = 'post', 'cpt', 'another'"; </code> or if it has to be in an array <code> $nopages = "AND $wpdb->posts.post_type = array( 'post', 'cpt', 'another' )"; </code> , or what..... I'm sure you know to have a backup available, and that if you get the syntax wrong, you could kill the plugin, or your site. But as long as you can ftp in, no harm no foul really. I know I've killed my sites a few times doing stuff like this. Its why I have a dev install of WP that is pretty much a copy of my live site.... so I can poke it with a stick to see what happens
|
Plugin: Wordpress Popular Posts > Possible to include custom post types?
|
wordpress
|
is there a built-in wordpress function to make the HTML or should I use plain-old PHP?
|
Since 3.1 there's a class <code> WP_List_Table </code> which makes it a hella lot easier to render tables for an array of data objects. There's very little documentation (read: none) on it yet, but you can check out the source if you're familiar with PHP.
|
How do I make an HTML table from a database table?
|
wordpress
|
I am developing a Wordpress site that will have a database of car modifications and an embedded youtube video with the results. For example: search for Honda Civic with a spoiler and exhaust. This would generate several posts. Each post has there own video, attributes, and an adsense ad. I am using the term posts loosely though, I really don't want to post them on the blog of the site. I am struggling to see how (if) this can work with the custom post type and taxonomy features in 3.0. Also I found this $200 theme on WooThemes, I'm not positive it will work and they wont talk to me about technical stuff unless i'm a "member". I would Like to insert youtube videos instead of their dealer listing, but it seems like the theme is a great start. WooThemes - "Listings" Thanks for any help and insight, I am at my wits end try to see if this is do-able.
|
Register a 'car' post type . Register 'spoiler' and 'exhaust' taxonomies to the 'car' post type. Use the Taxonomy Drill-Down plugin to create the "search" you need. The YouTube video URL could be stored as a custom field .
|
Having trouble understanding custom post type and taxonomy :/
|
wordpress
|
How would we query posts as long as the post does not equal the ID 2047? Here is the current query. <code> <?php $args1 = array( 'post_type' => 'options', 'tag_slug__and' => array( $triplevel, $divingtrip, 'accommodation' ), 'posts_per_page' => -1, 'offset' => 1, ); query_posts( $args1 ); while (have_posts()) : the_post(); ?> </code> I tried this... <code> query_posts( $args1 . 'p!=2047' ); </code> ..to no effect. Any ideas? Marvellous
|
Most of the things you can do with a query are described in the Codex page for WP_Query You need to use the 'post__not_in' parameter eg: <code> $args = array( 'post__not_in' => array('34','54'), // post ids 'post_type' => 'page' );` </code>
|
Query posts without a specific ID
|
wordpress
|
Is there a simple or easy way to exclude all posts from a custom taxonomy in the loop? I've been looking high and low, and neither SE, SO or Google seem to have a straight answer. I know it can be done via a WPDB query, but that just seems like massive rope to jump for something that should be fairly simple.
|
The solution to this isn't really that publicised, but it should be. You can do the following: <code> $args['tax_query'] = array( array( 'taxonomy' => 'category', 'terms' => array('cat', 'dog'), 'field' => 'slug', 'operator' => 'NOT IN', ), ); query_posts($args); </code> The operator argument can take other terms, but the above code is basically saying get all posts from the taxonomy 'category' that don't have the terms 'cat' or 'dog'.
|
How do I exclude a custom taxonomy from the post loop
|
wordpress
|
I've just installed XAMPP on Mac OSX and when trying to install a theme or plugin in WP admin, I'm getting this screen. I've never gotten this on my shared hosting account. how to get rid of it on localhost?
|
Hi @Scott B: Have you tried updating the permissions for your WordPress files to 755 or 777? UPDATE 1 Thanks to @anu in the comments ( <code> ~/Sites </code> assumes you put websites are in the Mac's default website directory): <code> cd ~/Sites sudo chmod -R 777 * </code> I just checked my <code> httpd.conf </code> file and here is what I found starting on line 127 so I think @gabrielk's answer is probably what you need. <code> # running httpd, as with most system services. # User mikeschinkel Group everyone </IfModule> </IfModule> </code> UPDATE 2 If you were to decide to use the built-in Apache a tool you should definitely consider getting for the Mac is VirtualHostX . It manages all your Apache and your hosts files for setting up local "domains" . It's one of my favorite tools on the Mac:
|
How to remove "Connection Information" requirement on localhost install of WP on MACOSX
|
wordpress
|
I'm using the FLIR for Wordpress plugin (v0.8.9.2) with FancyFonts enabled. I'm running Wordpress 3.1. The problem I'm having is that it appears the plugin is cutting off a couple pixels off of the end of some of the text that it generates. It doesn't do it for all text, but where it happens, it happens consistently. Here are some examples: In my search for a solution, I've found a number of people with this issue, but never any solutions. Any ideas would be greatly appreciated. Thank you!
|
Copy & Paste from comment. Seems like the plugin has a bug. The plugin doesn't seem to be actively maintained anyway, but your best bet is to contact the plugin author. The cufon project is pretty similar and production proven. Just google for it. But in times of CSS3 and HTML5 you could simply insert the font via @font-face. Edit: It is totally safe to use @font-face these days. IE actually supports font-face since IE4 via the .eot format. Not as nice as using the .otf like modern browsers do, but far better than any other solution.
|
Wordpress FLIR (Facelift Image Replacement) plugin clipping off end of text
|
wordpress
|
<code> <?php $rp = new WP_Query(array( 'post_type' => array( 'post','videos','projects' ), 'orderby' => 'date&order=DESC', 'posts_per_page' => 4 )); while ($rp->have_posts()) : $rp->the_post(); ?> </code> I noticed that if I change <code> date&order=DESC </code> to <code> rand </code> , it makes no difference, meaning the posts don't show up in random order even after multiple refreshes. Is there something wrong w/ this code?
|
It should be this: WP_Query Order By Parameters <code> <?php $rp = new WP_Query(array( 'post_type' => array( 'post','videos','projects' ), 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => 4 )); while ($rp->have_posts()) : $rp->the_post(); ?> </code>
|
Is there something wrong w/ this code?
|
wordpress
|
i have category-events.php to list my posts tagged 'events' but it wont work for 'events' child categories. ie i have some posts tagged 'events' and one of events' children 'exhibition'. I thought it would use category-events.php automatically but it doesn't. Is this possible as i want to user category-events.php for several of 'events' child categories. hope that makes sense and any pointers welcome. dan.
|
ah - found it here! stackexchange-url ("How can I make all subcategories use the template of its category parent?") thanks...
|
one category template for multiple categories
|
wordpress
|
I've been working away at a medium-size WordPress site. So far I've just been hosting the site on my local machine and showing it to internal consultants over our local network. Things are working well, and now it's time to show it off to the client. I've been using git all along, so pushing it to the dev server was a breeze. I duplicated the local DB and pushed it to the dev server manually, which was fairly easy except that I had to manually change a few URL entries. Now my question is: what's the best way to keep two instances of WordPress synced? I still have more work to do locally and the DB is going to need to get pushed up again. How do other people manage this in an automated way? One thought I had was to write a git hook to pull the MySQL data down when I push from my local machine and have a hook on the other end to import the data when the dev server pulls. However, if I do this I'll have to worry about changes to the wp_options table. Does anyone have any strategies for making this sort of thing easy? Thanks!
|
Assuming your wp-config.php is already in place and in order: Step 1. Mysqldump your development database Step 2. Replace all instances of development.domain.com to production.domain.com^^ Step 3. Login to MySQL, run a SOURCE command to import data e.g. <code> source /path/to/file </code> ^^ How to replace all instances of old domain with new: (1) Copy the script below. (2) <code> chmod +x </code> it. (3) Run it. Usage: <code> ./script.sh development-dump.sql > production-dump.sql </code> <code> #!/bin/sed -f s/'\([^\']*\)development.domain.com\([^\']*\)'/'\1production.domain.com\2'/g </code>
|
Migrating data between local and development server
|
wordpress
|
I'd like to employ a sort order option in my theme to allow categories to be sorted similar to pages. Can anyone recommend a plugin that does this?
|
I needed this requirement a while back. There's a selection of plugins available , but nothing took my fancy. They were (in my opinion) either too bloated, poorly written, or the UI was either lacking or overly complex. Then I stumbled upon Term Menu Order . Essentially it adds a <code> menu_order </code> field to the terms database, and you use it the same way as the menu order for pages. Very simple, does the job! NB: I actually took the concept and rewrote in what I considered an improvement. It's oh-so-slightly less heavy on memory Adds a simple <code> orderby=term_order </code> argument available for term function Can control which taxonomies support ordering, either through the <code> register_taxonomy() </code> call or with WordPress hooks Fixes one particular flaw - same terms in different taxonomies will share the same order, my plugin fixed this If this takes your fancy I can share :) My spin on the Term Order Plugin (MediaFire) The MediaFire upload has had it's day, apologies. Will get a replacement set-up, perhaps on GitHub, soon...
|
Plugin for custom sort order for categories?
|
wordpress
|
I'm having a lot of trouble using php query_posts(array('category__and'=> array(1,3))) - it seems to be pulling anything that's in category 1 regardless of whether it's also in category 3 and I only want the posts if they exist in both categories. And ultimately, I need a bunch of OR statements anyway, so is there a better way than query_posts to do this? I want a page of posts that exist in a variety of multiple categories -- i.e: categories 1 AND 3 OR categories 1 AND 5 OR categories 1 AND 6 But not categories 1 AND 4 Any help would be greatly appreciated. Thanks.
|
Strange, that usage of <code> category__and </code> should be working. As for following logic I don't think you can accomplish anything that complex with query parameters. There are several possible ways to deal with it that I can think of: simplify category structure and/or selection logic; modify raw SQL with <code> posts_where </code> filter; store selection criteria in post meta.
|
And/Or Category Query
|
wordpress
|
Is there a way to send the updated/added values from profile, when a member/user updates his/hers data, to the admin of the site or another emailadress? Can this be the first step? <code> /* do something when user edits profile */ add_action('personal_options_update', 'notify_admin_on_update'); function notify_admin_on_update(){ // send a mail with the updated values to [email protected] exit; } </code> What is best pracice to send emails from within WordPress?
|
you got the first part right about using <code> personal_options_update </code> but to be on the safe side add <code> edit_user_profile_update </code> also. and as for sending emails within WordPress the best way would be to use wp_mail , So something like this: <code> add_action( 'personal_options_update', 'notify_admin_on_update' ); add_action( 'edit_user_profile_update','notify_admin_on_update'); function notify_admin_on_update(){ global $current_user; get_currentuserinfo(); if (!current_user_can( 'administrator' )){// avoid sending emails when admin is updating user profiles $to = '[email protected]'; $subject = 'user updated profile'; $message = "the user : " .$current_user->display_name . " has updated his profile with:\n"; foreach($_POST as $key => $value){ $message .= $key . ": ". $value ."\n"; } wp_mail( $to, $subject, $message); } } </code>
|
Send automatic mail to Admin when user/member changes/adds profile
|
wordpress
|
Whereabouts can I edit which characters in permalinks are replaced? For example apostrophe's are replaced with nothing, and I would like to have them replaced with hyphens instead. Thanks.
|
You need to filter <code> 'sanitize_title' </code> and use the second argument, the raw title. See my plugin Germanix for an example.
|
Editing URL character replacement
|
wordpress
|
I have no use in categorizing/tagging my posts with anything, at all, and it doesn't look very good to have every post say "filed under: uncategorized." Is there any plugin to do this, or do I need to do some manual editing?
|
Why hack apart what's already there? If you remove the built in taxonomies, you'll end up creating hiccups in core code that expect them to be there! You're much better off just editing your theme file(s), or filtering out categories on the front-end (ask if you need help on that). For example, in your theme's <code> index.php </code> and <code> single.php </code> , you might have something like; <code> filed under: <?php the_category( ', ' ); ?>. </code> Just remove it and you're done!
|
Is there a plugin that will completely remove the category system?
|
wordpress
|
I'm currently implementing wp_nav_menu - all has gone well save for dynamic highlighting. The menu code looks like this (when home, which is a custom link, is selected): <code> <div class="menu-header"> <ul class="menu" id="menu-main-nav"> <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-126" id="menu-item-126"><a href="path.to.link">Home</a></li> <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-122" id="menu-item-122"><a href="path.to.link">Information</a></li> <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-123" id="menu-item-123"><a href="path.to.link">Contact</a></li> <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-124" id="menu-item-124"><a href="path.to.link">About</a></li> </ul> </div> </code> When a page other than home (which is a 'custom link') is selected this is written out: <code> <li class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-65 current_page_item menu-item-122" id="menu-item-122"><a href="path.to.link">Information</a></li> </code> As you can see this includes an active style 'current-menu-item' where the custom link only writes 'menu-item-type-custom menu-item-object-custom' So my question is is there any way to add a selected item style for custom links in wp3 menus?
|
I achieved this with some jQuery: <code> $("#sidebar ul li").each(function () { if ($(this).find("a").attr("href") == window.location.href) { $(this).addClass("current-menu-item"); } }); </code> (My nav is in a div with the id 'sidebar', you will need to change the first selector). It checks if the href of the links is the same as the current URL, and if so, adds "current-menu-item". You can then style active links with the .current-menu-style class.
|
Custom Menus: dynamic highlighting problem with custom home link
|
wordpress
|
I use this code to pull in an image based on a post's category. Images are named after the category they represent, so a post in category 50 pulls in 50.jpg. <code> <?php foreach((get_the_category()) as $category) { echo '<img src="/path/to/file/' . $category->cat_ID . '.jpg" alt="' . $category->cat_name . '" />'; } ?> </code> I'd like to be able to do the same but to include a php file (also named after the category - so 50.php using the above example). What's the best way to do this?
|
<code> <?php foreach((get_the_category()) as $category) { if( file_exists( '/path/to/file/to/include/' . $category->cat_ID . '.php' ) ) include( '/path/to/file/to/include/' . $category->cat_ID . '.php' ); } ?> </code> That should do the trick. If the file doesn't exist, it just skips it. This can be expensive to do if you have a large amount of categories to loop through, though. EDIT If you instead want to use custom functions on a per category basis you could do something like this: <code> <?php // Create one function like this for each category function my_custom_category_50(){ // Do some awesome stuff. } // Use this to loop through the categories foreach((get_the_category()) as $category) { $func = 'my_custom_category_' . $category->cat_ID; if( function_exists( $func ) $func(); } ?> </code> This method has the advantage of not requiring file inclusion. This advantage would be most visible if you're hitting the same category multiple times per page load.
|
Code to pull in a PHP file named after the category ID
|
wordpress
|
I am making <code> readme.html </code> file for a plugin with some detailed setup instruction that need to include screenshots. As rest of UI I want it be consistent with WordPress style and so I looked at its own <code> readme.html </code> . It includes stylesheet with relative path: <code> <link rel="stylesheet" href="wp-admin/css/install.css?ver=20100228" type="text/css" /> </code> So for a plugin file I might go with: <code> <link rel="stylesheet" href="/wp-admin/css/install.css" type="text/css" /> </code> But it is good way to include styling? There are really many ways to do it: link to <code> install.css </code> ; bundle copy of <code> install.css </code> with plugin; bundle own CSS file with plugin; embed style in <code> readme.html </code> . I am not aware of any recommendation about providing HTML documentation with plugins. Had you included HTML documentation with plugins (or themes, whatever)? What method had you chosen to style it and what was you reasoning for it?
|
It would be better to include your own CSS file that way you can: Use a relative path to your CSS. Avoid problems getting the path right to the <code> wp-admin </code> directory. Not all people put WordPress in the root directory, so your example above would break for them. Possibly redundancy by reusing the CSS in your HTML & admin pages for your plugin.
|
Styling readme.html in plugin?
|
wordpress
|
I'm writing a theme and adding a menu with several submenu pages. It works fine, except that I'm trying to use only one array to save all the settings into the database and this is causing some issues. The problem is that when each submenu pages is saved, it only saves the values from that page to the array and removes all the other values from the other pages that were stored before so the array only ends up holding the values from one page at a time. Here are the functions where I create the pages and register the setting. <code> add_action('admin_menu', 'theme_add_admin'); add_action('admin_init', 'register_theme_settings'); function theme_add_admin() { add_menu_page( 'Theme Settings', 'Theme Settings', 'update_themes', 'themesettings', 'settings_messages_page'); add_submenu_page( 'themesettings', 'messages', 'Titles and Messages', 'update_themes', 'themesettings'); add_submenu_page( 'themesettings', 'layout', 'Layout', 'update_themes', 'settings_layout', 'settings_layout_page'); add_settings_messages(); add_settings_layout(); } function register_theme_settings() { register_setting( THEMENAME . '_settingsgroup', THEMENAME . '_settings', 'validate_options' ); } </code> In add_settings_messages() and add_settings_layout I add the sections and fields: <code> function add_settings_layout() { add_settings_section('layout_styles', 'Archive Layout', 'settings_layout_styles_fn', __FILE__); add_settings_field('layout_index', 'Home Page Post Style', 'layout_home_fn', __FILE__, 'layout_styles'); add_settings_field('layout_paged', 'Paged Archives Post Style', 'layout_paged_fn', __FILE__, 'layout_styles'); } </code> And here's the page display function: <code> function settings_layout_page() { ?> <div class="wrap"> <div class="icon32" id="icon-options-general"><br></div> <h2>Layout</h2> <form action="options.php" method="post"> <?php settings_fields(THEMENAME . '_settingsgroup'); ?> <?php do_settings_sections('settings_layout'); ?> <p class="submit"> <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?>" /> </p> </form> </div> <?php } </code> I'm probably missing something obvious here, any help would be appreciated.
|
Yep you are missing something, On your validate_options function you need to: get an array of all existing options. update only the options your Submenu page handles. return that array. So something like: <code> function validate_options($input){ //do regular validation stuff //... //... //get all options $options = get_option(THEMENAME . '_settings'); //update only the neede options foreach ($input as $key => $value){ $options[$key] = $value; } //return all options return $options; } </code>
|
Submenu pages delete settings from options array when saved
|
wordpress
|
I found the code on the WP Recipies page to force excerpts on the home page: <code> function my_excerpts($content = false) { // If is the home page, an archive, or search results if(is_front_page() || is_archive() || is_search()) : global $post; $content = $post->post_excerpt; // If an excerpt is set in the Optional Excerpt box if($content) : $content = apply_filters('the_excerpt', $content); // If no excerpt is set else : $content = $post->post_content; $excerpt_length = 55; $words = explode(' ', $content, $excerpt_length + 1); if(count($words) > $excerpt_length) : array_pop($words); array_push($words, '...'); $content = implode(' ', $words); endif; $content = '<p>' . $content . '</p>'; endif; endif; // Make sure to return the content return $content; } add_filter('the_content', 'my_excerpts'); </code> But how do I modify that snippet to add a hyperlink to the full post for the "..." part?
|
Replace the last row of code from: <code> return $content; </code> To: <code> return $content.'<a href="'.get_permalink($post->ID).'">Read More...</a>'; </code>
|
How to link up "read more" on excerpts hack from WP Recipies
|
wordpress
|
Currently I am running a Wordpress MU blog using the Unfiltered MU plugin. However, when I try to insert an HTML5 tag, it gets stripped away. I believe it may be the WYSIWYG editor cleaning the code. Where can I change settings to allow ? Thanks
|
Just FYI... WordPress 3.2 includes an updated TinyMCE which allows HTML5 tags. It's still under development but is fairly stable if you want to take the risk of running it now. The alternative is to write any posts requiring the tag with the visual editor turned off. As long as you don't turn the editor on again on that same post the tags will stay there. Just turn the editor on once you have navigated away from that post in admin.
|
How to allow html5 tag in Wordpress
|
wordpress
|
I have to get specific page content (like page(12)) I used that : <code> <?php $id=47; $post = get_page($id); echo $post->post_content; ?> </code> Work nice execpt for compatibility with qtranslate it return french and english text But the loop is fine, return only the good language version <code> <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <div id="post"> <?php the_content(); ?> </div> <!-- .post --> </code> So the question.... HOW to get a specific page content insite the loop...
|
Here is the solution i have founs that work fine...the codex should be more specific about the apply_filter ... used it all everytime <code> <?php $id=47; $post = get_page($id); $content = apply_filters('the_content', $post->post_content); echo $content; ?> </code> But i have found a great place to ask question (HERE)! thanks guys !
|
Proper way to get page content
|
wordpress
|
I have installed the Google Analyticator plugin on my site. I am also using the MobilePress plugin to serve up a theme designed for non-smart-phone mobile browsers. I have set up Google Analytics for Mobile for use in this theme and would like to disable the Analyticator plugin since it includes a call to a larger js file. Does anyone know if it is possible to disable a plugin using functions.php or some other method? I believe I have located the code that adds the functions to the page, so if it's not possible to disable the entire plugin is it possible to stop the actions for executing? I have tried to disable them directly with no luck. Here is the code from the plugin file: <code> add_action('wp_head', 'add_google_analytics', 999999); add_action('init', 'ga_outgoing_links'); </code> I tried to remove those actions with: <code> remove_action('wp_head','add_google_analytics',9999999); remove_action('init', 'ga_outgoing_links'); </code> Any help is greatly appreciated.
|
When WordPress activates a plugin, it calls the <code> activate_plugin() </code> function. This function activates the plugin in a sandbox and redirects somewhere else on success. It's been used by a few authors to programmatically activate plugin dependencies. There's another function, <code> deactivate_plugin() </code> , that does a similar thing in reverse ... it's actually how WordPress deactivates plug-ins when you click on "deactivate" or "disable." To deactivate an installed plugin, just call: <code> deactivate_plugins( '/plugin-folder/plugin-name.php' ); </code> Or, to deactivate multiple plugins at once: <code> deactivate_plugins( array( '/first-plugin/first.php', '/second-plugin/second.php' ) ); </code> There's a second parameter (the first is either a string or array of the plugins to disable) that allows you to disable the plugins without calling deactivation hooks. By default, it's set to false, and I recommend you leave it that way. Unless for some reason you want to bypass the deactivation, then you'd do: <code> deactivate_plugins( '/plugin-folder/plugin-name.php', true ); </code> This would just turn off the plugin, but it wouldn't fire anything the plugin registered to do on deactivation. So if the plugin removes options or db tables when it's deactivated, you'd want to do this "silent" deactivation to preserve that information and use it elsewhere. Some documentation from A HitchHacker's Guide through WordPress
|
Disable plugin / plugin action via theme
|
wordpress
|
Hey guys..... I have a page template I have made up & I also was POST'ing to it to process the form.... originally it was working fine, but I moved around some code & now it's not working for some reason. It just redirects to a 404 page for some reason?? Not sure if it matters but here is the code from the template file.. <code> /* Template Name: Detailed Quote */ // Make paths up include(ABSPATH . '/includes/dq-config.php'); include(ABSPATH . '/includes/functions.php'); include(ABSPATH . '/includes/classes/class.detailedQuote.php'); // Instantiate new detailedQuote class $quote = new detailedQuote(); if (isset($_POST['process'])) { // Prepare post data $data = $quote->prepare_quote_data($_POST); try { // Error check submission $quote->error_check_quote($data); } catch (Exception $e) { // Display output with error message $quote->displayOutput($e->getMessage()); return false; } } else { // Display page output $quote->displayOutput(); } </code> Thanks a lot!
|
WordPress listens to both <code> $_GET </code> and <code> $_POST </code> when parsing a request. If your form input names are conflicting with native query parameters, you'll send WordPress on a wild goose chase (and most likely end up with a 404). For your leisure, I've kindly listed them here - if any one of your form inputs uses these for a name, that's the troublemaker. <code> Array ( [0] => m [1] => p [2] => posts [3] => w [4] => cat [5] => withcomments [6] => withoutcomments [7] => s [8] => search [9] => exact [10] => sentence [11] => debug [12] => calendar [13] => page [14] => paged [15] => more [16] => tb [17] => pb [18] => author [19] => order [20] => orderby [21] => year [22] => monthnum [23] => day [24] => hour [25] => minute [26] => second [27] => name [28] => category_name [29] => tag [30] => feed [31] => author_name [32] => static [33] => pagename [34] => page_id [35] => error [36] => comments_popup [37] => attachment [38] => attachment_id [39] => subpost [40] => subpost_id [41] => preview [42] => robots [43] => taxonomy [44] => term [45] => cpage [46] => post_type ) </code>
|
Why is POST'ing to my WP page template producing a 404?
|
wordpress
|
Is it possible to export the posts of a blog as a PDF? There is a blog with a couple of hundred posts that I'd like to read on my ereader, so I was wondering whether I could extract those posts into a PDF? Thanks for the help!
|
This kind of content scraping is frowned on. You're trying to grab someone else's content and put it into a transferable format over which they have no control. Yes, your intentions are sincere, but don't be surprised if several people are hesitant to help. You do have some options, though. Contact the blog author This is the option I'd recommend over all else. Just send them an email and ask for a PDF version of their content that you can put on your eReader. Asking will prevent any questions over whether or not you're stealing their content. It also lets the author know their stuff is popular enough to publish it as an eBook. There are several plug-ins around that allow blog owners to export their entire site as a PDF eBook, so it's relatively quick and simple for the site owner to create a PDF for you. Anthologize is a great option for doing just this. Import the site via RSS If you have an Internet-enabled ebook reader (i.e. Kindle, iPad) you can just browse the site's RSS feed. However, keep in mind that this feed will likely only include the latest 10 or so articles, not the entire site's content. You can also use a plug-in like Anthologize on a WordPress blog to import the content and then export everything as a PDF. Use an online Service There are a few online services that will read through and scrape the content of a site to create a PDF. However, they often use the RSS feed of the site and will be limited to the latest posts only. Zinepal is the latest one I've found. In Summary The reality of your situation is that there's no easy, stock way to grab all the content of a site and create a PDF ... mostly because it is a frowned upon practice as I mentioned at the beginning. If you wanted to write your own script, though, here's what it would need to do. Find the blog's sitemap Pull down the content of every page listed in the sitemap Create a PDF from the fetched content But this method would be dependent on the presence of a sitemap ... which isn't a surefire dependency. So, you can either depend on RSS and use an existing service, depend on a sitemap and create your own script, or contact the blog author directly and make a request. I'd recommend contacting the author. Most of us would be thrilled to get such a request.
|
Export a blog(not mine) as a PDF document
|
wordpress
|
Fiddling around with a custom post type which is quite heavy modified. Started doing some testing to see if I had broken some function, and realized that wordpress doesn't have a function that checks if a post has any content at all. Meaning, if I press "Add new" and just press publish, it won't say a word just save the information in the database. The problem is that it's not visible in the admin area, just in the database. An entry with the title Auto Draft and post status auto-draft is created. This isn't the worlds biggest problem, but still I want to avoid to be creating unnecessary entries in the database. So I wonder how I would go about to create some sort of function that checks if any data has been entered in the editor, and if it's blank it'll prompt the user to enter data before saving/publishing the post. The publish meta looks like this: <code> <?php if ( !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0 == $post->ID ) {?> <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" /> <?php submit_button( __( 'Create' ), 'primary', 'publish', false, array( 'tabindex' => '5', 'accesskey' => 'p' ) ); } else { ?> <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Save') ?>" /> <input name="save" type="submit" class="button-primary" id="publish" tabindex="5" accesskey="p" value="<?php esc_attr_e('Save') ?>" /> <?php } ?> </code>
|
When i needed a solution to the save "problem" i create an Ajax function to validate the fields and did some minor JQuery hacks: first we add our JavaScript to capture the submit/publish event and use it to submit our own ajax function before the actual submit <code> add_action('wp_print_scripts','my_publish_admin_hook'); function my_publish_admin_hook(){ if (is_admin()){ ?> <script language="javascript" type="text/javascript"> jQuery(document).ready(function() { jQuery('#post').submit(function() { var form_data = jQuery('#post').serializeArray(); form_data = jQuery.param(form_data); var data = { action: 'my_pre_submit_validation', security: '<?php echo wp_create_nonce( 'pre_publish_validation' ); ?>', form_data: form_data }; jQuery.post(ajaxurl, data, function(response) { if (response.indexOf('True') > -1 || response.indexOf('true') > -1 || response = true || response) { jQuery('#ajax-loading').hide(); jQuery('#publish').removeClass('button-primary-disabled'); return true; }else{ alert("please correct the following errors: " + response); jQuery('#ajax-loading').hide(); jQuery('#publish').removeClass('button-primary-disabled'); return false; } }); return false; }); }); </script> <?php } } </code> then we create the function to do the actual validation: <code> add_action('wp_ajax_my_pre_submit_validation', 'pre_submit_validation'); function pre_submit_validation(){ //simple Security check check_ajax_referer( 'pre_publish_validation', 'security' ); //do your validation here //all of the form fields are in $_POST['form_data'] array //and return true to submit: echo 'true'; die(); //or your error message: echo 'bal bla bla'; die(); } </code> you can always change it up a bit to do the validation on the client side but i prefer on the server side.
|
Stop wordpress from creating empty/null entries
|
wordpress
|
I have a Wordpress site that I just updated to 3.1. I want to make use of custom post types now, my question is how can I assign (transfer?) a post to a newly created custom post type ? For example, all my articles (news, poems, ideas to change the world) are in Posts. Now I have created the custom post types News, Poems, etc. and I want to transfer my old posts to these new custom post types. I hope this is clear enough, anybody ?
|
It seems that the easiest way is to do it manually in the DB. If you don't have access to the DB, or if you don't want to do it manually, you can install a plugin that will do it one post at a time, or a plugin that will bulk convert a lot of posts at once
|
How can I convert Posts into Custom type posts?
|
wordpress
|
I have NoSpamMX plugin installed. I was not getting spam comments for a long time. But now I am getting a lot of spam comments especially in one post. What is the reason that there is such a lot of spams only to that post?
|
+1 for akismet http://wordpress.org/extend/plugins/cookies-for-comments/ Is also amazing. Akismet is great at catching spam, but adding cookies for comments is awesome. It stops a lot of the auto-posted spam. (Which most of it is) Cookies for comments will stop the comment before it even gets to you. Akismet was catching 50 spams a day for me. But once I added CFC, I only get maybe 1 comment a week for akismet to deal with. The two combined are great
|
How to prevent spam comments?
|
wordpress
|
This is a bit of a specific question--I have found bits and pieces of information on the net, but nothing that puts the whole picture together for me. Hopefully I can get some help here. Background: I am a newbie to Wordpress. I'm using it as the CMS for a t-shirt shop I'm working on. My 't-shirts' custom post type is set up, but I want to create a 'T-shirts' page that will display all my available t-shirts in a gallery style. I really don't want to use an e-commerce plug-in because I want a bit more control over how my 'T-shirts' page looks and functions. Problem(s): 1. I need a code that will output the grid layout automatically. Each new 't-shirt' post should occupy the top left grid space. With each new 't-shirt' added, the old ones should automatically shift right to the next space. If it helps, the rest of my site uses a 16 column 960px grid--ideally each grid space will be 220px wide (4 columns). 2. I have set up the featured image in my 't-shirt' posts as a thumbnail preview, so I'd like the gallery to display JUST the featured image with the title beneath. 3. I want the gallery to begin paginating after about 12 posts. From the little I know about Wordpress, I think I'll need to use some loop functions but I have no clue which ones. Hopefully someone here can help shed some light on this for me.
|
http://www.rvoodoo.com/who-are-the-voodoo-empire/ Something like that I assume? That's a CPT displayed as sort of a grid. Basically, you wrap the loop in a div. Set the width of that div. Say your overall width is 900px for your page. You could set the post width as 250. so 3 of them will be 750 wide, that gives you 150px of padding to use, etc. You float the divs left.... then they automatically line up next to each other til they run out of space, then go to the next line. By default, WP would put the newest one top left, if you floated left. The older ones keep moving right until they wrap to the next line. To limit to 12 posts, and paginate afterwards, you just use a query. http://wordpress.org/search/query_posts Now I don't know your theme, your css selectors will be different than mine, etc. I'm just going to post what I use, and you can pick it apart. The code will be different, but the concept remains the same. You'll also notice I use enqueue style here. Since the grid layout is different from my normal posts, I only call the stylesheet for the grid on this page. the query I use here, I've modified to meet your needs, but the rest of the stuff you'll need to tweak. Like I display the excerpt here, you don't want that. And the whole entry-utility section I have will not apply to you. But, Like I said, I'm throwing this up in hopes it will help you with the concept. <code> <?php wp_enqueue_style( "member_css", $voodoo_template_dir . '/scheme/member-template.css', false, "1.0", "all" ); get_header(); query_posts( array( 'post_type' => 've_members', 'posts_per_page' => 12, 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ), )); ?> <?php if (have_posts()) : ?> <div> <?php while (have_posts()) : the_post(); ?> <div class="memberPost" id="post-<?php the_ID(); ?>"> <div class="memberBox"> <h2 class="entry-title"> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> </h2> <div class="clear"></div> <div class="memberThumb"> <a rel="lightbox" href="<?php $image_id = get_post_thumbnail_id(); $image_url = wp_get_attachment_image_src($image_id,'large', true); echo $image_url[0]; ?>"> <?php the_post_thumbnail('member-thumb', array( 'class' => 'member-thumb aligncenter' ) ); ?> </a> <div class="clear"></div> </div> <div class="entry-content"> <?php the_excerpt(); ?> <div class="clear"></div> </div> <hr /> <div class="entry-utility"> <div class="socialIcons"> <?php get_template_part( 'icons', 'members' ); ?> </div> <div class="fbConnect"> <?php if(function_exists('sfc_like_button')) : ?> <?php sfc_like_button(array('layout' => 'button_count')); ?> <?php endif; ?> </div> <div class="twitConnect"> <?php if(function_exists('stc_tweetbutton')) : ?> <?php stc_tweetbutton(); ?> <?php endif; ?> </div> <div class="clear"></div> <span class="comments-link"><?php comments_popup_link( __( '[Leave a Message]', 'voodoo_lion' ), __( '[1 Message]', 'voodoo_lion' ), __( '[% Messages]', 'voodoo_lion' ) ); ?></span> <div class="clear"></div> </div> </div> </div> <?php endwhile; ?> </div> <?php endif; ?> <?php get_footer(); ?> </code> And here is my stylesheet that I enqueue for just this template <code> .memberPost { float: left; width: 225px; margin: 10px; } .memberPost .fbConnect { width: 80px; float: left; overflow: hidden; } .memberPost .twitConnect { margin-right: -20px; } .memberPost h2 { text-align: center; margin-top: 5px; } .memberPost .memberThumb { height: 100px; } .memberPost .entry-content p { margin: 5px; height: 275px; text-align: left; } .memberPost .entry-utility { margin: 0 5px 10px 5px; } .memberPost .socialIcons { height: 28px; margin-bottom: 2px; } </code>
|
Displaying custom post types as a gallery
|
wordpress
|
I'm using this library to auto-update my plugin, but it's only extracting the new plugin files into a .tmp directory, while the old plugin files stay where they are. Can anybody help me fix this to overwrite the old files or any ideas as to why it would be doing that? Edit: I know that the library above does not actually install the update, but the WP core updater does, so it has something to do with that. Any ideas?
|
Are you able to update standard WP repo plugins? I am using that library and it seems to work well. What's the exact error that WordPress gives on the admin screen when it tries to run the update? I would take a look at permissions first. What are the permissions on the old plugin directory? Any different than any of your other plugin directories? I would also take a look at the format of the zip file you're feeding it. What software did you use to create the zip? When you unzip it, what does the directory structure look like? It should unzip as a folder with the same name as the plugin you're trying to replace. Did you set the slug attribute in the JSON file? Does that also match the folder name? Hope this helps. I was able to get that library going pretty quickly.
|
Auto-Update Plugin Creating .tmp directory, not overwriting old version
|
wordpress
|
i've found out that there are custom fields but i'm not able to activate them in the admin panel .. :( i've checked the screen options but there's no custom fields - looks like it depends on the template i'm using. any ideas how to modify it in order to enable custom fields for posts? thx
|
The visibility of custom fields on the post edit screen is controlled on the post edit page. There's a button called "Screen Options" towards the top of the screen. Clicking that button will display all of the available boxes and panels for the edit page. If custom fields is not visible here, then either your theme or a plug-in is disabling the feature.
|
enabling custom fields in admin?
|
wordpress
|
hey guys, is it somehow possible to do the following: <code> wp_list_pages() </code> lists each link inside a <code> <li> <a href="link"... </code> <code> <?php wp_list_pages('title_li=&depth=0&exclude='); ?> </code> Is it possible to add a #hash to those links? Like <code> <a href="link#something" </code> ? thank you for your help
|
I'd wrap it in a function (save it in <code> functions.php </code> ); <code> function wp_list_pages_with_hash( $hash, $args = '' ) { $add_hash = create_function( '$link', 'return $link . "#' . $hash . '";' ); add_filter( 'page_link', $add_hash ); $result = wp_list_pages( $args ); remove_filter( 'page_link', $add_hash ); return $result; // back compat in case 'echo' was null } </code> Then call it like so! <code> <?php wp_list_pages_with_hash( 'target', 'title_li=&depth=0' ); ?> </code>
|
adding a #hash to each link in list_pages()?
|
wordpress
|
How to list all existing sidebars? I want to show them all in the drop down list (so each item should have also the right value).
|
You can only gel list of registered sidebars, from variable $wp_registered_sidebars . <code> <?php global $wp_registered_sidebars; echo '<pre>'; print_r($wp_registered_sidebars); echo '</pre>'; </code>
|
Listing all sidebars
|
wordpress
|
I created a custom post type with a couple of fields where the user can enter the start date and the end date for a project. I am trying to implement the jQuery datepicker but nothing happens when I click on the input fields using 1.7.3; if I use 1.8 it throws an error <code> $(input).zIndex is not a function </code> Update: Here is the function <code> function webfolio_show_timespan_box(){ ?> <script type="text/javascript" src="<?php bloginfo('stylesheet_directory')?>/js/jquery.ui-core.js"></script> <script type="text/javascript" src="<?php bloginfo('stylesheet_directory')?>/js/jquery.picker.min.js"></script> <link type="text/css" rel="stylesheet" href="<?php bloginfo('stylesheet_directory')?>/css/smoothness/jquery.custom.css" /> <script> jQuery(function() { jQuery( ".datepicker" ).datepicker(); }); </script> <?php global $timespan_box, $post, $prefix; echo '<input type="hidden" name="webfolio_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />'; echo '<table class="form-table">'; foreach ($timespan_box['fields'] as $field) { // get current post meta data $meta = get_post_meta($post->ID, $field['id'], true); echo '<tr style="border:1px solid #e3e3e3;">', '<th style="width:20%; font-weight:bold;"><label for="', $field['id'], '">', $field['name'], '</label></th>', '<td>'; echo '<input class="datepicker" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:20%" />', '<br />', $field['desc']; echo '<td></tr>'; } echo '</table>'; } </code> Thank you for your help
|
maybe you include your scripts ui-core and picker too early. Use <code> wp_enqueue script() </code> to include on the right hook. You must not include ui-core, only datepicker! example: <code> wp_enqueue_script( 'jquery-ui-datetimepicker', \ $this->get_plugins_url( 'js/ui.datetimepicker.js', __FILE__ ), \ array('jquery-ui-core') , 0.1, TRUE );` </code> any tutorials: http://wpengineer.com/415/use-javascript-libraries-in-and-of-wordpress/ http://codex.wordpress.org/Function_Reference/wp_enqueue_script http://wpengineer.com/2028/small-tips-using-wordpress-and-jquery/ I use the datepicker on different plugins and works fine, but it is necessary, that the order is correctly.
|
Add jQuery UI datepicker to admin panel
|
wordpress
|
when attaching videos (eg. .flv) to a post - is it possible to query its dimensions? the problem is - i've got videos in 4:3 and 16:9 format and i need to get this information. any ideas? thanks
|
php-flvinfo and php-mp4info are php classes for reading flv and mp4 metadata. you could read it on the fly, or it may be possible to hook a save to get this info in the db somewhere.
|
getting video dimensions
|
wordpress
|
I created theme options page using Settings API, everything works fine but I can't save options. I tried to figure it out where I missed something but I failed. Any idea what can cause this problem? Here's code of my options page <code> <?php /** * This functions registers default options values for Evolutionary theme * settings */ function ev_theme_settings_defaults() { $options = array( 'color_scheme' => 'blue', 'copyright' => '', 'nav_hide_home' => false, 'nav_hide_sec' => false, 'nav_show_lvl' => false, 'featured_show' => false, 'featured_pause' => false, 'featured_speed' => 5, 'ad1_link' => '', 'ad1_image' => '', 'ad2_link' => '', 'ad2_image' => '', 'ad3_link' => '', 'ad3_image' => '', 'ad4_link' => '', 'ad4_image' => '' ); return $options; // Change to apply_filters( 'ev_theme_settings_defaults', $options ); } /** * Create helper function for theme colors */ function ev_get_valid_color_schemes(){ $color_schemes = array( 'blue' => __( 'Blue', 'evolutionary' ), 'green' => __( 'Green', 'evolutionary' ), 'red' => __( 'Red', 'evolutionary' ), 'black' => __( 'Black', 'evolutionary') ); return $color_schemes; } /** * Setup initial theme options */ function ev_options_init() { // Set options equal to defaults global $ev_options; $ev_options = ev_theme_settings_defaults(); if ( false === $ev_options ) { $ev_options = ev_theme_settings_defaults(); } update_option( 'theme_evolutionary_options', $ev_options ); } add_action( 'after_setup_theme', 'ev_options_init', 9 ); /** * Add theme options page to admin menu */ function ev_menu_options() { add_theme_page( __( 'Theme Options', 'evolutionary' ), __( 'Theme Options', 'evolutionary' ), 'edit_theme_options', 'evolutionary-settings', 'ev_admin_options_page' ); } add_action( 'admin_menu', 'ev_menu_options' ); /** * Register theme options */ function ev_register_options() { register_setting( 'theme_evolutionary_options', 'theme_evolutionary_options', 'ev_options_validate' ); /** * Defining settings sections and fields * fist setting creates sections for general options */ add_settings_section( 'ev_settings_general_options', __( 'General Options', 'evolutionary' ), 'ev_settings_general_options', 'evolutionary' ); // Creates section for navigation options add_settings_section( 'ev_settings_nav_options', __( 'Navigation', 'evolutionary' ), 'ev_settings_nav_options', 'evolutionary' ); // Section for featured post options add_settings_section( 'ev_settings_featured_options', __( 'Featured Posts', 'evolutionary' ), 'ev_settings_featured_options', 'evolutionary' ); // Section for Advertising options add_settings_section( 'ev_settings_ad_options', __( 'Advertising', 'evolutionary' ), 'ev_settings_ad_options', 'evolutionary' ); /** * Created empty callbacks for setions */ function ev_settings_general_options() { // Put callback code here } function ev_settings_nav_options() { // callback } function ev_settings_featured_options() { // callback } function ev_settings_ad_options() { // callback } /** * Registered fields */ add_settings_field( 'ev_settings_copyright_field', __( 'Copyright Name', 'evolutionary' ), 'ev_settings_copyright_field', 'evolutionary', 'ev_settings_general_options' ); add_settings_field( 'ev_settings_colors_field', __( 'Theme Color', 'evolutionary' ), 'ev_settings_colors_field', 'evolutionary', 'ev_settings_general_options' ); /** * Fields Callbacks */ function ev_settings_copyright_field() { $ev_options = get_option( 'theme_evolutionary_options' ); //var_dump( $ev_options ); ?> <input name="theme_evolutionary_options[copyright]" type="text" class="regular-text" value="<?php esc_attr_e( $ev_options['copyright'] ); ?>" /> <?php } // Callback for colorscheme function ev_settings_colors_field() { $ev_options = get_option( 'theme_evolutionary_options' ); $color_schemes = ev_get_valid_color_schemes(); echo '<select name="theme_evolutionary_options[color_scheme]">'; foreach( $color_schemes as $value => $caption ) : ?> <option value="<?php echo $value; ?>" <?php selected( $value, $ev_options['color_scheme'] ); ?>><?php echo $caption; ?></option> <?php endforeach; echo '</select>'; } } // ev_register_options add_action( 'admin_init', 'ev_register_options' ); /** * Creating options page HTML output */ function ev_admin_options_page() { ?> <div class="wrap"> <?php if ( isset( $_GET['settings-updated'] ) ) { echo "<div class='updated'><p>Theme settings updated successfully.</p></div>"; } ?> <?php screen_icon(); ?> <h2><?php _e( 'Theme Options', 'evolutionary' ); ?></h2> <form action="options.php" method="post"> <?php settings_fields( 'theme_evolutionary_options' ); do_settings_sections( 'evolutionary' ); ?> <input name="submit" type="submit" class="button-primary" value="<?php _e( 'Save Settings', 'evolutionary' ) ?>" /> <input name="reset" type="submit" class="button-secondary" value="<?php _e( 'Reset Settings', 'evolutionary' ) ?>" /> </form> </div> <?php } function ev_options_validate( $input ) { $ev_options = get_option( 'theme_evolutionary_options' ); $valid_input = $ev_options; $ev_options['color_scheme'] = array_key_exists( $ev_options['color_scheme'], ev_get_valid_color_schemes() ) ? $ev_options['color_scheme'] : 'blue'; $ev_options['copytright'] = wp_kses_data( $ev_options['copyright'] ); return $valid_input; } </code>
|
@Mamaduka: Here is why your settings aren't updating. Your validation function is wrong. To wit: <code> function ev_options_validate( $input ) { $ev_options = get_option( 'theme_evolutionary_options' ); $valid_input = $ev_options; $ev_options['color_scheme'] = array_key_exists( $ev_options['color_scheme'], ev_get_valid_color_schemes() ) ? $ev_options['color_scheme'] : 'blue'; $ev_options['copytright'] = wp_kses_data( $ev_options['copyright'] ); return $valid_input; } </code> You're updating $ev_options, but returning $valid_input. You need to be updating $valid_input, not $ev_options. Try this instead: <code> function ev_options_validate( $input ) { $ev_options = get_option( 'theme_evolutionary_options' ); $valid_input = $ev_options; $valid_input['color_scheme'] = array_key_exists( $ev_options['color_scheme'], ev_get_valid_color_schemes() ) ? $ev_options['color_scheme'] : 'blue'; $valid_input['copytright'] = wp_kses_data( $ev_options['copyright'] ); return $valid_input; } </code> See if that fixes your problem? EDITED TO ADD: Your next problem in the validation function is that you're comparing $ev_options to/against itself, when you need to be evaluating $input against $valid_input. Instead of this: <code> function ev_options_validate( $input ) { $ev_options = get_option( 'theme_evolutionary_options' ); $valid_input = $ev_options; $valid_input['color_scheme'] = array_key_exists( $ev_options['color_scheme'], ev_get_valid_color_schemes() ) ? $ev_options['color_scheme'] : 'blue'; $valid_input['copytright'] = wp_kses_data( $ev_options['copyright'] ); return $valid_input; } </code> Try this: <code> function ev_options_validate( $input ) { $ev_options = get_option( 'theme_evolutionary_options' ); $valid_input = $ev_options; $valid_input['color_scheme'] = array_key_exists( $input['color_scheme'], ev_get_valid_color_schemes() ) ? $input['color_scheme'] : 'blue'; $valid_input['copytright'] = wp_kses_data( $input['copyright'] ); return $valid_input; } </code> Specifically, change this: <code> $valid_input['color_scheme'] = array_key_exists( $ev_options['color_scheme'], ev_get_valid_color_schemes() ) ? $ev_options['color_scheme'] : 'blue'; $valid_input['copytright'] = wp_kses_data( $ev_options['copyright'] ); </code> To this: <code> $valid_input['color_scheme'] = array_key_exists( $input['color_scheme'], ev_get_valid_color_schemes() ) ? $input['color_scheme'] : 'blue'; $valid_input['copytright'] = wp_kses_data( $input['copyright'] ); </code> And then , I think, your options should work. @TheDeadMedic: The Settings API handles looking at any $POST data. That's not the problem. Regarding the default-settings updating on init, here's my original, example code: <code> function oenology_options_init() { // set options equal to defaults global $oenology_options; $oenology_options = get_option( 'theme_oenology_options' ); if ( false === $oenology_options ) { $oenology_options = oenology_get_default_options(); } update_option( 'theme_oenology_options', $oenology_options ); } // Initialize Theme options add_action('after_setup_theme','oenology_options_init', 9 ); </code> And here's Mamaduka's code: <code> function ev_options_init() { // Set options equal to defaults global $ev_options; $ev_options = ev_theme_settings_defaults(); if ( false === $ev_options ) { $ev_options = ev_theme_settings_defaults(); } update_option( 'theme_evolutionary_options', $ev_options ); } add_action( 'after_setup_theme', 'ev_options_init', 9 ); </code> Do you see the difference? There is a critical change from oenology_options_init() to ev_options_init(), to wit: This: <code> global $oenology_options; $oenology_options = get_option( 'theme_oenology_options' ); </code> Versus this: <code> global $ev_options; $ev_options = ev_theme_settings_defaults(); </code> Thus, in ev_options_init(), the function never actually does anything, because of the change.
|
Can't save options
|
wordpress
|
Im creating a simple login/registration page incorporating user moderation and bootstrapping wp for the heavy lifting. I can get the new user added to the db and a password gets created and hashed and all, but when i go to login w/ that account the password won't work. i'm stumped... Anyone see anything i'm missing? <code> require_once( ABSPATH . WPINC . '/registration.php' ); $user_pass = wp_generate_password(); $userdata = array( 'user_pass' => $user_pass, 'user_login' => esc_attr( $_POST['user_email'] ), 'user_email' => esc_attr( $_POST['user_email'] ), ); if( !$userdata['user_login'] ) $error .= __('An Email Address is required for registration.', 'frontendprofile'); elseif ( username_exists( $userdata['user_login'] ) ) $error .= __('Sorry, that Email Address is already in use for another account.', 'frontendprofile'); elseif ( !is_email( $userdata['user_email'] ) ) $error .= __('You must enter a valid Email Address.', 'frontendprofile'); elseif ( email_exists( $userdata['user_email'] ) ) $error .= __('Sorry, that Email Address is already for another account.', 'frontendprofile'); else{ $new_user = wp_update_user( $userdata ); } </code> thanks in advance,
|
Got it. Cant use wp_update_user for new addition i guess. need to use: <code> wp_create_user( $userdata['user_login'], $userdata['user_pass'], $userdata['user_email'] ); </code>
|
wp_generate_password sets password but can't login using created password
|
wordpress
|
I am thinking, how might I setup a development server locally then when done, upload and sync files + data to test/production server? I think options like <code> siteurl </code> and <code> home </code> in <code> wp_options </code> database table will need to be changed, also, in <code> wp-config.php </code> some settings like database connection and debug mode will be different too.
|
It's quite difficult to keep data from a dev version in sync with data on the production site. But for an initial deployment, you are correct that it requires changes to wp-config.php and the database. Install Wordpress on your dev machine, e.g. dev.example.com/blog/ Install Wordpress on your production machine, preferably with the same folder structure as the dev box, e.g. www.example.com/wordpress/ note: your wp-config.php settings will be different on production. That's fine, just maintain a safe copy of the file and do not overwrite. Sync the /wp-content/ directory from dev to production (themes, plugins, etc) Using PHPMyAdmin or similar, export the contents of your dev database to a text file In the text file, replace any instances of the dev url with the production url (dev.example.com/wordpress/ => www.example.com/wordpress/). This will change the siteurl as well as any links to images in the posts Using PHPMyAdmin or similar, import the contents of your dev database to the production database Try accessing the Wordpress admin module in the production server - you should be good to go. This technique works for me, but I'd love to hear of any cleaner migration techniques. UPDATE: There are a number of techniques discussed in the following post, including a plugin that handles the db grunt work: stackexchange-url ("Easily Move a WordPress Install from Development to Production?")
|
How might I setup a development server (local) and a test/production server (remote)
|
wordpress
|
i've attached a local .flv video to my post (it was uploaded and is inside my mediapool). my question: how can i display it inside my post? (the video player) thanks
|
The .flv is not a video player in itself, rather just a video file to be played in one. To display it, you'll need to play it from an actual video player. Unlike .wmv and .mp4, .flv files won't play natively in your browser without one. There's a couple great open source options out there. There are also a few plugins that might already have the functionality you're looking for.
|
displaying flv-video attachment in post
|
wordpress
|
Hi I'm trying to use this plugin: http://wordpress.org/extend/plugins/wordpress-simple-website-screenshot/ I am supposed to use the shortcode: <code> [screenshot url="www.example.com"] </code> Because I am writing the code in the single.php file I am using: <code> <?php echo do_shortcode( '[screenshot url="www.example.com"]' ); ?> </code> But, my problem is that the URL is defined in the title of the post, so I tried: <code> <?php echo do_shortcode( '[screenshot url="<?php the_title(); ?>"]' ); ?> </code> with no luck. Is it possible to do a workaround on this?
|
You're trying to execute PHP inside a string! Instead, concat the string; <code> <?php echo do_shortcode( '[screenshot url="' . get_the_title() . '"]' ); ?> </code>
|
Using the title of the post in a shortcode
|
wordpress
|
On my last Wordpress 3 projects I successfully used custom post types and taxonomies coding the implementation by myself. As regards to custom write panels, I always used the more fields plugin without any problem. Now I am developing a whole new theme which needs to be totally independent from that plugin therefore I need to add the custom write panels only by coding. I did a lot of searching but I was not able to find a good tutorial about it. Any suggestion? Thank you
|
I always loved this article mainly for the reason that its about creating a class to use for your metaboxes.
|
Good tutorial on how to make custom write panels in Wordpress 3?
|
wordpress
|
I've created a custom post type single template. I noticed that when I turn off comments, I get a notice that says "Comments are closed." Looking at my comments.php, I get this little bit of code: <code> <?php else : // or, if we don't have comments: /* If there are no comments and comments are closed, * let's leave a little note, shall we? * But only on posts! We don't want the note on pages. */ if ( ! comments_open() && ! is_page() ) : ?> <p class="nocomments"><?php _e( 'Comments are closed.', 'dukatheme' ); ?></p> <?php endif; // end ! comments_open() && ! is_page() ?> </code> This code makes it such that the notice is not shown on pages. How can I edit it to make sure it is not shown on pages AND my custom post type? My custom post type is named "duka". Thanks!
|
Add a post type check to the <code> if </code> clause; <code> if ( ! comments_open() && ! is_page() && 'duka' != get_post_type() ) : </code>
|
Remove "Comments are closed" Notice from Custom Post Type template
|
wordpress
|
My sidebar loops through all of the child pages based on the parent page. For example, if you're in the "About" section you'll only see "About" child pages in the sidebar. My problem is that I have no way of highlighting the current page. For example, if you're on the child page "Our Team" (under "About") I'd like to give the sidebar "Our Team" a tag link a "current-page" class. Is there a way to add a "current-page" class dynamically to the child page you're on? <code> <?php if ( $post->post_parent == '4' ) { query_posts("post_type=page&post_parent=4&orderby=menu_order&order=asc"); } elseif ( $post->post_parent == '6' ) { query_posts("post_type=page&post_parent=6&orderby=menu_order&order=asc"); } elseif ( $post->post_parent == '8' ) { query_posts("post_type=page&post_parent=8&orderby=menu_order&order=asc"); } elseif ( $post->post_parent == '10' ) { query_posts("post_type=page&post_parent=10&orderby=menu_order&order=asc"); } if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> ... </code>
|
I see that you are have a hard time on this so here: <code> <?php global $post; $curent_post = $post; $curent_post_id = $post->ID $parents = array('4','6','8','10'); if (in_array($post->post_parent,$parents)){ query_posts("post_type=page&post_parent=".$post->post_parent."&orderby=menu_order&order=asc"); } if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <a href="<?php the_permalink(); if ($curent_post_id = $post->ID){ echo ' class="highlight"'; } ?>"><?php the_title(); ?></a> </code> and at the end of your loop add <code> wp_reset_query(); $post = $curent_post; </code> no after that i would like to say that you really should use WP_Query instead of query_posts any time that its not the main query in the page. and when I'll get back I will post and example using wp_list_pages()
|
Dynamic sidebar nav with current page highlighting
|
wordpress
|
For some reason when I go to one of my clients WordPress installations, and I install a plugin that I made which has custom TinyMCE buttons, when they click on one of the buttons the popup appears but there's no text. In the JavaScript console of Google Chrome before I even click the buttons, there is the following: <code> Failed to load resource: the server responded with a status of 404 (Not Found) - Array - http://mywebsiteurl.com/wp-admin/Array </code> Could that have something to do with my plugin or their installation of WordPress? Thanks for the help.
|
If I am not mistaken in PHP <code> Array </code> commonly comes up when array variable is wrongfully used where string is expected. But from this information I have trouble suggesting where exactly that can go wrong.
|
Getting a 404 in Debugger for example.com/wp-admin/Array?
|
wordpress
|
If I wanted to put the scripts that all my plugins use at the end of the page, where would I do this? Using YSlow/Firebug it recommends this tactic.
|
The hook for registering the script in the footer is: <code> <?php function my_init_method() { wp_register_script( 'myscript', 'http://www.mydomain.com/js/myscript.js','','','true'); wp_enqueue_script( 'jquery' ); } add_action('init', 'my_init_method'); ?> </code> be sure to look at this and this , both are important.
|
Scripts at the end of the page
|
wordpress
|
I had upgraded from 3.0 to 3.1 and oembed worked normally. All of a sudden I've lost embedding when directly pasting video url into the editor. My embed setting is selected under "media". Any ideas what could be going on? I've changed themes, ultimately to the native 2010 and still no function. I've tried turning the embed setting on and off in the admin as well to no avail.
|
It appears I've been hoodwinked by my local setup & accidentally stopping connections to vimeo / youtube. This resulted in the video url appearing as only text. Once my setup was restarted everything appears to be working properly. Sorry for the confabulation.
|
OEMBED seems to have stopped working
|
wordpress
|
I need to make use of the ABSPATH constant but need to know what WP files I need to include so I can make use of it. Thanks a lot!
|
It is defined at the very start of <code> wp-load.php </code> . However it's value is very primitive - only a path to where file is located, which you could easily get without bothering with including it.
|
Using the ABSPATH constant - What files need to be loaded before use?
|
wordpress
|
after updating the permalinks from the default /?p=N to another setting (e.g. /%year%/%monthnum%/%postname%/) all my old links are broken and also the archive, catgories etc. side bars get 404 errors. How can I avoid this (or redirect) without changing the .htaccess (which I can't access using my hosting package)? Any suggestions or plugins that work with my current version (WP 3.1) are welcome! Thorsten
|
If you can't modify .htaccess then chances are WordPress can't either. Save your permalinks again and check if it tells you it couldn't save your htaccess file. That's your problem if so. Bigger question: why are you using a host that won't let you modify .htaccess? That's like renting an apartment from a landlord that won't let you use the bathroom. You're paying them for space on that server and you should be allowed to use it in any legal way you see fit. My advice is that you change hosting providers.
|
How do I change the permalink structure without getting 404s?
|
wordpress
|
I'm just wondering what is the correct way to do it? Add it in via the theme header? If so, what is the proper way to do it? I see a lot of the other current stuff in there using the bloginfo() function. Thank You!
|
You could tack it into header.php as you suggested (although this is not really the proper way to do it, it is best to use WPs enqueue function as described here). When do you need these? All the time? You can enqueue scripts and styles to be used all the time, or on an as-needed/per template basis http://codex.wordpress.org/Function_Reference/wp_enqueue_script http://codex.wordpress.org/Function_Reference/wp_enqueue_style
|
Correct way to include extra styles & script files?
|
wordpress
|
I am using the More Fields plugin which gives me the ability to create a date formatted YYYY/mm/dd and I want to convert that to be shown like: February 11, 2011 Is this possible?
|
Do you have issue with exactly converting or retrieval? Converting is trivial and is plain PHP: <code> date('F j, Y', strtotime($date)); </code> For more complex and WordPress-specific way with localization support see <code> date_i18n() </code> function.
|
converting custom field date format
|
wordpress
|
<code> $pp = new WP_Query('orderby=comment_count&posts_per_page=4'); ?> </code>
|
<code> $pp = new WP_Query(array( 'post_type' => array( 'post', 'custom_type' ), 'orderby' => 'comment_count', 'posts_per_page' => 4 )); </code>
|
how can i add an array of post types to this query?
|
wordpress
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.