question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
The title says it all. What is the best page ordering plugin that works well with WPML? It seems that may are reporting issues with different plugins such as my page order and WPML page order. WordPress 3.1 RC3 WPML 2.0.4
So far the best plugin that I have tested to order pages by language is CMS Tree Page View. It allows you to select the language in which to order pages. Ordering is done in a drag and drop tree view. http://wordpress.org/extend/plugins/cms-tree-page-view/
What is the best page ordering plugin that works well with WPML?
wordpress
I'm just trying to create my blog in WordPress hosted on my GoDaddy account (Windows Deluxe plan). WordPress is installed as subsite. When I check my blog after several hours of inactivity I have to wait more than 10 seconds before site opens. I checked it in Firebug and there is 10+ seconds delay between sending request and receiving response. I guess it has something to do with loading the application in IIS. Unfortunatelly I haven't found any setting in GoDaddy's management console to keep the site running. How to deal with this problem? Is there any trick to register my site somewhere and let it regulary check my site? I expect rare traffic to my blog so it would be pretty annoying for visitors to wait for each visit. Edit: This is not a problem of caching or too many plugins (my blog currently have one short post, one short page and All in one SEO plugin, nothing more). It is problem of slow response especially for the first call after long inactivity. Unfortunatelly Windows hosting does not offer Cron jobs. That is the reason why I'm looking for some additional service to regulary check my site. But anyway GoDaddy looks like pretty bad choice. It was recommended to me and I liked the idea of Windows multi site hosting because I can host several apps there including .NET ones. The hosting itself and management tools look pretty good. But by simply checking the response I see that there is delay 1,5+ seconds for almost any request. If I access my test blog hosted directly at Wordpress the delay is 300ms.
Hi @Ladislav Mrnka: It's a well-known problem among WordPress specialists that GoDaddy overloads their servers and you get tons of performance problems with it . If you are at GoDaddy because they are inexpensive let me recommend a host I've been using for years: A Small Orange. You can get a minimum account there for $US25/year, their Tiny plan . The other solution is to set up a cron task or scheduled task to call your home page once per minute or maybe once every 5 minutes and that should keep it loading fast. Since I don't know exactly how GoDaddy works I'll give you some pages that should help you figure out how: What is a Cron Job? Schedule a task to call a webpage using Task scheduler How to set up cron job on godaddy? (for Drupal, but it's mostly the same) running drupal cron jobs on godaddy hosting <a href="stackexchange-url How to emulate Cron Jobs on a Windows Server?
Performance problem with first load
wordpress
I'm working on a site for a client, which will have a custom post type (homes). I'd like the client to be able to add new posts, which would ideally include multiple pictures, in different 'categories', for each home (i.e. initial construction, finish work, completed home). Each different category would then get its own slider on that 'post'. I've considered using something like the Premium Slider plugin, which offers multiple sliders, and includes a metabox on each post, but it would definitely need to be modified to fit my requirements. Any ideas on the best way to go about doing this?
Basics of my approach to sliders: Query arguments for selection of posts. Get The Image (plus custom code and caching when needed) to mine for images. Separate function for markup generation so it could be easily swapped. Just add JavaScript slider you like. When you like/need another more just swap markup and script. Of course this approach is better for pre-configured slider or parameters are generated by code and it doesn't need to have manual controls.
Multiple auto-generated image slideshows/sliders on each (custom) post?
wordpress
I'm using HTML5 on two sites running two different versions of WordPress. They both exhibit the same behaviour and I would like some help with fixing this please. <code> &lt;label for="url"&gt;Website&lt;/label&gt; &lt;input type="url" name="url" id="url" value="&lt;?php echo esc_attr($comment_author_url); ?&gt;" placeholder="Enter Website Address (optional)" pattern="https?://.+"&gt; </code> In testing, we have identified a problem with comment_author_url that occurs when people do not input an URL. For some reason, WordPress is picking up the placeholder text and saving it into the database, like so: http://EnterWebsiteAddress(optional ) I'm having real trouble trying to identify why this is happening. The placeholder attribute isn't inside the input value so should not be getting picked up. This same code is being used in other applications without problems. Does anyone know how to correct this in WordPress? UPDATE: I've done considerable research on this and thought I'd share my findings. The issues come from the comment_form function within WordPress itself. To avoid the problems there are two options: Only use placeholders on required fields. When the fields get focus and something is input the placeholder gets cleared. Use JavaScript to clear placeholders before the form is submitted. I hope this helps the others that have run into the same issues. I'm not submitting a patch to WordPress because, at this time, WordPress only intends to support XHTML.
To avoid the problems there are currently only two options: Only use placeholders on required fields. When the fields get focus and something is input the placeholder gets cleared. Use JavaScript to clear placeholders before the form is submitted. Note: Answered my own question after much research.
Comment form problem with comment_author_url and HTML5 input placeholders
wordpress
I have created several wordpress sites for different clients and I want to have easy access to each site. I could always ftp into the files or edit the database, but i want it to be easier. I want it to be secret so a client doesn't accidently delete my user. Does anyone have any ideas how i could have a secret admin level user or a plugin that is a backdoor. Please believe me i'm not asking anyone to build this for me. I'm just asking for some ideas. like a brainstorming session. I have worked with lots of cms's but wordpress is still new. I thought there might be some veterans here that could point me in the right direction. OH I FORGOT THE MOST IMPORTANT PART. I need this to be a plugin!!! and obviously it needs to stay active even if the client upgrades the core. Any help/ideas would be great. Thanks. OK i see I'm getting a lot of heat from everybody thinking I am trying to accomplish an unethical task. I apologize and hope that no one deletes this. I guess I will try ask my question a different way. Lets be honest what can do i accomplish with this "secret user plugin" that i cannot accomplish with ftp and database access. I am the webmaster for each client. I setup the hosting. Half of them do not even have ftp log-in information. Nothing devious is happening I'm only trying to make my life easier.
Just in case you still have FTP access, you can make use of WPAAA.PHP – WordPress Access All Areas (Wordpress Support Tool) . It's a single file and you can easily create a Must-Use plugin out of it by just copying it into the must-use directory and doing some hacks. Additionally, it will auto-configure itself so that you have a secret URL to access the page.
have secret admin level user or build backdoor
wordpress
I want function that scan wordpress posts for youtube links or youtube shortcode and when found it, with regex selects only code from url (like '2SaZO4Gmfdc') and echo that code. For now, i edited one plugin that do exacly same this, but instead of echoing code, it echoes something like img.youtube.com/vi/2SaZO4Gmfdc/0.jpg So, for now, i have this code http://pastebin.com/6M70xpTX and it's not working, and plugins code that works is here pastebin.com/MX2fca96
Hi @Саша Стефано: Maybe I'm missing something but at first glance it looks like you just need to add a <code> return </code> statement (I've not tested this code so if that's not it let me know and I'll dig in to figure it out): <code> function get_youtube_kod($post_id=null) { // Get the post ID if none is provided if($post_id==null OR $post_id=='') $post_id = get_the_ID(); // Gets the post's content $post_array = get_post($post_id); $markup = $post_array-&gt;post_content; // Checks for a standard YouTube embed preg_match('#&lt;object[^&gt;]+&gt;.+?http://www.youtube.com/v/([A-Za-z0-9\-_]+).+?&lt;/object&gt;#s', $markup, $matches); // Checks for any YouTube URL if(!isset($matches[1])) { preg_match('#http://w?w?w?.?youtube.com/watch\?v=([A-Za-z0-9\-_]+)#s', $markup, $matches); } // If no standard YouTube embed is found, checks for one embedded with JR_embed if(!isset($matches[1])) { preg_match('#\[yt url=([A-Za-z0-9\-_]+)]#s', $markup, $matches); } if(!isset($matches[1])) { preg_match('#\[yt url=([A-Za-z0-9\-_]+)[^&gt;]*]#s', $markup, $matches); } // If we've found a YouTube video ID, create the thumbnail URL if(isset($matches[1])) { $youtube_kod = $matches[1]; } return $youtube_kod; }; </code>
Echo youtube code from url or shortcode
wordpress
I just transfered my website from shared hosting to VPS, I installed all the backup from previous website to the VPS, Everything was fine, My website was functioning all perfect, But I was not able to see wp-admin page, When I hit on url "mywebsite.com/wp-admin", I get a blank white page, I disabled all plugins and themes by renaming the folder names, Then I was able to login, no white screen was there, After digging my head into it for long time, I found that there is problem with the plugins folder, My theme is all up-to-date, and works fine without any errors If I de-activate all the plugins, then I don't get any blank white screen during login, but if any one plugin is activated the I get white blank screen on wp-admin page, This is not it, when trying to update any plugin or theme I am getting this message: Unpacking the update… Notice: Undefined offset: 1 in /home/admin/onlinemba.co.in/wp-admin/includes/class-ftp-sockets.php on line 93 Warning: Invalid argument supplied for foreach() in /home/admin/onlinemba.co.in/wp-admin/includes/class-wp-filesystem-ftpsockets.php on line 299 Notice: Undefined offset: 1 in /home/admin/onlinemba.co.in/wp-admin/includes/class-ftp-sockets.php on line 93 Installing the latest version… Notice: Undefined offset: 1 in /home/admin/onlinemba.co.in/wp-admin/includes/class-ftp-sockets.php on line 93 Warning: Invalid argument supplied for foreach() in /home/admin/onlinemba.co.in/wp-admin/includes/class-wp-filesystem-ftpsockets.php on line 299 Incompatible Archive. Plugin upgrade failed . (I have included <code> define("WP_DEBUG",true); </code> to wp-config file, after @Backie suggestions, so I am getting errors) I am not able to update my wordpress, but I did it manually, I am having the latest version of wordpress, I am not able to update my any plugins and themes.
Could be a whole host of problems but it seems you've tracked it to a plugin. Try deleting the entire plugin directory and re-downloading your plugins. It is also possible that something went wrong during the transfer (some files didn't transfer....became corrupt, etc.). If worst comes to worst, try the transfer again. You can also try replacing what's in the <code> class-ftp-sockets.php </code> file with this .
Upgrade not working & themes not supporting
wordpress
I'm looking for a library that can handle user registration (name, address, e-mail etc.) into my existing WordPress website. What options exist today, or will I have to pull my own?
This is tutorial on extending user information I have stored in bookmarks: Adding and using custom user profile fields . Take a look and see if it fits your needs. PS I am not following developments in user functionality closely so there might have been changes/improvements since tutorial was published.
What's the best user registration library to integrate WordPress?
wordpress
I almost always select "Open link in new window" when creating an URL/HREF. Is there any way to default this choice. Even if it requires a small source code change, I think it would be worthwhile (if someone can tell me where that might be.)
It seems TinyMCE provides no easy setting to select a default value. But there is another backdoor: the <code> external_link_list_url </code> option of TinyMCE can point to an extra Javascript file that will be loaded in the link editor window. You can use it to populate a dropdown of frequent link destinations, but since it is a regular Javascript file we can also drop other content in it. Like code that will change the selected value of the target list dropdown if we are not editing an existing link: <code> tinyMCEPopup.onInit.add( function() { if ( ! tinyMCEPopup.editor.dom.getParent( tinyMCEPopup.editor.selection.getNode(), 'A' ) ) { selectByValue( document.forms[0], 'target_list', '_blank' ); } } ); </code> You can create a WordPress plugin for this, so it will survive WP updates. Create a new directory under <code> wp-content/plugins/ </code> (call it whatever you like, so you can find it later). Create a PHP file in it (also called whatever you like), with the following contents. You can change the contents of the comment, this will define what you see in the Plugins administration area. <code> &lt;?php /* Plugin Name: WPSE 7785 Plugin URI: stackexchange-url Is there any way to set default for "Insert/Edit Link" to "Open link in new window"? Version: 1.0 Author: Jan Fabry */ add_filter( 'tiny_mce_before_init', 'wpse7785_tiny_mce_before_init' ); function wpse7785_tiny_mce_before_init( $initArray ) { $initArray['external_link_list_url'] = plugins_url( 'wpse-7785.js', __FILE__ ); return $initArray; } </code> Now also create a Javascript file in that plugin directory, next to the PHP file. I called it <code> wpse-7785.js </code> , you can choose something else, but be sure to update the name in the <code> plugins_url() </code> call above. Place the contents of the first block in that Javascript file. Activate the plugin and go to your editor. When you go to the post editor and click the "Edit link" button, the correct value should be set for the "Target" dropdown.
Is there any way to set default for "Insert/Edit Link" to "Open link in new window"?
wordpress
I am loading JQuery from the google CDN using the following code: <code> wp_deregister_script('jquery'); wp_register_script( 'jquery', // handle - WP uses this name to refer to script 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js', array(), // Array of handles representing scripts that this one depends on. false, // Version number - defaults to false. false // false = put script in header, true = put in footer ); wp_enqueue_script('jquery'); </code> In firebug I see that wordpress appends '?ver=3.0.4' to the URL to control caching. In fact there doesn't seem to be any way to stop WP from appending something to the URL - I can provide my own string in the call to wp_register_script() but WP will use the default 'ver=3.0.4' if i leave it blank (or "false") I believe the appended version string stop the user's browser from re-using a cached copy of the file that it might have downloaded from a different website. E.g. User visits www.example.com which loads ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js so it is now in browser cache. User then visits my site which loads ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js?ver=3.0.4 The user's browser not use it's cached copy because the URLs are different. Since cross-site caching is one of the main reasons I want to use Google's CDN, are there any solutions to this other than loading the script manually (not ideal) or hacking WP core? TIA /Eoin/
Use null as $ver param: <code> wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', false, null); wp_enqueue_script('jquery'); </code> Output: <code> &lt;script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'&gt;&lt;/script&gt; </code>
WP script versioning breaks cross-site caching?
wordpress
Reading wp_schedule_event() documentation got me code something like this: <code> add_action('cr_paid_link_manager_generate_expiring_link_email_action','cr_paid_link_manager_generate_expiring_link_email'); wp_schedule_event(time(), 'daily', 'cr_paid_link_manager_generate_expiring_link_email_action'); </code> The problem is, <code> cr_paid_link_manager_generate_expiring_link_email() </code> is generated everytime page load, or so it look's like. This code supposed to send email only once a day. I try to set first parameter of <code> wp_schedule_event() </code> to <code> $timestamp_start </code> : <code> $timestamp_start = '2011-01-26 00:00:00'; add_action('cr_paid_link_manager_generate_expiring_link_email_action','cr_paid_link_manager_generate_expiring_link_email'); wp_schedule_event($timestamp_start, 'daily', 'cr_paid_link_manager_generate_expiring_link_email_action'); </code> Still no result. The code keep sending email Every minute. Is there something missing on my code?
Where are you putting the wp_schedule_event() code? My guess is, you have it somewhere that's causing it to run on every page load, causing the action to be scheduled multiple times (like maybe you just dropped it in your functions.php?). You only need to schedule the action once. The easiest way is to do it on activation of your plugin. Try something like: <code> function wpsx_7780_myplugin_init() { wp_schedule_event(time(), 'daily', 'cr_paid_link_manager_generate_expiring_link_email_action'); } register_activation_hook( __FILE__, 'wpsx_7780_myplugin_init' ); add_action('cr_paid_link_manager_generate_expiring_link_email_action','cr_paid_link_manager_generate_expiring_link_email'); </code> Then deactivate and reactivate your plugin. This way, the event only gets scheduled once, but the action gets added on every page load. EDIT: I should also note that you'll probably need to clear all those existing events you've created using wp_clear_scheduled_hook()
wp_schedule_event() set daily, but processed every second
wordpress
I have seen and been using the following technique for adding php scripts to my plugin for handling custom forms in a wordpress plugin. from the quizzin plugin: <code> $code_pages = array('quiz_form.php','quiz_action.php', 'question_form.php', 'question.php'); foreach($code_pages as $code_page) { $hookname = get_plugin_page_hookname("quizzin/$code_page", '' ); $_registered_pages[$hookname] = true; </code> For example, the 'quiz_action.php' is later used as the target for an administration form (these forms are used only in wp-admin) <code> &lt;form name="post" action="&lt;?php echo $GLOBALS['my_plugin_folder'] ?&gt;/quiz_action.php" method="post" id="post"&gt; </code> UPDATE: This method is discussed here - stackexchange-url ("Admin config screen without menu") The final comment below by a Wordpress core dev seems to discourage this: http://wordpress.org/support/topic/how-can-i-execute-php-scripts-in-my-plugin-folder So what is best practice here? Should administration forms be posting to wp-admin/admin.php?action=foo or wp-admin/edit.php?action=bar. How does one register these actions? Is this documented anywhere? To be clear, these files should not be linked from an admin menu. I'm using Wordpress 3.0.4 Thanks!
Basically, it seems there are two ways to do this: 1) The $_registered_pages way detailed in the original question. This seems a bit non-standard and might confuse someone looking at your code. 2) Post your form to an admin url like admin_url('admin.php?page=show_form') where show_form is a registered menu item/function. Inside show_form(), you can switch on whether or not a form has been submitted. If it has you can include another php file conditionally i.e: <code> function show_form() { if ( $_SERVER["REQUEST_METHOD"] == "POST" &amp;&amp; isset($_POST['submit'])) { require_once('name_of_your_processing_script.php'); } else { //do something else. } } </code> Or just include the file and do any processing / switching in there (probably cleaner). If you try and just use a file you have created as the form's post action you will get an error. As mentioned in the comments above above you should prevent your files from being called directly and protect and guard against CSRF attacks using nonces. Apologies for the long comment thread. Would be grateful if people could confirm this is what they meant.
What is the recommended way to create plugin administration forms?
wordpress
Ive been trying to do this for a long time here... First of all, im working with Buddypress latest ver. under WP latest ver. What i want to do, is i want to understand how to call content within a php file via ajax. I know php is server side, so doing something like this: <code> $(#handle).click( function(){ $(#box).load('help.php' #content); }); </code> will only bring forth html within the document.But I have functions I need within, like let's say for example a user's avatar: <code> &lt;?php bp_loggedin_user_avatar()?&gt; </code> The returned content will stop at the function called. Will I have to create pages for all of the php files that I want to call content from? Or, <code> require </code> the file to retrieve the content? I've looked at some of the <code> $ajax </code> Jquery uses around here, but I 'm not sure which one to implement. I want to load certain content wrapped in specific divs in that php file. Basically, I just need help retrieving content that contains php lol. Any ideas?
Well you want to hook into the wp_loaded action. Do the stuff you need to do and then exit the process. You should probably look at http://codex.wordpress.org/AJAX_in_Plugins
Load created php file data via ajax
wordpress
I have this inside my posts page (set in the admin panel: Posts Page: Blog): blog.php <code> &lt;?php /** * Template Name: Blog * @package WordPress * @subpackage Prominent * @since Prominent 1.0 */ get_header(); ?&gt; &lt;div class="shadow-top"&gt; &lt;!-- Shadow at the top of the slider --&gt; &lt;/div&gt; &lt;div id="intro2"&gt; &lt;div class="container"&gt; &lt;/div&gt;&lt;!-- .container --&gt; &lt;/div&gt;&lt;!-- #featured --&gt; &lt;div class="shadow-bottom"&gt; &lt;!-- Shadow at the bottom of the slider --&gt; &lt;/div&gt; &lt;div id="content"&gt; &lt;div class="container"&gt; &lt;div id="blog"&gt; &lt;div class="container"&gt; &lt;?php /* Run the loop to output the posts. * If you want to overload this in a child theme then include a file * called loop-index.php and that will be used instead. */ get_template_part( 'loop', 'index' ); ?&gt; &lt;?php get_sidebar(); ?&gt; &lt;/div&gt;&lt;!-- .container --&gt; &lt;/div&gt;&lt;!-- #content-bottom --&gt; &lt;?php get_footer(); ?&gt; </code> index.php <code> &lt;?php /** * The main template file. * * This is the most generic template file in a WordPress theme * and one of the two required files for a theme (the other being style.css). * It is used to display a page when nothing more specific matches a query. * E.g., it puts together the home page when no home.php file exists. * Learn more: http://codex.wordpress.org/Template_Hierarchy * * @package WordPress * @subpackage Starkers * @since Starkers 3.0 */ get_header(); ?&gt; &lt;?php /* Run the loop to output the posts. * If you want to overload this in a child theme then include a file * called loop-index.php and that will be used instead. */ get_template_part( 'loop', 'index' ); ?&gt; &lt;?php get_sidebar(); ?&gt; &lt;?php get_footer(); ?&gt; </code> loop.php <code> &lt;?php /** * The loop that displays posts. * * The loop displays the posts and the post content. See * http://codex.wordpress.org/The_Loop to understand it and * http://codex.wordpress.org/Template_Tags to understand * the tags used in it. * * This can be overridden in child themes with loop.php or * loop-template.php, where 'template' is the loop context * requested by a template. For example, loop-index.php would * be used if it exists and we ask for the loop with: * &lt;code&gt;get_template_part( 'loop', 'index' );&lt;/code&gt; * * @package WordPress * @subpackage Starkers * @since Starkers 3.0 */ ?&gt; &lt;?php /* Display navigation to next/previous pages when applicable */ ?&gt; &lt;?php if ( $wp_query-&gt;max_num_pages &gt; 1 ) : ?&gt; &lt;?php next_posts_link( __( '&amp;larr; Older posts', 'twentyten' ) ); ?&gt; &lt;?php previous_posts_link( __( 'Newer posts &amp;rarr;', 'twentyten' ) ); ?&gt; &lt;?php endif; ?&gt; &lt;?php /* If there are no posts to display, such as an empty archive page */ ?&gt; &lt;?php if ( ! have_posts() ) : ?&gt; &lt;h1&gt;&lt;?php _e( 'Not Found', 'twentyten' ); ?&gt;&lt;/h1&gt; &lt;p&gt;&lt;?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyten' ); ?&gt;&lt;/p&gt; &lt;?php get_search_form(); ?&gt; &lt;?php endif; ?&gt; &lt;?php /* Display the contents of static page Posts page */ ?&gt; &lt;?php if ( 'page' == get_option('show_on_front') &amp;&amp; get_option('page_for_posts') &amp;&amp; is_home() ) : the_post(); $page_for_posts_id = get_option('page_for_posts'); setup_postdata(get_page($page_for_posts_id)); ?&gt; &lt;div id="post-&lt;?php the_ID(); ?&gt;" class="page"&gt; &lt;div class="entry-content"&gt; &lt;?php the_content(); ?&gt; &lt;?php edit_post_link('Edit', '', '', $page_for_posts_id); ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php rewind_posts(); endif; ?&gt; &lt;?php /* Start the Loop. * * In Twenty Ten we use the same loop in multiple contexts. * It is broken into three main parts: when we're displaying * posts that are in the gallery category, when we're displaying * posts in the asides category, and finally all other posts. * * Additionally, we sometimes check for whether we are on an * archive page, a search page, etc., allowing for small differences * in the loop on each template without actually duplicating * the rest of the loop that is shared. * * Without further ado, the loop: */ ?&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;?php /* How to display posts in the Gallery category. */ ?&gt; &lt;?php if ( in_category( _x('gallery', 'gallery category slug', 'twentyten') ) ) : ?&gt; &lt;h2&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;?php twentyten_posted_on(); ?&gt; &lt;?php if ( post_password_required() ) : ?&gt; &lt;?php the_content(); ?&gt; &lt;?php else : ?&gt; &lt;?php $images = get_children( array( 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'orderby' =&gt; 'menu_order', 'order' =&gt; 'ASC', 'numberposts' =&gt; 999 ) ); $total_images = count( $images ); $image = array_shift( $images ); $image_img_tag = wp_get_attachment_image( $image-&gt;ID, 'thumbnail' ); ?&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php echo $image_img_tag; ?&gt;&lt;/a&gt; &lt;p&gt;&lt;?php printf( __( 'This gallery contains &lt;a %1$s&gt;%2$s photos&lt;/a&gt;.', 'twentyten' ), 'href="' . get_permalink() . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark"', $total_images ); ?&gt;&lt;/p&gt; &lt;?php the_excerpt(); ?&gt; &lt;?php endif; ?&gt; &lt;a href="&lt;?php echo get_term_link( _x('gallery', 'gallery category slug', 'twentyten'), 'category' ); ?&gt;" title="&lt;?php esc_attr_e( 'View posts in the Gallery category', 'twentyten' ); ?&gt;"&gt;&lt;?php _e( 'More Galleries', 'twentyten' ); ?&gt;&lt;/a&gt; | &lt;?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?&gt; &lt;?php edit_post_link( __( 'Edit', 'twentyten' ), '|', '' ); ?&gt; &lt;?php /* How to display posts in the asides category */ ?&gt; &lt;?php elseif ( in_category( _x('asides', 'asides category slug', 'twentyten') ) ) : ?&gt; &lt;?php if ( is_archive() || is_search() ) : // Display excerpts for archives and search. ?&gt; &lt;?php the_excerpt(); ?&gt; &lt;?php else : ?&gt; &lt;?php the_content( __( 'Continue reading &amp;rarr;', 'twentyten' ) ); ?&gt; &lt;?php endif; ?&gt; &lt;?php twentyten_posted_on(); ?&gt; | &lt;?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?&gt; &lt;?php edit_post_link( __( 'Edit', 'twentyten' ), '| ', '' ); ?&gt; &lt;?php /* How to display all other posts. */ ?&gt; &lt;?php else : ?&gt; &lt;h2&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;?php twentyten_posted_on(); ?&gt; &lt;?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?&gt; &lt;?php the_excerpt(); ?&gt; &lt;?php else : ?&gt; &lt;?php the_content( __( 'Continue reading &amp;rarr;', 'twentyten' ) ); ?&gt; &lt;?php wp_link_pages( array( 'before' =&gt; '' . __( 'Pages:', 'twentyten' ), 'after' =&gt; '' ) ); ?&gt; &lt;?php endif; ?&gt; &lt;?php if ( count( get_the_category() ) ) : ?&gt; &lt;?php printf( __( 'Posted in %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?&gt; | &lt;?php endif; ?&gt; &lt;?php $tags_list = get_the_tag_list( '', ', ' ); if ( $tags_list ): ?&gt; &lt;?php printf( __( 'Tagged %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?&gt; | &lt;?php endif; ?&gt; &lt;?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?&gt; &lt;?php edit_post_link( __( 'Edit', 'twentyten' ), '| ', '' ); ?&gt; &lt;?php comments_template( '', true ); ?&gt; &lt;?php endif; // This was the if statement that broke the loop into three parts based on categories. ?&gt; &lt;?php endwhile; // End the loop. Whew. ?&gt; &lt;?php /* Display navigation to next/previous pages when applicable */ ?&gt; &lt;?php if ( $wp_query-&gt;max_num_pages &gt; 1 ) : ?&gt; &lt;?php next_posts_link( __( '&amp;larr; Older posts', 'twentyten' ) ); ?&gt; &lt;?php previous_posts_link( __( 'Newer posts &amp;rarr;', 'twentyten' ) ); ?&gt; &lt;?php endif; ?&gt; </code> Now it doesn't matter how much I modify the code inside blog.php nothing changes (Even deleting everything changes nothing). Am I misunderstanding Wordpress' loop?
Don't forget about the "Help" button in the top-right of the WP admin screen! The Help refers to the Settings Reading SubPanel page in the Codex which says the following: Posts page - Select in the drop-down box the name of the Page that will now contain your Posts. If you do not select a Page here, your Posts will only be accessible via other navigation features such as category, calendar, or archive links. Even if the selected Page is Password protected, visitors will NOT be prompted for a password when viewing the Posts Page. Also, any Template assigned the Page will be ignored and the theme's index.php (or home.php if it exists) will control the display of the posts. In other words, the page you choose in that drop-down will act as nothing more than a placeholder and its contents and template are ignored completely (only the title is used). Use <code> home.php </code> or <code> index.php </code> instead. Also see Creating a Static Front Page .
Template file for static posts page does not get loaded?
wordpress
Currently WPML adds /fr/ to permalinks to identify a url as French. The default language of the site is English, however WPML does not add /en/ by default for the default lannguage (English) permalinks. Is there a way to have the default language also show up in the permalinks?
EDIT: This feature has been added to the latest version of the plugin. This is not possible, and will not be implemented in the near future.
WPML - how to get the permalinks to display also the default language
wordpress
I have this in my functions.php : The images inside the slider were added as custom post types called " Page Content ." I'm not sure if the filter only applies to the main Posts . <code> /** * Remove paragraph tags around content and excerpt */ remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' ); </code> The the posts in the admin look like this: But something still wrapping the images of my Nivo Slider with p tags: CSS: <code> #slider-wrapper { float: left; height: 560px; } #slider { float: left; border: 1px solid #DDD; position:relative; background:url(images/loading.gif) no-repeat 50% 50%; } #slider img { top: 0px; left: 0px; display: none; float: left; position: absolute; width: 958px; height: 458px; } .nivo-controlNav { margin: 490px auto 0; overflow: hidden; } .nivo-controlNav a { background: url(images/bullets.png) no-repeat; border: 0; float: left; text-indent: -9999px; width: 22px; height: 22px; } .nivo-controlNav a.active { background-position: 0 -22px; } .nivo-directionNav a { display: block; width: 70px; height: 70px; background: url(images/arrows.png) no-repeat; text-indent: -9999px; border: 0; } a.nivo-nextNav { background-position: -70px 0; right: -20px; } a.nivo-prevNav { left: -20px; } .nivo-caption { text-shadow:none; font-family: Helvetica, Arial, sans-serif; } .nivo-caption a { color:#efe9d1; text-decoration:underline; } </code> Any suggestions to remove the p tags?
There are various functions aside from <code> wpautop() </code> that filter post content , such as <code> force_balance_tags() </code> , which was designed to balance bad HTML coming in via the editor. They're mostly defined in formatting.php , where you can see the various code in source. Removal of these filters can be as simple as one line, as you point out: <code> remove_filter('the_content', 'wpautop'); </code>
I'm using a filter to remove the tags auto wrap, but there still wrapped elements?
wordpress
How come pending comments are appearing in our admin dashboard? We haven't enabled comments in any way and aren't really interested in that feature. How did someone manage to "add" a comment. Some of them do appear to be genuine mentions of our blog post in Twitter, while others are rubbish. What would happen if we approved them?
Your dashboard got alerted by trackbacks and pingbacks . Check the links for more info. As @eileen.carpenter mentioned on the comments, you should uncheck <code> Allow link notifications from other blogs (pingbacks and trackbacks.) </code> in your dashboard for them to be disabled. If you approve them, they'll appear as comments in your posts/pages. Depending on the theme, they may actually appear as comments or trackbacks/pingbacks. Most modern themes display them differently. On code level, they're just comments with a different comment_type . So theme developers use this to display comments and trackbacks/pingback as different things.
How come pending comments are appearing in admin?
wordpress
I have two custom post type. Then I need to use title_save_pre to post title prior to saving it in the database. I need to use this filter just for one custom post type. This is my function: <code> &lt;?php function muda_titulo() { global $post; $type = get_post_type($post-&gt;ID); if ($type== 'event') { $title = $post-&gt;post_excerpt; $day= get_the_time('l, d F, Y'); return $title.' - '.$day; } else if ($type == 'post') { // do nothing } } add_filter ('title_save_pre','muda_titulo'); ?&gt; </code> On custom post type 'event' it works fine, but on custom post type 'post' the title changed to a white space. Thank u
Try the code below. Filter's take a value and returns it afterwards. <code> &lt;?php function muda_titulo($title) { global $post; $type = get_post_type($post-&gt;ID); if ($type== 'event') { $title = $post-&gt;post_excerpt; $day= get_the_time('l, d F, Y'); return $title.' - '.$day; } else if ($type == 'post') { return $title; } } add_filter ('title_save_pre','muda_titulo'); ?&gt; </code>
Title_save_pre - Simple problem that u know for sure
wordpress
I'm trying to implement this plugin on my live wordpress instilation: http://wordpress.org/extend/plugins/frontpage-slideshow/ I wouldn't usually ask a question about a plugin directly but this problem is a little strange, I have a local MAMP installation of wordpress running the plugin, everything db and file wise is identical to the live version, taken from my git repository and a up to date dump of the db. What's very strange here is that the plugin works with no problems on my MAMP instillation, i can access the admin section no problem. But on my live wordpress instillation, all javascript is broken on the plugins admin page, even the wordpress admin js that controls the menu drop downs. I'm not sure what is happening as i have 0 js errors in my console and can see exactly the same files are being loaded as on my local instillation. The only variable here are the servers, but i'm not sure what could be causing this, does anyone have any ideas? Edit: I've isolated the problem down to this line: <code> $attachments = get_children(array( 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'post_status' =&gt; null, 'post_parent' =&gt; null, )); </code> if i remove it everything works fine..
Removing the null paramaters fixed the problem: <code> $attachments = get_children(array( 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', )); </code>
Plugin admin panel JavaScript Broken
wordpress
I am filtering the map_meta_cap() function, which is called from $user-> has_cap (which is called from current_user_can()). I only want my filter to execute if the current user is an administrator, so I need a conditional in my filter that checks their role. I can't use current_user_can(), because that invokes my filter, causing an infinite loop. Is there a reliable way to check whether someone is an administrator without using current_user_can() ?
You could check the <code> $current_user </code> variable to determine the role. I believe it should be realiable after init(maybe even on init) for a logged in user, a guest visitor obviously won't have any data associated with him or her yet(so it'll be empty/unset). You can also call up <code> get_currentuserinfo() </code> to populate the <code> $current_user </code> var, but i've personally never found a need when calling <code> $current_user </code> after init(but i'm sure there may be cases when you need to call it, so it's linked below for reference). http://codex.wordpress.org/Function_Reference/get_currentuserinfo
How to check user role without using current_user_can()
wordpress
I'm trying to upgrade to WP 3 but I'm getting a weird error when I try to do so: <code> Downloading update from http://wordpress.org/wordpress-3.0.4.zip. Unpacking the update. Could not create directory: /my/path/web/wp-content/upgrade/wordpress-3.tmp Installation Failed </code> The reason it's weird is because the <code> upgrade </code> directory has 777 permissions. I ran <code> chmod -R 777 upgrade/ </code> and when I do an <code> ls </code> , I see that <code> upgrade </code> is world-writable. I'm sure I'm dealing with the right directory because if I delete <code> upgrade </code> , I get a different error. Any idea why this happening?
The fix turned out to be to change <code> vsftp </code> 's permissions in the <code> vsftp </code> config file.
WP upgrade can't create directory even though perms are 777
wordpress
I want to display comment form validation errors (as well as captcha error) on the comment form itself and not on a different page. How can I do that ?
This question have answered again, here: stackexchange-url ("Comment form validation") Also you can do the same with JQuery and Validation plugin http://bassistance.de/jquery-plugins/jquery-plugin-validation/
How to dispaly comment form error messages in the same page
wordpress
WP has a nice javascript loader included in wp-admin: http://core.trac.wordpress.org/browser/tags/3.0.4/wp-admin/load-scripts.php and a CSS loader: http://core.trac.wordpress.org/browser/tags/3.0.4/wp-admin/load-styles.php I was wondering if it's possible to use them in the front-end too, not just admin, because they can concatenate all enqueued scripts, and serve them as a single gzipped file
late answer From a brief look: You'd have to use <code> include( admin_url().'load-scripts.php' ); </code> and <code> include( admin_url().'script-loader.php' ); </code> Then jump into <code> $GLOBALS['wp_scripts'] </code> : Use&hellip; <code> $wp_scripts-&gt;default_dirs( array_merge( $wp_scripts-&gt;default_dirs ,array( '/themes/your_theme/js/' ) ); </code> &hellip;to extend it. And then use <code> $wp_scripts-&gt;add( $handle, $path_from_content_dir, false/array( $deps ), $ver ) </code> to add a script. Notes: <code> 1. Uncompressed scripts get searched by `.dev.js` (when `SCRIPT_DEBUG` is `TRUE`). 2. Same seems to be possible for $wp_styles. 3. EDIT: *WP 3.5* will change this behavior and use `.js` for "dev" versions and ".min.js" when (`SCRIPT_DEBUG` is `TRUE`); </code> (But I guess this will only work if you use a plugin or mu-plugin.) It´s not tested and I´m not shure if this will work.
Could the WP script/style loader be used to concatenate and gzip scripts and styles in the front-end?
wordpress
I read a tutorial about how to Display the contents of static page Posts page . Basically I had to place this code right before the Loop: <code> &lt;?php //This is the code from the tutorial if ( 'page' == get_option('show_on_front') &amp;&amp; get_option('page_for_posts') &amp;&amp; is_home() ) : the_post(); $page_for_posts_id = get_option('page_for_posts'); setup_postdata(get_page($page_for_posts_id)); ?&gt; &lt;div id="post-&lt;?php the_ID(); ?&gt;" class="page"&gt; &lt;div class="entry-content"&gt; &lt;?php the_content(); ?&gt; &lt;?php edit_post_link('Edit', '', '', $page_for_posts_id); ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php rewind_posts(); endif; ?&gt; </code> I wanted to also include <code> the_content </code> , but instead the <code> the_title </code> of the first post (blog) entry was shown: <code> &lt;div class="entry-content"&gt; &lt;?php the_title(); ?&gt; &lt;?php the_content(); ?&gt; &lt;?php edit_post_link('Edit', '', '', $page_for_posts_id); ?&gt; &lt;/div&gt; </code> picture: Code: loop.php <code> &lt;?php if ( 'page' == get_option('show_on_front') &amp;&amp; get_option('page_for_posts') &amp;&amp; is_home() ) : the_post(); $page_for_posts_id = get_option('page_for_posts'); setup_postdata(get_page($page_for_posts_id)); ?&gt; &lt;div class="shadow-top"&gt; &lt;!-- Shadow at the top of the slider --&gt; &lt;/div&gt; &lt;div id="intro2"&gt; &lt;div class="container"&gt; &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt; &lt;p&gt;&lt;?php the_content(); ?&gt;&lt;/p&gt; &lt;?php edit_post_link('Edit', '', '', $page_for_posts_id); ?&gt; &lt;/div&gt;&lt;!-- .container --&gt; &lt;/div&gt;&lt;!-- #featured --&gt; &lt;div class="shadow-bottom"&gt; &lt;!-- Shadow at the bottom of the slider --&gt; &lt;/div&gt; &lt;div id="content"&gt; &lt;div class="container"&gt; &lt;div id="blog"&gt; &lt;div class="posts"&gt; &lt;?php rewind_posts(); endif; ?&gt; &lt;/div&gt; &lt;?php /* Start the Loop. * * In Twenty Ten we use the same loop in multiple contexts. * It is broken into three main parts: when we're displaying * posts that are in the gallery category, when we're displaying * posts in the asides category, and finally all other posts. * * Additionally, we sometimes check for whether we are on an * archive page, a search page, etc., allowing for small differences * in the loop on each template without actually duplicating * the rest of the loop that is shared. * * Without further ado, the loop: */ ?&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; </code> (...) blog.php: <code> &lt;?php /** * Template Name: Blog * @package WordPress * @subpackage Prominent * @since Prominent 1.0 */ get_header(); ?&gt; &lt;?php // Start the Main Loop if ( have_posts() ) : ?&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;div class="posts"&gt; &lt;h2&gt;&lt;?php the_content(); ?&gt;&lt;/h2&gt; &lt;/div&gt;&lt;!-- .content --&gt; &lt;/div&gt;&lt;!-- .posts --&gt; &lt;?php endwhile; ?&gt; &lt;?php endif; ?&gt; &lt;?php get_sidebar(); ?&gt; &lt;/div&gt;&lt;!-- .container --&gt; &lt;/div&gt;&lt;!-- #content-bottom --&gt; &lt;?php get_footer(); ?&gt; </code> Any suggestions? EDIT: Right now I'm using the following code. It retrieves the page's specific the_content but when retrieving the_title, it still retrieving the first blog post. <code> &lt;?php /** * Template Name: Blog * @package WordPress * @subpackage Prominent * @since Prominent 1.0 */ get_header(); ?&gt; &lt;div class="shadow-top"&gt; &lt;!-- Shadow at the top of the slider --&gt; &lt;/div&gt; &lt;div id="intro2"&gt; &lt;div class="container"&gt; &lt;?php /* Display the contents of static page Posts page */ if ( 'page' == get_option('show_on_front') &amp;&amp; get_option('page_for_posts') &amp;&amp; is_home() ) : the_post(); $page_for_posts_id = get_option('page_for_posts'); setup_postdata(get_page($page_for_posts_id)); ?&gt; &lt;div id="post-&lt;?php the_ID(); ?&gt;" class="page"&gt; &lt;div class="content"&gt; &lt;h2&gt;&lt;?php the_content(); ?&gt;&lt;/h2&gt; &lt;?php edit_post_link('Edit', '', '', $page_for_posts_id); ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php rewind_posts(); endif; ?&gt; &lt;/div&gt;&lt;!-- .container --&gt; &lt;/div&gt;&lt;!-- #featured --&gt; &lt;div class="shadow-bottom"&gt; &lt;!-- Shadow at the bottom of the slider --&gt; &lt;/div&gt; &lt;div id="content"&gt; &lt;div class="container"&gt; &lt;div id="blog"&gt; &lt;div class="container"&gt; &lt;?php // find all content that has the type of video and then to loop through them. ?&gt; &lt;?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?&gt; &lt;div id="post-&lt;?php the_ID(); ?&gt;" &lt;?php post_class(); ?&gt;&gt; &lt;?php if ( is_front_page() ) { ?&gt; &lt;h2 class="entry-title"&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt; &lt;?php } else { ?&gt; &lt;h1 class="entry-title"&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt; &lt;?php } ?&gt; &lt;div class="entry-content"&gt; &lt;?php the_content(); ?&gt; &lt;?php wp_link_pages( array( 'before' =&gt; '&lt;div class="page-link"&gt;' . __( 'Pages:', 'twentyten' ), 'after' =&gt; '&lt;/div&gt;' ) ); ?&gt; &lt;?php edit_post_link( __( 'Edit', 'twentyten' ), '&lt;span class="edit-link"&gt;', '&lt;/span&gt;' ); ?&gt; &lt;/div&gt;&lt;!-- .entry-content --&gt; &lt;/div&gt;&lt;!-- #post-## --&gt; &lt;?php comments_template( '', true ); ?&gt; &lt;?php endwhile; ?&gt; &lt;/div&gt; &lt;?php get_sidebar(); ?&gt; &lt;/div&gt;&lt;!-- .container --&gt; &lt;/div&gt;&lt;!-- #content-bottom --&gt; &lt;?php get_footer(); ?&gt; </code>
This is a relatively simple task, and you only need to attach an appropriately coded page template to your chosen post's page. When the page first loads, the main query holds data on the page, such as the title, content and so forth, we can shortcut to that by calling <code> the_post </code> which will then allow us to simply call the template tags to produce the title(etc) for the page. Following that we can then call <code> query_posts </code> and refill the main query object with a selection of posts. This is very similar to the examples given on the codex, here. http://codex.wordpress.org/Pages#A_Page_of_Posts The main difference here, is that rather than creating a second query object, i'm just going to re-use the main one(why not, it makes sense in this context, imho). Adjust the code(Query parameters/HTML/Classes/IDs) as appropriate. <code> &lt;?php /** * Template Name: Page of Posts * * Selectable from a dropdown menu on the edit page screen. */ get_header(); ?&gt; &lt;div id="container"&gt; &lt;div id="content"&gt; &lt;?php the_post(); // Setup post data so it's possible to call the regular loop template tags ?&gt; &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;h2&gt; &lt;div &lt;?php post_class(); ?&gt;&gt;&lt;?php the_content(); ?&gt;&lt;/div&gt; &lt;?php $args = array( 'paged' =&gt; (int) get_query_var('paged'), 'post_type' =&gt; 'post', 'order' =&gt; 'desc', 'posts_per_page' =&gt; 3, 'caller_get_posts' =&gt; 1 ); // Now re-define the main query query_posts( $args ); ?&gt; &lt;?php if( have_posts() ) : ?&gt; &lt;?php while( have_posts() ) : the_post(); ?&gt; &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt; &lt;div &lt;?php post_class(); ?&gt;&gt;&lt;?php the_content(); ?&gt;&lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;?php endif; ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php //get_sidebar(); ?&gt; &lt;?php get_footer(); ?&gt; </code> Hope that helps.. Updated response follows The template that deals with a post's page will differ if you use the <code> page_for_posts </code> setting, don't try to use and a page template, use one or the other, since both will not work together. When you want to show the post list/index on a page, and let your native theme files deal with rendering, set the <code> page_for_posts </code> setting(admin > settings > reading). When you need to control how a page of posts renders, and do something custom with it, rather than fiddle around in the theme files trying to work out which file is dealing with the output, then adding conditional logic, instead create a page(or choose an existing one) and attach a page template to it. Only by not setting the <code> page_for_posts </code> setting do you allow this page to render using the attached template. Ignore my front page setting, obviously you may have a more appropriate page set for that, simply notice how i've not set the posts page setting. If you set yours as done in the screenshot, the template provided will work correctly, and the posts page will behave just as it would when setting the posts page setting(except it will obviously do some custom stuff to). Summary - When you set the <code> page_for_posts </code> setting you fore-go any ability to attach a template to that page, unset it and the template will work as expected. Edit: Rarst actually pointed out this behaviour to, in your other question... stackexchange-url ("Template file for static posts page does not get loaded")
Modifying the following code to displaying the title and the content of static page Posts page?
wordpress
Hopefully another simple one, I have some nested categories, like this: <code> - category-a - category-b -category-c </code> The permalink for category-c is as follows: <code> http://&lt;domain&gt;/category/category-a/category-b/category-c/ </code> What I'd really like is for the permalink to not include any parent categories, instead it would become this: <code> http://&lt;domain&gt;/category/category-c/ </code> Is there a way this can be achieved? I have some categories that do nothing but group sub-categories together, thus I don't really want them displaying to my users. Many thanks!
The following code changes all links to category archives so they don't include the parent category: <code> add_filter( 'category_link', 'wpse7807_category_link', 10, 2 ); function wpse7807_category_link( $catlink, $category_id ) { global $wp_rewrite; $catlink = $wp_rewrite-&gt;get_category_permastruct(); if ( empty( $catlink ) ) { $catlink = home_url('?cat=' . $category_id); } else { $category = &amp;get_category( $category_id ); $category_nicename = $category-&gt;slug; $catlink = str_replace( '%category%', $category_nicename, $catlink ); $catlink = home_url( user_trailingslashit( $catlink, 'category' ) ); } return $catlink; } </code> Add the code to the <code> functions.php </code> of your theme.
Changing the category permalink structure
wordpress
I'm developing a wordpress based site in English but I've installed the Italian version of it... In my blog page, I get dates, exactly months, in Italian instead of English... How can I translate this? Are there other things I must manually translate? For example, where should I translate errors? Thanks!
I do this with the One Backend Language plugin. This way, the <code> WPLANG </code> language is only used in the frontend, and another used in the admin area. There are more plugins that do this, some allow you to choose a language per user . The downside is that you can still be logged in when you visit the frontend, and thus get the language of the admin area there too.
Translate wordpress date from Italian to English
wordpress
Here is the link http://www.brianfunshine.com/voice-work/voice-page/ This is the code: <code> &lt;?php /** * Template Name: Voice Page (Two Columns) * @package WordPress * @subpackage Twenty_Ten * @since Twenty Ten 1.0 */ get_header(); ?&gt; &lt;?php breadcrumb(); ?&gt; &lt;?php // this is the main loop ?&gt; &lt;?php if(have_posts()) : while(have_posts()) : the_post(); ?&gt; &lt;div class="top-column"&gt; &lt;div class="post"&gt; &lt;h2 class="post-title"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;/h2&gt; &lt;div class="entry"&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; &lt;div class="post-meta-data"&gt; &lt;?php wp_link_pages('before=&lt;p&gt;'.__('Pages:','options').'&amp;after=&lt;/p&gt;'); ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;?php else: ?&gt; &lt;p&gt;&lt;?php _e('Sorry, no posts matched your criteria.','options'); ?&gt;&lt;/p&gt; &lt;?php endif; ?&gt; &lt;/div&gt;&lt;!-- .top-column --&gt; &lt;div class="left-column"&gt; &lt;?php // retrieve a list of posts with category Voice Audio Demos $args = array('category_name' =&gt; 'Voice Page (Left Column)', 'order' =&gt; 'DESC', 'posts_per_page'=&gt;-1); $customposts = get_posts($args); foreach($customposts as $post) : setup_postdata($post); ?&gt; &lt;div class="post"&gt; &lt;h2 class="post-title"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;/h2&gt; &lt;div class="entry"&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php endforeach; ?&gt; &lt;/div&gt;&lt;!-- .left-column --&gt; &lt;div class="right-column"&gt; &lt;?php // retrieve a list of posts with category Voice Audio Demos $args = array('category_name' =&gt; 'Voice Page (Right Column)', 'orderby' =&gt; 'DESC', 'posts_per_page'=&gt;-1); $customposts = get_posts($args); foreach($customposts as $post) : setup_postdata($post); ?&gt; &lt;div class="post"&gt; &lt;h2 class="post-title"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;/h2&gt; &lt;div class="entry"&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php endforeach; ?&gt; &lt;/div&gt;&lt;!-- .left-column --&gt; &lt;?php get_footer(); ?&gt; </code> It just retrieves posts with category Voice Page (Left Column) and Voice Page (Right Column). I ahve more than 5 posts in that category bu the page is only showing 5:
If you look at the <code> get_posts </code> documentation on Codex, you can see there's a parameter for number of posts you want to display: $numberposts (integer) (optional) Number of posts to return. Set to 0 to use the max number of posts per page. Set to -1 to remove the limit. Default: 5 That's why it's displaying just 5 posts. You need to add the parameter to your args array: <code> $args = array('category_name' =&gt; 'Voice Page (Right Column)', 'orderby' =&gt; 'DESC', 'posts_per_page'=&gt;-1, 'numberposts'=&gt;-1); </code>
Why get_posts are only showing five posts (retrieved by assigning a category to them?
wordpress
I'm using fetch_feed to display an rss feed on a theme i'm working on. I think the documentation implies that you can combine multiple feeds, can anyone confirm this, ideally with an example. Thanks in advance! George
You can technically pass multiple feed URLs to fetch_feed() as an array, and it'll grab them all at once. But the return is a total mess, and I couldn't personally figure out how to parse it. If nobody else knows how to do this with fetch_feed(), I can offer a solution using the SimplePie class (which fetch_feed actually uses anyway). The SimplePie class has some helper methods for parsing the return, and they make things pretty easy. Try something like: <code> // Contains the SimplePie class require_once (ABSPATH . WPINC . '/class-feed.php'); // New class instance $feed = new SimplePie(); // You feed URLs $feed-&gt;set_feed_url(array('http://rss.cnn.com/rss/cnn_topstories.rss', 'http://cuteoverload.com/feed/')); // Do it! $feed-&gt;init(); $feed-&gt;handle_content_type(); // Loop the results foreach($feed-&gt;get_items() as $item) { echo $item-&gt;get_title(); echo '&lt;hr/&gt;'; } </code> Additional SimplePie methods include get_permalink() and get_description(). The only downside to this approach is that is SimplePie is ever phased out of WordPress in favor of another class, this'll break. UPDATE As @Rarst pointed out in the comments, you don't need to access SimplePie directly. You can use its methods on the object that fetch_feed() returns. So the answer is much simpler than I thought: <code> $feed = fetch_feed(array('http://rss.cnn.com/rss/cnn_topstories.rss', 'http://cuteoverload.com/feed/')); // Loop the results foreach($feed-&gt;get_items() as $item) { echo $item-&gt;get_title(); echo '&lt;hr/&gt;'; } </code>
Combining multiple RSS feeds using fetch_feed
wordpress
Is there an existing function or call in which you can pass a category id to determine if the category has child posts?
The get_term() function accepts a term id and a taxonomy slug. It returns an object that contains a "count" for that term. <code> $obj_term = get_term(123, 'your-taxonomy-slug'); echo $term-&gt;count; </code> I'm not aware of any utility function that just counts posts in a particular category.
How to determine if a category is empty?
wordpress
I created a custom widget, but it's not saving if I click on save. When I refresh the page it is not saved. My code looks like follows <code> &lt;?php /** * Plugin Name: Sending a Contact SMS * Plugin URI: http://www.test.co.za * Description: Allows you to send a contact SMS to website owner * Author: test * Version: 1.0 * Author URI: http://test.co.za */ class sendSMS extends WP_Widget { function sendSMS() { $widget_ops = array( 'classname' =&gt; 'sendSMS', 'description' =&gt; 'Allows you to add a small contact form that will send out an sms to the user.', ); $control_ops = array( 'id_base' =&gt; 'smsForm-widget' ); $this-&gt;WP_Widget( 'smsForm-widget', 'Send SMS', $widget_ops, $control_ops); } function form ($instance) { $defaults = array('title'=&gt; __('Example', 'example'), 'name' =&gt; __('John Doe', 'example'), 'number' =&gt; __('+27825656994', 'example'), 'message' =&gt; __('Tell Us', 'example') ); $instance = wp_parse_args( (array) $instance, $defaults ); ?&gt; &lt;p&gt; &lt;label for="&lt;?php echo $this-&gt;get_field_id( 'title' ); ?&gt;"&gt;&lt;?php _e('Title:', 'hybrid'); ?&gt;&lt;/label&gt; &lt;input id="&lt;?php echo $this-&gt;get_field_id( 'title' ); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name( 'title' ); ?&gt;" value="&lt;?php echo $instance['title']; ?&gt;" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="&lt;?php echo $this-&gt;get_field_id( 'name' ); ?&gt;"&gt;&lt;?php _e('Your Name:', 'name'); ?&gt;&lt;/label&gt; &lt;input id="&lt;?php echo $this-&gt;get_field_id( 'name' ); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name( 'name' ); ?&gt;" value="&lt;?php echo $instance['name']; ?&gt;" /&gt; &lt;/p&gt; &lt;!-- Your Name: Text Input --&gt; &lt;p&gt; &lt;label for="&lt;?php echo $this-&gt;get_field_id( 'number' ); ?&gt;"&gt;&lt;?php _e('Your Cellphone Number:', 'number'); ?&gt;&lt;/label&gt; &lt;input id="&lt;?php echo $this-&gt;get_field_id( 'number' ); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name( 'number' ); ?&gt;" value="&lt;?php echo $instance['number']; ?&gt;" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="&lt;?php echo $this-&gt;get_field_id( 'message' ); ?&gt;"&gt;&lt;?php _e('Your Message:', 'message'); ?&gt;&lt;/label&gt; &lt;textarea id="&lt;?php echo $this-&gt;get_field_id( 'message' ); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name( 'message' ); ?&gt;"&gt;&lt;?php echo $instance['message']; ?&gt;&lt;/textarea&gt; &lt;/p&gt; &lt;?php } function update ($new_instance, $old_instance) { $instance = $old_instance; /* Strip tags (if needed) and update the widget settings. */ $instance['title'] = strip_tags( $new_instance['title'] ); $instance['name'] = strip_tags( $new_instance['name'] ); $instance['number'] = $new_instance['number']; $instance['message'] = $new_instance['message']; return $instance; } function widget ($args,$instance) { extract( $args ); /* Our variables from the widget settings. */ $title = apply_filters('widget_title', $instance['title'] ); $name = $instance['name']; $number = $instance['number']; $message = $instance['message']; /* Before widget (defined by themes). */ echo $before_widget; /* Display the widget title if one was input (before and after defined by themes). */ if ( $title ) echo $before_title . $title . $after_title; /* Display name from widget settings if one was input. */ if ( $name ) printf( '&lt;p&gt;' . __('Hello. My name is %1$s.', 'example') . '&lt;/p&gt;', $name ); if ( $number ) printf( '&lt;p&gt;' . __('Hello. My number is %1$s.', 'example') . '&lt;/p&gt;', $name ); if ( $message ) printf( '&lt;p&gt;' . __('Hello. My message is %1$s.', 'example') . '&lt;/p&gt;', $message ); /* After widget (defined by themes). */ echo $after_widget; } } function load_sms_form() { register_widget( 'sendSMS' ); } add_action('widgets_init', 'load_sms_form'); // register the widget ?&gt; </code>
there no "id_base" key in <code> $control_ops </code> ; from what I know it only accepts width/height. move it the id_base is the first argument you have there in <code> WP_Widget() </code>
My Custom Widget does not save in sidebar
wordpress
I have a site with custom taxonomy. I want to give the client the ability to control the taxonomy order. How can I do that ?
You can use the Advanced Taxonomy Terms Order it's a great plugin for terms order
Howto control custum taxonomy order?
wordpress
In the first function below, inside the foreach, I'm calling out to the 2nd function in order to test for the occurence of matching category ids that I want to remove from the category listing. However, the way I'm doing it in the 2nd function seems to me to be pretty crude, for lack of a better term. How could I improve this lookup? <code> function admin_trim_category_description( $terms, $taxonomies ) { if( 'category' != $taxonomies[0] )return $terms; foreach( $terms as $key=&gt;$term ) { $terms[$key]-&gt;description = strip_tags(substr( $term-&gt;description, 0, 75 ))."..."; if(ce4_get_utility_cats($terms[$key]-&gt;term_id)) { unset($terms[$key]); } } return $terms; } function ce4_get_utility_cats($cat_id) { if($cat_id == get_cat_ID('category1') OR $cat_id == get_cat_ID('hidden') OR $cat_id == get_cat_ID('category2') OR $cat_id == get_cat_ID('category3')) { return true; } else { return false; } } </code> EDIT: The above functions are called in the following manner... <code> add_action( 'admin_head-edit-tags.php', 'admin_edit_tags' ); function admin_edit_tags(){ add_filter( 'get_terms', 'admin_trim_category_description', 10, 2 ); } </code>
<code> function admin_trim_category_description( $terms, $taxonomies ){ if( 'category' != $taxonomies[0] )return $terms; $whatever_categories = array('category1', 'hidden', 'category2', 'category3'); foreach( $terms as $key =&gt; $term) if(!in_array($terms[$key]-&gt;name, $whatever_categories)) $terms[$key]-&gt;description = strip_tags(substr( $term-&gt;description, 0, 75 ))."..."; else unset($terms[$key]); return $terms; } </code>
How can this crude function be improved?
wordpress
I'm using a very lightweight plugin called WPAlchemy that lets me rapidly create meta-boxes for posts and pages. I've ben able to convert <code> &lt;textarea&gt; </code> 's into rich, TinyMCE's editors just fine. The problem is, I'd like to include the Media Upload buttons for those metaboxes / editors. I've been able to add the buttons above each TinyMCE editor but when I click "Insert into Post" it isn't (has no idea) which <code> &lt;textarea&gt; </code> to insert the requested picture/media. For reference, I'm adding the following line above my <code> &lt;textarea&gt; </code> : <code> &lt;div id="media-buttons" class="hide-if-no-js"&gt;&lt;?php do_action( 'media_buttons' ); ?&gt;&lt;/div&gt; </code> I'm aware this isn't valid since I'm using the same id, ( <code> #media-buttons </code> ) as what the default content editor uses at the top. Someone suggested the following JS code to kinda hook and grab the <code> src </code> but I can't get this working for my scenario. (Suggestions came from here http:(slash)(slash)farinspace.com/multiple-wordpress-wysiwyg-visual-editors/comment-page-1/#comment-3552) Finally, I'm attaching an image of what it currently looks like, but it just doesn't link the "Insert Into Post" button with the currently focused metabox. Image: http:(slash)(slash)cl.ly/4BMf Any help, please?
Here is a complete tutorial with source files that do exactly what you want, You can upload multi images by cloning the input field and also you can preview, delete images with ajax, add multi metaboxes to multiple/different post types and more. http://www.deluxeblogtips.com/2010/05/howto-meta-box-wordpress.html And here you can find some good information on how you call the attached images, http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpress/
I'm using add_meta_box() but want to include TinyMCE editor *and* Media Uploads for each box
wordpress
Is there an easy way to modifying custom post types in the front end? Maybe you can direct me to a plugin? For Example: I have a custom post type called "Product". The examples I see online shows me how I can perform CRUD on products in the dashboard. But, how can I let a user modify a product in the front end? Do I need to write my own crud code for the front end? Thanks in advance.
I'm from the World of Django, where CRUD is King, so I had a similar question. The best answer I've found so far is Pods and the associated Pods UI . Unlike "Custom Posts", which are kind of weird once you take a look under the hood, Pods actually creates real tables with real fields. Furthermore, you can crate relations ! What a concept! Try that with Custom Fields. I haven't done this for a user-facing page yet, but it makes for a very nice admin-facing input form. Update in response to comment: WP doesn't really have an ORM to speak of. It has <code> meta </code> tables ( <code> wp_usermeta </code> , <code> wp_postmeta </code> , and <code> wp_commentmeta </code> ) to store "extra" information in (this is where new fields are stored for Custom Post Types), but there is none of the very nice lazy-dereferencing you have in a proper ORM. Although relationships (foreign key, one-to-one, and many-to-many) are not natively supported by WP, there are a handful of plugins that address this issue and one of them that may make this situation palatable for you. I haven't used any of them (yet) so I can't speak for their relative strengths and weaknesses. http://wordpress.org/extend/plugins/posts-to-posts/ This plugin is by scribu , one of the WP core developers. I don't if that makes it better, but it's a data point. http://wordpress.org/extend/plugins/relation-post-types/ http://wordpress.org/extend/plugins/custom-post-relationships/
How to: CRUD for custom post types in the front end?
wordpress
I want to wrap the filter below in a conditional that tests whether the user is uploading an image from the Media Manager (Admin > Media > Add New) and not from the post editor image upload routine. Is it possible to tell? $pagenow in both cases appears to be the same... <code> //no extra thumbs global $pagenow; if($pagenow=="media-new.php"){ add_filter('intermediate_image_sizes_advanced','ce4_no_thumbs'); } function ce4_no_thumbs($sizes){return array();} </code> Update: It does appear that there is a post_id on the querystring when upload is accessed from within a post and not when it is accessed via "media manager > add new", however, the following test passes in either case... <code> if ( is_admin() &amp;&amp; !isset($_GET['post_id']) ) { /*This should not fire if user is uploading an image into a post, since post_id is on the querystring. However, in my test its still getting through.*/ add_filter('intermediate_image_sizes_advanced','ce4_no_thumbs'); } </code>
I answered this for you in the comments of stackexchange-url ("your previous question"). ...you can use the filter that @Backie suggested above ( <code> intermediate_image_sizes_advanced </code> ), and in the hooked function check for a field in the post collection named *_wp_http_referer*. It tells you where the upload request came from. If _wp_http_referer contains "media-new.php", you can return an empty array (which will temporarily stop thumbnail generation, but won't actually change any thumbnail settings). Otherwise, return the $sizes array untouched. Try: <code> function wpsx_7756_no_thumbnails($arr_sizes){ if(stristr($_POST['_wp_http_referer'], 'media-new.php')) { return array(); } return $arr_sizes; } add_filter('intermediate_image_sizes_advanced','wpsx_7756_no_thumbnails'); </code> Let me know if this works. Keep in mind that adding the filter while you're on the upload form won't do what you want--the form posts to a separate page that handles the upload, and it won't respect your filter.
Is it possible to determine when user is at "Media > Add New" vs "Post > Add an Image"
wordpress
I write a programming blog, so sometimes I just have to write a word to represent a <code> command </code> or <code> function </code> which I like writing between the code tags. (See, what I just did there). So, just like StackExchange has the "code" button, is there a plugin to add this button to the visual editor? I know I got it on the HTML editor, but I rarely use it. I was thinking of writing a plugin for this, but just in case I'm asking first in case anyone knows of a plugin doing this already.
There seem to be a few people scratching this itch over at the TinyMCE sourceforge tracker. http://sourceforge.net/tracker/?group_id=103281&amp;atid=738747 This looks promising.. "CodeExtras adds <code> &lt;var&gt; and &lt;code&gt; </code> markup buttons - ID: 2904557" http://sourceforge.net/tracker/?func=detail&amp;aid=2904557&amp;group_id=103281&amp;atid=738747
Is there a plugin to show the code tag button on the visual editor?
wordpress
I'm using the following to list my pages: <code> &lt;ul id="nav"&gt; &lt;?php wp_list_pages('title_li='); ?&gt; &lt;/ul&gt; </code> is there a way of highlight the link of the page of the current in the navigation. It shouldn't be fixed. The user should be able to call the page whatever he or she wants, and create as much pages as he or she wants (the highlight feature should still work). Any suggestions or tutorials?
wp_list_pages has support for CSS styles. The current page is marked with the class .current_page_item. You can style it as you want. Check http://codex.wordpress.org/Function_Reference/wp_list_pages#Markup_and_styling_of_page_items for reference.
Current navigation highlight for a menu that may be modified by the user?
wordpress
I would like to create an additional size for uploaded images which my users can then "insert into post". I understand that add_image_size() will add a new image size which I can use in my theme, but that new size isn't available on the media upload screen. Is there a way to get new sizes to appear on that screen so they're available to people as they add/edit posts? I have a tweaky theme that needs more than just the default 3 sizes + original. Thanks!
Here's another solution to simply add your additional image sizes to the list of sizes that can be inserted into posts. It worked great for me. http://kucrut.org/insert-image-with-custom-size-into-post/
Add new image size to media uploader so users can insert into post?
wordpress
I'm having a very peculiar bug with pagination :( I'm trying to display 4 posts per page for a category with slug "lastest-news". The pagination function seems to work correctly. There are 33 posts. The pagination gets constructed correctly with 9 pages and links of following format: /category/lastest-news/page// The interesting thing is that it works correctly (displaying 4 posts per page) from page 1-4 including. However, for pages 5-9 it doesn't work at all. It doesn't even seem to serve the template... the only error that I could spot is of the page saying "Nothing found for Category Lastest-news Page 5". I would understand if it won't work at all, but for randomly 4 pages and not more? I would really really appreciate any help! I've spend about over 4 hours trying to figure out what's wrong and it's bugging me. Thanks for help :) I'm using the following code for query: <code> &lt;?php $page = get_query_var('paged'); $posts_on_page = new WP_Query("posts_per_page=4&amp;category_name=lastest-news&amp;paged=".$page); //loop to display every one of 4 posts //pagination pagination($posts_on_page-&gt;max_num_pages); ?&gt; </code> I'm using pagination function from this post: http://www.kriesi.at/archives/how-to-build-a-wordpress-post-pagination-without-plugin Here is the function (which seems to work fine): <code> function pagination($pages = '', $range = 2){ $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = 1; if($pages == '') { global $wp_query; $pages = $wp_query-&gt;max_num_pages; if(!$pages) { $pages = 1; } } if(1 != $pages) { echo "&lt;div class='pagination'&gt;"; if($paged &gt; 2 &amp;&amp; $paged &gt; $range+1 &amp;&amp; $showitems &lt; $pages) echo "&lt;a href='".get_pagenum_link(1)."'&gt;&amp;laquo;&lt;/a&gt;"; if($paged &gt; 1 &amp;&amp; $showitems &lt; $pages) echo "&lt;a href='".get_pagenum_link($paged - 1)."'&gt;&amp;lsaquo;&lt;/a&gt;"; for ($i=1; $i &lt;= $pages; $i++) { if (1 != $pages &amp;&amp;( !($i &gt;= $paged+$range+1 || $i &lt;= $paged-$range-1) || $pages &lt;= $showitems )) { echo ($paged == $i)? "&lt;span class='current'&gt;".$i."&lt;/span&gt;":"&lt;a href='".get_pagenum_link($i)."' class='inactive' &gt;".$i."&lt;/a&gt;"; } } if ($paged &lt; $pages &amp;&amp; $showitems &lt; $pages) echo "&lt;a href='".get_pagenum_link($paged + 1)."'&gt;&amp;rsaquo;&lt;/a&gt;"; if ($paged &lt; $pages-1 &amp;&amp; $paged+$range-1 &lt; $pages &amp;&amp; $showitems &lt; $pages) echo "&lt;a href='".get_pagenum_link($pages)."'&gt;&amp;raquo;&lt;/a&gt;"; echo "&lt;/div&gt;\n"; } } </code>
WordPress does its own query on every page. You should modify that query instead of creating a new one. What happens now is that WordPress does a query with the standard posts per page of 10, but you don't do anything with these results and do your own query. This works... until WordPress goes beyond post #33, which is on page number 4. WordPress queries 1-10, your template queries 1-4 WordPress queries 11-20, your template queries 5-8 WordPress queries 21-30, your template queries 9-12 WordPress queries 31-40, your template queries 13-16 WordPress queries 41-50, but gets no results, so it gives 404. Your template doesn't load. So instead you should modify the standard query that WordPress will execute, by placing this in your <code> functions.php </code> or in a plugin: <code> add_action( 'pre_get_posts', 'wpse7687_pre_get_posts' ); function wpse7687_pre_get_posts( &amp;$wp_query ) { if ( $wp_query-&gt;is_category &amp;&amp; 'latest-news' == $wp_query-&gt;get_queried_object()-&gt;slug ) { $wp_query-&gt;set( 'posts_per_page', 4 ); } } </code>
Pagination with WP_Query is buggy - working for some pages, but not the others
wordpress
What's the code of the loop which retrieves the Page title and description? I checked the code inside page.php of the Starkers theme (I guess is the same as the TwentyTen theme): <code> &lt;?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?&gt; &lt;?php if ( is_front_page() ) { ?&gt; &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt; &lt;?php } else { ?&gt; &lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt; &lt;?php } ?&gt; &lt;?php the_content(); ?&gt; &lt;?php wp_link_pages( array( 'before' =&gt; '' . __( 'Pages:', 'twentyten' ), 'after' =&gt; '' ) ); ?&gt; &lt;?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?&gt; &lt;?php comments_template( '', true ); ?&gt; </code> I looks identical to the loop which retrieves the main (blog) posts. What's the difference? Which is the part which retrieves the title and content of the current Page?
As usual - <code> the_title() </code> and <code> the_content() </code> . Posts page and a PAGE page are different in amount and type of content, but mechanics of main Loop and template tags are essentially same.
What's the section of code (or loop) which retrieves the Page title and description?
wordpress
How would I create a list that only shows the ten most used tags for my site? Kind of how Delicious organizes tags. Any ideas?
Easy with <code> get_tags() </code> . Basic idea would be something like this: <code> $args = array( 'orderby' =&gt; 'count', 'order' =&gt; 'DESC', 'number' =&gt; 10, ); $tags = get_tags( $args ); </code>
Top ten tags ala Delicious
wordpress
I would like to exclude categories from the loop using the "name" instead of the "id", since the ID can change when using new databases. The name however will always be the same. Is this possible?
You can use List Category Posts (Disclaimer: I'm the author of List Category Posts) or you can code this yourself: <code> $category_id = get_cat_ID($category_name); </code> This way you can get the id and exclude it from the loop with the minus sign. Example: <code> get_posts(cat=-1); </code>
category__not_in -- anyway to use category name instead of id?
wordpress
I have a client who wants to use the trash feature, but keep items in there indefinitely (I have no idea why, but they insist on it). From reading this codex article on the trash status , I see that you can set the EMPTY_TRASH_DAYS constant to zero. But it says that this will disable Trash functionality altogether. I don't want to do this...I just want to disable the auto-trash emptying . Is there any way to do this? Or am I stuck with just entering some huge number for the EMPTY_TRASH_DAYS value?
My guess is - yes, you are stuck with exactly that. Checks for <code> EMPTY_TRASH_DAYS </code> seem to be hardcoded as condition for switching interface between trash and delete in several places.
Turn Off Automatic Trash Deletion?
wordpress
My site is running on site say : www.xyz.com My blog is at say : http://www.xyz.com/blog I have one header implemented in my main site, I want to use that header file as a worpress header. Is there any way I can do this?
You should reproduce your site's header on the header.php file on your theme. If you want any more help you could show us some code. But basically that's it, WordPress gets the header for the page from the header.php on your theme. Check out say Twenty Ten's header as an example (wp-content/themes/twentyten/header.php), and try to adapt your site's header to this format.
Use custom header as WordPress header
wordpress
<code> the_content </code> is always surrounded by paragraphs, it doesn't matter if I'm in HTML view and there's nothing there. Does WordPress have a function to remove them? IS there any way?
Removing the filter that adds the P is the best option. <code> remove_filter('the_content','wpautop'); remove_filter('the_content','shortcode_autounp'); // You may want to do this aswell </code>
the_content is always surrounded by paragraphs (how to disable or remove them)?
wordpress
I use the following to add in a post a YouTube thumbnail and display the video in a fancybox: <code> &lt;div&gt;&lt;a class="fancybox" href="#video2"&gt; &lt;img src="http://img.youtube.com/vi/dm36W5NTPag/0.jpg" alt="Welcome To High Output" width="220px" height="120px" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;div id="video2" style="display: none;"&gt; &lt;iframe title="YouTube video player" class="youtube-player" type="text/html" width="480" height="390" src="http://www.youtube.com/embed/dm36W5NTPag" frameborder="0" allowFullScreen&gt;&lt;/iframe&gt;&lt;/div&gt; </code> Basically the shortcode must have one fields to enter the ID of the video in the thumbnail, the link to the video, the link of the first div, and the id of the second div. <code> http://img.youtube.com/vi/(HERE)/0.jpg </code> and <code> http://img.youtube.com/vi/(HERE)/0.jpg </code> <code> &lt;a class="fancybox" href="#(HERE)"&gt; </code> and <code> &lt;div id="(HERE)" style="display: none;"&gt; </code> So the shortcode should look like: <code> [youtube VIDEO ID:(Enter ID)] </code> Does anybody know how to do this?
<code> add_shortcode('youtube', 'youtube_shortcode'); function youtube_shortcode($atts){ if(!isset($atts[0])) return; $id = strip_tags($atts[0]); ob_start(); ?&gt; &lt;div&gt;&lt;a class="fancybox" href="#video_&lt;?php echo $id; ?&gt;"&gt; &lt;img src="http://img.youtube.com/vi/&lt;?php echo $id; ?&gt;/0.jpg" alt="Welcome To High Output" width="220px" height="120px" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;div id="video_&lt;?php echo $id; ?&gt;" style="display: none;"&gt; &lt;iframe title="YouTube video player" class="youtube-player" type="text/html" width="480" height="390" src="http://www.youtube.com/embed/&lt;?php echo $id; ?&gt;" frameborder="0" allowFullScreen&gt;&lt;/iframe&gt;&lt;/div&gt; &lt;?php return ob_get_clean(); } </code> use it like: <code> [youtube "dm36W5NTPag"] </code>
How to create a shortcode to let the user add the ID of a YouTube video?
wordpress
I'm trying to list events (custom posttype 'kurs') by event date, which are stored as custom fields ('dato'). My loop so far looks like this: <code> &lt;ul&gt; &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'kurs' ) ); ?&gt; &lt;?php while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); ?&gt; &lt;li&gt;&lt;?php the_title( '&lt;a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark"&gt;', '&lt;/a&gt;' ); ?&gt;&lt;/li&gt; &lt;?php endwhile; ?&gt; &lt;/ul&gt; </code> What I need is a list of post(event)-titles from today forward in the future...
You need to use the <code> meta_key </code> to sort your events in your array. Like so: <code> &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'kurs', 'meta_key' =&gt; 'dato', 'order_by' =&gt; 'meta_value', 'order' =&gt; 'ASC' ) ); ?&gt; </code>
sort events based on event date custom field
wordpress
I am trying to add in a script and css file for my plugin into the admin header. Is there a function similar to <code> get_bloginfo('url') </code> that I could use to reference the files correctly without having to hard code url's?
I am trying to add in a script and css file for my plugin into the admin header. Then like any good developer you should be using <code> wp_enqueue_script </code> or <code> wp_enqueue_style </code> so you're not hard-coding those script/style includes into the plugin(meaning a user can unhook them if he/she needed to). http://codex.wordpress.org/Function_Reference/wp_enqueue_script http://codex.wordpress.org/Function_Reference/wp_enqueue_style If the styles/scripts are only to be loaded in the plugin page(s), then you should ideally use some conditional logic inside a generic admin head hook, or alternatively hook some enqueues specifically to the page(s). First work out the hook for your page or pages, this is the fourth parameter used in calls to <code> add_menu_page </code> and the fifth in <code> add_submenu_page </code> , so let's take this example(taken straight from this codex page ) and imagine these represent your plugin page(s). <code> add_menu_page('Page title', 'Top-level menu title', 'manage_options', 'my-top-level-handle', 'my_magic_function'); add_submenu_page( 'my-top-level-handle', 'Page title', 'Sub-menu title', 'manage_options', 'my-submenu-handle', 'my_magic_function'); </code> In this case, the two hooks(or handles) are <code> my-top-level-handle </code> and <code> my-submenu-handle </code> respectively. Now, to hook scripts or styles into the admin head specifically for plugin pages there's a few different ways we can go about it, but i'll cover the two most obvious(and my preferred) methods. Method #1 Use the <code> admin_print_scripts-$hook </code> and <code> admin_print_styles-$hook </code> that are specific to your plugin and enqueue the CSS/JS for each plugin page. $hook represents the hook(or handle) for a given admin page, every admin page has one. Scripts Enqueue JS files for both parent and submenu page <code> add_action( 'admin_print_scripts-my-top-level-handle', 'enqueue_my_js' ); add_action( 'admin_print_scripts-my-submenu-handle', 'enqueue_my_js' ); function enqueue_my_js() { wp_enqueue_script( .. YOUR ENQUEUE ARGS HERE .. ); } </code> Stylesheets Enqueue stylesheet files for both parent and submenu page <code> add_action( 'admin_print_styles-my-top-level-handle', 'enqueue_my_style' ); add_action( 'admin_print_styles-my-submenu-handle', 'enqueue_my_style' ); function enqueue_my_style() { wp_enqueue_style( .. YOUR ENQUEUE ARGS HERE .. ); } </code> Method #2 Enqueue both scripts and styles across all your plugin admin pages by hooking on the more generic admin head hooks. admin_print_scripts + admin_print_styles With this approach we'll use the more generic hooks that run for every admin page, but with a little conditional logic we can determine what kind of page we're viewing and return if it's not one of the plugin's pages(so it essentially has the same effect as the first approach). Scripts Enqueue JS for any of the plugin's page <code> add_action( 'admin_print_scripts', 'enqueue_my_js' ); function enqueue_my_js() { global $parent_file; if( 'my-top-level-handle' != $parent_file ) return; wp_enqueue_script( .. YOUR ENQUEUE ARGS HERE .. ); } </code> Styles Enqueue CSS for any of the plugin's page <code> add_action( 'admin_print_styles', 'enqueue_my_style' ); function enqueue_my_style() { global $parent_file; if( 'my-top-level-handle' != $parent_file ) return; wp_enqueue_style( .. YOUR ENQUEUE ARGS HERE .. ); } </code> <code> $parent_file </code> will only match for your plugin's pages, so we simply <code> return; </code> when it's not a match, ie. stop executing code inside the function so the enqueue only gets to fire when <code> $parent_file </code> matches the handle. Additional If you're intending to enqueue a script or style for more than one page, you can make that process alot easier by registering the script. http://codex.wordpress.org/Function_Reference/wp_register_script http://codex.wordpress.org/Function_Reference/wp_register_style The advantage to registering a script or style is that calling that file then becomes a simple case of.. <code> wp_enqueue_script( 'my_script_handle' ); </code> ..same applies for the style equivalent. This avoids any need to provide a path, dependancies and so forth with every enqueue call. I had to wrap the answer up toward the end due to time, but hopefully i've provided enough valuable information to work with. If you get stuck trying to understand something, just post a comment.. ;)
URLs of plugin resources?
wordpress
Right, hopefully a nice and simple one... I'm on a category page with the id of 4, I want to get the category object back so I can interogate a few values. I've had a good old look in the WP codex with little success, remember I don't want to get the categories from a post, I want the category object from the current category. Many thanks, Ben :-)
To get the category object use <code> get_category </code> ( codex ). It's easy if you know the name, slug or ID, but if you don't you could use <code> is_category </code> to check on which category you are and pass the ID to <code> get_category </code> .
On the category page, get the category object
wordpress
Whenever I create a new website I first create a staging site on a subdomain like "stage.domain-name.com". After everything works correctly I export the database, open it in notepad++ and do a find/replace for "subdomain.domain-name.com" and replace it with "domain-name.com"... finally I import it into a new database for the live site. My question is... what SQL query would I need to run if I just wanted to do this simple find/replace on the entire database using phpmyadmin? -CH
The table where your URL is saved is wp_options. You should do an update on the columns that use the URL for your site: <code> UPDATE TABLE wp_options SET option_value = "new domain" WHERE option_name = "siteurl" UPDATE TABLE wp_options SET option_value = "new domain" WHERE option_name = "home" </code> I might be missing some value, but whenever you do this find/replace process again, you can notice the values and tables that should be updated and add them to this script. WordPress Codex has a nice guide on how to change a site URL, maybe that's even handier for you: Changing the Site URL
What SQL Query to do a simple find and replace
wordpress
I would like to have some links which load the page content of the page they reference to inside a Fancybox popup(pages like "shipping" or "returns", mainly text content). I would create the pages an then I will add the permalinks to these pages to other sections, like footer or sidebar, and they will open in the popup window. Have you come across anything like that? What would be the best way to implement it?? Any suggestion will be greatly appreciated.
I have found that the best way to include WordPress pages into a fancybox is to create a new template to use for those pages. For example I have some of my contact forms in a fancy box and the template I use is called custom-page-plain.php and doesn't call header.php and contains a link to an alternate style sheet. <code> &lt;?php /* Template Name: plain page */ ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-type" content="text/html; charset=utf-8" /&gt; &lt;meta name="MSSmartTagsPreventParsing" content="true" /&gt; &lt;meta http-equiv="Imagetoolbar" content="No" /&gt; &lt;title&gt;My Form Title&lt;/title&gt; &lt;link rel="stylesheet" href="http://xxxxxxx.com/wp-content/themes/revision3/stylemin2.css?rev=676777" type="text/css" media="screen,projection" /&gt; &lt;?php wp_head(); ?&gt; &lt;/head&gt; &lt;body&gt; &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;?php the_content('read more'); ?&gt; &lt;?php endwhile; endif; ?&gt; &lt;?php wp_footer(); ?&gt; &lt;/body&gt; &lt;/html&gt; </code> As you can see the template contains the the wp_head and wp_footer calls directly in the template. Whenever I want to create a page to go in a fancybox I just choose my plain template then add the fancybox class to the link.
Best way to load page content in Fancybox popup?
wordpress
Under "Settings > Permalinks", we can set up the default category base name to use for our category landing pages. For example, site.com/ categories /my-first-category/. Is there a setting I can add to my functions.php to allow the option to remove the category base and direct link to the category? For example, the above link becomes: site.com/my-first-category/ I realize that this opens up the possibility of having conflicting post names and category names (assuming I have a post slug that's the same as a category slug for example), but in this case, my post permalinks end in .html and my category permalinks will not, so there should never be a conflict (I expect).
there is an answer to on how to do that in the WordPress way stackexchange-url ("here") but a faster way is using the .htaccess file by adding this line <code> RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L] </code> just make sure you change http://www.yourblog.com/ to what ever is needed. Hope this helps.
What are the permalinks options for "Category" base and removing it?
wordpress
I have a setting in my theme that seeks to prevent the WP media manager upload utility from creating multiple copies of each image I upload. Apparently the latest versions of WP have changed the required settings to defeat this? Here's the current settings I have in my theme's functions.php... <code> if(get_option('thumbnail_size_h')!==0){update_option('thumbnail_size_h', 0);} if(get_option('thumbnail_size_w')!==0){update_option('thumbnail_size_w', 0);} if(get_option('medium_size_h')!==0){update_option('medium_size_h', 0);} if(get_option('medium_size_w')!==0){update_option('medium_size_w', 0);} </code> Even with these settings, I'm still getting a duplicate image every time I upload. For example, if my image filename is foo.jpg and it is 800x600 pixels, WP creates two images foo.jpg and foo-800x600.jpg How can I force WP to not create the duplicate?
I believe the following should stop thumbnails from being created. If you're wanting to remove some then and unset the $size[{size}]. Following sizes are there "thumbnail","medium","large","post-thumbnail". <code> add_filter('intermediate_image_sizes_advanced','stop_thumbs'); function stop_thumbs($sizes){ return array(); } </code>
How can I stop WP media uploader from creating duplicates of my uploaded images?
wordpress
The following code retrieves only custom post types with the custom taxonomy "Slider." I would like to change their order to ASC. The code: <code> &lt;?php // Retrive custom post type with a custom taxonomy assigned to it $posts = new WP_Query('post_type=page_content&amp;page_sections=Slider (Front Page)') ?&gt; &lt;?php while ( $posts-&gt;have_posts() ) : $posts-&gt;the_post(); ?&gt; &lt;?php the_content(); ?&gt; &lt;?php endwhile; ?&gt; &lt;?php wp_reset_query(); ?&gt; </code> Not sure if I should use an array (not sure how anyways). Any suggestions?
just change this line in your code: <code> $posts = new WP_Query('post_type=page_content&amp;page_sections=Slider (Front Page)') ?&gt; </code> to this: <code> $posts = new WP_Query('post_type=page_content&amp;page_sections=Slider (Front Page)&amp;order=ASC') ?&gt; </code> Basically it adds the order parameter witch can take two values (ASC,DESC). hope this helps.
How do I change the order (ASC and DESC) in the following retrieval method using WP_Query?
wordpress
I'm looking at converting several PHP-Fusion sites to WordPress. I'm wondering how to convert a page like this: http://biztalk-training.com/weblinks.php . Is there a plug-in for links that will create a similar type page. Each link can have an abstract and the URL, and with PHP-Fusion it even tracks which links get clicked, but I can do without the counts or use Google-Analytics for that.
I've found Link Library to be pretty flexible. http://wordpress.org/extend/plugins/link-library/
Converting a hierarchy of off-site web-links to Word-Press
wordpress
Few days ago I asked a question about stackexchange-url ("How to show a custom taxonomy in a custom post type column (and insert some 'default' terms to the custom taxonomy)"). Then I saw an answer for stackexchange-url ("Adding a Taxonomy Filter to Admin List for a Custom Post Type"). (Both stackexchange-url ("answered") by stackexchange-url ("MikeSchinkel")) I would like to merge both features: to create a custom post type, a custom taxonomy, adding some terms in the custom taxonomy, displaying the custom taxonomy in the custom post type's column, and adding a taxonomy filter. I know it sounds long, they are all done in those two questions, just need to merge them. How that code would look like?
Hi @janoChen: So, you want this? Alright, here ya go: <code> &lt;?php /* Plugin name: Static Content */ if (!class_exists('YourSite_StaticContent')) { class YourSite_StaticContent { static function on_load() { add_action('init',array(__CLASS__,'init')); add_filter('manage_static_content_posts_columns', array(__CLASS__,'manage_static_content_posts_columns')); add_filter('manage_posts_custom_column', array(__CLASS__,'manage_posts_custom_column'),10,2); add_action('restrict_manage_posts', array(__CLASS__,'restrict_manage_posts')); add_filter('parse_query', array(__CLASS__,'parse_query')); } static function init() { register_post_type('static_content',array( 'labels' =&gt; array( 'name' =&gt; __( 'Static Content' ), 'singular_name' =&gt; __( 'Static Content' ), 'add_new_item' =&gt; 'Add New Static Content', 'edit_item' =&gt; 'Edit Static Content', 'new_item' =&gt; 'New Static Content', 'search_items' =&gt; 'Search Static Content', 'not_found' =&gt; 'No Static Content found', 'not_found_in_trash' =&gt; 'No Static Content found in trash', ), 'public' =&gt; true, 'hierarchical' =&gt; false, 'taxonomies' =&gt; array( 'section'), 'supports' =&gt; array('title','editor','excerpt'), 'rewrite' =&gt; array('slug'=&gt;'static_content','with_front'=&gt;false), )); register_taxonomy('section','static_content',array( 'hierarchical' =&gt; true, 'labels' =&gt; array( 'name' =&gt; __( 'Section' ), 'singular_name' =&gt; __( 'Section' ), 'add_new_item' =&gt; 'Add New Section', 'edit_item' =&gt; 'Edit Section', 'new_item' =&gt; 'New Section', 'search_items' =&gt; 'Search Section', 'not_found' =&gt; 'No Sections found', 'not_found_in_trash' =&gt; 'No Sections found in trash', 'all_items' =&gt; __( 'All Sections' ), ), 'query_var' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'section' ), )); if (!get_option('yoursite-static-content-initialized')) { $terms = array( 'Footer', 'Header', 'Front Page Intro', 'Front Page Content', ); foreach($terms as $term) { if (!get_term_by('name',$term,'section')) { wp_insert_term($term, 'section'); } } update_option('yoursite-static-content-initialized',true); } } function manage_static_content_posts_columns($columns){ $new = array(); foreach($columns as $key =&gt; $title) { if ($key=='author') // Put the Sections column before the Author column $new['sections'] = 'Sections'; $new[$key] = $title; } return $new; } function manage_posts_custom_column( $column,$post_id ) { global $typenow; if ($typenow=='static_content') { $taxonomy = 'section'; switch ($column) { case 'sections': $sections = get_the_terms($post_id,$taxonomy); if (is_array($sections)) { foreach($sections as $key =&gt; $section) { $edit_link = get_term_link($section,$taxonomy); $sections[$key] = '&lt;a href="'.$edit_link.'"&gt;' . $section-&gt;name . '&lt;/a&gt;'; } echo implode(' | ',$sections); } break; } } } function parse_query($query) { global $pagenow; $qv = &amp;$query-&gt;query_vars; if ($pagenow=='edit.php' &amp;&amp; isset($qv['taxonomy']) &amp;&amp; $qv['taxonomy']=='section' &amp;&amp; isset($qv['term']) &amp;&amp; is_numeric($qv['term'])) { $term = get_term_by('id',$qv['term'],'section'); $qv['term'] = $term-&gt;slug; } } function restrict_manage_posts() { global $typenow; global $wp_query; if ($typenow=='static_content') { $taxonomy = 'section'; $section = get_taxonomy($taxonomy); wp_dropdown_categories(array( 'show_option_all' =&gt; __("Show All {$section-&gt;label}"), 'taxonomy' =&gt; $taxonomy, 'name' =&gt; $taxonomy, 'orderby' =&gt; 'name', 'selected' =&gt; $wp_query-&gt;query['term'], 'hierarchical' =&gt; true, 'depth' =&gt; 3, 'show_count' =&gt; true, // This will give a view 'hide_empty' =&gt; true, // This will give false positives, i.e. one's not empty related to the other terms. TODO: Fix that )); } } } YourSite_StaticContent::on_load(); } </code>
How can I merge this function(s) that inserts terms to a custom taxonomy with this other that adds a custom taxonomy filter?
wordpress
I am following the WP Example . I know my rewrite rule is being added into wordpress, so I just need to fix the actual rule. So here is my current code: <code> add_filter('rewrite_rules_array','mcs_TextbookRewriteRules'); add_filter('query_vars','mcs_insertTextbookQueryVars'); // Adding a new rule function mcs_TextbookRewriteRules($rules) { $newrules = array(); $newrules['textbook/(cantonese|mandarin)/([C|M]K?[0-9]+)/([0-9]+)$'] = 'index.php?pagename=textbook/$matches[1]/?cls=$matches[2]&amp;ch=$matches[3]'; //$newrules['textbook/(cantonese|mandarin)/([C|M]K?[0-9]+)/([0-9]+)$'] = 'textbook/$matches[1]/index.php?cls=$matches[2]&amp;ch=$matches[3]'; return $newrules + $rules; } // Adding the id var so that WP recognizes it function mcs_insertTextbookQueryVars($vars) { array_push($vars, 'cls'); array_push($vars, 'ch'); return $vars; } </code> I want to map <code> http://localhost/wordpress/textbook/cantonese/CK1/6 </code> to <code> http://localhost/wordpress/textbook/cantonese/?cls=CK1&amp;ch=6 </code>
I see a second <code> ? </code> in your query variables (before the <code> cls </code> query variable), probably from experimenting with the commented-out form, I think you want to use <code> &amp; </code> there. Your <code> query_vars </code> hook currently adds the <code> id </code> variable, but you use <code> cls </code> and <code> ch </code> in your rewrite rule, so this will not have an effect. If you are changing the rewrite rules I recommend stackexchange-url ("my rewrite analyzer plugin") (soon in the repository, but get the current version via Dropbox ), it helps you debug these things.
Fixing custom rewrite rule
wordpress
How can I have one larger banner on the home page, but a smaller banner on all other pages. My home page is actually a page (as opposed to a post). But I'm thinking the banner is too big (and the newness/cuteness of it is warn off to see it over and over on every page). http://NealWalters.com P.S. - Someone with enough points, please add "banner" as a tag!
if you like a simple solution, you can use Wordpress Frontpage Banner plugin, it shows a banner or article only on frontpage http://wordpress.org/extend/plugins/wp-frontpagebanner/
Different banner on home page
wordpress
Suppose I want to blog about three somewhat unrelated main topics: Money, Languages, and Information-Technology on the same blog. How should I organize things for the best user experience? How does would such a structure affect the default menu structure at the top So far I found this: Category-manager and researching further. Apparently Category-Manager is a plug-in, I'm installing it now.
Hi @NealWalters: This is obviously more of an opinion question rather than a technical one but here's my opinion. My advice: use no more than 10 categories. Those &lt;=10 categories when viewed together should define the essence of your blog. Don't use subcategories. Then use lots of tags to define the topics you are talking about for each post. So if for example you are writing a blog post in your "Money" category, you might tag it with "401k" or "stocks" and so on. Viewed another way: Force yourself to be very disciplined with categories and allow yourself to be very liberal with tags. If you do it this way then your questions about your menu becomes easy; use a tag cloud on your main page for each category but filter the tag cloud to be specific to the category.
Organizing by super-categories (or nested categories)?
wordpress
Does anyone have experience with using the jQuery UI plugins in the Wordpress admin area? I´ve been trying to use the datepicker functionality in jQuery UI, but its conflicting with the built- in jQuery in wordpress admin. http://docs.jquery.com/UI/Datepicker This is the error message I get in console: <code> Uncaught TypeError: Cannot read property 'apply' of undefined a.widget.a.extend._trigger b.Widget._createWidget b.widget.b b.widget.bridge.b.fn c.extend.each c.fn.c.each b.widget.bridge.b.fn postboxes.init postboxes.add_postbox_toggles (anonymous function) c.extend.ready L </code> What could I possibly do to avoid this conflict? Adding the code used to include the jquery: <code> wp_register_script( 'jquery-tooltip', 'http://cdn.jquerytools.org/1.2.5/jquery.tools.min.js'); wp_register_script( 'jquery-ui-datepicker', get_bloginfo('template_directory') . '/js/jquery-ui-1.8.8.custom.min.js' ); wp_register_script( 'jquery-admin-internal', get_bloginfo('template_directory') . '/js/jquery.admin.internal.js' ); wp_register_script( 'jquery-internal', get_bloginfo('template_directory') . '/js/jquery.internal.js' ); function enqueue_admin_jquery() { wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_script('jquery-admin-internal'); } add_action('admin_init', 'enqueue_admin_jquery'); </code>
It worked when i used version 1.7.3 of the jQuery UI. Version 1.8.9 seems to have compatibility issues with the jQuert used by Wordpress admin.
jquery UI in wordpress admin
wordpress
I want to load head js first and then all enqueued scripts into it's function. Like so... <code> &lt;script src="&gt;/js/head.load.min.js" type="text/javascript" charset="UTF-8"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; head.js("/path/to/jquery.js", "/google/analytics.js", "/js/site.js", function() { // all done }); &lt;/script&gt; </code> How would I do this? For those that don't know HeadJS is the 2.30KB script that speeds up, simplifies and modernizes your site... http://headjs.com/
You should be forewarned that not all plugins/themes use enqueue. When I first started dealing with all the JavaScripts and CSS files outputed I just hooked into the enqueued files. This resulted in me only getting 2 out of 10 JavaScript files and 1 out of 3 CSS files. Here is some quick PoCs. Neither tested but meant to put you in the right direction, if you can code. Once I get home I'll whack together something more fitting and functional. <code> add_action('wp_print_scripts','head_files'); function head_files(){ global $wp_scripts, $auto_compress_scripts; print 'print out head.js'; $queue = $wp_scripts-&gt;queue; $wp_scripts-&gt;all_deps($queue); $to_do = $wp_scripts-&gt;to_do; $headArray = array(); foreach ($to_do as $key =&gt; $handle) { $src = $wp_scripts-&gt;registered[$handle]-&gt;src; $headArray[] = $src; } print 'print out head.js("'.implode("'",$headArray.'")'; } </code> (Basically swiped most of the code from JS &amp; CSS Script Optimizer) <code> add_filter('wpsupercache_buffer', 'head_files' ); function head_files($buffer){ if ( $fileType == "js" ){ preg_match_all('~&lt;script.*(type="["']text/javascript["'].*)?src=["'](.*)["'].*(type=["']text/javascript["'].*)?&gt;&lt;/script&gt;~iU',$content,$matches); $headArray = $matches[2]; } print 'print out head.js'; print 'print out head.js("'.implode("'",$headArray.'")'; return $buffer; } </code> Using WP Super Cache output buffering.
How to use Head JS with all enqueued scripts?
wordpress
Is there a way o changing user's avatar without plugins? Why there's no "Avatar Upload" section in Users > Your Profile? I can't use a plugin. Am I blind or being forced to use Gravatar? ;/
Avatars are meant to be controlled by the user, not by you. So yes, in a way, you're being forced to use the Gravatar service. But remember, it gives the user the ability to use the same avatar anywhere, and you can always restrict the display of a gravatar based on content ratings (G, PG, PG-13, R). Gravatar is a hosted service, which is why there's no "Upload Avatar" section in the profile. You say you "can't use a plugin," but really that's the only way you can add features. If you want to use something other than Gravatar, you'll need to load a plug-in to support it. There are a few plug-ins that support local avatars: Add Local Avatar Simple Local Avatars Otherwise, I recommend you educate your users on what Gravatars are and how to use them.
How to change user`s avatar?
wordpress
I want to make a weblog that has with every date 1 or more weblog posts, e.g.: Januari 24 Year 41 : Roman Emperor Caligula was murdered by Cassius Chaerea and the disgruntled Praetorian Guards. Caligula's uncle Claudius was proclaimed emperor in his place. or Januari 1 Year 153 BC : Roman consuls begin their year in office. or Februari 1 Year 2038 : Humans survived What would be the best way to do this in WordPress if I want to support URL hacking? p.s. custom fields + custom posts + custom taxonomy was the first thing I thought of but maybe there are better alternatives relying on the current date system. related: http://en.wikipedia.org/wiki/Unix_time#Representing_the_number
Unix time is defined as the amount of seconds since the "Unix epoch," which is 00:00:00 UTC on 1 January 1970. It works both forwards and backwards -- so technically you shouldn't have trouble representing dates all the way back to Jan. 1, year 1, but the numbers would be negative and extremely large. EDIT: PHP appears not to be able to handle those dates easily, at least according to one basic test. Both <code> echo $time = strtotime("January 1, 1"); </code> and <code> echo $time = strtotime("January 1, 0001"); </code> result in <code> 978325200 </code> . I think the best option is, as you muse, categories. Whether or not you want to deal with custom categories might be a matter of preference, but I suspect normal categories with the names you lay out would work just fine.
What is the best workaround for supporting all existing DATEs?
wordpress
How can I change the for loop below so that I can assign the array's "key" value as the "value" for each input instead of the array's "option" value as I'm now doing (I still want to echo the array's "option" value as the label)? <code> $myradiooptions = array("grid1" =&gt; "Grid View (default)", "list1" =&gt; "List View (1 column)", "list2" =&gt; "List View (2 column)" ); $options = array ( array( "name" =&gt; "My Theme Options","type" =&gt; "title"), array( "type" =&gt; "open"), array( "name" =&gt; "Category Layout", "desc" =&gt; "description goes here", "id" =&gt; "my_category_layout", "type" =&gt; "radio", "options" =&gt; $myradiooptions ), ...etc} //switch, case "radio": ?&gt; &lt;li class="section"&gt; &lt;label class="left" for="&lt;?php echo $value['id']; ?&gt;"&gt;&lt;?php echo $value['name']; ?&gt;&lt;/label&gt; &lt;?php $count=1;foreach ($value['options'] as $option) { ?&gt; &lt;input type="radio" name="&lt;?php echo $value['id']; ?&gt;" id="&lt;?php echo $count; ?&gt;" value="&lt;?php echo $option; ?&gt;" &lt;?php checked($option, get_settings($value['id'])); ?&gt;/&gt;&lt;label style="color:#666; margin:0 20px 0 5px;" for="&lt;?php echo $count; ?&gt;"&gt;&lt;?php echo $option; ?&gt;&lt;/label&gt; &lt;?php $count++;} ?&gt; &lt;label class="description" style="margin-top:-5px;"&gt;&lt;?php echo $value['desc']; ?&gt;&lt;/label&gt; &lt;/li&gt; &lt;?php break; </code>
If I am understanding you correctly just change <code> &lt;?php $count=1;foreach ($value['options'] as $key =&gt; $option) { ?&gt; </code> and you can access the key from $key.
How can I access 'key' and 'value' from an array in a for loop?
wordpress
I have function that check what is main top category of post. So i have category tree like this <code> Foo -bar --foobar cat2 </code> and if post is in foobar, my function post_is_in_descendant_category shows me "foo" and i can style that post with style-foo.css. What i want now is to make this same possible for styling category page "foobar". Wordpress functions in_category works only for posts. So, my code <code> if ( in_category( 'foo' ) || post_is_in_descendant_category( get_term_by( 'name', 'foo', 'category' )) || is_category('56') ) </code> doesn't work for subcategories.
If i understand right your "post_is_in_descendant_category" function checks if a post is descendant of a category and you want to check if a category is descentand. If so the add this function to your functions.php <code> function is_desc_cat($cats, $_post = null) { foreach ((array)$cats as $cat) { if (in_category($cat, $_post)) { return true; } else { if (!is_int($cat)) $cat = get_cat_ID($cat); $descendants = get_term_children($cat, 'category'); if ($descendants &amp;&amp; in_category($descendants, $_post)) return true; } } return false; } </code> and use it like this: <code> if (is_desc_cat("foo")) { // use foo.css } else { // use default.css } </code> Hope this helps.
If category is in parent category?
wordpress
I am trying to add a menu box to <code> Pages &gt; Pages </code> or <code> Pages &gt; Add New </code> , basically whenever they access a page, be it to edit an existing page or add a new one, I would like to add a menu box under the <code> Page Attributes </code> box on the right, or anywhere on those pages that I can add a input form into to work in conjunction with the plugin I am trying to build. I am very very new to wordpress plugin development, so please forgive my ignorance on the subject, any learning materials or good resources on the subject would also be greatly appreciated! Thanx in advance!
<code> add_action('add_meta_boxes', 'add_testbox'); function add_testbox() { add_meta_box( 'testmetabox', 'Test Meta Box', 'testmetabox_content', 'post', 'side', 'low'); } function testmetabox_content() { echo "hi"; } </code> You can drag and drop the box into the spot you want it to display. Make sure you always wrap the <code> add_meta_box() </code> function in another function, then hook that in like I showed. If you call <code> add_meta_box() </code> outside the function, you'll get a fatal error. This example is for WordPress 3.0 and above. As the WordPress Codex shows , the 'add_meta_boxes' hook I used was added in WP 3.0. If you're using an older version of WordPress, (which you shouldn't be), use 'admin_init' instead of 'add_meta_boxes'.
Adding admin menus to wordpress
wordpress
Twenty Ten gives the option to change the background image of the header. Where is the code involved in this feature? (uploading the picture and adding the picture). I would like to mimic this feature to archive the following: Upload a custom logo and upload various images (maybe 10) into a slider. So <code> front-page.php </code> would look like this: Custom Logo: <code> &lt;div id=logo&gt; &lt;!-- add custom logo here --&gt; &lt;/div&gt; </code> Custom images for slider: <code> &lt;div id=nivo-slider&gt; &lt;!--- add the uploaded images for the slider here --&gt; &lt;div&gt; </code> EDIT: I realised that the theme uses this: add_custom_image_header(). Does Wordpress have a similar function to add other type of custom images (like logo, feature image, etc...) ? (The simpler way I found was this , but I think it has a bug. In order for the image to appear, I have to upload it twice).
The only currently available Theme Features of this kind are for header and background. Sliders are very popular feature so best bet to get such functionality is look through available plugins.
Uploading and inserting an image using a custom option panel like in the Twenty Ten theme?
wordpress
I'm trying to modify the default WP calendar (get_calendar()) so that it shows posts from a specific category and then use that as a shortcode. Here's what I've done: Copied across the get_calendar() function from the core (from wp-includes) into my child theme's functions.php file. In order to make it an 'independent' calendar, I changed the name of the get_calendar() function to osu_get_calendar() and have successfully hardcoded the calendar into my template using osu_get_calendar(); Now I'm trying to get my hands a bit dirtier and do the following: 1) Restrict the posts shown in the calendar to a specific category (while maintaining the previous and next navigation so visitors can search through those posts by month) 2) Make it into a shortcode so my client can essentially embed a calendar with posts from a category they choose at the bottom of their posts. I'm stuck on 1) at the moment as it looks like I need to modify the SQL queries so that it pulls posts from a specific category. Looking at the code below from the get_calendar() function, how would I filter the posts pulled from the database so that they are from a specific category? There are other SQL queries in there, but hopefully someone can help me with this one for now: <code> $previous = $wpdb-&gt;get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb-&gt;posts WHERE post_date &lt; '$thisyear-$thismonth-01' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); $next = $wpdb-&gt;get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb-&gt;posts WHERE post_date &gt; '$thisyear-$thismonth-01' AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date ASC LIMIT 1"); </code> Thanks, osu
You were starting on the right track but you had several bits of WordPress hookage you still needed to add. An approach I like to use is to encapsulate a call to <code> get_calendar() </code> in a class so we can use the low-level <code> 'query' </code> hook but only use for it for the one call. So I wrote up an example which you can drop into your theme's <code> functions.php </code> file (or in a <code> .php </code> file for a plugin you might be writing) using a class I named <code> YourSite_Category_Calendar() </code> , and here is how you'd call it in place of your call to <code> get_calendar() </code> : <code> $cc = new YourSite_Category_Calendar('your-category'); echo $cc-&gt;get_calendar(); </code> And here's the code for the class: <code> &lt;?php class YourSite_CategoryCalendar { var $category; var $initial; var $echo; static function on_load() { add_shortcode('category-calendar',array(__CLASS__,'shortcode')); add_action('init',array(__CLASS__,'init')); global $wp_rewrite; $wp_rewrite-&gt;add_rule('^events/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?$', 'index.php?post_type=event&amp;year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;category_name=$matches[4]', 'top'); $wp_rewrite-&gt;flush_rules(false); // Remove this after you've got it working } static function shortcode($attributes) { $attributes = wp_parse_args($attributes,array( 'category' =&gt; false, )); $cc = new YourSite_CategoryCalendar($attributes['category']); echo $cc-&gt;get_calendar(); } static function init() { register_post_type('event',array( 'hierarchical' =&gt; true, 'label' =&gt; 'Events', 'public' =&gt; true, 'show_ui' =&gt; true, 'query_var' =&gt; 'event', 'rewrite' =&gt; array('slug' =&gt; 'events'), 'supports' =&gt; array('title','editor','custom-fields'), 'taxonomies' =&gt; array('category'), )); } function __construct($category,$initial=true,$echo=true) { $this-&gt;category = $category; $this-&gt;initial = $initial; $this-&gt;echo = $echo; } function get_calendar() { add_filter('query',array(&amp;$this,'query')); ob_start(); get_calendar($this-&gt;category,$this-&gt;initial,$this-&gt;echo); $calendar = ob_get_clean(); remove_filter('query',array(&amp;$this,'query')); list($header,$body) = explode('&lt;tbody&gt;',$calendar); $find = '#(href="http://[^/]+)(/[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/)#'; $replace = '$1/events$2'.$this-&gt;category.'/"'; $body = preg_replace($find,$replace,$body); return "{$header}&lt;tbody&gt;{$body}"; } function query($query) { if ($this-&gt;category) { global $wpdb; $find = "FROM {$wpdb-&gt;posts}\\s+WHERE"; $add =&lt;&lt;&lt;SQL INNER JOIN {$wpdb-&gt;term_relationships} calendar_term_relationship ON calendar_term_relationship.object_id={$wpdb-&gt;posts}.ID INNER JOIN {$wpdb-&gt;term_taxonomy} calendar_term_taxonomy ON calendar_term_taxonomy.term_taxonomy_id=calendar_term_relationship.term_taxonomy_id INNER JOIN {$wpdb-&gt;terms} calendar_term ON calendar_term.term_id=calendar_term_taxonomy.term_id WHERE calendar_term_taxonomy.taxonomy='category' AND calendar_term.slug='%s' AND SQL; $replace = "FROM {$wpdb-&gt;posts} {$add} "; $query = preg_replace("#{$find}#Us",$replace,$query); $query = preg_replace("#post_type\s*=\s*'post'#","post_type='event'",$query); $query = $wpdb-&gt;prepare($query,$this-&gt;category); } return $query; } } YourSite_CategoryCalendar::on_load(); </code> UPDATE Based on the comments I've added the URLs rewriting needed as well as a shortcode you'd call like this: <code> [category-calendar category="party"] </code>
Overriding default calendar to show posts from a category
wordpress
I have a post_meta "thevoters" that store users ids like: 1,2,20 ...etc, How i can turn this id's to User Names to list them in a single page? This will echo the numbers as text, <code> echo get_post_meta(get_the_ID(), "thevoters", true); </code> any help? thanks a lot!
<code> $thevoters_ids = get_post_meta( get_the_ID(), "thevoters", true ); // get a comma separated list of ids $thevoters_ids = explode( ',', $thevoters_ids ); // turn the list into an array foreach ( $thevoters_ids as $thevoter_id ) { // loop through the ids $thevoter = get_user_by( 'id', $thevoter_id ); // get the user object by id echo $thevoter-&gt;display_name; // display the user name } </code>
Convert User ID's to User Names in a single.php file
wordpress
Example post <code> &lt;p&gt;Lorem ipsum dolor sit amet&lt;/p&gt; &lt;p&gt;Morbi elementum odio vel tortor adipiscing vel tempor risus ullamcorper.&lt;/p&gt; </code> What I have done : <code> function first_paragraph($content){ return preg_replace('/&lt;p([^&gt;]+)?&gt;/', '&lt;p$1 class="first-paragraph"&gt;', $content, 1); } add_filter('the_content', 'first_paragraph'); </code> Which will have different <code> class </code> for first paragraph Now I want add <code> &lt;span class="first-letter"&gt;L&lt;/span&gt; </code> and result should be like <code> &lt;p class="first-paragraph"&gt;&lt;span class="first-letter"&gt;L&lt;/span&gt;orem ipsum dolor sit amet&lt;/p&gt; &lt;p&gt;Morbi elementum odio vel tortor adipiscing vel tempor risus ullamcorper.&lt;/p&gt; </code> Let me know Update: I got it worked but not a perfect solution. <code> function first_paragraph($content){ $content = substr_replace($content, '&lt;/span&gt;', 4, 0); $content = substr_replace($content, '&lt;span class="first-letter"&gt;', 3, 0); $content = preg_replace('/&lt;p([^&gt;]+)?&gt;/', '&lt;p$1 class="first-paragraph"&gt;', $content, 1); return $content; } add_filter('the_content', 'first_paragraph'); </code>
This drop caps plugin does what you are looking for: http://wordpress.org/extend/plugins/drop-caps/ If you're trying to do drop caps this should be enough. If you want to do more you could look into the code and see how the plugin wraps the 1st char in a span. It probably uses preg replace too. Id look myself but I'm answering this on my phone and have no way of looking at the code.
Add span to the first letter of post
wordpress
Logically, I'm thinking it should something like... <code> &lt;input type="radio" id="my_category_layout"&gt; &lt;option value="Item1"&gt;Item 1&lt;/option&gt; &lt;option value="Item2"&gt;Item 2&lt;/option&gt; &lt;option value="Item3"&gt;Item 3&lt;/option&gt; &lt;/input&gt; </code> But from what i've seen radio buttons dont markup like that. My existing code is below that creates a select list pulldown menu that allows me to capture a selected value. I'm struggling with how to convert this into a radio group. The main issue is that there is only one ID to represent the select, but I can't figure how to create three radio buttons with a single ID value that can be passed to represent the selected button. How would I do that? Here's my existing code for creating a select with a single id and multiple values... <code> &lt;?php $mySelectOptions = array("list" =&gt; "List View", "grid1" =&gt; "Grid View Multi Column", "grid2" =&gt; "Grid View Two Column"); array( "name" =&gt; "Category Layout", "desc" =&gt; "description goes here", "id" =&gt; "my_category_layout", "type" =&gt; "select", "options" =&gt; $mySelectOptions ), ?&gt; &lt;form method="post"&gt; &lt;?php foreach ($options as $value) { switch ( $value['type'] ) { case "select": ?&gt; &lt;select class="input" name="&lt;?php echo $value['id']; ?&gt;" id="&lt;?php echo $value['id']; ?&gt;"&gt; &lt;?php foreach ($value['options'] as $option) { ?&gt; &lt;option&lt;?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?&gt; value='&lt;?php echo $option; ?&gt;'&gt; &lt;?php echo $option; ?&gt;&lt;/option&gt;&lt;?php } ?&gt; &lt;/select&gt; &lt;?php break; case "radio": ?&gt; </code>
<code> case "radio": foreach ($value['options'] as $option) { ?&gt; &lt;label for="&lt;?php echo "{$value['id']}_{$option}"; ?&gt;"&gt; &lt;input type="radio" name="&lt;?php echo $value['id']; ?&gt;" id=&lt;?php echo "{$value['id']}_{$option}"; ?&gt; value="&lt;?php echo $option; ?&gt;" &lt;?php checked($option, get_settings($value['id'])); ?&gt; /&gt; &lt;?php echo $option; ?&gt; &lt;/label&gt; &lt;?php } break; </code> But I don't recommend coding theme/plugin settings this way. The array above doesn't just represent the option:value, but also the type of input, possible values (description, id?)... This just feels wrong. And you're making the code lack flexibility. What if you decide later to change a select field with a radio field? Or what if you want to add a image describing the option, or a color picker? Why do you think WP's core options are not coded this way?
How to create a multiple choice radio group for a single theme option
wordpress
I have primarydomain.com and an addondomain.com addondomain.com points to primarydomain.com/addondomain I have installed 2 seperate installs of wordpress on primarydomain.com and primarydomain.com/addondomain Can I activate multisite on primarydomain.com/addondomain as addondomain.com ? My reason for this is these are two separate sites with two separate functions, so I wanted to use separate databases. Is this possible?
Yes, it is possible, as long as you use addondomain.com to access the Multisite.
Can you install / activate the multisite when the install is in a subfolder?
wordpress
I have an archive.php page with the following code: <code> &lt;?php // Start your custom WP_query $my_query = new WP_query(); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array('posts_per_page' ?&gt; 1, 'paged' =&gt; $paged, 'category_name' =&gt; 'Casino Slots'); // Assign predefined $args to your query $my_query-&gt;query($args); // Run your normal loop if ($my_query-&gt;have_posts()) : while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt; Test &lt;?php endwhile; else : // do stuff for no results endif; wp_pagenavi(); // RESET THE QUERY wp_reset_query(); ?&gt; </code> and it displays the posts fine, but the pagination never shows?
I think your issue is that wp_pagenavi() is doing pagination based off of the global $wp_query instance instead instance you created. You should either switch to using query_posts() to replace the global query instead, or use WordPress' built in paginate_links to output the paging.
Pagination on archive.php page
wordpress
I'm just starting to store data in multi-dimensional arrays in wp_options and I need some help to retrieve some data... My data is below and is stored as option_name "my_category_fields" I need to pull a string of category ids in which the my_cat_hide is set to true. I've stubbed my function here. How do I complete it? <code> function get_hidden_cats() { $my_cats = get_option('ce4_category_fields'); //how do I capture the list of category ids where my_cat_hide is 'true'? $my_hidden_cats = ? return $my_hidden_cats; } </code> my_category_fields: <code> a:17:{ i:20;a:1:{s:13:"my_cat_title";s:30:"Black Tea is Good for the Soul";} i:9;a:1:{s:13:"my_cat_title";s:58:"Herbal Chinese Tea is a spectacular blend of herbs and tea";} i:44;a:1:{s:13:"my_cat_title";s:24:"This is my 9th category!";} i:7;a:1:{s:13:"my_cat_title";s:0:"";} i:19;a:1:{s:13:"my_cat_title";s:0:"";} i:4;a:2:{s:13:"my_cat_title";s:28:"My test Title for Chai Tea 4";s:12:"my_cat_hide";N;} i:37;a:1:{s:13:"my_cat_title";s:0:"";} i:16;a:1:{s:13:"my_cat_title";s:0:"";} i:5;a:2:{s:13:"my_cat_title";s:0:"";s:12:"my_cat_hide";N;} i:6;a:1:{s:13:"my_cat_title";s:0:"";} i:8;a:1:{s:13:"my_cat_title";s:0:"";} i:3;a:1:{s:13:"my_cat_title";s:0:"";} i:10;a:1:{s:13:"my_cat_title";s:59:"Iced Tea: The Great Southern Choice for Cooling Refreshment";} i:36;a:1:{s:13:"my_cat_title";s:28:"Full title for this category";} i:38;a:2:{s:13:"my_cat_title";s:0:"";s:12:"my_cat_hide";s:4:"true";} i:39;a:2:{s:13:"my_cat_title";s:0:"";s:12:"my_cat_hide";s:4:"true";} i:40;a:2:{s:13:"my_cat_title";s:0:"";s:12:"my_cat_hide";s:4:"true";} } </code>
The following should do it: <code> function get_hidden_cats() { $my_cats = get_option('ce4_category_fields'); $my_hidden_cats = array(); foreach( $my_cats as $cat_id =&gt; $cat_attrs ) { if( 'true' == $cat_attrs['my_cat_hide'] ) $my_hidden_cats[] = $cat_id; } $my_hidden_cats = implode( ',', $my_hidden_cats ); return $my_hidden_cats; } </code>
How do I retrieve multiple values from a multidimensional array in wp_options?
wordpress
I've been reading around and trying to figure out how to do this, but for some reason I can't seem to override parent functions in my child theme. I'm using TwentyTen as a parent - can anyone tell me why this function in my child theme isn't overriding the parent function please? <code> // Override read more link function osu_twentyten_continue_reading_link() { return ' &lt;a href="'. get_permalink() . '"&gt;' . __( 'Read on &lt;span class="meta-nav"&gt;&amp;rarr;&lt;/span&gt;', 'twentyten-child' ) . '&lt;/a&gt;'; } function osu_twentyten_auto_excerpt_more( $more ) { return ' &amp;hellip;' . osu_twentyten_continue_reading_link(); } remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' ); add_filter( 'excerpt_more', 'osu_twentyten_auto_excerpt_more' ); </code> I thought you had to remove the filter/action etc. before re-adding it right? Thanks, osu
You should run the code after theme setup. <code> function osu_twentyten_continue_reading_link() { return ' &lt;a href="'. get_permalink() . '"&gt;' . __( 'Read on &lt;span class="meta-nav"&gt;&amp;rarr;&lt;/span&gt;', 'twentyten-child' ) . '&lt;/a&gt;'; } function osu_twentyten_auto_excerpt_more( $more ) { return ' &amp;hellip;' . osu_twentyten_continue_reading_link(); } function my_child_theme_setup() { remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' ); add_filter( 'excerpt_more', 'osu_twentyten_auto_excerpt_more' ); } add_action( 'after_setup_theme', 'my_child_theme_setup' ); </code>
How to override parent functions in child themes?
wordpress
Is there a plugin for Wordpress that will change a post's category based on how long that post has existed? I have seen other Wordpress plugins that use a library called "simple pie" to manage a wp-blog's timed tasks, is there one that does something like this?
Don't know of a plugin but you can use wp_schedule_single_event function. First create a meta box that takes to values: time for removal and what category we want to set it to when removed from featured. <code> /* hook meta box */ add_action("admin_init", "admin_init"); /* hook meta box function */ function admin_init(){ add_meta_box("Featured Removal", "Featured Removal", "Featured_Removal_options", "post", "normal", "high"); } /* display meta box */ function Featured_Removal_options() { global $post; $custom = get_post_custom($post-&gt;ID); echo '&lt;input type="hidden" name="wp_meta_box_nonce" value="', wp_create_nonce('Featured Removal'), '" /&gt;'; &lt;? &lt;table border=0&gt; &lt;tr&gt; &lt;th style="width:20%"&gt;&lt;label for="Remove_after"&gt;Remove From Featured After:&lt;/label&gt;&lt;/th&gt; &lt;td&gt;&lt;input type="text" name="Remove_after" id="Remove_after" value="&lt;?php $custom['Remove_after'] ? $custom['Remove_after'] : ''; ?&gt;"/&gt;&lt;br/&gt; Enter time in Seconds Ex: 1 Hour = 3600 Seconds , 1 Day = 86400 Seconds. &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th style="width:20%"&gt;&lt;label for="Remove_after_to_cat"&gt;Remove From Featured To Category:&lt;/label&gt;&lt;/th&gt; &lt;td&gt;&lt;input type="text" name="Remove_after_to_cat" id="Remove_after_to_cat" value="&lt;?php $custom['Remove_after_to_cat'] ? $custom['Remove_after_to_cat'] : ''; ?&gt;"/&gt;&lt;br/&gt; Enter the category id of the category you want to remove the post after the time has passed. if more then one separate by commas Ex: 12,13,24 &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php } /* save meta box hook*/ add_action('save_post', 'save_Featured_Removal_options'); /* save meta box function*/ function save_Featured_Removal_options($post_id) { if (!wp_verify_nonce($_POST['wp_meta_box_nonce'], "Featured Removal")) { return $post_id; } // check autosave if (defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE) { return $post_id; } If (isset($_POST['Remove_after']) &amp;&amp; isset($_POST['Remove_after_to_cat'])){ //cerate scheduled event $time = time() + $_POST['Remove_after']; wp_schedule_single_event($time, 'Clean_my_featured',$post_id); //save meta data update_post_meta($post_id, 'Remove_after', $_POST['Remove_after']); update_post_meta($post_id, 'Remove_after_to_cat', $_POST['Remove_after_to_cat']); } } </code> Now watch the save Meta Box function , if the user has enter both time for removal and category id for the new category then we set a scheduled event with wp_schedule_single_event and hook it to " Clean_my_featured ". So now we only need to add the action for that hook and the function for the removal itself: <code> /* hook removal event function */ add_action('Clean_my_featured','remove_post_from_featured'); // the function that removes a post form a category and sets a new one function remove_post_from_featured($post_id) { $cats = get_post_meta($post_id, 'Remove_after_to_cat', true); wp_set_post_terms( $post_ID, $cats, 'category'); } </code> I have no Idea if this works but it should so just copy all of it to a plugin file or your themes functions.php file and it should work. if not let me know.
Plugin for changing a post's category based on it's post date?
wordpress
I'd like to add a checkbox to the category editor screen to allow the category to be "deactivated" (perhaps while the site owner works on the category content and posts). Once I've done this, what are my options for excluding the category's that are set to "inactive"? One way I'm thinking I can do this is to just run a filter on wp_list_categories and in the exlude= list, I'd just insert a utility function that returns all cat_ids where inactive is checked true. Are there other ways to do this?
Hi @Scott B: If you are talking 5 or 10 categories then just save them as a comma-separated string of IDs in using <code> update_option() </code> and use it as you suggested with your <code> wp_list_categories() </code> <code> 'exclude' </code> argument. And this answer should show you how to add a field to the category screen: stackexchange-url ("Adding Custom Field to Taxonomy Input :Panel")
filter "inactive" categories from wp_list_categories?
wordpress
In my Wordpress site I've created, I'm having issues hiding or not displaying one of the category titles I set up. I'll try to explain better. Wordpress Admin Side I have a post that is in two categories, a " <code> Work </code> " &amp; " <code> Front_Page </code> " Main Page / index.php On my main index page, I have 3 features below the header image. One of those features is a "Featured Project". This is how I'm starting the loop... Single Project Page Now on this page, the visual layout is Category Name Which is called <code> &lt;h2 class="single_category"&gt;&lt;?=$cat[0]-&gt;name;?&gt;&lt;/h2&gt; </code> Project Title Large Header Image Project Desription THE PROBLEM!!! For whichever post I put in " <code> Front_Page </code> ", it displays that in the Category Name. I want it to default to the main category. Is there a way to basically say "if post is in " <code> front_page </code> " category, don't display " <code> front_page </code> " category as name?
Here is a bad way that works. <code> &lt;h2 class="single_category"&gt;&lt;? if ($cat[0]-&gt;name != "Front_Page") { echo $cat[0]-&gt;name; } else { echo $cat[1]-&gt;name; } ?&gt;&lt;/h2&gt; </code> Here is a bad way that works and takes up less space. <code> &lt;?php echo ($cat[0]-&gt;name != "Front_Page") ? $cat[0]-&gt;name : $cat[1]-&gt;name; ?&gt; </code>
Post thats in Two Categories, only want to display name for one
wordpress
I have been wanting to do something similar like this for a long time. I have a url http://studionumberone.com/portfolio/obey-clothing/ which just shows the jquery gallery of images, I then have studionumberone.com/portfolio/obey-clothing/?view=all. Which shows all of the images in the gallery one above each other. I would like the url to be studionumberone.com/portfolio/obey-clothing/all The custom post type just does a basic: <code> &lt;?php get_header(); $view = $_GET['view']; ?&gt; &lt;?php if ($view == "all") { ?&gt; show all images &lt;?php } else { ?&gt; show gallery shortcode &lt;?php } ?&gt; &lt;?php get_footer(); ?&gt; </code> I have tried (no luck): <code> add_action( 'init', 'ss_permalinks' ); function ss_permalinks() { add_rewrite_rule( '([^/]+)/all/?', 'index.php?view=all&amp;service=$matches[1]', 'top' ); } add_filter( 'query_vars', 'ss_query_vars' ); function ss_query_vars( $query_vars ) { $query_vars[] = 'view'; return $query_vars; } </code>
Hi @westondeboer: Since you are saying your post type is <code> 'portfolio' </code> here's what works on my WordPress v3.0.4 test site with a <code> 'portfolio' </code> custom post type defined. It replaces all the code you have: <code> add_action('init','yoursite_init'); function yoursite_init() { global $wp,$wp_rewrite; $wp-&gt;add_query_var('view'); $wp_rewrite-&gt;add_rule('portfolio/([^/]+)/all', 'index.php?view=all&amp;post_type=portfolio&amp;name=$matches[1]', 'top'); // Once you get working, remove this next line $wp_rewrite-&gt;flush_rules(false); } </code> You also need to flush your rewrite rules which you can do by saving your Permalinks in the admin console. Let me know if this solves your issue and if not please give me clarification. UPDATE You also need to capture the query parameter differently than using `$_GET['view']'; either of these will work: <code> // Option 1 $view = {$GLOBALS['wp']-&gt;query_vars['view']; // Option 2 global $wp; $view = $wp-&gt;query_vars['view']; </code>
add_rewrite_rule and custom variable
wordpress
I have a custom post type which is working fine, however the meta box does isn't saving. Long &amp; short, i'm stumped! <code> add_action('init', 'portfolio'); function portfolio() { $args = array( 'label' =&gt; __('Portfolio'), 'singular_label' =&gt; __('Portfolio'), 'public' =&gt; true, 'show_ui' =&gt; true, 'menu_position' =&gt; 5, 'capability_type' =&gt; 'page', 'hierarchical' =&gt; false, 'rewrite' =&gt; true, 'show_in_nav_menus' =&gt; true, 'supports' =&gt; array('title', 'editor', 'thumbnail', 'excerpt'), 'has_archive' =&gt; true ); register_taxonomy( 'type', 'portfolio', array( 'hierarchical' =&gt; false, 'label' =&gt; __('Project Type'), 'query_var' =&gt; 'type', 'rewrite' =&gt; array('slug' =&gt; 'portfolio/type' ) ) ); register_post_type( 'portfolio' , $args ); } add_action("admin_init", "admin_init"); add_action('save_post', 'save_meta_data'); function admin_init(){ add_meta_box("portfolio_text", "Main Text", "portfolio_options", "portfolio", "normal", "high"); } /* Meta Values for Shorts */ function portfolio_options() { global $post; $custom = get_post_custom($post-&gt;ID); $short_embed = $custom["portfolio_text"][0]; ?&gt; &lt;textarea name="portfolio_text" cols="40" rows="1" style="width:98%; height:100px"/&gt;&lt;?php echo get_option('portfolio_text'); ?&gt;&lt;/textarea&gt; &lt;?php } /* Save Changes */ function save_meta_data($ID = false, $post = false) { if($post-&gt;post_type != 'portfolio') return; update_post_meta($ID, 'portfolio_text', $_POST['portfolio_text']); } </code> Your help is appreciated! Cheers, George
Hi @George Wiscombe: So close, yet so far! (I know the pain, I'm there often. :) You almost had it but are using the wrong hook to do the post meta update. Use the <code> 'wp_insert_post_data' </code> hook instead of the <code> 'save_post' </code> hook: <code> &lt;?php if (!class_exists('YourSite_Portfolio')) { class YourSite_Portfolio { static function on_load() { add_action('init',array(__CLASS__,'init')); add_action("admin_init",array(__CLASS__,'admin_init')); add_action('wp_insert_post_data',array(__CLASS__,'wp_insert_post_data'),10,2); } static function init() { register_post_type( 'portfolio',array( 'label' =&gt; __('Portfolio'), 'singular_label' =&gt; __('Portfolio'), 'public' =&gt; true, 'show_ui' =&gt; true, 'menu_position' =&gt; 5, 'capability_type' =&gt; 'page', 'hierarchical' =&gt; false, 'rewrite' =&gt; true, 'show_in_nav_menus' =&gt; true, 'supports' =&gt; array('title', 'editor', 'thumbnail', 'excerpt'), 'has_archive' =&gt; true )); register_taxonomy( 'type', 'portfolio', array( 'hierarchical' =&gt; false, 'label' =&gt; __('Project Type'), 'query_var' =&gt; 'type', 'rewrite' =&gt; array('slug' =&gt; 'portfolio/type' ) )); } static function admin_init(){ add_meta_box('portfolio_text','Main Text',array(__CLASS__,'portfolio_options'),'portfolio','normal','high'); } static function portfolio_options($post,$metabox) { $portfolio_text = get_post_meta($post-&gt;ID,'portfolio_text',true); $html =&lt;&lt;&lt;HTML &lt;textarea name="portfolio_text" cols="40" rows="1" style="width:98%; height:100px"/&gt;{$portfolio_text}&lt;/textarea&gt; HTML; echo $html; } static function wp_insert_post_data($data,$postarr) { if ($postarr['post_type'] == 'portfolio') { update_post_meta($postarr['ID'], 'portfolio_text', $postarr['portfolio_text']); } return $data; } } YourSite_Portfolio::on_load(); } </code> The <code> 'wp_insert_post_data' </code> hook is where WordPress captures the values from the <code> $_POST </code> array; by the time you reach <code> 'save_post' </code> WordPress has reloaded the post and that's why <code> 'portfolio_text' </code> empty when you are trying to save it.
Meta Box on Custom Post Type not saving
wordpress
I am trying to create a home page where it is a list of categories with an associated thumbnail for each. I would like it so it returns each category once and returns the associated thumbnail from the latest post, or even better does not require me to add a featured image to each post, but rather grabs the thumbnail from the image of the post, using post_mime_type ? I am still a ways off as it is returning the category for each post that is within that category and then associating the image with every category. Here is the function I am working with: <code> function home_filter() { if ( is_home() ) { add_filter( 'the_content', 'home_cats' ); } } add_action('template_redirect', 'home_filter'); function home_cats(){ $args=array( 'orderby' =&gt; 'name', 'order' =&gt; 'ASC', ); $categories=get_categories($args); foreach($categories as $category) { echo '&lt;li&gt;&lt;a href="' . get_category_link( $category-&gt;term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category-&gt;name ) . '" ' . '&gt;' . get_the_post_thumbnail($page-&gt;ID, 'thumbnail') . $category-&gt;name.'&lt;/a&gt;&lt;/li&gt; '; } } </code> The home page is simply : <code> &lt;ul&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;?php the_content();?&gt; &lt;?php endwhile; ?&gt; &lt;/ul&gt; </code> The output is something like: <code> &lt;ul&gt; &lt;li&gt;&lt;a href="../?cat=1" title="View all posts in Cat A" &gt;&lt;img src="..image-A.jpg" /&gt;Cat A&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="../?cat=3" title="View all posts in Cat B" &gt;&lt;img src="..image-A.jpg" /&gt;Cat B&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="../?cat=1" title="View all posts in Cat A" &gt;&lt;img src="..image-B.jpg" /&gt;Cat A&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="../?cat=3" title="View all posts in Cat B" &gt;&lt;img src="..image-B.jpg" /&gt;Cat B&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="../?cat=1" title="View all posts in Cat A" &gt;&lt;img src="..image-C.jpg" /&gt;Cat A&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="../?cat=3" title="View all posts in Cat B" &gt;&lt;img src="..image-C.jpg" /&gt;Cat B&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code> Can someone please help me understand how to return each category only once and include the thumb from the latest post in that category? And even better can anyone think of a way to accomplish this without having to set the feature image every time?
Hi @zac: Normally I like to shy away from recommending direct SQL, but in your use-case I think it is warranted. I've coded this up as a direct SQL query; as you may notice is a bit complex. You can copy the following code to your theme's <code> functions.php </code> file or add it to the <code> .php </code> file of a plugin you might be writing: <code> function home_cats($max_image_height=150){ $categories= get_taxonomy_latest_posts_with_attachment('category'); echo '&lt;h1&gt;Categories&lt;/h1&gt;'; foreach($categories as $category) { $category_link = get_category_link( $category-&gt;term_id ); $category_title = sprintf( __( "View all posts with category: '%s'" ),$category-&gt;term_name ); $post_title = get_the_title($category-&gt;post_id); $post_link = get_permalink($category-&gt;post_id); $img_html = wp_get_attachment_image( $category-&gt;attachment_id, array( 'thumbnail',$max_image_height ) ); $html = &lt;&lt;&lt;HTML &lt;div id="category-{$category-&gt;term_slug}" class="category"&gt; &lt;span style="float:right;"&gt;{$img_html}&lt;/span&gt; &lt;span style="float:left;"&gt; &lt;h2&gt;&lt;a href="{$category_link}" title="{$category_title}"&gt;{$category-&gt;term_name}&lt;/a&gt;&lt;/h2&gt; &lt;p style="float:left;"&gt;Latest post: &lt;a href="{$post_link}" title="{$post_title}"&gt;$post_title&lt;/a&gt;&lt;/p&gt; &lt;/span&gt; &lt;/div&gt; &lt;br clear="both" /&gt; HTML; echo $html; } } function get_taxonomy_latest_posts_with_attachment($taxonomy) { global $wpdb; $sql =&lt;&lt;&lt;SQL SELECT categorized_posts.rownum, categorized_posts.term_id, categorized_posts.term_name, categorized_posts.term_slug, categorized_posts.post_id, categorized_posts.post_date, categorized_posts.post_title, attachments.ID AS attachment_id, attachments.post_title AS attachment_title, attachments.post_mime_type AS attachment_mime_type, attachments.guid AS attachment_guid FROM ( SELECT rownum, term_id, term_name, term_slug, post_id, post_date, post_title, post_parent, post_name, post_type FROM ( SELECT IF( @prev &lt;&gt; {$wpdb-&gt;terms}.term_id, @rownum := 1, @rownum := @rownum+1 ) AS rownum, @prev := {$wpdb-&gt;terms}.term_id, {$wpdb-&gt;terms}.term_id, {$wpdb-&gt;terms}.name AS term_name, {$wpdb-&gt;terms}.slug AS term_slug, {$wpdb-&gt;posts}.ID as post_id, {$wpdb-&gt;posts}.post_date, {$wpdb-&gt;posts}.post_title, {$wpdb-&gt;posts}.post_parent, {$wpdb-&gt;posts}.post_name, {$wpdb-&gt;posts}.post_type FROM {$wpdb-&gt;term_taxonomy} INNER JOIN {$wpdb-&gt;terms} ON {$wpdb-&gt;term_taxonomy}.term_id={$wpdb-&gt;terms}.term_id INNER JOIN {$wpdb-&gt;term_relationships} ON {$wpdb-&gt;term_relationships}.term_taxonomy_id={$wpdb-&gt;term_taxonomy}.term_taxonomy_id INNER JOIN {$wpdb-&gt;posts} ON {$wpdb-&gt;posts}.ID={$wpdb-&gt;term_relationships}.object_id INNER JOIN (SELECT @rownum := NULL, @prev := 0) AS rownum_initializer ON 1=1 WHERE 1=1 AND {$wpdb-&gt;posts}.post_type='post' AND {$wpdb-&gt;posts}.post_status='publish' AND {$wpdb-&gt;term_taxonomy}.taxonomy='%s' ORDER BY {$wpdb-&gt;posts}.post_parent DESC, {$wpdb-&gt;posts}.post_date DESC ) x ) categorized_posts INNER JOIN (SELECT MAX(ID) AS post_id,post_parent FROM {$wpdb-&gt;posts} WHERE post_type='attachment' GROUP BY post_parent) attachment_join ON attachment_join.post_parent=categorized_posts.post_id INNER JOIN {$wpdb-&gt;posts} attachments ON attachments.ID=attachment_join.post_id WHERE categorized_posts.rownum=1 GROUP BY categorized_posts.term_id ORDER BY categorized_posts.term_name SQL; return $wpdb-&gt;get_results($wpdb-&gt;prepare($sql,$taxonomy)); } </code> You'll note I separated the logic so that you can get the list of any taxonomy terms and their latests posts with a photo by calling the <code> get_taxonomy_latest_posts_with_attachment() </code> function and passing it a taxonomy identifier, like this: <code> $post_tags = get_taxonomy_latest_posts_with_attachment('post_tags'); </code> Because of the complexity of the SQL in that function I'm not going to try to explain it (or I'd be here all night) but if you have specific follow up questions, just ask. Anyway, here's what the code looks like on my test side with test data: P.S. The people in the photos are friends of mine and all work with WordPress in one way or another. Hope they don't mind me using their likeness. :)
Limit get_categories to show each category once
wordpress
I got some option pages for my theme. I did this whit add_menu_page, add_submenu_page. I further got settings with register_setting and there i got add_settings_section and add_settings_field(s). The field callback functions come from a class that auto-generates my fields. I then built a form callback function (for add_(sub)menu_page like the following. <code> public function render() { $this-&gt;notify(); ?&gt; &lt;div class="wrap"&gt; &lt;div id="icon-themes" class="icon32"&gt;&lt;br /&gt;&lt;/div&gt; &lt;h2&gt;&lt;?php echo $this-&gt;page_title; ?&gt;&lt;/h2&gt; &lt;p&gt;&lt;?php _e('The developer mode allows access to some of your most important rapid prototyping tools.', MY_TEXTDOMAIN); ?&gt;&lt;/p&gt; &lt;div class="postbox-container"&gt; &lt;div class="postbox "&gt; &lt;div class="inside"&gt; &lt;form action="options.php" method="post"&gt; &lt;?php settings_fields( MY_OPTIONS ); do_settings_sections(__FILE__); ?&gt; &lt;p class="submit"&gt; &lt;input class="button-primary" name="Submit" type="submit" value="&lt;?php _e('Save Changes', MY_TEXTDOMAIN); ?&gt;" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;form method="post"&gt; &lt;p class="submit"&gt; &lt;input class="button-secondary" name="Reset" type="submit" value="&lt;?php _e('reset', MY_TEXTDOMAIN); ?&gt;" /&gt; &lt;input name="action" type="hidden" value="reset" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;?php } private function notify() { if ( isset($_POST['save']) ) : ?&gt; &lt;div id="message" class="updated fade"&gt; &lt;p&gt;&lt;?php sprintf(__('$1$s Options update %2$ssuccessfull%3$s.', MY_TEXTDOMAIN), $this-&gt;name, '&lt;strong&gt;', '&lt;/strong&gt;'); ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php elseif ( isset($_POST['reset']) ) : delete_option( MY_OPTIONS ); ?&gt; &lt;div id="message" class="updated fade"&gt; &lt;p&gt;&lt;?php sprintf(__('$1$s Options have been %2$sdeleted%3$s.', MY_TEXTDOMAIN), $this-&gt;name, '&lt;strong&gt;', '&lt;/strong&gt;'); ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php endif; } </code> (This is all done in a class) I can set default values, change and save them and everything works out fine. But one problem stays: I can't delete my options and can't reset them to the defaults. Does anybody know how to achieve that? Thanks!
You should (and must for security) use validation function, that is part of Settings API. I don't seem to see it in your code. There you should be able to simply pass empty value for option under circumstances it should be saved as disabled. Of course you can also just use regular Options API functions to access and modify your settings directly, from any appropriate place in code.
Best way to reset some admin options form to default?
wordpress
I created a plugin but I just came across a bug that I don't really know how to solve. When you activate my plugin, it creates a file in the active theme directory and when you deactivate it, it deletes that file. The problem is, if you activate the plugin, and then switch the theme, the files won't exist in the new theme's directory. Is there a line of code I can add in my plugins functions file to deactivate the plugin before the theme is switched, and then activate it after the new theme has been activated? Thanks, this is a great community so I know I'll get a great answer. :)
There is a 'switch_theme' action that runs right after the theme is switched. <code> function my_on_switch_theme($new_theme) { $current_themes = get_themes(); $new_theme_info = $current_themes[$new_theme]; /* $new_theme_info bhould now be an associative array with the following: $new_them_info['Title']; $new_them_info['Version']; $new_them_info['Parent Theme']; $new_them_info['Template Dir']; $new_them_info['Stylesheet Dir']; $new_them_info['Template']; $new_them_info['Stylesheet']; $new_them_info['Screenshot']; $new_them_info['Description']; $new_them_info['Author']; $new_them_info['Tags']; $new_them_info['Theme Root']; $new_them_info['Theme Root URI']; ...so do you what you need from this. */ } add_action('switch_theme', 'my_on_switch_theme'); </code>
Is there a hook for when you switch themes?
wordpress
Right now I use the following code to create a custom post type and assign a taxonomy to it: <code> // === CUSTOM TAXONOMIES === // add_action('init', 'my_custom_taxonomies', 0); function my_custom_taxonomies() { register_taxonomy( 'section', // internal name = machine-readable taxonomy name 'static_content', // object type = post, page, link, or custom post-type array( 'hierarchical' =&gt; true, 'labels' =&gt; array( 'name' =&gt; __( 'Section' ), 'singular_name' =&gt; __( 'Section' ), 'add_new_item' =&gt; 'Add New Section', 'edit_item' =&gt; 'Edit Section', 'new_item' =&gt; 'New Section', 'search_items' =&gt; 'Search Section', 'not_found' =&gt; 'No Sections found', 'not_found_in_trash' =&gt; 'No Sections found in trash', 'all_items' =&gt; __( 'All Sections' ), ), 'query_var' =&gt; true, // enable taxonomy-specific querying 'rewrite' =&gt; array( 'slug' =&gt; 'section' ), // pretty permalinks for your taxonomy? ) ); wp_insert_term('Footer', 'section'); wp_insert_term('Header', 'section'); wp_insert_term('Front Page Intro', 'section'); wp_insert_term('Front Page Content', 'section'); } // === CUSTOM POST TYPES === // add_action( 'init', 'create_my_post_types' ); function create_my_post_types() { register_post_type( 'static_content', array( 'labels' =&gt; array( 'name' =&gt; __( 'Static Content' ), 'singular_name' =&gt; __( 'Static Content' ), 'add_new_item' =&gt; 'Add New Static Content', 'edit_item' =&gt; 'Edit Static Content', 'new_item' =&gt; 'New Static Content', 'search_items' =&gt; 'Search Static Content', 'not_found' =&gt; 'No Static Content found', 'not_found_in_trash' =&gt; 'No Static Content found in trash', ), '_builtin' =&gt; false, 'public' =&gt; true, 'hierarchical' =&gt; false, 'taxonomies' =&gt; array( 'section'), 'supports' =&gt; array( 'title', 'editor', 'excerpt' ), 'rewrite' =&gt; array( 'slug' =&gt; 'static_content', 'with_front' =&gt; false ) ) ); } </code> When I click the menu of the custom post type (in this case "Static Content"), I see in the table/column (where all the posts are displayed) the following information: Title, Author and Date. I would like to show the taxonomy assigned to that post (in this case the "Section".) How do I do that?
Hi @janoChen: Using my test site and some test code this is what I think you were looking for? To achieve this you need to use two (2) hooks, one being specific to your post type: <code> 'manage_static_content_posts_columns' </code> and <code> 'manage_posts_custom_column' </code> . In order to make it work I took your code and packaged it in a class, and also made it a plugin (it doesn't have to be a plugin; you could just take the code and put in in your theme's <code> functions.php </code> file if you like.) <code> &lt;?php /* Plugin name: Static Content */ if (!class_exists('YourSite_StaticContent')) { class YourSite_StaticContent { static function on_load() { add_action('init',array(__CLASS__,'init')); add_filter('manage_static_content_posts_columns', array(__CLASS__,'manage_static_content_posts_columns')); add_filter('manage_posts_custom_column', array(__CLASS__,'manage_posts_custom_column')); } function manage_static_content_posts_columns($columns){ $new = array(); foreach($columns as $key =&gt; $title) { if ($key=='author') // Put the Sections column before the Author column $new['sections'] = 'Sections'; $new[$key] = $title; } return $new; } static function manage_posts_custom_column($column){ global $post; switch ($column) { case "sections": echo get_the_term_list($post-&gt;ID, 'section', '', ', ',''); break; } } static function init() { register_post_type('static_content',array( 'labels' =&gt; array( 'name' =&gt; __( 'Static Content' ), 'singular_name' =&gt; __( 'Static Content' ), 'add_new_item' =&gt; 'Add New Static Content', 'edit_item' =&gt; 'Edit Static Content', 'new_item' =&gt; 'New Static Content', 'search_items' =&gt; 'Search Static Content', 'not_found' =&gt; 'No Static Content found', 'not_found_in_trash' =&gt; 'No Static Content found in trash', ), 'public' =&gt; true, 'hierarchical' =&gt; false, 'taxonomies' =&gt; array( 'section'), 'supports' =&gt; array('title','editor','excerpt'), 'rewrite' =&gt; array('slug'=&gt;'static_content','with_front'=&gt;false), )); register_taxonomy('section','static_content',array( 'hierarchical' =&gt; true, 'labels' =&gt; array( 'name' =&gt; __( 'Section' ), 'singular_name' =&gt; __( 'Section' ), 'add_new_item' =&gt; 'Add New Section', 'edit_item' =&gt; 'Edit Section', 'new_item' =&gt; 'New Section', 'search_items' =&gt; 'Search Section', 'not_found' =&gt; 'No Sections found', 'not_found_in_trash' =&gt; 'No Sections found in trash', 'all_items' =&gt; __( 'All Sections' ), ), 'query_var' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'section' ), )); if (!get_option('yoursite-static-content-initialized')) { $terms = array( 'Footer', 'Header', 'Front Page Intro', 'Front Page Content', ); foreach($terms as $term) { if (!get_term_by('name',$term,'section')) { wp_insert_term($term, 'section'); } } update_option('yoursite-static-content-initialized',true); } } } YourSite_StaticContent::on_load(); } </code>
How to show the taxonomy assigned to a post in the table (where all the posts are displayed) of the custom post type?
wordpress
I am using the theme 3Grey. It is widget enabled. There are few widgets that are hard coded in the theme. These widgets donot appear in the sidebar in the widgets page. If i try adding new widgets the old ones get deleted. Is this ths normal case. Or is there any problem here.
Most themes will have a default set of widgets that appear when you don't add any widgets yourself (using the widget page in admin). You can normally just drag the widgets that were "hard-coded" into the correct sidebar, and all should be ok.
Problem with widgets
wordpress
I tried the Satoshi Theme in Wordpress 3.1 and when the Theme Options are saved, they do get saved but the "Satoshi Options Saved." message is not displayed. (the message is displayed in Wordpress 3.0.4). functions.php: <code> /* -- Theme Options Page -- */ function theme_options_admin() { $option_fields = array(); if ( $_GET['updated'] ) echo '&lt;div id="message" class="updated fade"&gt;&lt;p&gt;Satoshi Options Saved.&lt;/p&gt;&lt;/div&gt;'; echo '&lt;link rel="stylesheet" href="'.get_bloginfo('template_url').'/styles/functions.css" /&gt;'; ?&gt; &lt;div class="wrap"&gt; &lt;h2&gt;Satoshi Options&lt;/h2&gt; &lt;div id="message"&gt;&lt;/div&gt; &lt;div class="metabox-holder"&gt; &lt;form method="post" action="options.php"&gt; &lt;?php wp_nonce_field('update-options'); ?&gt; &lt;div id="theme-options"&gt; &lt;div id="left-column"&gt; &lt;?php include("options/custom-logo.php"); include("options/custom-intro.php"); include("options/frontpage-headline.php"); include("options/featured-project.php"); ?&gt; &lt;/div&gt;&lt;!--end left-column--&gt; &lt;div id="right-column"&gt; &lt;?php include("options/contact-details.php"); include("options/footer-text.php"); include("options/google-analytics.php"); ?&gt; &lt;/div&gt;&lt;!--end right-column--&gt; &lt;/div&gt;&lt;!--theme-options--&gt; &lt;input type="hidden" name="action" value="update" /&gt; &lt;input type="hidden" name="page_options" value="&lt;?php echo implode(",", $option_fields); ?&gt;" /&gt; &lt;/form&gt; &lt;/div&gt;&lt;!--end metabox-holder--&gt; &lt;/div&gt;&lt;!--end wrap--&gt; &lt;?php } add_action('admin_menu', "theme_options_admin_init"); function theme_options_admin_init() { add_theme_page( "Satoshi Theme Options", "Theme Options", 8, __FILE__, 'theme_options_admin'); } </code>
This line is wrong, i couldn't even get the theme options page up without changing it.. <code> add_theme_page( "Satoshi Theme Options", "Theme Options", 8, __FILE__, 'theme_options_admin'); </code> Update that to read something like.. <code> add_theme_page( "Satoshi Theme Options", "Theme Options", 8, 'satoshi-theme-options', 'theme_options_admin'); </code> Saving options did produce the updated message as expected. UPDATE: Looks like the <code> $_GET </code> key has changed in 3.1 when performing settings updates. Update the following line. <code> if ( $_GET['updated'] ) echo '&lt;div id="message" class="updated fade"&gt;&lt;p&gt;Satoshi Options Saved.&lt;/p&gt;&lt;/div&gt;'; </code> To.. <code> if ( $_GET['settings-updated'] ) echo '&lt;div id="message" class="updated fade"&gt;&lt;p&gt;Satoshi Options Saved.&lt;/p&gt;&lt;/div&gt;'; </code> And you'll now see the updated message when saving.
$_GET['updated'] does not work in Wordpress 3.1?
wordpress
This problem was reported on the WP forum a month ago: Error when trying to logout . Whenever you logout, you get (Chrome): This webpage is not available. The webpage at http://my.site.com/blog/wp-login.php?action=logout&amp;_wpnonce=2d5b319c49 might be temporarily down or it may have moved permanently to a new web address. More information on this error Below is the original error message Error 101 (net::ERR_CONNECTION_RESET): Unknown error. I've had this problem since at least 3.0.2 and it's still there with 3.0.4. My host is IPOWER. I was wondering if anyone here has seen this problem, and even more importantly, has a solution. Thanks. A little more information: I get the same connection reset error with FireFox and IE. The Apache access log shows the following (I don't have access to the error logs): [22/Jan/2011:00:01:39 -0500] "GET /blog/wp-login.php?action=logout&amp;_wpnonce=2d5b319c49 HTTP/1.0" 302 212 "http://my.site.com/blog/wp-admin/" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10" The temporary redirect to /blog/wp-admin/ seems to make sense -- after logging out you go back to the login page.
I updated to WP 3.0.5 a couple of days ago and the problem persisted. I just updated to Askimet 2.5.3 , and voila!, the logout problem is solved.
Error when trying to logout
wordpress
Possible noob question -- please be nice. I'm doing up a theme options page using the sample from Themeshaper , and one of the options I want to have is to set the width of the sidebar. To do this with the CSS I already have, I need to change class attributes in my HTML in two places (one for the main column width, one for the sidebar). The Themeshaper code is fine for adding little theme option tweaks, but I can't figure out how to get a single option to modify two places in the code at once. Possibly (hopefully!) a simple question, but beyond my current abilities. Any help greatly appreciated. Thanks. Update: I should clarify that I'm not a programmer, and I'm already waaay out of my depth. That said, here's what I'm going for... In my theme options page, I want to have a drop-down menu with two options: 'wide sidebar' and 'narrow sidebar'. One of these will be the default. Changing the default needs to modify two CSS classes. I appreciate Rarst's answer below but I simply don't know enough about PHP to be able to get it to work. Is there a simple(r) explanation for how to get this to happen? Again, sorry if this is basic stuff.
Nothing prevents you from retrieving your option in several places. You can do several <code> get_option() </code> calls or create global variable and assign your value to it once. It is hard to come up with specific example without knowing what exactly you store in option and which classes you want to generate for your markup. Update One of the ways to get it done. Depending on how you organize code you might need to declare variables as <code> global </code> : <code> $options = get_option('sample_theme_options'); $sidebar_width = $options['sidebar_width']; // let's say we have stored integer '2' here $column_width = 8 - $sidebar_width; // total width minus sidebar // and then in template echo "&lt;div class='main-{$column_width}col'&gt; main &lt;/div&gt;"; echo "&lt;div class='sidebar-{$sidebar_width}col'&gt; sidebar &lt;/div&gt;"; </code>
Can I use theme options to change two things at once?
wordpress
Im trying to implement a tag-based search. When i specify certain tags, tagged posts will be searched and the post-id will be displayed that matches the searchcriteria. Currently it only works for a single tag. <code> $query = "SELECT DISTINCT $wpdb-&gt;posts.ID FROM $wpdb-&gt;terms LEFT JOIN $wpdb-&gt;term_taxonomy ON ($wpdb-&gt;terms.term_id = $wpdb-&gt;term_taxonomy.term_id) LEFT JOIN $wpdb-&gt;term_relationships ON ($wpdb-&gt;terms.term_id = $wpdb-&gt;term_relationships.term_taxonomy_id) LEFT JOIN $wpdb-&gt;posts ON ($wpdb-&gt;term_relationships.object_id = $wpdb-&gt;posts.ID) WHERE $wpdb-&gt;term_taxonomy.taxonomy = 'post_tag' " . $substring; </code> Substring looks like following: <code> $substring = "AND $wpdb-&gt;terms.slug IN ('tag1','tag2')" </code> And here is the problem. It does not look for single posts that match all criteria. Instead it 'collects' all posts with all tags searched. For example: <code> // postid1 -&gt; tag1 // postid2 -&gt; tag2 // postid3 -&gt; tag1, tag2 $substring = "AND $wpdb-&gt;terms.slug IN ('tag1')" //Output: postid1, postid3 - - - CORRECT $substring = "AND $wpdb-&gt;terms.slug IN ('tag1','tag2')" //Output: postid1, postid2, postid3 - - -WRONG! //Expected: postid3 </code> So far i have no idea howto solve it in a single mysql query. Maybe im missing something. Thanks for your help in advance.
These are normal <code> IN </code> mechanics - it matches anything in set, not all of set combined. Type of match you want is called <code> tag_slug__and </code> in WP query arguments. You can see code that generates SQL for it in source of <code> WP_Query-&gt;&amp;get_posts() </code> method. Resulting SQL is like this: <code> SELECT p.ID FROM wp_posts p INNER JOIN wp_term_relationships tr ON (p.ID = tr.object_id) INNER JOIN wp_term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) INNER JOIN wp_terms t ON (tt.term_id = t.term_id) WHERE tt.taxonomy = 'post_tag' AND t.slug IN ('is', 'filler') GROUP BY p.ID HAVING count(p.ID) = 2 </code>
Tags to Post-ID mysql query. Tag Search
wordpress
I found that the longest part of a plugin or theme development is creating the options panel, at least in my case. So i like to know what's your take on that. Do you use a ready made framework or class? And if so witch one? Or do you write it up from scratch? Use the settings API or plain options? Thanks.
OK so found some more: JeffreyWay / WordPress-Theme-Options-Page - open source class the project is hosted on github aimed at theme developers, looks nice, haven't used it. (link dead) . devinsays / Options-Framework - open source Framework the project is hosted on github aimed at theme developers , i later learned that is has evolved in to Thematic-options very large scaled project that has lots of features. (link dead) helgatheviking / thematic-options-KIA - open source Framework the project is hosted on github aimed at help developers build options into their thematic child themes , witch was forked for Thematic-options very much up to date.(link dead) Wordpress AdminPage Class - a commercial solution, packed it features and very easy to use. OptionTree plugin - and IDE for creating option panels , lots of feature and constantly updated, downside is: it's not easily integrated in plugins or themes and default options are not an option (up to version 1.1.1). that's it for now but still looking to here about your experience. Update After a long time of trying I've managed to integrate Options tree with my plugin and after that part was done , I have to say that its never been easier to add options to my plugin, EVER! all done with no code, but using the slick UI that comes with it. So as of now its my favorite with a small exception of being a plugin by it self and not a framework witch makes the integration part a lot harder. Update2 If you read the first update then this will be 180 degree turn, i have stopped using Option-Tree witch was hard to integrate in the first place but mainly for the reason that it create an option row in the options database table for each option you add to it so my plugin has created 287 rows in the database and thats bad for many reasons but the main ones are its hard to remove all of them at plugin deactivation and you have to create a get-option call for each one of them so that's a lot of database calls. Since that little set back,I found that most of the frameworks listed up here work in the same manner of each option gets its own row. So i modified AdminPage Class to save all options per admin page in an array of options and and now my plugin only generates 7 Rows in the database and at most i only need to call the get_option function 7 times so that saves lots of database calls, I'll contact the creator of AdminPage Class and ask him to consider this modification but other then that it very easy to use and even easier to manage. Last Update if anyone is still keeping score here, then i ended up coding my own <code> option panel class </code> which it's main features are: Open source, GPL licensed. Works with plugins as well as themes OOP Code all the way (which means easy to extend and modify). Import Export Options. All Options saved as a single row in a database. Available fields are: Input Textarea Radio button Checkbox Select Dropdown File Upload Image Upload WYSIWYG editor Date Picker Time Picker Color Picker Taxonomy List Dropdwon or checkboxes Post list Dropdown or checkboxes WordPress User Roles Dropdown or checkboxes Syntax Highlighted Code Editor (PHP, CSS, HTML, JAVASCRIPT) Typography Field (set of size, color, face, family fields) Sortable Drag &amp; Drop Repeater Field Plupload field hooks and filters all over the place so you can customize just the way you'd like
framework for plugin/theme options panel?
wordpress
I'm cleaning up an old, controversial blog entry and I need to remove all the comments from the post. Surprisingly, I can't find a way to do this within the existing WordPress (3.0.4) UI. I can certainly go through and click "trash" on all 200+ comments, but that seems.. excessive. Is there another way to do this that I am missing?
Alternative for people reading this with a fear for SQL............... (or finding this via Google after Januari 2011): Wait for this action until 3.1 comes out, then go to a post, check all comments and bulk "move to trash" :) (it should come out any day now) (http://wordpress.org/about/roadmap/) (or download 3.1 RC3 from http://wordpress.org/download/release-archive/) Example:
How do I delete all comments from a specific old blog post?
wordpress
I have created a custom post type called "events" and have also created a custom taxonomy which only shows up on this specific post type through which the admin must select an "event category" (terms). Currently on the public site when the event detail page is requested it looks like this: http://www.domain-name.com/events/title-of-the-event Additionally, on the public side a web browser can access just a specific event category to view all associating events where the url looks like this: http://www.domain-name.com/events/event-category Both of the above situations currently works fine. The problem I am having is that I would like to customize the URL slug for the event details page as follows: Instead of having the event detail page slug being built from the entered title I would like for it to include the taxonomy term and a specific custom field. In end effect I would like for it to look like this: <code> http://www.domain-name.com/events/&lt;taxonomy-term&gt;-event-title-&lt;custom-field&gt;/ </code> <code> &lt;taxonomy-term&gt; </code> is the event category (the way I programed the metabox the admin is only able to select a single term). <code> &lt;custom-field&gt; </code> is a specific custom field the user is required to enter before the event post can be saved. Does anyone know how I might go about doing this correctly? All my experiments have led nowhere.
Hi @NetConstructor: Well if I had thought about how much work with was going to be before writing it, you wouldn't be able to get me points right now. :) Needless to say, it's rather involved (though I don't think it really should have to be, but it is what it is.) First off, you can't (easily) do it like you wanted; the problem is how to differentiate between these two URLs: Event Type = "Day Time" , Event Title = "For a Change" Event Type = "Day" , Event Title = "Time For a Change" Both would have a portion of their URLs looking like this and how could we tell which is which? <code> day-time-for-a-change </code> So, I modified your pattern to use tildes (~) as separators and that works fine: <code> http://www.domain-name.com/events/&lt;taxonomy-term&gt;~event-title~&lt;custom-field&gt;/ </code> Anyway, I wrote a plugin that does what you need. It does the following things: It sets the rewrite rule in the the plugin activation hook using <code> $wp_rewrite-&gt;add_rule() </code> . It applys the pattern to create actual event post links using the <code> 'post_type_link' </code> hook, and It simplifes editing of the URL slug by using the <code> 'get_sample_permalink_html' </code> hook (I didn't try to show the full URL because it would have been too tricky for something I'm writing for free. :) So here's what the edit screen looks like: Which produces this view on the front end: And here ya go with the plugin code (let me know if you have questions, but not toooo many. ;-): <code> &lt;?php /* Plugin Name: SEO URLs for Events */ if (!class_exists('SeoUrlsForEvents')) { class SeoUrlsForEvents { static function on_load() { add_action('init', array(__CLASS__,'init')); add_filter('post_type_link', array(__CLASS__,'post_type_link'),10,4); add_filter('get_sample_permalink_html',array(__CLASS__,'get_sample_permalink_html'),10,4); } static function get_sample_permalink_html($sample, $post_id, $new_title, $new_slug) { $post = get_post($post_id); if ($post-&gt;post_type=='event') { $post_slug = self::make_post_slug($post); if ($post_slug) { $sample = str_replace('&lt;strong&gt;Permalink:&lt;/strong&gt;','&lt;strong&gt;Permalink Slug:&lt;/strong&gt;',$sample); $sample = preg_replace('#(&lt;span id="sample-permalink"&gt;).+?(&lt;span id="editable-post-name" title="Click to edit this part of the permalink"&gt;).+?&lt;/span&gt;/&lt;/span&gt;#Us',"$1$2{$post-&gt;post_name}&lt;/span&gt;&lt;/span&gt;",$sample); $permalink = get_post_permalink($id); $sample = preg_replace("#(&lt;span id='view-post-btn'&gt;&lt;a href=').+?(' class='button' target='_blank'&gt;View Post&lt;/a&gt;&lt;/span&gt;)#","$1{$permalink}$2",$sample); } } return $sample; } static function make_post_slug($post) { $post_slug = false; $post = (object)$post; if ($post-&gt;post_type=='event') { $when = get_post_meta($post-&gt;ID,'when',true); if (!empty($when)) { // If we don't have a when, use default $types = wp_get_object_terms($post-&gt;ID,'event-type'); if (count($types)) // If we don't have an event-type, use default else use the first one $post_slug = "{$types[0]-&gt;slug}~{$post-&gt;post_name}~{$when}/"; } } return $post_slug; } static function post_type_link($post_link, $post, $leavename, $sample) { if ($post-&gt;post_type=='event' &amp;&amp; $sample) { $post_link = '%event%'; } else { $post_slug = self::make_post_slug($post); if ($post_slug) { $post_link = get_bloginfo('wpurl') . '/events/' . $post_slug; } } return $post_link; } static function activate() { global $wp_rewrite; $wp_rewrite-&gt;add_rule('events/([^~]+)~([^~]+)~([^/]+)','index.php?post_type=event&amp;taxonomy=event-type&amp;term=$matches[1]&amp;name=$matches[2]&amp;meta_key=when&amp;meta_value=$matches[3]', 'top'); $wp_rewrite-&gt;flush_rules(false); } static function init() { register_post_type('event', array( 'label' =&gt; 'Events', 'public' =&gt; true, 'rewrite' =&gt; array('slug' =&gt; 'events'), 'hierarchical' =&gt; false, 'supports' =&gt; array('title','editor','custom-fields'), ) ); register_taxonomy('event-type', 'event', array( 'hierarchical' =&gt; false, 'label' =&gt; 'Event Types', 'rewrite' =&gt; array('slug' =&gt; 'event-types' ), ) ); } } SeoUrlsForEvents::on_load(); } register_activation_hook(__FILE__,array('SeoUrlsForEvents','activate')); </code>
Interesting Custom Post Type Slug with Taxonomy and Custom Field
wordpress
When one creates a custom post type you have the ability to define various elements related to that post type which essentially allow you to define things such as the menu title, "add new post" text and stuff like that. What I am trying to figure out is what code I need to add to my functions.php file so I can set these things for an existing "default" post type which wordpress adds. So, for example lets say I want to change the "Pages" post type to "Main Sections". Currently what I have done is used the following code: <code> add_filter( 'gettext', 'change_admin_menu_pages' ); add_filter( 'ngettext', 'change_admin_menu_pages' ); function change_admin_menu_pages( $translated ) { $translated = str_replace( 'Page', 'Core Page', $translated ); $translated = str_replace( 'page', 'core page', $translated ); return $translated; } </code> Although this works and just replaces every instance of "pages" with "main sections", what I have noticed is that it also effects other areas of the site such as plugins which use "pages=" within their url. As such... is there a simple way to define post type settings for default wordpress post types like "pages" and "posts"? If so, could someone please quickly illustrate how that might work? On a different note... I feel that using the filter add_filter( 'ngettext',...) is actually very useful but what I don't understand is how to restrict the area where its allowed to filter things. An answer to both or either question would be greatly appreciated Thanks in advance!
Hi @NetConstructor: Another easy one! :) As you know I think very highly of WordPress in general, but the admin menu architecture is one of the nastiest hacks I think I've ever seen in open-source software. What's only greater in magnitude is the core WordPress team's unwillingness to acknowledge how bad it is and their lack of willingness to discuss improving it. But I digress... Anyway, here's what you want (I think): And here's how to get it: <code> add_action('admin_menu','rename_pages_to_main_sections'); function rename_pages_to_main_sections() { global $menu; global $submenu; $menu[20][0] = 'Main Sections'; $submenu['edit.php?post_type=page'][5][0] = 'Main Sections'; } </code> P.S. Also, you might find the code I posted here helpful too: <a href="stackexchange-url How to Resolve Some Challenges when Modifying the WordPress Admin Menu System?
How to change the admin menu "Pages" to something else
wordpress
Is there a plugin that allowed me to add google map embed code by only supplying address?
5secGoogleMaps by WebFactory is a very promising one . You enter a map like this: <code> [gmap]your address[/gmap] </code>
Add Google Map By Address
wordpress
Personally I really dislike how wordpress shows all the "popular terms" in different sizes on the taxonomy add/edit screen in the admin area. Does anyone know of a way to either remove this entire area completely by adding code to your functions.php file and/or how to just change this specific area so that none of the popular terms show up with different font sizes/styles? Thank you
Hi @NetConstructor: Oh, I love it when you give me an easy one. Starts to make up for all those harder ones... (well, partly. ;-) So what you want is to replace this: With this: How? Use the <code> 'wp_tag_cloud' </code> hook which you can put into your theme's <code> functions.php </code> file or in a <code> .php </code> file of a plugin you might be writing. For this one I tested the global variable <code> $pagenow </code> to make sure it was on the term edit page. In the hook just strip out the <code> style </code> attribute from each of the <code> &lt;a&gt; </code> elements: <code> add_action('wp_tag_cloud','modify_taxonomy_tag_cloud',10,2); function modify_taxonomy_tag_cloud($html,$args) { global $pagenow; if ('edit-tags.php'==$pagenow) // Only for the tag edit page $html = preg_replace("#style='[^']+'#Us",'',$html); return $html; } </code>
Removing the "Popular Terms" area from the Taxonomy Edit Screen in the Admin Area
wordpress
Im trying to display latest comments from all the post on a page named comments, now im able to use <code> &lt;?php wp_list_comments('per_page=25', get_comments()) ?&gt; </code> and it gets all the comments but when I try to use <code> &lt;?php get_paginate_comments_links() ?&gt; </code> nothing shows even the next and previous buttons dont show, what am i doing wrong? This is my current code, any help is appreciated <code> &lt;?php wp_list_comments('per_page=5', get_comments()) ?&gt; &lt;div class="navigation"&gt; &lt;?php get_paginate_comments_links(array() ?&gt; &lt;?php previous_comments_link() ?&gt; &lt;?php next_comments_link() ?&gt; &lt;/div&gt; </code>
I cannot find that function in source and also not sure about your code nesting there. There is <code> paginate_comments_links() </code> function. Usage is around this: <code> if ( get_option( 'page_comments' ) ) paginate_comments_links(); </code>
Display latest comments on page with pagination
wordpress
By default WordPress orders custom taxonomies (as tags in this case) by alphabetical order not by the order they were entered in the tag box. Is anyone aware of a way to show the custom taxonomies in the order they were entered in the post edit screen? The url in question is: http://granadatheater.com/ The GGW (Goes Good With) artists are currently in alphabetical order and they want it changed so that they are ordered the same way they were entered. So if the enter it Artist1, Artist3, Artist2 that's how it should show up on the frontend of the site.
This isn't possible "out of the box"... The default 'orderby' options are (ascending or descending) ID name Default slug count term_group These are all detailed in the codex. -- That said there are some clever ladies &amp; gents here. If anyone can solve it, one of these guys can i'm sure!
Change order of Custom Taxonomy List
wordpress
Where can I download the schema (or DTD) for the layout of the WordPress import/export file format?
It seems to be an RSS Feed http://en.wikipedia.org/wiki/RSS extended with some of WordPress's own extensions. Unfortunately, it applies only to posts and pages. I was thinking about using it to migrate data from PHP-Fusion to WordPress, but it would only be a partial solution. I tried some of the naemspaces below in the browser to see if they would give me a schema or DTD, but they did not. Here's an example: <code> &lt;rss version="2.0" xmlns:excerpt="http://wordpress.org/export/1.0/excerpt/" - xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wp="http://wordpress.org/export/1.0/" &gt; &lt;channel&gt; &lt;title&gt;MrHebrew.com&lt;/title&gt; &lt;link&gt;http://mrhebrew.com&lt;/link&gt; &lt;description&gt;My Site Descr&lt;/description&gt; &lt;pubDate&gt;Wed, 05 Jan 2011 05:54:07 +0000&lt;/pubDate&gt; &lt;generator&gt;http://wordpress.org/?v=3.0.3&lt;/generator&gt; &lt;language&gt;en&lt;/language&gt; &lt;wp:wxr_version&gt;1.0&lt;/wp:wxr_version&gt; &lt;wp:base_site_url&gt;http://mrhebrew.com&lt;/wp:base_site_url&gt; &lt;wp:base_blog_url&gt;http://mrhebrew.com&lt;/wp:base_blog_url&gt; &lt;wp:category&gt;&lt;wp:category_nicename&gt;adam-and-eve&lt;/wp:category_nicename&gt;&lt;wp:category_parent&gt;&lt;/wp:category_parent&gt;&lt;wp:cat_name&gt;&lt;![CDATA[Adam and Eve]]&gt;&lt;/wp:cat_name&gt;&lt;/wp:category&gt; &lt;wp:category&gt;&lt;wp:category_nicename&gt;book-of-joshua&lt;/wp:category_nicename&gt;&lt;wp:category_parent&gt;&lt;/wp:category_parent&gt;&lt;wp:cat_name&gt;&lt;![CDATA[Book of Joshua]]&gt;&lt;/wp:cat_name&gt;&lt;/wp:category&gt; &lt;wp:tag&gt;&lt;wp:tag_slug&gt;jeremiah&lt;/wp:tag_slug&gt;&lt;wp:tag_name&gt;&lt;![CDATA[Jeremiah]]&gt;&lt;/wp:tag_name&gt;&lt;/wp:tag&gt; &lt;wp:tag&gt;&lt;wp:tag_slug&gt;joshua&lt;/wp:tag_slug&gt;&lt;wp:tag_name&gt;&lt;![CDATA[Joshua]]&gt;&lt;/wp:tag_name&gt;&lt;/wp:tag&gt; &lt;wp:tag&gt;&lt;wp:tag_slug&gt;judges&lt;/wp:tag_slug&gt;&lt;wp:tag_name&gt;&lt;![CDATA[Judges]]&gt;&lt;/wp:tag_name&gt;&lt;/wp:tag&gt; &lt;wp:tag&gt;&lt;wp:tag_slug&gt;king-saul&lt;/wp:tag_slug&gt;&lt;wp:tag_name&gt;&lt;![CDATA[King Saul]]&gt;&lt;/wp:tag_name&gt;&lt;/wp:tag&gt; &lt;item&gt; &lt;title&gt;Another Possible Punctuation Changes Meaning Entirely&lt;/title&gt; &lt;link&gt;http://mrhebrew.com/?p=136&lt;/link&gt; &lt;pubDate&gt;Wed, 05 Jan 2011 05:52:49 +0000&lt;/pubDate&gt; &lt;dc:creator&gt;&lt;![CDATA[Administrator]]&gt;&lt;/dc:creator&gt; &lt;category&gt;&lt;![CDATA[Isaiah]]&gt;&lt;/category&gt; &lt;category domain="category" nicename="isaiah"&gt;&lt;![CDATA[Isaiah]]&gt;&lt;/category&gt; &lt;category&gt;&lt;![CDATA[Punctuation]]&gt;&lt;/category&gt; &lt;category domain="category" nicename="punctuation"&gt;&lt;![CDATA[Punctuation]]&gt;&lt;/category&gt; &lt;category domain="tag"&gt;&lt;![CDATA[punctuation]]&gt;&lt;/category&gt; &lt;category domain="tag" nicename="punctuation-2"&gt;&lt;![CDATA[punctuation]]&gt;&lt;/category&gt; &lt;category domain="tag"&gt;&lt;![CDATA[question-mark]]&gt;&lt;/category&gt; &lt;category domain="tag" nicename="question-mark"&gt;&lt;![CDATA[question-mark]]&gt;&lt;/category&gt; &lt;guid isPermaLink="false"&gt;http://mrhebrew.com/?p=136&lt;/guid&gt; &lt;description&gt;&lt;/description&gt; &lt;content:encoded&gt;&lt;![CDATA[ text of blog here ]]&gt;&lt;/content:encoded&gt; &lt;excerpt:encoded&gt;&lt;![CDATA[]]&gt;&lt;/excerpt:encoded&gt; &lt;wp:post_id&gt;136&lt;/wp:post_id&gt; &lt;wp:post_date&gt;2011-01-05 05:52:49&lt;/wp:post_date&gt; &lt;wp:post_date_gmt&gt;2011-01-05 05:52:49&lt;/wp:post_date_gmt&gt; &lt;wp:comment_status&gt;open&lt;/wp:comment_status&gt; &lt;wp:ping_status&gt;open&lt;/wp:ping_status&gt; &lt;wp:post_name&gt;another-possible-punctuation-changes-meaning-entirely&lt;/wp:post_name&gt; &lt;wp:status&gt;publish&lt;/wp:status&gt; &lt;wp:post_parent&gt;0&lt;/wp:post_parent&gt; &lt;wp:menu_order&gt;0&lt;/wp:menu_order&gt; &lt;wp:post_type&gt;post&lt;/wp:post_type&gt; &lt;wp:post_password&gt;&lt;/wp:post_password&gt; &lt;wp:is_sticky&gt;0&lt;/wp:is_sticky&gt; &lt;wp:postmeta&gt; &lt;wp:meta_key&gt;_edit_lock&lt;/wp:meta_key&gt; &lt;wp:meta_value&gt;&lt;![CDATA[1294206847]]&gt;&lt;/wp:meta_value&gt; &lt;/wp:postmeta&gt; &lt;wp:postmeta&gt; &lt;wp:meta_key&gt;_edit_last&lt;/wp:meta_key&gt; &lt;wp:meta_value&gt;&lt;![CDATA[1]]&gt;&lt;/wp:meta_value&gt; &lt;/wp:postmeta&gt; &lt;wp:postmeta&gt; &lt;wp:meta_key&gt;_encloseme&lt;/wp:meta_key&gt; &lt;wp:meta_value&gt;&lt;![CDATA[1]]&gt;&lt;/wp:meta_value&gt; &lt;/wp:postmeta&gt; &lt;wp:postmeta&gt; &lt;wp:meta_key&gt;_wp_old_slug&lt;/wp:meta_key&gt; &lt;wp:meta_value&gt;&lt;![CDATA[]]&gt;&lt;/wp:meta_value&gt; &lt;/wp:postmeta&gt; &lt;wp:postmeta&gt; &lt;wp:meta_key&gt;_pingme&lt;/wp:meta_key&gt; &lt;wp:meta_value&gt;&lt;![CDATA[1]]&gt;&lt;/wp:meta_value&gt; &lt;/wp:postmeta&gt; &lt;wp:postmeta&gt; &lt;wp:meta_key&gt;_wp_old_slug&lt;/wp:meta_key&gt; &lt;wp:meta_value&gt;&lt;![CDATA[another-possible-punctuation-changs-meaning-entirely]]&gt;&lt;/wp:meta_value&gt; &lt;/wp:postmeta&gt; &lt;wp:comment&gt; &lt;wp:comment_id&gt;267&lt;/wp:comment_id&gt; &lt;wp:comment_author&gt;&lt;![CDATA[sex tubes]]&gt;&lt;/wp:comment_author&gt; &lt;wp:comment_author_email&gt;[email protected]&lt;/wp:comment_author_email&gt; &lt;wp:comment_author_url&gt;http://41tube.com&lt;/wp:comment_author_url&gt; &lt;wp:comment_author_IP&gt;89.149.244.89&lt;/wp:comment_author_IP&gt; &lt;wp:comment_date&gt;2011-01-08 20:26:32&lt;/wp:comment_date&gt; &lt;wp:comment_date_gmt&gt;2011-01-08 20:26:32&lt;/wp:comment_date_gmt&gt; &lt;wp:comment_content&gt;&lt;![CDATA[I can see the logic in your argument but I think you've painted your strokes]]&gt;&lt;/wp:comment_content&gt; &lt;wp:comment_approved&gt;spam&lt;/wp:comment_approved&gt; &lt;wp:comment_type&gt;&lt;/wp:comment_type&gt; &lt;wp:comment_parent&gt;0&lt;/wp:comment_parent&gt; &lt;wp:comment_user_id&gt;0&lt;/wp:comment_user_id&gt; &lt;/wp:comment&gt; &lt;/item&gt; &lt;/channel&gt; &lt;/rss&gt; </code>
Download/View Schema (or DTD) for XML Import
wordpress
I am using the WP-Paginate plug-in and need to apply a class to the containing LIs for the next/previous links. Can someone tell me how to do this? If there's a better/easier way to do this other than using WP-Paginate, then I'm open to suggestions. Thanks!
Hi @user1462: Happy to say that it's not hard at all to achieve what you are looking for. As I understand it, you have to add a call to <code> wp_paginate() </code> in (one of) your theme (s) template file (s) when using this plugin, and that call looks something like this: <code> &lt;?php if(function_exists('wp_paginate')) { wp_paginate(); } ?&gt; </code> To do what you need just create your own function, let's call it <code> mysite_paginate() </code> and call it instead of the code above. Within your function <code> mysite_paginate() </code> call <code> ob_start() </code> to start output buffering, then call <code> wp_paginate() </code> , and then call <code> ob_get_clean() </code> to capture the output created by <code> wp_paginate() </code> . The final step is to then use a regular expression search and replace with <code> preg_replace() </code> to add the classes you want and then echo the results to the browser. The code you need is below. You can add it to your theme's <code> functions.php </code> file or in a <code> .php </code> file of a plugin you may be writing: <code> function mysite_paginate() { if(function_exists('wp_paginate')) { ob_start(); wp_paginate(); $html = ob_get_clean(); $html = preg_replace('#&lt;li&gt;(&lt;a href="[^"]+" class="next"&gt;)#Us', '&lt;li class="next"&gt;$1',$html); $html = preg_replace('#&lt;li&gt;(&lt;a href="[^"]+" class="prev"&gt;)#Us', '&lt;li class="prev"&gt;$1',$html); echo $html; } } </code> And if all goes as planned, this is what you should expect to see when using an element inspector with your browser:
How to apply next/previous classes to LIs for pagination links?
wordpress
I use this function to get some information to the user columns, <code> function column_company( $defaults ) { $defaults['usercolumn-company'] = __('Company', 'user-column'); $defaults['usercolumn-myoffers'] = __('Applied Offers', 'user-column'); $defaults['usercolumn-totaloffers'] = __('Total Offers', 'user-column'); return $defaults; } function custom_column_company($value, $column_name, $id) { if( $column_name == 'usercolumn-company' ) { return get_the_author_meta( 'company', $id ); } elseif( $column_name == 'usercolumn-myoffers' ) { return get_the_author_meta( 'offersiget', $id ); } elseif( $column_name == 'usercolumn-totaloffers' ) { return get_the_author_meta( 'totaloffers', $id ); } } add_action('manage_users_custom_column', 'custom_column_company', 15, 3); add_filter('manage_users_columns', 'column_company', 15, 1); </code> i return the get_the_author_meta( 'offersiget', $id ); and here i get from the db some post id's as text, like: 8,12,51 is it possible to return this, not as a text but as a link to the edit post (/wp-admin/post.php?post=(8)&amp;action=edit)? I try this by @hakre <code> return sprintf('&lt;a href="/wp-admin/post.php?post='.get_the_author_meta( 'offersiget', $id ).'&amp;action=edit"&gt;'.get_the_author_meta( 'offersiget', $id ).'&lt;/a&gt;'); </code> and it works but it return one link with all the post id's inside, is it possible to split them? any help? Thanks, Philip
Your <code> get_the_author_meta() </code> calls must be returning a string(following your comments), so what you'll need to do is split that string up into an array, loop over it and build an array of links, then join it back together at the end using a seperator. <code> /* Meh, no license, do as you want with it.. Example code */ function ids_to_post_editlink( $ids = array(), $seperator = ' ' ) { if( empty( $ids ) || '' == $ids ) return; if( !is_array( $ids ) ) $ids = explode( ',', $ids ); $links = array(); $ids = array_map( 'intval', $ids ); foreach( $ids as $pid ) $links[] = "&lt;a href='" . admin_url( "post.php?action=edit&amp;post=$pid" ) . "'&gt;$pid&lt;/a&gt;"; return implode( $seperator, $links ); } </code> Add that function alongside your code, then update your <code> get_the_author_meta </code> calls to one of the following.. <code> // Default(space seperated) return ids_to_post_editlink( get_the_author_meta( 'your-meta-key', $id ) ); // Comma seperated return ids_to_post_editlink( get_the_author_meta( 'your-meta-key', $id ), ', ' ); // Pipe seperated return ids_to_post_editlink( get_the_author_meta( 'your-meta-key', $id ), ' | ' ); </code> Hope that helps..
Return User Meta text as links to post edit inside the user columns
wordpress