question
stringlengths 0
34.8k
| answer
stringlengths 0
28.3k
| title
stringlengths 7
150
| forum_tag
stringclasses 12
values |
---|---|---|---|
In a theme I built from scratch I'm using the WP Photo Album Plus plugin. Per some books I've been using as guides, I need to include this code in the header in order to make comments work in a blog: <code> <?php if ( is_singular() ) wp_enqueue_script ( 'comment-reply'); wp_head() ; ?> </code> I've been including this line in the header of all my custom themes, whether the site includes a blog or not (my sites are all business sites, some with blogs included but none are primarily or only blogs). This site didn't have a blog so I removed that line of code. Doing that caused the photo albums to stop appearing on the pages. The shortcodes appeared as text instead. The albums were still in the admin and the plugin was still there, and everything else still worked. Can anyone explain the connection? Thanks!
|
This line has wrong syntax: <code> <?php if ( is_singular() ) wp_enqueue_script ( 'comment-reply'); wp_head() ; ?> </code> The call to <code> wp_head() </code> should not be on the same line as the conditional for the comment-reply script. Change it to this: <code> <?php // Conditional to determine if comment-reply form script should be included if ( is_singular() ) wp_enqueue_script ( 'comment-reply'); // Fire the `wp_head` hook, which should happen always, on every pageload wp_head(); ?> </code>
|
Why does this line of code make photo albums appear?
|
wordpress
|
I'm making a new theme for a blog that will be slightly narrower. Thus I need to resize every image and also change the image url in every post. Is there any kind of plugin handling this?
|
This plugin might help you : Regenerate Thumbnails Just change the image dimensions in WP's Media Settings and run the plugin.
|
How to batch resize images and change image url?
|
wordpress
|
I'm trying to add a table to a php page template. The headers and cells contents show well, but the table attributes are being ignored. This code: <code> <table border="1" cellspacing="10"> <tr> <th>Name</th><span/> <th>Address</th> </tr> <tr> <td>name_1</td> <td>name_2</td> </tr> </table> </code> produces the following result: <code> Name Address name_1name_2 </code> I get no border and no spacing (the headers are bolded, I just couldn't do it here). Does it have something to do with wordpress? How can it be solved?
|
Remove the border="1" attribute but leave the cellspacing. Then go into styles.css and either add your CSS selectors or modify the existing selectors. If your table is within the id="content" block, the styling is being affected by the existing selectors. The ones you will want to adjust are: <code> #content table { border: 1px solid #e7e7e7; margin: 0 -1px 24px 0; text-align: left; width: 100%; } #content tr th, #content thead th { color: #888; font-size: 12px; font-weight: bold; line-height: 18px; padding: 9px 24px; } #content tr td { border-top: 1px solid #e7e7e7; padding: 6px 24px; } #content tr.odd td { background: #f2f7fc; } </code>
|
HTML table attributes ignored
|
wordpress
|
For a custom post type (review) I have enabled a few custom taxonomies. One of them is author rating and for that I have added images to the description field of the terms in the taxonomy (1 star to 5 stars). Now I am wondering how to show that description instead of the term itself on the <code> single-review.php </code> ? I am already using the function to allow XHTML in category descriptions as per Justin Tadlock's function described on his website
|
If i understand correctly what you are trying to achieve then you can use <code> get_the_terms </code> function to get the rating terms object and from that echo out the description. replace: <code> <?php echo get_the_term_list( $post->ID, 'rating', __('Author Rating: ', 'appz'), ', ', '' ); // HERE I WANT THE DESCRIPTION (I.E. THE IMAGE THAT I USED AS THE DESCRIPTION INSTEAD OF THE TERM) ?> </code> with: <code> <?php echo '<span class="rating-author">'.__('Author Rating: ', 'appz').'</span>'; $reating_terms = get_the_terms ($post->id, 'rating'); foreach ($reating_terms as $term){ echo $term->description; } ?> </code>
|
show term description instead of list terms of custom taxonomy
|
wordpress
|
I am wondering how do you create a home page with a custom design like banners different layout from other pages while allowing users to edit it. I used to use <code> home.php </code> problem is user cannot edit it ... unless they know PHP. An option will be to create shortcodes for each section of the home page eg. <code> [banner] </code> , <code> [services] </code> or even an empty tag <code> [latestBlogPosts] </code> etc. I dont think its correct. Whats the way of accomplishing this? A quick "mockup" below of a typical home page Things like latest blog post and portfolio are dynamic from wordpress.
|
First, do not use <code> home.php </code> for this purpose. It is a reserved template file name, and is used to display the Blog Posts Index . Your best option is probably to create a <code> front-page.php </code> template file, and make the output Widget-based, so that users can modify the display via <code> Dashboard -> Appearance -> Widgets </code> .
|
Allow users to edit home page from WordPress (home.php problems)
|
wordpress
|
I was testing a new website with Chrome (latest build), everything working fine (no new plugin installed during the test) when suddendly when I try to post a comment, after pressing the "reply" button it stops on a blank wp-comments-post.php without posting. I am testing on localhost with MAMP. The funny thing is on the other browsers installed in the same machine (Safari, FF) it is working regularly. I have tried to overwrite the file from a wordrpess install, clear the cache, reboot, reboot MAMP, but nothing. I also checked the file wp-comments-post.php in the root and it is not blank and Akismet is disabled. any ideas?
|
Problem solved. It was an unclosed div. Lesson learned: first validate your code completely, then ask for help ;)
|
blank page after submitting a comment
|
wordpress
|
been seaching on google for a plugin for this and can't seem to find anything realiable. The only plugin I found is called "old post promoter". Any ideeas? Can this be done with googl old fashion coding, not a plugin? Ty!
|
http://wordpress.org/extend/plugins/oldest-2-newest-redux/ it takes your oldest post and reposts it in the front every 24 hours, but you can change the hours on the php file in the plugin folder not sure if this is what u are looking for.
|
Automatically republish old posts
|
wordpress
|
I have a running normal WP blog (blog 1). I want to create a Q&A section for my users, so I setup another blog with WP-Answer theme (blog 2). The problem is I don't want my users at blog 1 have to register at blog 2 to post questions. I want they automatically grant the same privileges at blog 2. How can this be achieved? Do you have any advice for me? Thank you very much.
|
I think you want to install your second site on the same database but with a different table prefix, e.g. <code> $table_prefix = "qa_"; </code> in <code> wp-config.php </code> You are then able to define a custom user and/or user_meta table by adding the following lines to <code> wp-config.php </code> <code> define('CUSTOM_USER_TABLE', [orig_table_prefix].'my_users'); define('CUSTOM_USER_META_TABLE', [orig_table_prefix].'my_usermeta'); </code> Source: http://codex.wordpress.org/Editing_wp-config.php#Custom_User_and_Usermeta_Tables I have read somewhere before that you may have to sort out a couple of issues of admin users on the second site, can't find the link at the moment.
|
How can 2 blogs share the same users
|
wordpress
|
I've never messed with the comments loop before, but I'm trying something out here. Basically, I have my comments form in a popup iframe, an ajax action which handles the form submission, inserts the comment, and updates the list of comments. I'm having a problem running the comments loop a second time on the page, though. The comments form comes through fine, but the comments don't show on the Ajax refresh. <code> have_comments() </code> turns up false, and <code> wp_list_comments() </code> outputs nothing. Any ideas what's going wrong? Here's my Ajax handler, in case there's an issue in there: <code> /* Submit Comments Through AJAX */ add_action ( 'wp_ajax_submit_comment', 'ajax_insert_comment' ); add_action ( 'wp_ajax_nopriv_submit_comment', 'ajax_insert_comment' ); function ajax_insert_comment() { /* obviously all of this needs sanitization, its oversimplified, just to get the idea across */ $data = extract( wp_parse_args( $_POST ) ); $current_user = wp_get_current_user(); $comment = wp_insert_comment( array( 'user_id' => $current_user->ID, 'comment_author' => $current_user->display_name, 'comment_author_email' => $current_user->user_email, 'comment_post_ID' => intval( $comment_post_ID ), 'comment_parent' => intval( $comment_parent ), 'comment_content' => $comment, 'comment_type' => $comment_type ) ); wp_reset_query(); global $post; $wp_the_query; $post = get_post( $comment_post_ID ); setup_postdata( $post ); /* Here's the problem: How to rewind the comments query so that it will actually display comments. I've tried all of these things, but they're not working right now */ $wp_query->current_comment = -1; $wp_query->rewind_comments(); // send comments list again. include( get_stylesheet_directory(). '/comments.php' ); die(0); } </code> The callback just takes the Ajax reponse and updates the comments div with the result. But its missing the whole comment list. Any ideas what I need to call to rewind the comments loop and make it actually display?
|
Ajax handler runs in completely separate instance of WordPress, it has no access to global variable from your pages and such. Basically there is nothing to rewind here, you need to pass those environment variables in request and query for comments from scratch.
|
How to use rewind_comments() - when and how to use it?
|
wordpress
|
On a themes site they stipulate, in the terms and conditions, that their themes inherit the GNU general public license from WordPress. I believe that this means that they can be copied and modified. However the themes are being sold. Shouldn't they be free? Could someone enlighten me.
|
The GPL absolutely does not preclude selling code, for cost. In fact, the terms of the license explicitly allow for selling of code. The GPL merely allows the end user, whether he received the GPL-licensed code for free or for cost, to use the code however he likes, to redistribute the code, to modify the code, and to redistribute the modified code - provided that any such-distributed code be licensed under the same license.
|
Wordpress themes under GPL license
|
wordpress
|
How can I permanently disable pingbacks on my wordpress multi user installation? I have disabled access to the wp-trackback.php file through permissions (chmod 000 trackback.php) thinking this would stop any pingbacks from being received. I do not want to run any SQL queries on the posts table, as there is a separate posts table for each blog.
|
Put this in a network activated plugin. <code> add_filter('pings_open','__return_false'); </code> No more incoming pings.
|
How do I permanently disable Pingbacks?
|
wordpress
|
I have two different kinds of search results on my site and I'd like to change the look of the search result page entirely. I've played around with the search form a bit but I'm unsure how to force it to redirect to an alternate search.php Any help would be appreciated <code> <form role="search" method="get" id="searchsupport" action="/"> <label class="screen-reader-text" for="s">Search for:</label> <input type="text" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'search';}" id="s" name="s" value="search" class="search-form round"> <input type="hidden" id="searchsubmit"> <input type='hidden' name='post_type' value='software, documents' /> </form> </code>
|
you can add an hidden filed to your search form and include a different template based on that: <code> <form role="search" method="get" id="searchsupport" action="/"> <label class="screen-reader-text" for="s">Search for:</label> <input type="text" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'search';}" id="s" name="s" value="search" class="search-form round"> <input type="hidden" id="searchsubmit"> <!-- this is the magic field ---> <input type="hidden" name="custom_search" value="1"> <input type='hidden' name='post_type' value='software, documents' /> </form> </code> then in your theme's search.php at the very top add: <code> if (isset($_GET['custom_search']) && $_GET['custom_search'] == 1){ include('custom_search.php'); // change it to whatever template file you would like to use break; } </code>
|
Varying Search Result Pages
|
wordpress
|
I'm using the advanced custom field plugin to convert WP into a CMS (it's works brilliantly for this). There's just one issue - with an image field it's not quite a smooth process as images need to be selected twice, this causes user confusion. Rather than me up all the images again - please see here for step by step process of the problem. I'm not sure if this is a WP problem or a problem with the plugin.
|
This has now been solved. It was a case of fixing the http error I was getting with the flash uploader. It then gives you the select button rather than the insert into post.
|
Unable to select image with custom field
|
wordpress
|
The default Archive widget display monthly archives in a dropdown. I would like to limit the number of months to 12 (in dropdown). What filter I should apply in my functions.php? I tried this, but it gives me parsed error: <code> add_filter('WP_Widget_Archives','set_number_months'); function set_number_months($args) { $args = array('number' => 12); return $args; } </code> I also tried with wp_get_archives but same parsed error
|
Use the <code> widget_archives_args </code> filter to add the archives limit. <code> function my_limit_archives( $args ) { $args['limit'] = 12; return $args; } add_filter( 'widget_archives_args', 'my_limit_archives' ); </code> And to limit the number of months in Archives widget dropdown use the following drop down filter. <code> add_filter( 'widget_archives_dropdown_args', 'my_limit_archives' ); </code>
|
Archive widget - limit number of months to 12
|
wordpress
|
When I use <code> wp_nav_menu(array( 'theme_location' => 'mainnav', 'container' => 'nav', 'container_id' => 'mainnav', 'container_class' => 'clearfix', 'depth' => 4 )); </code> If the user hasn't set a nav menu under Appearance menu, I notice theres a fallback like <code> <div class="menu"><ul><li class="page_item page-item-2"><a title="Sample Page" href="http://dev.klifmedia.net/ae/?page_id=2">Sample Page</a></li></ul></div> </code> How can I have the fallback use whats specified in <code> wp_nav_menu </code> ? How can I check if theres a menu to display then display it, else show nothing?
|
The default fallback menu is created with wp_page_menu() function and if you want to customize it the you need to create your own fallback function : <code> function my_fallback_menu(){ $args =array('whatever'); wp_page_menu($args); } </code> and then call that function in your wp_nav_menu call as the fallback: <code> wp_nav_menu(array( 'theme_location' => 'mainnav', 'container' => 'nav', 'container_id' => 'mainnav', 'container_class' => 'clearfix', 'depth' => 4, 'fallback_cb' => 'my_fallback_menu' )); </code> to check if a menu exists you can use <code> has_nav_menu() </code> function: <code> if (has_nav_menu( 'mainnav' )){ //display the menu }else{ //no menu yet do something else } </code> and to simplify the things even more you can just call the menu and set the fallback to false: <code> wp_nav_menu(array( 'theme_location' => 'mainnav', 'container' => 'nav', 'container_id' => 'mainnav', 'container_class' => 'clearfix', 'depth' => 4, 'fallback_cb' => false )); </code>
|
wp_nav_menu and its fallback
|
wordpress
|
I am using contact form 7 plugin in my blog.I am having donate option in the form with price option in radio button. user can select and submit.After submitting the form it should redirect to the paypal. with selected price . i tried on_sent_ok: "location = 'https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_xclick&[email protected]&currency_code=USD&amount=100&return=http://http://cratecreative.com/norpac&item_name=contribution';" in additional option in form management. But here value of price is static . I need to change that value what user selects. Thanks in advance
|
First change the `on_sent_ok' to: <code> on_sent_ok: 'my_redirect();' </code> then create that <code> my_redirect() </code> function in the page that displays the form: <code> <script> function my_redirect() { var price = document.getElementById('PRICE_FIELD').value; var url = 'https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_xclick&[email protected]&currency_code=USD&amount='+price+'&return=http://http://cratecreative.com/norpac&item_name=contribution'; window.location = url; } </script </code> and done! Just make sure that you correct the email in that url and replace <code> PRICE_FIELD </code> with the actual id of the price field.
|
get values from contact form 7 wp plugin
|
wordpress
|
I am in the process of creating a wordpress mobile theme for one of my wpmu networks. I have created 2 + pages that show our other sites and a custom login form. Right now i have labeled them page-other-sites.php and page-login.php and created 2 pages in the backend. When you click on the link it loads the page-(slugs).php Now instead of having to create a page every time is there a way to have my themes function.php file create a set of default pages.?
|
So instead of creating a theme for it i ended up using the <code> template_redirect </code> with an if statement to check the url for a certain thing. <code> function page_redirect() { if ($_SERVER['REQUEST_URI'] == $home . '/other-sites') { require(TEMPLATEPATH . '/includes/other-sites.php'); } if ($_SERVER['REQUEST_URI'] == $home . 'login') { require(TEMPLATEPATH . '/includes/login.php'); } } add_action('template_redirect', 'page_redirect'); </code> Simply all this does is check to see if the requested URI is <code> wpsite.com/other-sites </code> or <code> wpsite.com/login </code> and if this is true then load this template instead. Since i am using some WordPress features though in these custom templates i have also made a check for the title since WordPress will return a page not found title.
|
Create a page for a theme only
|
wordpress
|
I have custom post-type 'sermon' with custom taxonomy 'speaker' attached to it. I wanted to assign custom meta values to the speaker taxonomy, so I am using the taxonomy meta class from Rilwis: http://www.deluxeblogtips.com/p/taxonomy-meta-script-for-wordpress.html I have used the class to add a metabox with the id of 'bio'. According to his directions, I need to use the following code in order to output the value of the 'bio' meta into my template: <code> $meta = get_option('meta_id'); if (empty($meta)) $meta = array(); if (!is_array($meta)) $meta = (array) $meta; $meta = isset($meta['term_id']) ? $meta['term_id'] : array(); $value = $meta['field_id']; echo $value; // if you want to show </code> Here is what ended up working for me: <code> $taxmeta = get_option('speaker_meta'); if (empty($taxmeta)) $taxmeta = array(); if (!is_array($taxmeta)) $taxmeta = (array) $meta; $taxmeta = isset($taxmeta['221']) ? $taxmeta['221'] : array(); $value = $taxmeta['bio']; echo $value; // if you want to show </code> Question In the above code you see the number '221'. That is the actual term-id of the taxonomy assigned to the post in question (hardcoded to test it out). What I don't understand is how to populate the term_id dynamically. I can't query the url because this is simply being used on a custom post-type single page, so the term-id is not available there. How would I modify that snippet to put in the proper term-id belonging to the 'sermon' that I am looking at? thanks edit This function does return the proper term_id for me: <code> $terms = wp_get_post_terms($post->ID, "speaker"); foreach ($terms as $termid) { echo $termid->term_id; } </code> Using that snippet within my loop on my example page returns the value of '221'. If I manually put 221 in place of term_id in the function then it does pull the term meta 'bio' just perfectly. Where I am still stuck Now that I have that little snippet above which works, how do I get that to output to the term_id so the primary function will work? <code> $meta = isset($meta['term_id']) ? $meta['term_id'] : array(); </code> thanks again
|
you can use the <code> get_the_terms() </code> function to get the terms of that post in a specific taxonomy: <code> $terms = get_the_terms( $post->ID , 'speaker' ); //change speaker to whatever you call your taxonomy //then you can use just the first term $term_id = $terms[0]->term_id; </code> and now you have the term id inside <code> $term_id </code> . update Once you have the term_id you can use it in your function like so: <code> $term_id = $termid->term_id; $meta = isset($meta[$term_id]) ? $meta[$term_id] : array(); </code>
|
Get the term id belonging to custom taxonomy on a custom single-post-type.php template page
|
wordpress
|
How do I create a simple dropdown menu with 3 options in a widget? I'm using $instance to do it. How would it look in a barebones widget?
|
This is what I do: Static Options <code> <select id="<?php echo $this->get_field_id('posttype'); ?>" name="<?php echo $this->get_field_name('posttype'); ?>" class="widefat" style="width:100%;"> <option <?php selected( $instance['posttype'], 'Option 1'); ?> value="Option 1">Option 1</option> <option <?php selected( $instance['posttype'], 'Option 2'); ?> value="Option 2">Option 2</option> <option <?php selected( $instance['posttype'], 'Option 3'); ?> value="Option 3">Option 3</option> </select> </code> Generate with options with PHP (example) <code> <select id="<?php echo $this->get_field_id('posttype'); ?>" name="<?php echo $this->get_field_name('posttype'); ?>" class="widefat" style="width:100%;"> <?php foreach(get_post_types($getposttype_args,'names') as $post_type) { ?> <option <?php selected( $instance['posttype'], $post_type ); ?> value="<?php echo $post_type; ?>"><?php echo $post_type; ?></option> <?php } ?> </select> </code> You want to change all instances of <code> posttype </code> to whatever field_id you want to use.
|
How do I create a drop down menu in a widget?
|
wordpress
|
I was thinking about creating a network of user-created blogs. I've read somewhere about wordpress multisite feature, and i was wondering if this is what i'l looking for... What i need to do is create a website where users register and create their onw blog. Does wordpress multisite offer this feature out of the box ? If not, would manually implementing this feature into wp be doable, or should i start from 0 or another platform ? Thank you!
|
WordPress multisite sounds exactly like what you are looking for. It takes a little work to get multisite set up, but once that's done, the options for allowing anybody to register and create a new site are built right in. See http://codex.wordpress.org/Create_A_Network for setting up a multisite instance.
|
Multisite features
|
wordpress
|
Is there a way to hide the comments column in the backend? When you look at the pages, there's a comments column even though I'v disabled them. I made WP into a cms and it may cause some confusion.
|
Try this: <code> add_filter("manage_edit-page_columns", "my_page_edit_columns"); function my_page_edit_columns($columns){ unset($columns['comments']); return $columns; } </code> If you need it for posts instead of pages, use <code> manage_edit-post_columns </code> instead. The same goes for any post type, really, as <code> manage_edit-{post_type}_columns </code> .
|
Hide comments column in WP backend
|
wordpress
|
I've made WP into a cms and there's a few niggling things that cause confusion. The main one is that when you create a page, you have to first select a template then enter a title then save as draft for it to show the correct fields on the page (I'm using the advanced custom field plugin). Is there any way to get around this? A couple of users have now said "why aren't I seeing the correct fields to fill in?", this is down to not selecting the template and saving first.
|
Why are custom fields conditional upon the Page template? Wouldn't an easier, more elegant, and more intuitive approach be to use Custom Post Types ?
|
CMS - User confusion when creating new page and having to select template and save first to see correct fields
|
wordpress
|
For some reason the WP_Query instance in my shortcode function won't take the query attribute sent from the shortcode. The shortcode is like this: [postlist query="post_type=any&posts_per_page=5" style="list"] Here's the code. <code> function hey_query_shortcode( $atts ) { extract( shortcode_atts( array( 'query' => '', 'style' => '' ), $atts ) ); ob_start(); $the_query = new WP_Query( $query ); while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <h3><?php the_title(); ?></h3> <?php the_excerpt(); ?> <h2>I know $style is set bc it shows up here: <?php echo $style; ?></h2> <h2>I know $query is set bc it shows up here: <?php echo $query; ?></h2> <?php endwhile; echo '<hr>'; wp_reset_postdata(); $list = ob_get_clean(); return $list; } add_shortcode( 'postlist', 'hey_query_shortcode' ); </code> Any idea what is going on here? $query echoes out fine but for some reason it doesn't affect the WP_Query query.
|
Sorry I deleted my comment because I found the issue. You need to do an html entity decode on query variable. Use the code below. <code> function hey_query_shortcode( $atts ) { extract( shortcode_atts( array( 'query' => '', 'style' => '' ), $atts ) ); $query = html_entity_decode( $query ); ob_start(); $the_query = new WP_Query( $query ); while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <h3><?php the_title(); ?></h3> <?php the_excerpt(); ?> <h2>I know $style is set bc it shows up here: <?php echo $style; ?></h2> <h2>I know $query is set bc it shows up here: <?php echo $query; ?></h2> <?php endwhile; echo '<hr>'; wp_reset_postdata(); $list = ob_get_clean(); return $list; } add_shortcode( 'postlist', 'hey_query_shortcode' ); </code>
|
Trouble passing attribute into shortcode function
|
wordpress
|
Does Wordpress have the ability to use the currently defined template to serve up content in the database? For example, I have a database of a bunch of custom content-- the name of an item, the price, etc. I want all requests for http://myshop.com/buy/ * to be redirected to the plugin (so that the plugin handles the content generation), where the * is an item number or some other parameter. Can I use the Wordpress template and display my custom content? I would be handling all of the HTML generation for inserting into the template... The best example I can find is the WP Ecommerce plugin here: http://getshopped.org/ . Basically, the plugin is handling the checkout page (/checkout in most cases, /icons/checkout on IconDock). How can I do this?
|
There are two different things happening here. I'll start with your second example, as that's easier. Most shopping carts, in your example WP-Ecommerce, create placeholder pages with a shortcode for things like the cart page and checkout page. All they're doing to handle that is creating a shortcode function and inserting it on a page, then outputting whatever they need to in the shortcode function. In this case the shortcode is static, and there isn't any other data being passed via the url. The actual product pages in WP-Ecommerce are just a WordPress custom post type with some extra meta data. What you're talking about, creating your own url structure via a plugin to pass data, involves writing your own rewrite rules via the WP_Rewrite class and inserting your own query vars.
|
Have Plugin Handle Specific URLs
|
wordpress
|
When I build a theme from scratch I have to "enable" sidebars and specific menus in the functions.php. Similarly, do I need to "enable" access to the javascript and jquery libraries that come bundled with WordPress? I ask because 2 How-to books I've been using (WordPress 2.8 Theme Design, and Beginning WP 3) both talk about needing to do this and provide code, but neither of them makes explicit whether you need to do this just to make things work in general, or whether you need to do this only if you want to include your own "standalone" javascript(s) as opposed to a script that is part of a plugin/widget. I'm assuming the latter but want to confirm -
|
If you'll be using jQuery in your theme you need to "enqueue" it. If you do not need the JS , ie if you do not run custom jQuery plugins, you don't need to "enqueue" it via wp_enqueue_script
|
Custom Theme Design: do I need to "enable" jquery/javascript libraries?
|
wordpress
|
I've been playing around with the jquery plugin Fancybox on this page, but for some reason since making a few changes my page seems to be displaying blog archives rather than the normal content it should be displaying. I just wondered whether people have had a similar problem? There must be something I've done wrong for this page because all of the other page's content are displaying fine. This is the code for the portfolio.php page, but it is outputting something completely different. <code> <?php </code> /* Template Name: Portfolio */ ?> <code> <section> <?php include("includes/slideshow/slideshow-home.php"); ?> </section> <header> <div id="titleHeader" class="clear"> <h2 class="entry-title"><?php the_title(); ?></h2> </div> </header> <section> <article> <div id="mainContent" class="clear"> <?php /* Run the loop to output the page. * If you want to overload this in a child theme then include a file * called loop-page.php and that will be used instead. */ get_template_part( 'loop', 'page' ); ?> <ul id="portfolioContent"> <?php $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 10)); ?> <?php while ( $loop->have_posts() ) : $loop->the_post(); ?> <?php $custom = get_post_custom($post->ID); ?> <li class="portfolioThumb"><a href="<?php echo get_permalink(); ?>" class="various2"><?php the_post_thumbnail('thumbnail'); ?></a></li> <?php endwhile; ?> </ul> </div> </article> </section> <section> <aside> <?php get_sidebar(); ?> </aside> </section> <?php get_footer(); ?> </code> Thanks, Ash
|
Does slideshow-home.php has a loop as well? You need to ensure that you reset the queries or rewind posts while using multiple Loops <code> <?php wp_reset_query(); ?> </code> Multiple_Loops Reset Query
|
Page is displaying blog archives
|
wordpress
|
I use the Google XML Sitemaps (Wordpress Plugin) and the latest wordpress version. Recently i have had a lot of 404 not found errors in webmasters. The urls show up without any categories and it links to the sitemap.xml file. It shows the url as http://mysite.com/welcome-to-my-site/ instead of http://mysite.com/general/welcome-to-my-site/ Since the categories are missing these links return a 404 not found error. These faulty links are piling up and i am in a fix. Please help.
|
the XML sitemaps plugin should be pulling your URL structure that you've set in the permalinks setting. Are you using a plugin or other method to remove the /category-name/ from the URL?
|
Getting lots of errors with sitemap on google webmasters
|
wordpress
|
Im just wondering if its possible to create user role that allows to write/edit custom post type for example: Consultants, but not allow to write normal posts (used for as news for example). I know that if user wants to edit posts its a must to have edit_post enabled for him. Question is if i can create something like: edit_[custom_post_type] or something? Thanks in avance if anyone can help me with this issue... Kindest regards
|
I suspect that Justin Tadlock's Members Plugin would make this very easy for you.
|
User roles - enable custom posts disable posts
|
wordpress
|
This may be more of a php best practices question, but here goes... I am using a custom excerpt trim function: <code> function new_wp_trim_excerpt($text) { // Fakes an excerpt if needed global $post; if ( '' == $text ) { $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]&gt;', $text); $text = strip_tags($text, '<p>'); $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text); $excerpt_length = 100; $words = explode(' ', $text, $excerpt_length + 1); if (count($words)> $excerpt_length) { $dots = '&hellip;'; array_pop($words); $text = implode(' ', $words).$dots.'<p class="moarplz"><a href="'. get_permalink($post->ID) . '">Read More &raquo;</a></p'; } else { $text = get_the_content(); } } return $text; } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'new_wp_trim_excerpt'); </code> Basically, for posts over a hundred words, a "faked" excerpt is produced of the first 100 words, with a "Read More" link. Posts having less than 100 words are outputted in their entirety. You can see this at work here: http://www.mbird.com/ Complicating this matter is 1) that an author can choose to override the excerpt per post. Also, 2) there is a function that tries to find an image that can serve as a post thumbnail from the post attachments if none is specified. All these things act as flags, determining the layout of the post on the index page. For example, if a full post is output, it needs to have extra padding to avoid the image wrap CSS I have in place, and it shouldn't have a teaser thumbnail. If no teaser thumbnail can be found for a excerpt it needs to avoid the same. Etc etc. Anyway, in order to determine what the layout out wrapper should be, I end up reusing a lot of the <code> new_wp_trim_excerpt </code> function in my page template to sniff if an excerpt or a full post will happen. Like so: <code> <?php while (have_posts ()) : the_post(); global $excerpt_checkbox_mb; $exmeta = $excerpt_checkbox_mb->the_meta(); //override excerpt? $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]&gt;', $text); $text = strip_tags($text, '<p>'); $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text); $excerpt_length = 100; $words = explode(' ', $text, $excerpt_length + 1); if (count($words) > $excerpt_length) { $word_count = true; } else { $word_count = false; } ?> </code> Then I use that to determine if an image should be hunted for: <code> <?php if (($exmeta['cb_single'] != "yes") && $word_count) { // we're printing an excerpt, get a teaser image! get_the_image(array( 'meta_key' => null, 'image_class' => 'thumb', 'callback' => 'find_image' )); } ?> </code> And finally what the wrapper should be: <code> <?php $image = find_image(); ?> <!--if full post, add left padding to avoid image wrap--> <?php if (($exmeta['cb_single'] == "yes") || !$word_count) : ?> <div class="post-content"> <?php the_content(); elseif ($image) : ?> // we found an image, apply css psuedo-col <div class="post-content post-psuedo-col"> <?php the_excerpt(); else : ?> // no image, reduce padding <div class="post-content"> <?php the_excerpt(); endif; ?> </div> </code> Anyway, it seems bad to reuse so much of the <code> new_wp_trim_excerpt </code> function to sniff, especially since I have to change <code> $excerpt_length </code> in two places! But I can't really figure out an elegant way to re-factor. I was considering adding another function that both parts can call on, that would return array containing a bool regarding <code> count($words) > $excerpt_length </code> and optionally the text itself, but that still seems clunky. If you've somehow managed to read all this, help!
|
I'd simply set a flag as second input argument for the function: <code> function new_wp_trim_excerpt( $text, $case = 'plain' ) { switch ( $case ) { default : case 'plain' : // do stuff - your function so far break; case 'image' : break; } } </code> Notes: Avoid names like <code> class="moarplz" </code> . It's hard to read for others and hard for yourself in a year. Never <code> count </code> inside an <code> if/for/while/foreach/else/elseif </code> statement - it's up to 5 times slower than counting it in the line before.
|
Custom excerpt function re-factoring
|
wordpress
|
What I'm looking to do it get the 16 latest posts from 16 different authors. In other words there would be the 16 latest posts, but no one single author would have more that 1 post on the page. The way I've thought about doing it, is looping through all the authors, removing the duplicates, then limited that to 16 and use that to generate the posts in a for each loop, but I'd imagine that would be heavy on the server. Any suggestions?
|
Use a custom SQL query to grab the latest 16 post IDs with unique authors; <code> $post_IDs = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'product' AND post_status = 'publish' GROUP BY post_author ORDER BY post_date DESC LIMIT 16" ); </code> Then start up a new query with the <code> post__in </code> argument; <code> $recent_posts = new WP_Query( array( 'post__in' => $post_IDs, 'post_type' => 'product' ) ); </code>
|
Find most recent authors
|
wordpress
|
I want to allow users to upload images for use in a rotating banner. I tried using the media library, stackexchange-url ("but didn't get much help") ... So I thought, I'd just implement the upload myself. But I encountered another problem... I am using the settings API they do the update options and stuff for me. How can I handle the upload then? I thought of using the validate callback to upload images and then set $_POST variables manually so that Settings API can save those. But it sounds wrong. Any ideas?
|
You should only need a list of URL's selected from the Media Loader. There are others out there, but I have a Theme Options Panel for your admin that is Settings API compliant. It has an 'upload' option that uses the Media Loader to upload a file and fill a text field with the returned URL of that file. This is saved as an option with the Settings API. Perhaps you can get an idea from that. You could provide a pre-set amount of 'upload' options (5 URLS/images for example) or modify the code to handle it differently. Theme Options Panel Framework
|
How to upload images using Settings API
|
wordpress
|
Is there a plugin with the social media share buttons where I have more control of where to place them? At the moment, the only one's I can find only allow you to place the buttons at the top or bottom of pages/posts. Ideally I'd like a snippet of code to just place wherever I wanted.
|
I finally came across one that wasn't over the top and there was also a manual function: http://wordpress.org/extend/plugins/wp-social-bookmarking-light/
|
Plugin - Social media share buttons
|
wordpress
|
I have a custom post type without title support and I'm trying to generate one from post's taxonomies and custom fields. To do so, I'm using this code: <code> function custom_post_type_title_filter( $data , $postarr ) { if ($postarr['post_type'] == 'cars'){ $id = get_the_ID(); $engine= ', '.get_post_meta($id, 'Engine', true).'l'; $terms = wp_get_object_terms($id, 'brand'); $abrand= ' '.$terms[0]->name; $amodel = ' '.$terms[1]->name; $data['post_title'] = $id.$abrand.$amodel.$engine; } return $data; } add_filter( 'wp_insert_post_data' , 'custom_post_type_title_filter' , 99, 2 ); </code> Problem is, to make it work, I have to republish my post. It does not work with new post (it has no ID yet, I guess) and if I change custom field values in post, it won't generate name from them yet, I'll have to save it twice to get it done. Can someone share a solution with example how it's done properly? Also, would be nice to be able to set custom slug too (different from the title).
|
You can try the following code. <code> function custom_post_type_title ( $post_id ) { global $wpdb; if ( get_post_type( $post_id ) == 'cars' ) { $engine= ', '.get_post_meta($post_id, 'Engine', true).'l'; $terms = wp_get_object_terms($post_id, 'brand'); $abrand= ' '.$terms[0]->name; $amodel = ' '.$terms[1]->name; $title = $post_id.$abrand.$amodel.$engine; $where = array( 'ID' => $post_id ); $wpdb->update( $wpdb->posts, array( 'post_title' => $title ), $where ); } } add_action( 'save_post', 'custom_post_type_title' ); </code>
|
Custom Post Type with Custom Title
|
wordpress
|
I looking at the docs for <code> add_meta_box </code> . They used a nonce. <code> wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' ); </code> I am wondering, probably the save post form itself should already have a nonce so this is redundant?
|
Yes, the save action has a nonce already. But you don’t know it – so you cannot validate it. Besides that, you may want to fill a meta box from other places like a user profile or the dashboard, and then you need your own nonce anyway. An example from my current work: There is a custom post type <code> domicile </code> with a booking schedule meta box. My client is the agent or broker (English is not my native language …) for the domicile and fills the schedule from the editor for the CPT. But the owners of the domiciles can fill the schedule too – from their dashboard. I just load all booking schedules they are assigned to and they edit them without ever seeing the complete data of the domicile. Without separate nonces this would be very awkward.
|
Is there a need for nonce with Post Metabox?
|
wordpress
|
Suppose I store all my post meta data in an array like <code> $meta = array( 'img' => '', 'caption' => '' ); update_post_meta($post->ID, 'theme_banner', $meta); </code> Can I query posts where the img is filled?
|
Short answer: NO! I've asked a similar question before stackexchange-url ("mysql order by serialized data")? and the answer i got is: The only possible case when serialized data is acceptable is when you don't need to search , filter or order by through that data. In all other cases - store your data as a separated fields.
|
Metadata Query when storing data as array possible?
|
wordpress
|
I would like the htaccess rewrite rule to compare to IIS rewrite rule I tried which doesn't seem to work: <code> <rule name="rewrite /blog/"> <match url="^blog/([_0-9a-zA-Z\-]+)/$" /> <action type="Rewrite" url="/{R:1}/" /> </rule> </code>
|
This is not a WordPress question. Anyway … <code> RewriteRule ^blog/(.*) /$1 [L,R=301] </code>
|
How to redirect http://mydomain/blog/blahblah/ to http://mydomain/blahblah/ in wordpress htaccess?
|
wordpress
|
Instead of having an email on every comment on a blog post I've wrote, I'm looking for a visual notification on wordpress itself, an "inbox" if you get what I mean. Does that exist? Thanks, Dennis
|
This should be visible by default on your WP admin dashboard under "recent comments". is there something else you're looking for it to do?
|
Alternative to email notification system?
|
wordpress
|
I am using this wordpress Script to add metaboxes under posts.. I followed as it was written.. but I am having trouble on how to get those values in singe.php Example an uploaded image Please guide me on this..
|
<code> <?php if ( get_post_meta($post->ID, 'your_metabox_id', true) ) : ?> <?php echo get_post_meta($post->ID, 'your_metabox_id', true) ?> <?php endif; ?> </code> The trick is to use get_post_meta hook
|
How to get the value of particular get $meta value in wordpress
|
wordpress
|
The following code is supposed to allow for a shortcode that includes many attributes, but not all of the attributes may always be present in which case I do not want the containing element to show anything. However, with or without the conditional statements, when I upload my functions file I receive only a blank page on the front and back end. Here is the full shortcode with conditional statements: <code> function info($atts, $content = null) { extract(shortcode_atts(array( "name" => '', "image" => '', "address" => '', "phone" => '', "email" => '', "website" => '', "description" => '', "amenities" => '' ), $atts)); return '<span class="sort">' if($image) { '<img src="'.$image.'" />'}' <span class="name">'.$name.'</span> <span class="details">' if($phone) { $phone } if($address) { '&bull; <a href="http://maps.google.com/?q='.$address.'" target="_blank">'.$address.' <img src="<?php bloginfo('template_directory'); ?>/_/images/mapmarker.png" width="16" height="16" alt="Map" /></a><br/>'} if($email) { '<a class="infomail" href="mailto:'.$email.'">Send Email</a>' } if($website) { '<a class="infosite" href="'$website'">Visit Website</a>' } if($description) { '<p class="infodetails">'.$description.'</p>' } if($amenities) { '<p class="amenities">'.$amenities.'</p>' } '</span> </span>'; } add_shortcode("info", "info"); </code> Thanks for your suggestions!
|
your conditional breaks the concatenation of the strings (which is not in your code, anyway) try to re-write this section: <code> function info($atts, $content = null) { extract(shortcode_atts(array( "name" => '', "image" => '', "address" => '', "phone" => '', "email" => '', "website" => '', "description" => '', "amenities" => '' ), $atts)); $output = '<span class="sort">'; if($image) { $output .= '<img src="'.$image.'" />';} $output .= '<span class="name">'.$name.'</span> <span class="details">'; if($phone) { $output .= $phone; } if($address) { $output .= ' &bull; <a href="http://maps.google.com/?q='.$address.'" target="_blank">'.$address.' <img src="' . get_bloginfo('template_directory') . '/_/images/mapmarker.png" width="16" height="16" alt="Map" /></a><br/>'; } if($email) { $output .= ' <a class="infomail" href="mailto:'.$email.'">Send Email</a>'; } if($website) { $output .= ' <a class="infosite" href="'.$website.'">Visit Website</a>'; } if($description) { $output .= '<p class="infodetails">'.$description.'</p>'; } if($amenities) { $output .= '<p class="amenities">'.$amenities.'</p>'; } $output .= '</span> </span>'; return $output; } add_shortcode("info", "info"); </code>
|
Can shortcodes contain conditional statements? Even without them my shortcode renders blank page
|
wordpress
|
There're the functions <code> get_theme_data(); </code> & <code> get_plugin_data(); </code> - which both use <code> get_file_data(); </code> that needs a specific file as <code> $input </code> . I got a set of classes that may be used by a plugin or a theme, without a specific location. Everything works, but I don't know how i would determine what the main plugin or theme file is - I mean the one containing the comment header that holds the information (Version, Author, etc.) about the Theme/Plugin.
|
How do get the comment header data of a theme OR plugin... ... that holds a specific class. The following shows how you can drop a class inside any plugin or theme and still be able to get any theme or plugin data from the comment header. This is useful for updating settings/db-options for example. You don't know: if it's a plugin, mu-plugin or a theme and how deeply nested your container/root theme or plugin folder is. Notes: Works for mu-plugins too. Might not work if an additional theme directory was registered later (thanks to @toscho for the hint). Performance test for a theme shows 0.0042 sec. loading time on 1.000 runs. The following functions are meant to reside in a class. <code> /** * Plugin root * @return Full Path to plugin folder */ public function set_root_path() { $_path = trailingslashit( str_replace( basename( __FILE__ ), "", plugin_basename( __FILE__ ) ) ); // Allow overriding the location $_path = apply_filters( __CLASS__.'_root', $_path ); return $this->_path = $_path; } /** * Gets the data of the base 'theme' / 'plugin' / 'wpmuplugin' * Performance: average loading time on a local (not vanilla) install for 1.000 runs: 0.0042 sec. * * @param (mixed) $value * @return (array) $value | Theme/Plugin comment header data OR false on failure | default: 'Version' */ public function get_data( $value = 'Version' ) { // Class basename - String to Array $_path_data = explode( '/', $this->_path ); // Get rid of the last element, as it's only a trailing slash array_pop( $_path_data ); // reverse for faster processing krsort( $_path_data ); // Themes basename $theme_roots = get_theme_roots(); // In case some used register_theme_directory(); before // Might not work if an additional themes directory will be registered later // Thanks to @Thomas Scholz <http://toscho.de> for the hint if ( is_array( $theme_roots ) ) { foreach ( $_path_data as $_path_part ) { foreach( $theme_roots as $root ) { if ( in_array( $root, $_path_data ) ) $_theme_root = $root; } } } else { // Get rid of the leading slash $_theme_root = str_replace( '/', '', $theme_roots ); } // Plugins basename $_plugin_root = basename( WP_PLUGIN_DIR ); # >>>> get file & load data $base_file = ''; // Themes if ( in_array( $_theme_root, $_path_data ) ) { foreach ( search_theme_directories() as $folder => $data ) { foreach ( $_path_data as $_path_part ) { if ( $_path_part == $folder ) $base_file = trailingslashit( $data['theme_root'] ).$data['theme_file']; } } $file_data = get_theme_data( $base_file ); } // Plugins elseif( in_array( $_plugin_root, $_path_data ) ) { $plugins = get_plugins(); foreach ( $plugins as $plugin_file => $plugin_info ) { $data = explode( '/', $plugin_file ); $file = $data[1]; foreach ( $_path_data as $_path_part ) { if ( $_path_part !== $file ) $base_file = WP_CONTENT_DIR.$_type.'/'.$data[0].'/'.$data[1]; } } $file_data = get_plugin_data( $base_file ); } // WPMU Plugins else { // MU plugins basename - compatible for older MU too // Thanks (again) to @Thomas Scholz <http://toscho.de> for the hint that mu plugins really exists $mu_plugin_dir = ! version_compare( $GLOBALS['wp_version'], '3.0.0', '>=' ) ? MUPLUGINDIR : WPMU_PLUGIN_DIR; $_mu_plugin_root = basename( $mu_plugin_dir ); if ( ! in_array( $_mu_plugin_root, $_path_data ) ) return false; $mu_plugins = get_mu_plugins(); foreach ( $mu_plugins as $mu_plugin_file => $mu_plugin_info ) { $data = explode( '/', $mu_plugin_file ); $file = $data[1]; foreach ( $_path_data as $_path_part ) { if ( $_path_part !== $file ) $base_file = WP_CONTENT_DIR.$_type.'/'.$data[0].'/'.$data[1]; } } $file_data = get_plugin_data( $base_file ); } # <<<< get file & load data // return if ( ! empty ( $file_data ) ) return $file_data[ $value ]; // return false to determine that we couldn't load the comment header data return false; } </code> Usage Example: <code> echo $this->get_data( 'Author' ); // The Plugin or Theme Author echo $this->get_data( 'Version' ); // The Plugin or Theme Version echo $this->get_data( 'Name' ); // The Plugin or Theme Name </code>
|
How to: get main plugin/theme file?
|
wordpress
|
I'm in need of a forum plugin for Wordpress that has an option for a private forum that is only accessible (both for reading and posting) to registered users. Restricted posting appears to be de rigueur , but restricted viewing appears to be harder to find. Ideally, it'll integrate directly with Wordpress but if it needs to open in a separate window ( a la BBPress) then that's fine. I've been looking around at different Wordpress forum options (such as BBPress and Mingle), but I can't see whether any support this feature. Does anyone know of a simple forum solution that offers this? Thanks.
|
Simple:Press Can limit forums to no access, read only, limited, standard, full, moderator It's decently simple, I've been using it a bit for my personal blog. I didn't have too hard of a time integrating it. Lots of features available, with pretty fine grained ability to turn things on and off Also, as information, bbPress no longer requires stand-alone operation It is now developed as a plugin and is maturing rapidly. I've integrated it into one of my sites with no problems. However, I don't think it meets your needs. Just wanted to include the info in case you were interested.
|
Forum plugin with private forum option
|
wordpress
|
I have a wp_query that works great but I can't have both a meta query and a tax_query in it. <code> <?php $event_query = new WP_Query( array( 'post_type' => 'event', // only query events 'meta_key' => 'event-date', // load up the event_date meta 'orderby' => 'meta_value', 'order' => 'asc', // ascending, so earlier events first 'posts_per_page' => '-1', 'meta_query' => array( array( // restrict posts based on meta values 'key' => 'event-date', // which meta to query 'value' => date("Y/m/d"), // value for comparison 'compare' => '>', // method of comparison 'type' => 'DATE' ) ), 'tax_query' => array( array( 'taxonomy' => 'event_category', 'field' => 'slug', 'terms' => $term_id, 'operator' => 'IN') ), ) // end array ); // close WP_Query constructor call ?> </code> I am trying to find all the events in taxonomy $term_id and then make sure they are all in the future and order by ASC Any ideas?
|
The query looks about right and I know that <code> meta_query </code> and <code> tax_query </code> work together just fine. the only thing i can think of is that you are query taxonomy by slug and passing the term id which are two different things, change: <code> 'field' => 'slug', </code> with <code> 'field' => 'id', </code> in your tax_query.
|
How to create a wp_query that contains both meta_query and tax_query
|
wordpress
|
I am looking for the code that renders the below page. Where can I find it, it does not appear to be in functions.php? I want to learn how they allow users to upload images
|
The code you are looking for is in functions.php (line 106 to 211). To understand what they have done in TwentyTen, I would suggest that you read the following: http://codex.wordpress.org/Function_Reference/add_custom_image_header
|
Looking for the code in twentyten that allows users to select images for the header/banner
|
wordpress
|
I'm trying to put my own function in a widget but it doesn't run. I want to use it everywhere within the widget. If I could see an example,that'd be great.
|
there are a few way to run a function in widgets: option 1 - ShortCodes You can create a custom shortcode and run that function by entering the shortcode into a simple text widget: <code> //this is to make sure WordPress renders the shortcodes in a text widget add_filter('widget_text', 'do_shortcode'); add_shortcode('my_short_code','my_function'); function my_function(){ //do whatever you want } </code> and then simply add <code> [my_short_code] </code> to any text widget to run your function. Option 2 Plugins You can use one of the many plugins out there that let you run php in a widget like: PHP Code Widget WP Sidebar Essential PHP-Widgetify Option 3 Custom Widgets The last way is to write your own widget using the very simple Widgets API
|
how to put functions inside of widgets
|
wordpress
|
I'm using different method to form a gallery in Wordpress, so I would like to hide an option to insert images and galleries into post for anyone but Administrator. Can someone show me an example how it's done?
|
If you actually wanted to remove it instead of just hiding it you could remove the 'admin-gallery' script that is used to insert the gallery settings form. And if you wanted it to be remove only for non-admins then something like this should work: <code> function disable_wp_gallery() { if( !current_user_can('manage_options') ) wp_deregister_script('admin-gallery'); } add_action('admin_enqueue_scripts', 'disable_wp_gallery'); </code>
|
Hide "Gallery Settings" and "Insert into Post" button from Attachment window
|
wordpress
|
I have a feature in my current project that will be allow multiple ajax requests - I've got a single nonce request worked out (via this tute ), but am somewhat unsure how to figure in multiple nonce requests. functions.php: localize, create a single nonce <code> wp_localize_script( 'B99-Portfolio', 'B99ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'requestNonce' => wp_create_nonce('b99-request-nonce') ) ); </code> calling js: <code> $.ajax({ type : 'POST', url : B99ajax.ajaxurl, data : { action : 'b99-ajax-submit', requestNonce : B99ajax.requestNonce },... </code> receiving php <code> public function b99_ajax_submit() { $nonce = $_POST['requestNonce']; if ( ! wp_verify_nonce( $nonce, 'b99-request-nonce' ) ) ... sql, response </code> At this point, I can reuse this nonce repeatedly, but I think that defeats the purpose of the nonce check. My solution will be to request a new nonce in the receiving php, assign <code> B99ajax </code> js object that variable, and send it back to the requesting page for the "next" ajax sequence. Is there a better way?
|
That is basically the way WordPress does it and pretty much the only way to do it, simply have your receiving PHP function create a new nonce add send it back with your response, then just update the value on your JS before the next round.
|
Multiple ajax nonce requests
|
wordpress
|
So, I'd like to add some custom write panels when you go to write a new post in the WP admin. I'd like it to have a heading for each, and then a text input field where I can write in some text. I would need it to be inserted into the single.php file, and then output as a definition list. So, each custom field heading would be a pre-determined , like "Materials Needed" (without the quotes...), and then whatever I put within the blank text field would spit out as a . Here's an example of what it would need to output as... <code> <dl> <dt>Purpose of Activity</dt> <dd>To improve the skill to strike an object with a paddle.</dd> <dt>Prerequisites</dt> <dd>practice of striking skills - focusing on the following cue words: <ul> <li>Flat Paddle</li> <li>Stiff Wrist (pretend it is in a cast)</li> <li>Watch the Object</li> </ul></dd> <dt>Suggested Grade Levels</dt> <dd>K-2</dd> <dt>Materials Needed</dt> <dd>one paddle for each student, 2-4 folding mats, 50+ balloons</dd> <dt>Description of Idea</dt> <dd>Use paddles and balloons in self-space prior to this activity. Practice the underhand hit (with the face of the paddle to the ceiling). The class is divided into six teams of "farmers" scattered around the room. Each team will have their own "barn" made of two folding mats standing upright and forming a barn-like structure. Fifty plus (50+) balloons will be scattered on the gym floor. On the "go" signal, students use their paddle to round up the farm animals (balloons) and herd them into their barn. Only one balloon can be taken at a time. Once a student has a balloon, other students are not allowed to touch that particular balloon. The game continues until all balloons are in the barn. Students then return to their starting positions and sit with their paddles at rest.</dd> <dt>Variations</dt> <dd>Use koosh balls, a shuttlecock, a foam ball, a dead tennis ball</dd> <dt>Teaching Suggestions</dt> <dd>To apply math skill integration, balloons can be worth various points and students can add the points at the end of each round.</dd> <dt>Adaptations for Students with Disabilities</dt> <dd>larger/lighter paddle, balloon tied to chair for continuous hitting</dd> </dl> </code>
|
The Metabox Script for WordPress has been of great help to me: http://www.deluxeblogtips.com/p/meta-box-script-for-wordpress.html You will be able to ouput all that you shown above and more too. Completely customizable to your wishes.
|
How to Do Custom Fields to Output a Definition List
|
wordpress
|
I am new to WP. What i allready have - I am building a news blog with few posts categories. each category function as a different section (Economics, Sports etc.) What i want to achieve- What i am trying to achieve is to set a static page that will preview the last post from each category and will serve as the main page of the "news site". how can i nest posts preview on a static page (I understand that static pages are posts right?). is there a way to retrieve all the posts from a specific date? is there a way to group them by category? I know it is a "Big" question. I am only looking for directions and not tutorial. Thanks a lot Shani
|
You will need to set a Static Page as your front page, create and assign a PHP Template for that page, and stack multiple Queries in the template to search out your required categories and display them. Here is one, you might have many: <code> // get the last post (any date) from 'Featured' category $featured = new WP_Query( 'category_name=Featured&posts_per_page=1' ); if ( $featured->have_posts() ) { while ( $featured->have_posts() ) { $featured->the_post(); // fill $post with data ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <!-- output markup and display the post(s) --> </div> <?php } } rewind_posts(); // start next query </code> That should give you an idea, at least, there is a fair bit to it. Good luck.
|
previewing my posts on static page?
|
wordpress
|
I'd like to enqueue scripts only for an admin page that I've created. There's an example of this here: http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Load_scripts_only_on_plugin_pages But it's not working for me, I think because I'm writing my plugin within a class. add_action only works with in the constructor?? Is there a way to add scripts to a specific page from within a class? I came up with this method: My main plugin page is a list of custom post types (if you set <code> 'show_in_menu' => 'custom_page_slug' </code> in the post type args it takes over that page with a list of posts). When I created the post type, I set a variable up with the post type name: <code> $args = register_post_type('post-type', $args ); $this->posttype = $args->name; </code> Then this call in the constructor: <code> add_action( 'admin_print_scripts', array( &$this, 'scripts_init' ) ); </code> And this in the <code> scripts_init </code> function: <code> global $current_screen; if( $current_screen->id == $this->posttype ) { wp_enqueue_script( ... ); } </code> It works. But it seems more complicated than it needs to be. Is there a better way to accomplish this? Thanks!
|
Instead of hooking into <code> admin_print_scripts </code> only , you should hook into your specific page slug which is appended to <code> admin_print_scripts- </code> . (note trailing hyphen). The reference page you linked to shows this, but you seem to be omitting the <code> $page </code> concatenation to <code> admin_print_scripts- </code> . eg: <code> $page = add_theme_page( 'Options', 'Options', 'edit_theme_options', 'options-panel', 'topf_admin_options_markup' ); add_action( "admin_print_scripts-$page", 'enqueue_my_admin_scripts' ); </code> I'm using the slug <code> $page </code> returned from <code> add_theme_page; </code> you should provide your own slug. Scripts will only be loaded for your specific page and there is no need to check within your enqueue function.
|
Adding Scripts in the Admin Area
|
wordpress
|
I'm embarrassed to say that I am a bit clueless on the procedure used to update a plugin via tortoise svn even though my plugin has been on the repository for years and had over 300,000 downloads! there's a lot of questions about svn here but they've only confused me further :-z somehow I've managed so far but I need to know the proper procedure for updating my plugin to the new version with regards to committing the trunk and making a tags directory. This is what I've been doing so far. code the plugin updates on my local until I'm happy with it copy over all the files inside my local plugin folder to the /trunk/ (the plugin and readme file have updated version numbers) commit the trunk directory right click the trunk directory and choose create branch/tag and set it to copy to a folder in /tags/ with the name being the version number Is that correct and in the right order? if not, what is the correct way? also, about version numbers... for some reason, I went from version 2.8.1 to 2.81.2 on my last update, does this mean that it wont show as an update available in the dashboards of people that have version 2.81.2 if I change the next version number to 2.9 ? how does wordpress determine which is the latest version and if the user should update their version? does it do a version_compare ? that only works with proper php version format doesn't it? eg. 2.9.2 is considered a lower version than 2.81.2 ? (because, as I understand it, version_compare starts at the left and compares higher/lower for each digit so 9 would be considered less than 81) another question, if I spot a silly mistake in the code that doesn't really affect the working of the plugin, maybe a typo or an additional image. What do I edit and commit to make any new downloads of the plugin contain the change? do I have to edit the trunk AND the tag folder and commit both?
|
I'm embarrassed to say that I am a bit clueless on the procedure used to update a plugin via tortoise svn even though my plugin has been on the repository for years and had over 300,000 downloads! Don't be. SVN can be tricky for a lot of people ... so let's go through things step-by-step ... This is what I've been doing so far. code the plugin updates on my local until I'm happy with it copy over all the files inside my local plugin folder to the /trunk/ (the plugin and readme file have updated version numbers) commit the trunk directory right click the trunk directory and choose create branch/tag and set it to copy to a folder in /tags/ with the name being the version number Is that correct and in the right order? if not, what is the correct way? Almost ... The steps you should be following: Code the plugin updates locally until you're happy with it Increment the "stable" tag in your <code> readme.txt </code> file to match the new version number Copy your local updates into the <code> /trunk </code> directory of the local plugin folder Commit the entire plugin to save the changes to <code> /trunk </code> to the repository Right click <code> /trunk </code> and create a new tag, copying into <code> /tags/X.X.X </code> where x.x.x is the same version in the "stable" tag of <code> readme.txt </code> (step 2) Commit the entire plugin to save the tag for some reason, I went from version 2.8.1 to 2.81.2 on my last update, does this mean that it wont show as an update available in the dashboards of people that have version 2.81.2 if I change the next version number to 2.9 ? Bingo. If you committed version 2.81.2 as an update and people actually downloaded that update, they won't see 2.9 when you release it. how does wordpress determine which is the latest version and if the user should update their version? does it do a version_compare ? that only works with proper php version format doesn't it? eg. 2.9.2 is considered a lower version than 2.81.2 ? (because, as I understand it, version_compare starts at the left and compares higher/lower for each digit so 9 would be considered less than 81) Exactly. A standard PHP version comparison will see version 2.81.2 as being a newer version than 2.9 because 81 > 9. I recommend you release a version 3.0 next, then be very careful when versioning in the future to prevent this kind of typo. if I spot a silly mistake in the code that doesn't really affect the working of the plugin, maybe a typo or an additional image. What do I edit and commit to make any new downloads of the plugin contain the change? do I have to edit the trunk AND the tag folder and commit both? If you need to make a minor change, consider it a maintenance release . I typically following this kind of versioning schema: <code> 2 . 1 . 3 . 5 major minor maint build </code> Build numbers I only ever use internally or for beta releases ... you'll almost never see a build number from me unless I manually email you a file (it's how I can distribute pre-release versions that won't break WordPress updates). If I notice a bug in a live version, I'll make a quick patch and release a maintenance version. Let's say I've released version 2.2 of a plugin and someone notices I forgot to invoke jQuery in noConflict() mode. I'll do a quick patch and immediately release 2.2.1. The increment in the version will force WordPress to recognize the update and provide the fix to anyone who's already installed version 2.2. To release a maintenance version, you need to follow the exact same steps as if you were releasing a full version of the system. So make changes, increment the version in <code> readme.txt </code> , commit <code> /trunk </code> , tag, etc. But once you've tagged something, you never change it again. Think of your <code> /tags </code> folder as frozen in time. Each version in that folder is a snapshot of your plugin at a specific point in time. You should never change any files in the <code> /tags </code> folder directly. If you find yourself thinking it might be a good idea, smack yourself on the back of the head and release a maintenance version instead :-) As Piet mentioned, I wrote stackexchange-url ("a good set of step-by-step instructions earlier") ... but the site seems to have lost my screenshots. Here's another version of the same step-by-step guide with screenshots from Tortoise hosted on my own site: http://eamann.com/tech/how-to-publish-a-wordpress-plugin-subversion/
|
what is the correct way to update a plugin via tortoise svn to the repository?
|
wordpress
|
trying to convert a plugin I wrote to use wp_http instead of Curl (so it'll work on servers without curl) the plugin posts to paypal nvp api and gets back an encrypted button when I try to use the WP_Http class i get "Invalid HTTP Response for POST" would be glad for any help figuring this help - since I want to make this plugin as generic and adhering to standards as possible. this is the original plugin code for the posting part using php Curl (and working) <code> $API_UserName = urlencode($username); $API_Password = urlencode($password); $API_Signature = urlencode($signature); //the curl part - maybe we should change this into wp post functions // setting the curl parameters. $ch = curl_init(); //calling curl phplib inside $CH curl_setopt($ch, CURLOPT_URL, $API_Endpoint);//setting the endpoint curl_setopt($ch, CURLOPT_VERBOSE, 1); //should check this, i don't really know // turning off the server and peer verification(TrustManager Concept). curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); // NVPRequest for submitting to server- including endpoint,credentials,the button data $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature&$nvpStr_"; // setting the nvpreq as POST FIELD to curl curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq); // getting response from server $httpResponse = curl_exec($ch); $httpResponse = $request->request($API_Endpoint,array('method'=>'post', 'body'=>$nvpreq)); if(!$httpResponse) { exit("$methodName_ failed: "/*.curl_error($ch).'('.curl_errno($ch).')'*/); } // Extract the button response details $httpResponseAr = explode("&", $httpResponse->body); $httpParsedResponseAr = array(); foreach ($httpResponseAr as $i => $value) { $tmpAr = explode("=", $value); if(sizeof($tmpAr) > 1) { $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1]; } } if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) { exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint."); } return $httpParsedResponseAr;// an array we'll parse back in the calling function - currently using only websitecode. but in the future maybe also the email code </code> And this is the code with wordpress http api (that doesn't work properly): <code> if (!class_exists('WP_Http')) { include_once ('c:/wamp/www/wp/wp-includes/class-http.php'); } $request = new WP_Http; $httpResponse = $request->request($API_Endpoint,array('method'=>'post', 'body'=>$nvpreq)); if(!$httpResponse) { exit("$methodName_ failed: "/*.curl_error($ch).'('.curl_errno($ch).')'*/); } // Extract the button response details $httpResponseAr = explode("&", $httpResponse->body); $httpParsedResponseAr = array(); foreach ($httpResponseAr as $i => $value) { $tmpAr = explode("=", $value); if(sizeof($tmpAr) > 1) { $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1]; } } if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) { exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint."); } </code>
|
Looking at your original code, I'd say you need to add the <code> sslverify </code> arg. And on a side note, use the HTTP functions available, rather than instantiating the class yourself (you shouldn't have to load the class manually). <code> wp_remote_post( $url, array( 'sslverify' => false, // this is true by default! 'body' => array( 'METHOD' => $methodName, // if you're using an array, no need to URL encode 'VERSION' => $version, 'PWD' => $API_Password, 'USER' => $API_UserName, 'SIGNATURE' => $API_Signature ) ) ); </code>
|
problem using WP_Http with paypal nvp api
|
wordpress
|
I'm am attempting to change the rewrite argument after it has been defined and passed as an argument for 'register_post_type' in a plugin. My issue is that I am utilizing a plugin that defines a custom post type. I can manually edit the rewrite argument in the plugin; however, doing so will mean that I have to do this every time the plugin updates. I was wondering if there is a way that I can change this with some code in another plugin or functions.php file. I was thinking there might be a function that would allow me to alter these arguments or a way in which I could unregister and reregister the custom post type. Any ideas?
|
I had a very similar question and found the answer. Take a look, it might be helpful for You aswell: stackexchange-url ("SOLVED: Change custom post type to hierarchical after being registered")
|
Changing 'rewrite' argument after custom post type is registered
|
wordpress
|
I'd like users to be able to create and remove additional meta box fields as needed. For example, say a music podcast with a variable amount of songs played per episode. The user should be able to click a button that will add additional fields to enter each song as needed. Ideally this would be done without the use of a plugin, but coded into the functions file.
|
So you mean something like this? and when you click on Add tracks it becomes this: if it is what you mean the its done by creating a metabox that has simple jquery function to add and remove fields in it, and the data is saved as an array in of data in a single meta row, here you go: <code> add_action( 'add_meta_boxes', 'dynamic_add_custom_box' ); /* Do something with the data entered */ add_action( 'save_post', 'dynamic_save_postdata' ); /* Adds a box to the main column on the Post and Page edit screens */ function dynamic_add_custom_box() { add_meta_box( 'dynamic_sectionid', __( 'My Tracks', 'myplugin_textdomain' ), 'dynamic_inner_custom_box', 'post'); } /* Prints the box content */ function dynamic_inner_custom_box() { global $post; // Use nonce for verification wp_nonce_field( plugin_basename( __FILE__ ), 'dynamicMeta_noncename' ); ?> <div id="meta_inner"> <?php //get the saved meta as an arry $songs = get_post_meta($post->ID,'songs',true); $c = 0; if ( count( $songs ) > 0 ) { foreach( $songs as $track ) { if ( isset( $track['title'] ) || isset( $track['track'] ) ) { printf( '<p>Song Title <input type="text" name="songs[%1$s][title]" value="%2$s" /> -- Track number : <input type="text" name="songs[%1$s][track]" value="%3$s" /><span class="remove">%4$s</span></p>', $c, $track['title'], $track['track'], __( 'Remove Track' ) ); $c = $c +1; } } } ?> <span id="here"></span> <span class="add"><?php _e('Add Tracks'); ?></span> <script> var $ =jQuery.noConflict(); $(document).ready(function() { var count = <?php echo $c; ?>; $(".add").click(function() { count = count + 1; $('#here').append('<p> Song Title <input type="text" name="songs['+count+'][title]" value="" /> -- Track number : <input type="text" name="songs['+count+'][track]" value="" /><span class="remove">Remove Track</span></p>' ); return false; }); $(".remove").live('click', function() { $(this).parent().remove(); }); }); </script> </div><?php } /* When the post is saved, saves our custom data */ function dynamic_save_postdata( $post_id ) { // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !isset( $_POST['dynamicMeta_noncename'] ) ) return; if ( !wp_verify_nonce( $_POST['dynamicMeta_noncename'], plugin_basename( __FILE__ ) ) ) return; // OK, we're authenticated: we need to find and save the data $songs = $_POST['songs']; update_post_meta($post_id,'songs',$songs); } </code>
|
Create more Meta Boxes as needed
|
wordpress
|
I have some custom-made widgets: <code> echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; echo $output; echo $after_widget; </code> Let's assume the $title is "Widget's Title" and the output is "Hello world". I'm getting something like: Widget's Title Hello world Now, I don't know where it comes, but there's container wrapping every one of my widgets, it looks like: <code> <li id="widgets-id" class="widget widget_name"> <h3>$title</h3> <ul> <li>$output</li> </ul> </li> </code> Any ideas how to change the first "li" into "section" or a "div"? :)
|
It's the default behavior of a dynamic sidebar to output li tags around widgets. You can override that though in the sidebar declaration . You would do that by passing the sidebar registration the following additional arguments: <code> register_sidebar( array( 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => "</div>" ) ); </code>
|
Widget's container?
|
wordpress
|
In my header I use this code: <code> if(is_page("stores")) { // Do something } </code> I run some code if on the page <code> stores </code> but what I want to do is run that code if the page is <code> stores </code> or any page that is a sub page of stores. Not only that, but is recursive so if we are on a sub sub sub page of <code> stores </code> the code still runs.
|
When using pretty permalinks, I simply check against the request; <code> if ( preg_match( '#^stores(/.+)?$#', $wp->request ) ) { // away we go! } </code> No extra DB queries, little computation, and works right down the tree!
|
A function like is_page() but returns true if on any sub page of given page
|
wordpress
|
I just bought and installed the WP-Facebook-AutoConnect plugin but I am unable to login. Below is the debug log I got by email. <code> ---LOG:--- Starting login process (Client: 178.156.161.15, Version: 2.0.4, Browser: Chrome 13.0.782.15 for Mac) PREMIUM: Premium Addon Detected (#671, Version: 22) WP: nonce check passed WP: Found redirect URL (http://blog.i18n.ro/wp-admin/) FB: Initiating Facebook connection via the new API... FB: Connected to session (uid 685872843) FB: Got user info (Sorin Ionuț Sbârnea) FB: Email privilege granted, but only for an anonymous proxy address (apps+116692738389663.685872843.060155133d98d19b8fa5f9c49090e749@proxymail.facebook.com) WP: Searching for user by meta... FP: Searching for user by email hashes (8 candidates of 8 total users)... Checking Users #0-7 WARNING: Could not register hashes with Facebook (connect_registerUsers generated an exception). Hash lookup will cease here. WP: No user found. Automatically registering (FB_685872843) PREMIUM: Autoregistration is Disabled; redirecting to /. ---REQUEST:--- Array ( [redirectTo] => http://blog.i18n.ro/wp-admin/ [rememberme] => 1 [_wpnonce] => 3786067e30 [_wp_http_referer] => /wp-login.php ) </code>
|
I used the premium plugin and I had to solve the following problems: remove the application from facebook, because initially I allowed access to the proxied email address. Verifiy that your facebook account is a verified account before adding the application, otherwise the application will default to proxied emails instead of real ones. checked the request real email address in plugin settings - be sure you press the right save button (there are several different ones on the page) retried to login and when the permission popup appears you have to press the small change hyperlink under the email address permission and allow the application to access you real email address.
|
WP-FB-AutoConnect: Unable to login with administrator account
|
wordpress
|
How can I change the standard 7MB upload limit? I have full shell and admin access to my Wordpress blog.
|
add this to your .htaccess file in the root of WordPress installation directory: <code> php_value upload_max_filesize 20M php_value post_max_size 20M </code> and you can change 20 to whatever you want, unless your hosting server is limiting it it should work just fine. Update: Create the php.ini File and add the Following: <code> memory_limit = 20M upload_max_filesize = 192M post_max_size = 20M file_uploads = On </code> then Upload the File to your wp-admin Directory.
|
Setting higher upload limit
|
wordpress
|
Is there a convenient and configurable way to alternate between different header images? The main features I'm looking for are: Random select from a set of images Specific header image in given date range (a la Google Doodle ) Specific header image for specific posts or pages
|
You can try this Random from a set of images : <code> <img src="http://www.mywebsite.com/images/image_<?php echo rand(1,10); ?>.jpg" alt="" /> </code> This would load a random image from image_1.jpg, image_2.jpg ... to image_10.jpg or <code> $images = array("cool_image.jpg", "nice_pic.jpg", "sunset.jpg"); $rand = array_rand($images); <img src="http://www.mywebsite.com/images/<?php echo $images[$rand]; ?>" alt="" /> </code> This would select a randow image from thoses specified in the $images array. Date range : <code> <?php if ((date('m') == 3) && (date('d') == 17)) { ?> <img src="http://www.mywebsite.com/images/stpatrick.jpg" alt="" /> <?php } ?> </code> This would show an image for St Patricks Specific posts or pages : See : stackexchange-url ("Change image based on menu item id")
|
Alternate header image
|
wordpress
|
How would I do this? <code> archive.php </code> only has this: <code> wp_get_archives('type=monthly'); </code> And <code> wp_get_archives() </code> does not have a parameter to display all post types. Also I think <code> archive-[post_type].php </code> is not the one I am looking for since I want all post types to be displayed in one archive page. Thanks! W
|
If you set up the right parameters for your custom post type using <code> 'has_archive' => true // Will use the post type slug, ie. example // or 'has_archive' => 'my-example-archive' // Explicitly setting the archive slug </code> http://codex.wordpress.org/Function_Reference/register_post_type
|
Display all custom post types in archives.php
|
wordpress
|
I'm queueing several scripts in my themes Functions.php: <code> if ( ! function_exists('b99_init_scripts') ) : function b99_init_scripts(){ if ( !is_admin()){ wp_deregister_script('jquery'); wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', false, null, false); wp_enqueue_script('jquery'); wp_register_script('B99', get_template_directory_uri().'/javascript/site/B99.js', array('jquery'), null, false); wp_enqueue_script('B99'); wp_register_script('B99-Nav', get_template_directory_uri().'/javascript/site/module/B99.Navigation.js', array('B99'), null, false ); wp_enqueue_script('B99-Nav'); if ( is_page('portfolio') || is_front_page() ){ wp_register_script('B99-Portfolio', get_template_directory_uri().'/javascript/site/module/B99.Portfolio.js', array('B99-Nav'), null, false); wp_enqueue_script('B99-Portfolio'); } // fails if add_action is set to 'init' if ( is_singular() && get_option( 'thread_comments' ) ){ wp_enqueue_script( 'comment-reply' ); } } } endif; add_action( 'wp_enqueue_scripts', 'b99_init_scripts' ); </code> I have read that the proper place to add_action is to 'init' <code> add_action( 'init', 'b99_init_scripts' ); </code> However, my <code> is_page('xxx') </code> checks all fail during init. Coded as I have pasted above: <code> add_action( 'wp_enqueue_script', 'b99_init_scripts' ); </code> works as expected and the page checks work normally, but I don't think I should be deregistering, registering, and enqueueing during the wp_enqueue_scripts routine. Is there a better location to hook into, or can I alter my page check during init to function correctly (I assume the page check doesn't work because the needed queries haven't fired yet).
|
I would suggest creating a function named <code> b99_register_scripts() </code> and hook this into <code> init </code> . Then you can create another function named <code> b99_enqueue_scripts() </code> and hook it into <code> wp_print_scripts </code> .
|
Correct place to register and enqueue scripts
|
wordpress
|
I want to change the name and menu_name of the profile menu in the default menu without altering the core files.
|
you could filter gettext to change it. Note that this will change every translatable instance of "Profile". <code> function change_admin_profile_to_account( $thename ){ $thename = str_replace( 'Profile', 'Account', $thename ); return $thename; } add_filter( 'gettext', 'change_admin_profile_to_account' ); </code>
|
Change name & menu_name for Profile in the default menu, w/o altering core files?
|
wordpress
|
I have posts which i would like to put in to 3 categories News, Events, and Press Releases, then i have three pages which are using the same template. I would like to display those posts on to relevant pages so News posts on News page etc. Could someone tell me what would be the best way to do that. I guess its something easy but I'm fairly new to Wordpress. Many thanks,
|
You could simply use the category pages WordPress generates using the <code> category.php </code> template, or <code> category-{slug}.php </code> . If you don't like the /category/categoryname/ url format WP uses, there are a few plugins that remove the category base- I use Yoast SEO plugin for this, which gives you lots of other great features on top. Your other option is to create a special template for these pages with some additional code to load posts from your category. The WP Codex actually has exactly this code for you already, using a custom field on each page to designate which category you'd like it to load.
|
post categories
|
wordpress
|
I have a shortcode that contains a form. I want to use jQuery/Ajax for POSTing. For this, I want to add javascript to the page where shortcode is added? Which hook should I use? wp_enqueue_scripts wp_print_scripts wp_print_footer_scripts
|
You want to use <code> wp_enqueue_scripts </code> , but you'll probably first want to: Loop through the Posts Grep your shortcode Enqueue the script, if shortcode is found Rewind Posts That way, you only enqueue the script where necessary.
|
Which hook to use when adding ajax to viewer-facing side?
|
wordpress
|
If WP_DEBUG is not set, as I understand it, you should never ever see warnings. But on some sites on some servers, I'm still seeing a few. Not all the warnings that would be displayed if WP_DEBUG was set, but a select few. I've tried changing the error level in php.ini, but that seems to have no effect on whether warnings appear or not, but they do appear in differing amounts on different servers (i.e. no warnings on development, one warning on staging, and a few more warnings on production).
|
WP_DEBUG has no impact on PHP error output. In addition to error_reporting setting, set display_errors=0 in your php.ini file. It's enabled by default for development. But you'll want it off on production servers.
|
WP_DEBUG is not set, but I'm still getting warnings
|
wordpress
|
My WP site has 2 custom post types, "Projects" and "People". There can be unlimited number of "People" per project and I'm thinking about a way to integrate the projects section with "People" section. My first impression was using custom taxonomies. But the problem is, is there a way to set a relationship between these 2? If custom taxonomy is the only way, is there a way to make it so when adding new people custom taxonomy get created as well?
|
As you haven't stated your requirements of People type and Project type. So I am assuming that you must have both as a post type. To create relations between them you can use @scribu's Post 2 Post relations plugin.
|
Custom post type with custom taxonomy
|
wordpress
|
What should I call the archive file for a post format? Ex archive-gallery.php? (doesn't work) I would like to create a list of all the gallery formats with a preview and some custom taxonomies thrown in.
|
Well.... for querying, formats are a taxonomy parameter...so that should work.... http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters Lemme loook... And yep, here's how that works http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display taxonomy-post_format-post-format-link.php
|
Post Format Archive template name for theme folder?
|
wordpress
|
I have events that have an event-date custom field. I want to create a date based page to display all events for a given day, and my hope was to use the url to help with that. I have a 7 day calendar working, and it shows a "featured" event for a given day. Then I want to link to a page that shows all the events for that day. Not sure if this is at all possible but I figured the geniuses in this Stack would know.
|
Assuming that your event rewrite slug is event and you want your datebased URLs to look like: http://domain.com/event/2011-06-14/ <code> function custom_permalink_for_my_cpt( $rules ) { $custom_rules = array(); // a rewrite rule to add our custom date based urls $custom_rules['event/([0-9]{4}-[0-9]{2}-[0-9]{2})/?$'] = 'index.php?post_type=event&event-date=$matches[1]'; return $custom_rules + $rules; } add_filter( 'rewrite_rules_array', 'custom_permalink_for_my_cpt' ); // add a query var so we can read the date passed in url function my_custom_query_vars( $query_vars ) { $query_vars[] = 'event-date'; return $query_vars; } add_filter( 'query_vars', 'my_custom_query_vars' ); // modify the main wordpress query function my_date_based_event_archives() { // only modify the wordpress query if its event archive and // we have got the event-date passed through the url if ( is_archive( 'event' ) && get_query_var( 'event-date' ) ) { global $wp_query; $meta_query = array( 'meta_query' => array( array( 'key' => 'event-date', 'value' => get_query_var( 'event-date' ) ) ) ); $args = array_merge( $wp_query->query, $meta_query ); query_posts( $args ); } } add_action( 'get_template_part_loop', 'my_date_based_event_archives' ); </code>
|
How to give a CPT (custom post type) a date based url
|
wordpress
|
I'm building a menu which contains categories. Is there a way to make each menu option show a list of recent posts in that category when you hover over it?
|
you can use a walker like this, <code> class Walker_Recent_Post_Category extends Walker_Category { function start_el(&$output, $category, $depth, $args) { extract($args); $cat_name = esc_attr( $category->name); $cat_name = apply_filters( 'list_cats', $cat_name, $category ); $list_recent_cat_post = '<ul class="show-hide">'; $args = array( 'numberposts' => 5, 'category_name' => $category->name ); $myposts = get_posts( $args ); foreach( $myposts as $mypost ) : $list_recent_cat_post .= '<li><a href="' . get_permalink($mypost->ID) . '">' . $mypost->post_title . '</a></li>'; endforeach; $list_recent_cat_post .= '</ul>'; $link = '<a href="' . get_category_link( $category->term_id ) . '" '; if ( $use_desc_for_title == 0 || empty($category->description) ) $link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"'; else $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"'; $link .= '>'; $link .= $cat_name . '</a>'; if ( (! empty($feed_image)) || (! empty($feed)) ) { $link .= ' '; if ( empty($feed_image) ) $link .= '('; $link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"'; if ( empty($feed) ) $alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"'; else { $title = ' title="' . $feed . '"'; $alt = ' alt="' . $feed . '"'; $name = $feed; $link .= $title; } $link .= '>'; if ( empty($feed_image) ) $link .= $name; else $link .= "<img src='$feed_image'$alt$title" . ' />'; $link .= '</a>'; if ( empty($feed_image) ) $link .= ')'; } if ( isset($show_count) && $show_count ) $link .= ' (' . intval($category->count) . ')'; if ( isset($show_date) && $show_date ) { $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp); } $link .= $list_recent_cat_post; if ( isset($current_category) && $current_category ) $_current_category = get_category( $current_category ); if ( 'list' == $args['style'] ) { $output .= "\t<li"; $class = 'cat-item cat-item-'.$category->term_id; if ( isset($current_category) && $current_category && ($category->term_id == $current_category) ) $class .= ' current-cat'; elseif ( isset($_current_category) && $_current_category && ($category->term_id == $_current_category->parent) ) $class .= ' current-cat-parent'; $output .= ' class="'.$class.'"'; $output .= ">$link\n"; } else { $output .= "\t$link\n"; } } } </code> then call the walker like this, <code> <ul> <?php wp_list_categories( array( 'show_count'=>1, 'title_li' =>'', 'walker' => new Walker_Recent_Post_Category() ) ); ?> </ul> </code> it will display something like this, <code> <ul> <li> <a href="http://localhost/wordpress/category/my-category/" title="View all posts filed under my category">my category</a> (1) <ul class="show-hide"> <li><a href="http://localhost/wordpress/2011/06/twetwetewrwe/">twetwetewrwe</a></li> </ul> </li> <li> <a href="http://localhost/wordpress/category/uncategorized/" title="View all posts filed under Uncategorized">Uncategorized</a> (7) <ul class="show-hide"> <li><a href="http://localhost/wordpress/2011/06/5th/">5th</a></li> <li><a href="http://localhost/wordpress/2011/06/twtwe/">twtwe</a></li> <li><a href="http://localhost/wordpress/2010/08/five-ways-widget-manufacturing-can-be-bungled/">Lorem Ipsum dolor sin amet</a></li> <li><a href="http://localhost/wordpress/2010/08/help-me/">help-me!</a></li> <li><a href="http://localhost/wordpress/2010/08/hello-world-2/">Hello world!</a></li> </ul> </li> </ul> </code> and some jQuery touches on the html : demo
|
Show recent posts in menu?
|
wordpress
|
<code> http://localhost/lyrics/don't-turn-me-away/ </code> is a custom post type. my question is how to display <code> http://localhost/lyrics/ </code> as a page and not an archive? my goal really is just for it be added to <code> wp_nav_menu </code> . I have created a page named <code> lyrics </code> but it won't direct me there. Instead it brings me to <code> archive.php </code> . With that, the <code> lyrics </code> in menu, don't have the <code> current-menu-item </code> class.
|
Look for this in the code where you registered the lyrics post type: <code> 'has_archive' => true, </code> Set <code> 'has_archive' => false </code> . That won't work right away, however. So you need to go in an "refresh" your permalinks. Just go to the permalinks options page, and hit the save button.
|
archive as a page, so that it can be added in the wp_menu_nav
|
wordpress
|
After much research, I think I can wrap my brain around WP's rewrite system. I would like to know, though, how to properly test rewrite rules to see if the right rule/tags is being used and the right query vars are being passed. Is there a way to create a temporary template that supersedes everything in a theme whose sole purpose is to spit out current query_vars?
|
Check out my favorite Rewrite Analyzer plugin written by @Jan Fabry. It allows you to analyze your rewrite rules and really helps in debugging those rules.
|
How to test custom rewrite rules /permalinks?
|
wordpress
|
I'm using php to dynamically create a custom post, and I need the author to be someone other than the logged in user. I found this stackexchange-url ("stackexchange-url but I'm wondering if there is a way to do it after the post is already inserted. I guess I could just do a db query...
|
If you know the ID of the author you can use wp_insert_post specifying the ID and the author ID to it. <code> $id = $post->ID; // change this to whathever $user_id = '4'; // change this too $the_post = array(); $the_post['ID'] = $id; $the_post['post_author'] = $user_id; wp_insert_post( $the_post ); </code> The trick is to specify the ID to update the post. See <code> wp_insert_post() </code> .
|
how can I set the post author of a post I just created with php?
|
wordpress
|
My source links are something linke this : <code> http://sample.com/entertainment/default.aspx?tabid=2305&conid=102950 http://sample.com/entertainment/default.aspx?tabid=2418&conid=104330 http://sample.com/entertainment/default.aspx?tabid=2429&conid=104264 http://sample.com/entertainment/default.aspx?tabid=2305&conid=102949 . . . </code> I cache content form links.I use wp_insert_post to post cached content from source site to wordpress: <code> $my_post = array( 'post_title' => "$title", 'post_content' => "$content", 'post_status' => 'draft', 'post_author' => 1, 'post_category' => array(1), ); wp_insert_post( $my_post ); </code> I want to put each link in custom fields and in the next cache , before post to WP , check new links with links in custom fields. If link is repeated , prevent insert content. Sorry for my bad description.
|
To save the link in the post meta you can use <code> update_post_meta </code> like this for example: <code> $url = "http://sample.com/entertainment/default.aspx?tabid=2305&conid=102950" $my_post = array( 'post_title' => "$title", 'post_content' => "$content", 'post_status' => 'draft', 'post_author' => 1, 'post_category' => array(1), ); $post_id = wp_insert_post( $my_post ); update_post_meta($post_id,'source_link',$url); </code> and to prevent the insertion add a simple conditional check: <code> $args = array("meta_key" => "source_link", "meta_value" =>$url); $posts = get_posts($args); if (count($posts) < 0){ //add new post } </code> <code> if (count($posts) < 0){ //add new post } </code> is not working, change it to <code> if (empty($posts)){ //add new post } </code>
|
Prevent duplicate posts in wp_insert_post using custom fields
|
wordpress
|
is there any way to easily update a plugin installed on multiple sites from a github repo. I know I can do it from the command line of each server using git pull. but is there a way to do it from the wordpress admin similar to how plugins are updated?
|
I wrote a PHP class that allows a plugin developer to incorporate updates from GitHub within their plugin. Here's a link for it -> https://github.com/jkudish/WordPress-GitHub-Plugin-Updater
|
How can I update a wordpress plugin from a Git repository (github)
|
wordpress
|
My for-fun WordPress blog at http://fakeplasticrock.com (running WordPress 3.1.1) got hacked -- it was showing an <code> <iframe> </code> on every page like so: <code> <iframe src="http://evilsite.com/go/1"></iframe> <!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" xml:lang="en" lang="en"> </code> I did the following Upgraded to 3.1.3 via the built-in WordPress upgrade system Installed the Exploit Scanner (lots of critical warnings on unusual files) and AntiVirus (this showed all green and clean, so I uninstalled and removed it after running) Changed MySQL password. Changed all WordPress user passwords. Connected via FTP and downloaded the whole filesystem (not large, this is a WordPress-only Linux shared host) Diffed the filesystem against an official ZIP of WordPress 3.1.3 and removed or overwrote anything that did not match. I am quite sure that all the files on disk are official WordPress 3.1.3 files there are no "extra" files on disk other than my one <code> /theme </code> , the Exploit Scanner plugin (which I just downloaded), the <code> /uploads </code> folder, and a tiny handful of other expected files. My other plugin, wp-recaptcha, matches the current official downloaded version. I also checked the <code> .htaccess </code> file and nothing looks wrong there I did not touch the database , but I am struggling to think how anything in the database could be malicious without special PHP code to make it work? My WordPress blog appears OK and hack-free now (I think), but is there anything else I should check?
|
Have you identified the exploit vector? If not, you may be leaving yourself open to future exploit. Other things to consider: Change WordPress admin user passwords - done Change Hosting account user password Change FTP passwords Change MySQL db user password - done Change the db table prefix Update your wp-config nonces/salt Check your directory/file permissions Block directory-browsing access, via <code> .htaccess </code> Go through everything in the Hardening WordPress Codex entry Go through everything in the FAQ My Site Was Hacked Codex entry
|
Verifying that I have fully removed a WordPress hack?
|
wordpress
|
Each time I register I end up in the wp-login page (back-end): Is there any way of redirecting the users who register to a page template (front-end)?
|
You can use the filter <code> registration_redirect </code> to pass back your own URL, for example; <code> function __my_registration_redirect() { return home_url( '/my-page' ); } add_filter( 'registration_redirect', '__my_registration_redirect' ); </code> Drop it in your <code> functions.php </code> or a plugin :)
|
How to redirect a sucessful registration to a page template?
|
wordpress
|
How do I add a class to the comment submit button? The simplified function <code> comment_form(array('id_submit'=>'buttonPro')); </code> obviously only changes the id and <code> class_submit </code> does not seem to exist. I have read through both Otto's and Beau's writeups but to no avail.
|
If you check out the source of the function <code> comment_form() </code> , you'll see it doesn't even print a class on the input; <code> <input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" /> </code> I'm guessing you need to add a class for styling? Why not modify your CSS to just; <code> input.submit, #buttonPro { /* some awesome style */ } </code> Otherwise I guess the 'easiest' solution would be to simply copy the function to your <code> functions.php </code> , rename it, add in a class argument & print, and use that instead - which you can find here ;)
|
How to add a class to the comment submit button?
|
wordpress
|
I know that WP 3.1 has added support for archives for custom post types but is there any way to customize the permalinks for them?
|
Take an example custom post type called <code> movie </code> the code below will create custom permalinks <code> awesomemovies/ </code> regardless of the one created by using the has_archive and rewrite options of register_post_type. <code> add_filter( 'rewrite_rules_array', 'custom_permalink_for_my_cpt' ); function custom_permalink_for_my_cpt( $rules ) { $custom_rules = array(); // for archive urls $custom_rules['awesomemovies/?$'] = 'index.php?post_type=movie'; // for individual post urls e.g: http://blog.com/awesomemovies/post-name/ $custom_rules['awesomemovies/([^/]+)/?$'] = 'index.php?post_type=movie&pagename=$matches[1]'; return $custom_rules + $rules; } </code> For more information see WP_Rewrite
|
Custom Permalinks for Custom post Type Archives?
|
wordpress
|
I have a home.php file which I am using as my home page and it is showing a specific page. In my index.php I have my main timeline. But when I access this page I get redirected to home.php. How can I do that? To show my main timeline in a differente path then home. Something like mysite.com/blog
|
Rename your <code> home.php </code> template file as <code> front-page.php </code> . In WordPress parlance, "home" is the Blog Posts Index . The front page of the site is Front Page . Likewise, the <code> home.php </code> template file corresponds to the Blog Posts Index and the <code> front-page.php </code> template file corresponds to the Site Front Page , and the <code> is_home() </code> conditional returns true when on the Blog Posts Index while the <code> is_front_page() </code> conditional returns true when on the Site Front Page . To summarize: Site Front Page : Front Page, <code> front-page.php </code> , <code> is_front_page() </code> Blog Posts Index : Home, <code> home.php </code> , <code> is_home() </code> EDIT: How to setup a static Page as Blog Posts Index: Create two static Pages, with any arbitrary names (we'll call them "Front Page" and "Blog") Go to: <code> Dashboard -> Settings -> Reading </code> Set "Front Page Displays" to "Static Page" Select "Front Page" in the dropdown for "Front page" Select "Blog" in the dropdown for "Posts page" Now (assuming you have configured pretty permalinks at <code> Dashboard -> Settings -> Permalinks </code> ): Front Page URL: <code> www.example.com </code> Blog Posts Index URL: <code> www.example.com/blog/ </code>
|
Main timeline in a different path
|
wordpress
|
I have installed wordpress on one membership site and found that whenever editor writes post on wordpress and attempts to post it, deletes the half of post randomly. I don't know what could be the problem. I have already did my search within community forums here and here . These two threads explain the same problem that i'm having but none of the solutions are working for me. I also tried post revision plugins, sql query (for deletion of revisions), wp-config file modification and everything i could find on google. WP is just on spree of eating half the post no matter what. Is there any solution for this ?
|
The issue is related with the server permissions. I asked my hosts support to fix this. I found that they somehow fixed the issue. Also i noticed that stackexchange-url ("ciprian's answer") helped some of my friends but i was unable to solve issue that way.
|
Wordpress Post Deletion Issue
|
wordpress
|
I would like to learn how to create a plugin from scratch, there are tons of tutorials out there on the internet, but they are either premium or not a reliable resource. would like to know which are the best resources available on the internet.
|
A very first advice from me will be: Don't follow the tutorials on the tutorial sites blindly they are full of bad coding practices. Some of the resources that I follow: Mark on Wordpress Justin Tad Lock (You can also buy the copy of his e-book Professional Wordpress Plugin Development) Otto on Wordpress scribu's development blog And here is the list of Specific tutorials that you should consider going through, some are old but are still valid. http://markjaquith.wordpress.com/2006/03/04/wp-tutorial-your-first-wp-plugin/ http://www.devlounge.net/extras/how-to-write-a-wordpress-plugin
|
WordPress Plugin Development from Scratch. How?
|
wordpress
|
I created an additional site on my multisite subdomain installation. Now when I try to visit the new site or its wp-admin, I get a 404 error. My wordpress instance is hosted on AWS Checked the following AllowOverride is set to All in httpd.conf contents of .htaccess are the same as those in Network settings added the necessary statements to wp-config.php Tried restarting httpd as well What else could I be doing wrong? Thanks.
|
You need to set a wildcard serveralias in that site's virtualhost declaration. Right under where it says <code> ServerName example.com </code> you should add another line like this: <code> ServerAlias *.example.com </code> You might have already done that, but it was the only thing missing from the list of things you had checked.
|
Multisite - getting a 404 for additional site created using subdomain install
|
wordpress
|
I would like to hack the default Recent Comments widget to show also the avatar of commenter. The modification should be really easy, if I change directly the code in <code> default-widgets.php </code> <code> if ( $comments ) { foreach ( (array) $comments as $comment) { $output .= '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . get_avatar($comment->user_id , 20) . '</li>'; } } </code> but I don't like change core files and I would prefer a more ortodox way to implement it. How can I do it?
|
Sounds like you just need to make another widget of your own in a plugin. So copy the complete code from the default widgets file, and change the class name, then just edit the code you'd like to edit. <code> class YOUR NEW WIDGET NAME extends WP_Widget { // ... foreach ( (array) $comments as $comment) { $output .= '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; } // ... } </code> Then you just register the new widget: <code> add_action( 'widgets_init', 'register_my_widget' ); function register_my_widget() { register_widget ( YOUR NEW WIDGET NAME ); } </code> All that should probably go inside a plugin so you don't loose your widget when changing themes. More info: http://xavisys.com/wordpress-widget/ http://codex.wordpress.org/Writing_a_Plugin http://codex.wordpress.org/Widgets_API
|
How to hack recent comments default widget?
|
wordpress
|
I'm creating a custom post form that is supposed to take an external image and uploads it to the media library and attach it to that post. This should be possible by using media_sideload_image, but I'm getting a blank page instead of working correctly, no error either. My code: <code> // Add the content of the form to $post as an array $new_post = array( 'post_title' => $title, 'post_content' => $description, 'tags_input' => $tags, 'post_type' => 'link_submit', 'post_status' => 'publish' ); //save the new post and return its ID if ($stop == false){ $pid = wp_insert_post($new_post); update_post_meta($pid,'Link',$link,true); update_post_meta($pid,'Type',$type,true); // attach image set_time_limit(300); $upload = media_sideload_image($link, $pid, "test"); if ( is_wp_error( $upload ) ){ die( 'Nope' ); } $link = get_permalink( $pid ); wp_redirect( $link."?posted" ); die(); } </code> Ideas? Thanks, Dennis edit: new code: <code> if (is_page('Upp')){ require_once(ABSPATH . 'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/media.php'); set_time_limit(300); $upload = media_sideload_image("http://29.media.tumblr.com/tumblr_lmp1tbiYwh1qzlfumo1_500.jpg", "202", "my description"); die ( $upload ); } </code>
|
Firstly, reverse the order in your conditional. You should use <code> if ( false == $stop ) { ... </code> It's called a "Yoda conditional" and is on the list of best practices for WP code. Secondly, <code> media_sideload_image </code> won't return a WP error object if things fail. If things fail, it will return the ID of the post passed in ( <code> $pid </code> in your case). If successful it will return the HTML to render the image just inserted. I would recommend just dumping the contents of <code> $upload </code> to see what's in there and see if things are successful. So the <code> if(is_wp_error()) </code> code ... replace it with <code> wp_die( $upload ) </code> and see what comes out. If it's an id, then something's wrong on your system and you need to investigate why your server can't download images. If it's HTML markup for an image, then the image is being added and you're ready to go. For reference, take a look at the actual <code> media_sideload_image() </code> function in <code> /wp-admin/includes/media.php </code> around line 569. Edit: 6/20/11 I took a deeper look at the code, and started walking through breakpoints I set in the WordPress code, which is where I finally found the problem. While processing the image, <code> media_sideload_image() </code> will eventually make a call to <code> media_handle_image() </code> , which is in the same file. No problems here. But this other function makes a call to <code> wp_read_image_metadata() </code> , which is a function defined in another file that we haven't yet included! Unfortunately for us (and it obviously hasn't been discovered yet because this code goes against WP best practices), there's a nasty <code> @ </code> symbol before that function call. The <code> @ </code> symbol in PHP will silence any errors thrown by the parser, so PHP sees a "function not defined" error and stops ... giving us a blank page and leaving us scratching our heads. So adding the following line to the list of <code> require_once() </code> s will actually load and insert the image: <code> require_once(ABSPATH . 'wp-admin/includes/image.php'); </code> The only other thing giving me a headache was that you code was for <code> post_type=link_post </code> ... I didn't have that post type defined, so I was running in circles trying to figure out why <code> wp_insert_post() </code> wasn't working ... it was, and I now have 100 "Test Post"s in my DB :-)
|
media_sideload_image generates blank?
|
wordpress
|
I'm trying to create a custom form which takes an image (offsite) and attaches it to the post so I can use it as a thumbnail in the loop. I've been looking at media_handle_upload but that appears to only be working for content that's locally uploaded. Ideas? Thanks, Dennis
|
When you link to an external image, WordPress will reference the external URL. <code> media_handle_upload </code> is meant to handle uploaded images that are now living on your server. So unless you're telling the server to download the image from the external source and save it on your server, <code> media_handle_upload </code> won't apply. It sounds like you're building your own custom importer. I recommend you take a deeper look at the process. A typical upload: User selects file from local system File uploads through form to $_POST variable WordPress takes file out of POSTed form, runs it through <code> media_handle_upload </code> , and stores it on the server If you're referencing an offsite image and attaching it to the post, WordPress won't do steps 2 and 3. You'll need to add your own scripts to grab the remote image and store a copy locally.
|
Upload image through URL?
|
wordpress
|
A theme normally posts to wp-comments-post.php when someone leaves a comment. When successful, it does a redirect to the page again but tacks on "#comment-" into the URL. What I was wanting to do was leave a message, "Your comment awaits moderation, which takes about 24 hours." Sure, I can intercept location.href and see if it contains "#comment-" in it, and show the moderation message then. But there are other ways one can click on a page and "#comment-" gets shown, which makes this a visual quirk, not the way I intended it. What's an easy way to make a WordPress theme detect that a comment was just posted and redirected back to the page?
|
The easiest and most straight-forward way is to put appropriate code in your <code> wp_list_comments() </code> callback, that outputs a message if a comment is awaiting moderation. The usual code looks something like this: <code> <?php if ($comment->comment_approved == '0') : ?> <em><?php _e('Your comment is awaiting moderation.') ?> </code> Otherwise, if you're not using a callback, you can hook into an appropriate action hook, such as <code> pre_comment_content </code> , to inject the same content.
|
How To Detect Posted Comment in Theme Development?
|
wordpress
|
Done some reasonable searching for this and don't think it's been asked before. I've got a site which I'm developing a custom template/theme for. The site will use a page as the front page (rather than the list of posts), but I want to create a link in the template to the page of blog posts. There are some functions for finding various URL's like site_url() and admin_url(), and, of course, there's bloginfo(), but I can see anything that will get me the name/slug/URL/ID of the page used as the blog page. I'm sure I've seen this somewhere before but can't track it down now that I need it. Any ideas? Thanks RW
|
<code> <?php $blog_link = get_page_link( get_option( 'page_for_posts' ) ); ?> </code>
|
Is there a template tag/function for getting the URL (or slug or name or ID) of the blog page when using a "static" front page
|
wordpress
|
When registering a new taxonomy, the second argument of <code> register_taxonomy($taxonomy, $object_type, $args) </code> is the post type (or types) that this taxonomy is registered for. However, when registering a custom post type, you can also pass taxonomy as one of the arguments: taxonomies (array) (optional) An array of registered taxonomies like category or post_tag that will be used with this post type. This can be use in lieu of calling register_taxonomy_for_object_type() directly. Custom taxonomies still need to be registered with register_taxonomy(). Default: None This is redundant. Which should be used? Can you register a taxonomy without associating it with a specific post type, and then later, when registering the custom post type, associate it then? As a little backgrounder to why I should care (other than that I don't like inconsistencies and redundancy): I'm creating a fairly generic taxonomy that I can foresee using across a variety of implementations. I'd love to define this taxonomy once (in a separate file), without any foreknowledge of the custom post types that may want to take advantage of it in the future. Then, on a specific implementation, as I'm creating the custom post type, I know I have this taxonomy that I can associate with the post type. Hope this explains my reasons a bit.
|
So I dug into the source and discovered that even though the documentation STATES that <code> $object_type </code> is "required", there's nothing in the logic that makes this so. <code> $object_type </code> is just added to the properties of the tax object, which presumably is also done when you register the tax while creating the custom post, and also when you use <code> register_taxonomy_for_object_type() </code> . I tried creating a custom taxonomy with null for the <code> $object_type </code> parameter, and then assigning the tax when creating the custom post type and it worked as hoped-for. Codex updated.
|
Is $object_type truly required with register_taxonomy()?
|
wordpress
|
i have a bit odd question but here it goes: Due to page styling issues with the copyright logo, i deleted the whole div that says: "Powered by Wordpress (logo)". Now due to my SEO plugin, the source doesn't include the meta-generator tag. Now am i in violation of the Wordpress License, or im ok (although i do look irresponsible)?
|
There is no requirement to retain the "Powered by WordPress" note in the footer or the WordPress reference in the <code> <meta> </code> tags in your header. There is nothing in the WordPress license (GPL) that requires these remain intact. To take things a bit further ... the "Powered by WordPress" tag in the footer is added by your theme , not by WordPress itself. And the <code> <meta> </code> tag in the header is pluggable specifically to make it easy to remove.
|
Wordpress Copyright Dillema (i.e. Powered by)
|
wordpress
|
I get a "update available" notification for my custom plugin "breadcrumbs trail nav" (not hosted in the official repo). Point is that there's a) no update available and b) it wants to get updated to version whatever from the yoast-breadcrumb plugin. Case: local install. My plugin header comment: <code> /* Plugin Name: Breadcrumbs Trail Nav. Plugin URI: https://github.com/franz-josef-kaiser Description: Offers the <code>whatever( $args );</code> template tag for a semantically correct, seo-ready (well performing) breadcrumbs trail. All links are nofollow by default, but can be adjusted. Author: Franz Josef Kaiser Author URI: https://github.com/franz-josef-kaiser Version: 0.2.1 License: extended MIT/Expat license (c) Copyright 2010-2011 - Franz Josef Kaiser */ </code> Yoast plugin header comment: <code> /* Plugin Name: Yoast Breadcrumbs Plugin URI: http://yoast.com/wordpress/breadcrumbs/ Description: Outputs a fully customizable breadcrumb path. Version: 0.8.5 Author: Joost de Valk Author URI: http://yoast.com/ Copyright (C) 2008-2010, Joost de Valk */ </code> What's the problem?
|
The updater works based on the plugin's installation path and the name of the file containing the header. I'm guessing both plugins are housed in a <code> /breadcrumbs </code> folder (since that seems to be Yoast's setup. Though Yoast's plugin uses <code> yoast-breadcrumbs.php </code> for its main file. I'm assuming you're using a different filename, so you have indeed run into an interesting problem. I'd take a closer look at your system, because the updater sends two variables when checking for updates: "plugin_slug" ... in this case likely <code> breadcrumbs </code> "plugin_path" ... <code> /breadcrumbs/yoast-breadcrumbs.php </code> There's a naming collision between your system and Yoast's if they're both called "Breadcrumbs" to WordPress. I'd recommend changing your system to put things in the <code> /kaiser-breadcrumbs </code> directory instead. That might solve your problem.
|
plugin wants to update to wrong plugin
|
wordpress
|
I have purchased the DynamiX theme, and I'm trying to use it for the first time. I was looking at the widgets, and I saw some neat customized (Dynamic maybe?) widgets in the Inactive Widgets section. I was going to drag one to my Sidebar, but accidentally dropped it, and now it is gone. Is there any way to retrieve those? I don't even know exactly what it was, I just know that it was part of my theme. I'm pretty new to Wordpress, so please bear with me. Thanks in advance!
|
Inactive widgets are just normal widgets from the "Available widgets" list, which have been put in the "Inactive" section in order to keep the data they contained. What probably happened is that you dropped one of them over the "Available widgets" space and it dissapeared. But don't worry that doesn't mean that the widget is gone, widgets cannot "dissapear", in the worst case you just lost the data of the widget. For example if you have a text widget in your colum, with the title "My cool widget" and the text "Hey check this out", and you decide to temporarly remove it from your website, but wish to keep the text data, you would drop it to the "Inactive" space. You can then drop it back whenever you wish to use it again with the same text. BUT, if you remove it completely, then there will always still be the "Text" widget available in the upper space "Available widgets". Hope that helps.
|
What happened to my Inactive Widgets?
|
wordpress
|
I have a table in my database containing vote a tally I'm trying to order posts by. screenshot: the table I've tried something like this, which brings up all the voted posts and pagination okay but does not order them by DESC. Any advice if I'm approaching this right is appreciated. <code> <?php global $wpdb; $my_posts = $wpdb->get_col("SELECT like_pid FROM wp_likes_count ORDER BY like_count"); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post__in' => $my_posts['like_pid'], 'paged' => $paged, 'posts_per_page' => 6, 'order' => 'DESC' ); query_posts($args); ?> <?php while (have_posts()) : the_post(); ?> <!-- do stuff --> <?php endwhile; ?> </code>
|
The Problem <code> $my_posts </code> doesn't contain any posts. It contains post IDs and likes. And you're dropping both into <code> post__in </code> , which can't work. I guess even the number of posts wouldn't work if the plugin(?) wouldn't add any post with a 0-x integer to the db-table per default. The Debug Try the following: <code> $my_likes = $wpdb->get_col("SELECT like_pid FROM wp_likes_count ORDER BY like_count DESC"); echo '<pre>'; print_r( $my_likes ); echo '</pre>'; </code> which will likely show you an array containing two sub-arrays. Way to a solution Then try to get the sub-array you need and drop it into your query. Example: <code> 'post__in' => $my_likes['like_pid'] </code> . The Plugin Anyway, a plugin should store something like this in the post_meta table in a field and not add an unnecassary table for something like that. There should be a facebook plugin by otto in the wp.org repo. This one's much stronger, better written & by a trustable author. You should consider switching.
|
How do I order my loop query?
|
wordpress
|
http://bigpicturepartnering.com I can log into the site. When I try to access the WP console I get the following error: PHP Fatal error: Call to undefined function is_site_admin() in D:\websites\bigpicturepartnering\wp-content\plugins\wordpress-related-posts\related-posts.php on line 81 How can I get into the console to disable the plugin?
|
Using the FTP client of your choice, go to <code> wp-content\plugins\ </code> , and delete (or move) the <code> wordpress-related-posts </code> directory. By the way: what version of WordPress are you using? And is this a local install or a live site?
|
Cannot Access Console
|
wordpress
|
I'm in the process of developing a plugin, and I'd like to figure out which versions of WordPress to support. But to get a good idea I'd need to know what percentages of old Wordpress versions make up the install base. Does such information exist? Alternatively if such information doesn't exist, does anyone have a suggested version I should support my plugin back to?
|
There's a page in the Codex that shows exactly that: WordPress > About » Statistics But really, it all depends on what features you're using. A safe bet for a new plugin would be to support WordPress 3.1.X and above (since that's the current stable release). You're setting yourself up for a lot of hurt if you try to do too much backwards compatibility work.
|
What are WordPress installation percentages by version?
|
wordpress
|
I'm developing a group blog on wordpress (first time working with it) and the client has requested that a 'None' option be added where an item can be posted without a "by" attribution. So basically there would be one article / excerpt template for attributed author's posts and another for the none option where the byline would just be the date posted without the "by [author name]." Is this possible with wordpress? Thanks!
|
This is entirely possible. Though, I would recommend using the Post custom metadata (i.e. custom fields, or better yet, a custom metabox). I would use a custom metabox, with two radio select options: <code> Byline: (*) Author ( ) None </code> Then, in your template file, you can output the author byline only if the appropriate post_meta key has the appropriate value. If you want to get really fancy with it, you can even use the post_meta key/value to customize the Loop for your Author archive index output, so that Posts indicated not to display the byline don't output in the Author's archive index.
|
Creating an option for writing a post without an author attribution for a group blog on Wordpress
|
wordpress
|
I have created a custom taxonomy as described on the Codex . I have "public" set to true, which show_in_nav_menus is supposed to inherit from, and have also explicitly added the show_in_nav_menus variable and set it to true. However, it only shows up for the user with the username "Admin". None of the other users can see it under Appearance > Menus, even ones marked as being an "Administrator". Here's my exact code: <code> function create_con_casino_reviews() { register_post_type( 'con_casino_reviews', array( 'labels' => array( 'name' => __( 'Casino Reviews' , 'continuum'), 'singular_name' => __( 'Casino Review' , 'continuum'), 'add_new' => __('Add new review', 'continuum'), 'edit_item' => __('Edit review', 'continuum'), 'new_item' => __('New review', 'continuum'), 'view_item' => __('View review', 'continuum'), 'search_items' => __('Search reviews', 'continuum'), 'not_found' => __('No reviews found', 'continuum'), 'not_found_in_trash' => __('No reviews found in Trash', 'continuum') ), 'public' => true, 'menu_position' => 25, 'menu_icon' => get_stylesheet_directory_uri() . '/images/review-casino.png', 'rewrite' => array('slug' => 'casino-review'), 'supports' => array('title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions'), 'taxonomies' => array('category', 'post_tag'), 'show_in_nav_menus' => true ) ); } add_action( 'init', 'create_con_casino_reviews' ); </code> If I change: <code> register_post_type( 'con_casino_reviews', </code> to be: <code> register_post_type( 'con_casino_reviewss', </code> It works just fine.
|
Make sure you click "Screen Options" and check the checkbox for each menu you want to be able to select. For each user. -_-
|
Post Type only showing for "Admin" under "Appearance" > "Menus"
|
wordpress
|
i got a wp site with the WPML plugin and the CFT plugin. I set up custom fields for posts and what i'm trying to do is to keep the content of an <code> input type file </code> from the original post to its translation. That would save time as the pictures are the same between both posts and also save disk space on the ftp. So far i couldnt get it working, not even to get basic <code> input type text </code> automatically pasted from the 1st post to its translation. I tried the different options in WPML > Translation management > Mutlilingual content setup > Custom fields translation without any result. PS: am using WP 3.1.3, WPML 2.0.4.1 and CFT 1.9.2.
|
The latest version of WPML (version 2.3) has a new module for Media and this module takes care of the previous images issue. Now there is no longer the need to upload the same image twice. Just like copying the content from the original language, it is now also possible to duplicate the images and/or the featured image:
|
WPML & CFT: keeping custom field file to translation
|
wordpress
|
A WordPress site I'm doing a redesign for has around 1.400 posts by approximately 30 different authors. Unfortunately the authors of the posts have so far been entered as a custom field within the post, and not as separate authors in WP. I'd like to transfer this to the 'proper way', where each post has an author attached to it, since this would make it possible to display more posts by each author without resorting to plugins like Search Everything . Does anybody know of a script that could look through all the posts, search for the custom field containing and author and create that author, and then link the post to that author? (I know, long shot...) Is that even possible or is there an another way apart from going through 1.400 posts and changing them by hand?
|
Not knowing your specific setup makes this pretty tricky ... but here are some ideas for alternatives that might save you time: Leave it as-is If these authors aren't actually users of the site to begin with, don't change anything. Non-users shouldn't be turned into users just for the sake of making search easier. Creating so many non-user user accounts will open up just that many potential entry points for malicious visitors. Create a taxonomy Again, assuming these authors aren't actually users ... Create a custom "Authors" taxonomy and dump the author names in there. Taxonomical data is pretty easy to use in a theme to change styling, add attribution, etc. It also gives you archive pages and search functionality so you can index by author name. The long way If these authors absolutely do need to be turned into users ... you've got a lot of work ahead of you. I'd recommend sitting down with phpMyAdmin and running some queries: Run a query to get a list of all author names For each author name, run a query to see if that author exists If the author doesn't exist, run a query to create a dummy use for that author Yes, it will take a while ... but I'm hoping you don't have 1,400 different authors for your 1,400 different posts. Your first query should return maybe 100 or so (hopefully you don't really have 100 different authors!) results ... that should definitely save you some time!
|
Transferring author information from a custom field to a proper author
|
wordpress
|
i've installed a LAMP server on my ubunutu 11.04. i've installed wordpress and hooked it right with the MySQL db. i've changed the permissions of the www-data group to read and write files. every thing is seems to work and i can manage the site through the admin panel, but i can't install plugins cause the system is asking me the FTP details, and i can't seem to go through it. can any body help? please...
|
I usually do this when that happens : <code> chown -R nobody:nobody /path/to/wordpress </code>
|
wordpress on localhost lamp doesn't let me install plugins
|
wordpress
|
I'm developing a group blog on wordpress (first time working with it) and the client has requested that a 'None' option be added where an item can be posted without a "by" attribution. So basically there would be one article / excerpt template for attributed author's posts and another for the none option where the byline would just be the date posted without the "by [author name]." Is this possible with wordpress? Thanks!
|
It's possible to do, but would take hacking up the theme. One convention I've seen is to create a user with a generic name, like Guest, or the name of your site. If you would still like to hack away. Then put a condition around the line\s in the template that displays the author like so: <code> <?php if (get_the_author() != 'none') : ?> <?php the_author(); ?> <?php endif; ?> </code> or alternately, the shorthand... <code> <?php echo (get_the_author() != 'none') ? get_the_author() : ''; ?> </code> Then you define an author named 'none'. The post will only display the author's name if the name isn't 'none'.
|
Creating an option for writing a post without an author attribution for a group blog on Wordpress
|
wordpress
|
Let me explain. I have a link <code> www.mydomain.com/%artist-name%/%song-title%/ </code> . <code> artist-name </code> is a custom post type. <code> song-title </code> is the title of the post. Now, <code> www.mydomain.com/%artist-name%/%song-title%/ </code> displays the song entry -which is working great. The problem is when I'm in <code> www.mydomain.com/%artist-name%/ </code> . It would display all the post titles. I don't want it to be that. Is there a way to make it post the artist's info? note: <code> %artist-name% </code> and <code> %song-title% </code> can have any value. That's why it's really a problem.
|
You can create specific <code> single.php </code> for your custom post types, in the form <code> single-customposttype.php </code> (it's the same with <code> archive.php </code> , see Template Hierarchy ) for example <code> single-artist-name.php </code> . Then in those templates you can do pretty much whatever you want. UPDATE Here's a very simple example of <code> single-artist-name.php </code> : <code> <?php get_header(); ?> <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <div id="content"> <h2>Artist : <?php the_title(); ?></h2> <?php the_content(); ?> </div> <?php endwhile; ?> <?php get_footer(); ?> </code> With this, if you visit <code> www.mydomain.com/miles-davis/ </code> you'll see for example : Artist : Miles Davis Widely considered one of the most influential musicians of the 20th century etc. And so on, the same single post template would be applied to any <code> artist-name </code> post. What sounds strange to me is why would you see all post titles when you visit <code> www.mydomain.com/%artist-name%/ </code> , that looks more like a taxonomy archive. Are you sure that <code> artist-name </code> is registered as a custom post type?
|
custom post type problem
|
wordpress
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.