question
stringlengths 0
34.8k
| answer
stringlengths 0
28.3k
| title
stringlengths 7
150
| forum_tag
stringclasses 12
values |
---|---|---|---|
When I try to upload an image to a post, I get an error: "The uploaded file could not be moved to /home/httpd/xxxx/xxxx/xxx/wp/wp-content/uploads." My server is set up in safe_mode - is that the problem? What can I do about it?
|
It has nothing to do with safe_mode try this: login to your ftp make your wp-content folder 755 inside wp-content create a new folder called "uploads", make it 777 (755 should also work) inside the control admin panel, go to settings> miscellaneous and on the first line enter "wp-content/uploads" as where your uploads will go to. Save and go try !
|
File Upload with Server in safe_mode
|
wordpress
|
this is what im doing... In BuddyPress, before delete user account, if a user has attachments previously uploaded, he or she will be redirected to their own attachments list: <code> function custom_get_count_before_delete() { global $bp, $wpdb; $user_id = $bp->loggedin_user->id; return $wpdb->get_var( $wpdb->prepare( " SELECT COUNT(DISTINCT p.ID) FROM $wpdb->posts p WHERE p.post_author = %d AND p.post_status = 'inherit' AND p.post_type = 'attachment'", $user_id ) ); } function custom_check_delete_account () { global $bp; if ( $bp->current_component == 'settings' && $bp->current_action == 'delete-account' ) { if ( $count = custom_get_count_before_delete() ) { wp_redirect('http://www.mysite.lh/wp-admin/upload.php', 301 ); exit; } } } add_action('init', 'custom_check_delete_account', 11); </code> My question is: How do I set or inject a message or warning message before to redirect and print it after redirect on the "/wp-admin/upload.php" list of attachments? Thanks in advance.
|
I got it: <code> function custom_get_count_before_delete() { global $bp, $wpdb; $user_id = $bp->loggedin_user->id; return $wpdb->get_var( $wpdb->prepare( " SELECT COUNT(DISTINCT p.ID) FROM $wpdb->posts p WHERE p.post_author = %d AND p.post_status = 'inherit' AND p.post_type = 'attachment'", $user_id ) ); } function custom_check_delete_account() { global $bp; if ( $bp->current_component == 'settings' && $bp->current_action == 'delete-account' ) { if ( $count = custom_get_count_before_delete() ) { $message = 'please_delete_your_media_before_delete_your_account'; wp_redirect('http://www.mysite.lh/wp-admin/upload.php?message=' . $message, 301 ); exit; } } } add_action('init', 'custom_check_delete_account', 11); function custom_upload_notice() { echo '<div id="message" class="updated below-h2"> <h2>Primer paso:</h2><p>Para borrar su cuenta, por favor borre todos sus Chaines primero.</p> </div>'; remove_action('admin_notices', 'custom_upload_notice'); } function custom_check_delete_account_upload() { global $pagenow; if ( !isset($_REQUEST['deleted']) ) { if ( 'please_delete_your_media_before_delete_your_account' == $_REQUEST['message'] && 'upload.php' == $pagenow ) { add_action('admin_notices', 'custom_upload_notice'); } } } add_action('admin_init', 'custom_check_delete_account_upload', 11); </code> Please let me know what you think or if there exist a better way to do it.
|
Delete user account - If user has attachments uploaded then redirect (with a message)
|
wordpress
|
I'm querying a custom taxonomy for a post, hoping to get a list of all terms for that post and taxonomy. <code> get_the_terms($post_id, $taxonomy) </code> works, but gives this ungodly array of term objects that will require an extra layer of parsing before I can run the following code: <code> if (in_array($list_of_term_ids, $my_term_id)){ do good stuff... } </code> I'm looking to see whether anyone has come across a native WP function or method that extracts term ids into a flat list before rolling my own utility function, just so I can be using built-in best practices.
|
Well, I had seen it and was thrown off by the first argument, but it does exactly what is needed. From wp-includes/taxonomy.php: <code> function wp_get_object_terms($object_ids, $taxonomies, $args = array()) </code> And to use it as I wished, giving me a flat list of matching IDs, push 'fields'=> 'ids' into $args, like so: <code> wp_get_object_terms($post_id, TAXONOMY_NAME, array('fields'=>'ids')); </code>
|
WordPress built-in method to extract array of term IDs?
|
wordpress
|
Case: I got a set of classes that build form fields based on data from an input array. The class can build the following types of form fields: input (basic, hidden, password) textarea radio checkbox select colorpicker datepicker file upload EDIT: The class uses <code> wp_register_script/_style </code> & <code> wp_enqueue_script/_style </code> to load the scripts & styles. The functions containing the actions are hooked inside the class like this: <code> add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue' ) ); </code> . Example: (Inside <code> functions.php </code> ) <code> // meta box callback function function test_meta_box_cb() { $input_args = array( 'type' => 'color' ,'id' => 'color-id' ,'label' => 'Input Colorpicker Label' ,'opt_name' => 'abc_xyz' ,'value' => '009ee0' ); new FormClass( $input_args, true ); } // add the meta box function add_test_meta_box() { add_meta_box( 'test_box', __('TestBox'), 'test_meta_box_cb', 'post', 'advanced', 'high' ); } add_action( 'add_meta_boxes', 'add_test_meta_box' ); </code> Problem: This way, my call for <code> wp_enqueue_script </code> & <code> wp_enqueue_style </code> doesn't work. I get the form fields rendered, but no scripts or styles. Situation & Backtracing of the problem: So far I could track down the problem to the wordpress core architecture: WP doesn't question what happens inside the callback function until <code> do_action('add_meta_boxes', $post_type, $post) </code> get's called (inside edit-form-advanced.php ). That call happens long after admin-header.php was called (which contains <code> do_action('admin_enqueue_scripts', $hook_suffix); </code> ). Therefore the script & style can't get loaded (if I'm not wrong). Question: How could i load styles before the meta box form fields get called? How could i avoid repeating the same stylesheet over and over again - i want to use <code> wp_enqueue_style </code> & <code> wp_register_style </code> ? I'm open to any answers including those who force me to rewrite my class architecture. Note: I need to use this class in a lot of different szenarios, so bundling it to close together with the <code> add_meta_box </code> function is not good. I'm close to making an abstraction layer that divides the call for the meta box and the style/script part, but why would I want to add another layer above a core function?
|
Your problem is adding the scripts, styles inside the class, and because the class instance is created when the hook <code> add_meta_box </code> is fired, at that time the <code> wp_enqueue_script/style </code> are already finished. A solution for you is adding the scripts, styles outside the function and the class. And because meta boxes are used only at editing pages, you can do as the following: <code> // the editing pages are actually post.php and post-new.php add_action('admin_print_styles-post.php', 'custom_js_css'); add_action('admin_print_styles-post-new.php', 'custom_js_css'); function custom_js_css() { wp_enqueue_style('your-meta-box', $base_url . '/meta-box.css'); wp_enqueue_script('your-meta-box', $base_url . '/meta-box.js', array('jquery'), null, true); } </code> Actually, I wrote a meta box class for WP , that uses another approach. Instead of writing form class for form fields like you did, my class is a wrapper for meta boxes. If you interested in, it's worth to take a look.
|
Loading scripts & styles from a meta box callback function
|
wordpress
|
I want to simply create a link to a page that I know the title (or ID), but I want to make sure it works on any Wordpress install. What is the best way to do this?
|
You probably want to use get_permalink and get_the_title. Example: <code> <a href="<?php echo get_permalink( YOUR POST ID ); ?>"><?php echo get_the_title( YOUR POST ID ); ?></a> </code> Replace YOUR POST ID with the ID of the post you'd like to link to. Post ID's will change from install to install, however, so this might not work as expected. http://codex.wordpress.org/Function_Reference/get_the_title http://codex.wordpress.org/Function_Reference/get_permalink
|
Link to Particular Page Within Template PHP Code
|
wordpress
|
I have 2 custom post types that use some of the same taxonomies. I would like to be able to show all entries in the taxonomy ( no problem here) and then just each of the post types. But I would like to do it without creating a mess of custom pages using a template. Can I set up a function to change the post_type query_var when the link is clicked? SO if I had a set of navigation links in my left sidebar, the set to 'designer' post type would set the post_type query_var to 'designer'. The same would need to happen for the 'boutique' post type navigation links. I think I may need to use some javascript but am unsure. Is this possible? I'm not an expert by an means but I believe this MIGHT be possible, Thanx in advance!
|
You can use <code> pre_get_posts </code> filter hook to set the post type passed by the user: paste this code in your theme's functions.php file: <code> function user_set_type( $query ) { //only on your taxonomy page if ( $query->is_tax('YOUR_CUSTOM_TAXONOMY') ) { //and only if the guesst has selected a type if (isset($_GET['UTYPE']) && !empty($_GET['UTYPE'])){ $query->set( 'post_type', $_GET['UTYPE'] ); } } return $query; } add_filter( 'pre_get_posts', 'user_set_type' ); </code> Change <code> YOUR_CUSTOM_TAXONOMY </code> to the name of your taxonomy, then on your taxonomy page or widgets all you need to do is create links with the post_type as parameters in them eg: <code> <a href="<?php echo get_permalink() . '?UTYPE=designer"; ?>">Designers</a> - <a href="<?php echo get_permalink() . '?UTYPE=boutique" ?>">Boutiques</a> </code>
|
Can I set the post_type query_var as a link is clicked?
|
wordpress
|
Is there any way to create internal anchors without using the HTML rendering option? I don't mind but I guess my customer will ;) Thanks!
|
In the "tinyMCE Advanced" plugin has a special icon for that. The default WordPress installation don't offer the anchor icon/attribute editor.
|
Create anchor from Wysiwyg editor
|
wordpress
|
am running the CFT plugin version 1.9.2 on a 3.1.3 wordpress site and in the admin i did set up 30 input file fields related to a custom post type. It all works fine until the 21st field (and beyond) that does not save any file (small picture) that is selected. I did a local test on wamp, and it all works fine, all the 30 fields are saving (and displaying) well the pictures. I did another test online (different server) on a test installation. I uploaded the database used locally and all the files, checked the site and the post is displaying well the pictures: link and has obviously all 30 saved in the admin. So after that i tried to create a new post on this test site and uploaded the pictures from the admin and bam there goes the same problem, stuck at 20: link . The media upload works fine by the admin works fine, even with high res pics. Here's the beginning of my template's content in the CFT admin: <code> [project-introduction] type = textarea label = Introdução cols = 50 rows = 6 [p-img-1] type = file label = Imagem projeto #1 (capa) [p-img-2] type = file label = Imagem projeto #2 [p-img-3] type = file label = Imagem projeto #3 </code> I also tried to add the <code> blank = true </code> to my <code> type= file </code> fields but didnt seem to help. I'd be glad to have your point of view on this cos am stuck. Thanks in advance.
|
Update, just got the problem back and found a 'real solution, to update the php.ini file at the root of the site with this: <code> max_file_uploads = 100 </code>
|
[Custom field template plugin] Upload limited to 20 inputs file
|
wordpress
|
I'm using this bit of code to generate a page full of items but they won't sort into the menu order, any ideas as to why? <code> <?php $pages = get_pages(array('child_of', 'menu_order')); ?> </code>
|
It should look sth like this <code> <?php $pages = get_pages( array('sort_column' => 'menu_order') ); ?> </code>
|
Sort "get_pages" by menu order not ordering
|
wordpress
|
I'm currently creating a bunch of (empty) pages and performing conditionals such as is_page('Blabla') on it, which increases my page.php significantly. I'm already using require_once for different content, but is there a cleaner way of doing this?
|
Wordpress has a function for including template parts, which you can use for that purpose : get_template_part You can also use <code> include(TEMPLATEPATH . '/includes/myfunction.php'); </code>
|
What's the best way to include php code in to pages?
|
wordpress
|
I have created a custom post type in a plugin for a site I'm working on. I'm allowing users assigned a custom role to add/edit/delete the custom post type. I would like to give these users as little functionality as possible in the admin beyond posting. So I've used <code> remove_meta_box </code> to remove a few panels on the conversation post edit screen for these users via a plugin. One of the meta boxes I've disabled is commentsstatusdiv which includes the form elements for comment status and trackbacks. It seems that if the comments status form element is missing, the <code> comment_status </code> field gets set to off. I'd like to default comments on for the post type and prevent users in this role from changing the comments setting. But when the users save the post comment status is set to off. I can force a setting with the <code> wp_insert_post_data </code> filter. But I don't want to override for admins. I'd like admins to have control. How do I force comments status to be on by default and prevent users of a specific role from changing it while still allowing admins to turn them on/off?
|
Here's what I ended up with. For limited access users, I set comments on when the post guid is empty. Otherwise, I completely remove the comment_status field for those users. That defaults new posts to comments enabled, prevents limited access user edits from switching them off, while allowing admins to override the setting on/off. <code> add_filter( 'wp_insert_post_data', 'handle_comments_setting' ); function handle_comments_setting( $data ) { if ( current_user_can( 'limited_role_name' )) { if ( $data['guid'] == '') { //Default new posts to allow comments $data['comment_status'] = "open"; } else { //Otherwise ignore comment setting for community_member role users unset($data['comment_status']); } } return $data; } </code>
|
Enable comments for post with comments meta box removed
|
wordpress
|
I'm creating a form in a blog for users to register their emails so I can send a newsletter later but I don't want to use any newsletter plugin for that. I'd like to save the emails and than export them to something else like excel or a cvs file. Is there any plugin or any other solution to do that?
|
You have some options: the cformsII plugin, with tracking enabled the Contact Form 7 , plus the Contact Form 7 to Database Extension other may be suitable as well!
|
Saving data to database and exporting to excel
|
wordpress
|
My group does not have command line access to the machine that is running our WordPress instance. However, we would still like to install/update using Subversion. Is this possible? Also, does Subversion need to be on the same machine?
|
You would need to have subversion installed on the same machine and command line access to the machine.
|
Do you have to have command line access to use Subversion with Wordpress?
|
wordpress
|
I am using year/month/post-name permalinks, and also using the download-monitor plugin to handle file downloads. I added rewrite rules to the top of the .htaccess file following the instructions at perishable press . I just did this same thing at another blog and it worked just fine. The only differences are that blog did not use the download-monitor and the install was in the root of the domain, instead of a <code> /blog/ </code> sub-directory. If I comment out this line: <code> RewriteCond %{REQUEST_URI} ^/?feed.* [NC] </code> It works. I am simply curious as to why would this line be in the instructions if it doesn't work? Does it have something to do with the sub-directory? .htaccess: <code> # temp redirect all wordpress feeds to feedburner # from http://perishablepress.com/press/2008/03/25/redirect-wordpress-feeds-to-feedburner-via-htaccess-redux/ <IfModule mod_rewrite.c> RewriteEngine on RewriteBase /blog/ RewriteCond %{REQUEST_URI} ^/?feed.* [NC] RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC] RewriteRule ^feed/?.*$ http://feeds.feedburner.com/mysite [L,NC,R=302] </IfModule> # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine on RewriteBase /blog/ RewriteRule ^download/([^/]+)$ http://www.mysite.com/blog/wp-content/plugins/download-monitor/download.php?id=$1 [L] </IfModule> <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /blog/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] </IfModule> # END WordPress </code>
|
Try this. This format works for me. You don't have to keep repeating IfModule, RewriteEngine, RewriteBase. <code> # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /blog/ RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC] RewriteRule ^feed/?.*$ http://feeds.feedburner.com/mysite [L,NC,R=302] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] RewriteRule ^download/([^/]+)$ http://www.mysite.com/blog/wp-content/plugins/download-monitor/download.php?id=$1 [L] </IfModule> # END WordPress </code> Here is a nice how-to for htaccess: http://codeigniter.com/wiki/mod_rewrite/ And if you continue to have trouble, perhaps consider using a plugin: http://wordpress.org/extend/plugins/tentbloggers-feedburner-rss-redirect-plugin/screenshots/
|
Issue with using .htaccess to redirect feedburner feed
|
wordpress
|
I'm surprised by the fact that my function that I've tacked onto the <code> save_post </code> action fires when I click the "New Post" link in the Admin Dashboard. Note - this is before I've pressed Save or Update , and it fires immediately, not after an elapsed time or auto-update. On the other hand, when I then type in something and press the Publish or Update or Save Draft buttons, the echo statement I've put inside my action handler does not echo out, so it appears that the action is NOT firing at any other time. This may be unrelated. Here's my code: <code> add_action('save_post', 'MyNS\save_event_metabox', 10, 2); function save_event_metabox($post_id, $post){ echo "<h1>YES!</h1>"; } </code> This YES echoes (at the top of the page) when I press the "New Post" link but does NOT echo when I type something and then press Update or Publish or Save Draft . This seems to contradict the documentation on the <code> save_post </code> action and the <code> wp_insert_post() </code> function. Can anyone clear this up for me?
|
When you click 'New Post', you're simply loading the page <code> wp-admin/post-new.php </code> . In doing so, WordPress will always create a new post (an 'Auto Draft') to ensure all other features (such as media uploads) and plugins work as normal, even before you actually save a draft or publish the post. And this, in turn, triggers <code> save_post </code> . Hence your echo. Okay, so why don't I get an echo when updating or publishing? In between saving and the following page load, WordPress is actually sending a <code> GET </code> redirect back to the same page, which appears transparent (you can witness this with an HTTP monitor, such as HttpFox). In other words; You click <code> Update </code> or <code> Publish </code> Browser sends data to server WordPress handles it, and in the process triggers <code> save_post </code> WordPress sends back a redirection header, and exits, before any browser output occurs (including your echo)* Browser follows redirection and loads 'edit post' page. The redirect might seem unnecessary (since you could just <code> POST </code> to the same page), but it's part of a technique known as Post/Redirect/Get in avoiding stackexchange-url ("duplicate form submissions"). If you're attempting to print out custom messages based on a result of a function hooked to <code> save_post </code> , check out stackexchange-url ("some of the answers already here on WA"). *Not strictly true, your echo will in fact occur before the redirect header is sent, but the browser will either discard it, or things happen so quickly it never renders.
|
Why does save_post action fire when creating a new post?
|
wordpress
|
I'd like to display captions with my featured images. This is another feature that should be available by default but for some reason is not. There are a few routines out there that claim to accomplish the task, but they come up blank for me. Is there any reliable way to display a caption with a featured image?
|
To use this you will need to add this to in place of your themes thumbnail function: <code> function your_thumbnail_caption($html, $post_id, $post_thumbnail_id, $size, $attr) { $attachment =& get_post($post_thumbnail_id); if ($attachment->post_excerpt || $attachment->post_content) { $html .= '<p class="thumbcaption">'; if ($attachment->post_excerpt) { $html .= '<span class="captitle">'.$attachment->post_excerpt.'</span> '; } $html .= $attachment->post_content.'</p>'; } return $html; } add_action('post_thumbnail_html', 'your_thumbnail_caption', null, 5); </code> Your current call to the post thumbnail should work, but just in case here is the code I use in the index.php or the post.php (whichever your theme is using). <code> <?php the_post_thumbnail(); ?> </code> Now when you add a post thumbnail you can type your caption for the image. Make sure you save the image after adding the thumbnail. You can also add captions to existing thumbnails by going to the post edit screen, select the post and click the current featured image to bring up the image caption area.
|
Displaying caption with featured image
|
wordpress
|
What is the best way to store post meta in an array (using a custom write box, know how to do that) so that all post meta is in a single custom field?
|
From codex: $meta_value (mixed) (required) The value of the custom field you will add. An array will be serialized into a string. Default: None So <code> <?php add_post_meta(7, 'fruit', 'banana', 'apple', 'tornado', 'bob saget') </code> To grab them you can also use http://codex.wordpress.org/Function_Reference/get_post_custom_values besides just <code> get_post_meta </code> .
|
How to store post meta in an array?
|
wordpress
|
WordPress auto corrects the permalinks(URLs) even if it is entered incorrectly. For e.g. WordPress will land you in <code> example.com/some-post </code> even if you enter <code> example.com/idontexist/some-post </code> or even <code> example.com/some </code> It could be that, WordPress uses RegEx like or some matching algorithm that compares from right to left and if it finds a match, it will take you to the page even if there are <code> /.*/ </code> left on the left. Just a guess! How does WordPress do this? Edit: I also noticed that the .htaccess file checks for virtual file/directories using <code> !f </code> and <code> !d </code> and redirects the request to index.php on the blog folder.
|
The redirect_canonical function in /wp-includes/canonical.php is called on any given URL and will attempt to best-guess the URL the user wanted, and redirect them to there, when a URL does not exist. It has a whole huge amount of code to do this for all sorts of common errors.
|
How does WordPress handle permalinks?
|
wordpress
|
I want to grab all posts from an author under category X. Right now, I am using 4 separate loops to do this for 4 different categories. Is there a better way to do this? <code> query_posts </code>
|
Have a look at the category parameters of WP_Query
|
Instead of 4 loops, how can I do it better?
|
wordpress
|
I've created a custom taxonomy and I want to add it as an option for custom menus (under Appearance > Menus). How do I get it to show up there (see the illustration, I want it to show up where the red square is).
|
Your custom taxonomy should show up as an option for custom menus, if you have <code> 'show_in_nav_menus' => true </code> as a parameter when you register your post type with <code> register_post_type() </code> . You can check all the available parameters in the codex entry http://codex.wordpress.org/Function_Reference/register_post_type#Arguments
|
How do I add a custom taxonomy as an option for menus under "Appearance" > "Menus"
|
wordpress
|
Im wanting to show a profile/logo pic on author.php via a simple shortcode: <code> function wpaluploader_showauthorimage() { $wpaluploader_authorlogo = '<img src="' . get_bloginfo('url'). '/wp-content/uploads/wpal_logos/'.$curauth->ID.''.get_option(wpal_mime) .'"/>'; return $wpaluploader_authorlogo; } </code> I know i need to get: global $author inside this function, however no matter how i go around it i can get it to work, i have a similar shortcode for all other posts/pages which doesnt need the global and $author declarations as they use the wp loop to get the info. The plugin im working on takes an uploaded image from frontend, renames it to user_id and pops it in a folder, so its pretty important that i can pull this curauth-> ID info to display it on author.php via the shortcode edit, complete working code: <code> function wpaluploader_showauthorimage() { global $author, $profileuser; if(isset($_GET['author_name'])) { $curauth = get_userdatabylogin(get_the_author_login()); } else { $curauth = get_userdata(intval($author)); } $wpaluploader_authorlogo = '<img src="' . get_bloginfo('url'). '/wp-content/uploads/wpal_logos/'.$curauth->ID .''.get_option(wpal_mime) .'" />'; return $wpaluploader_authorlogo; } </code>
|
<code> /wp-admin/user-edit.php </code> starting on line 99. Just check the hooks and filters there and how <code> $profileuser </code> get's called. (Pay attention on the switch.) :)
|
Getting $curauth-> ID to work inside a shortcode
|
wordpress
|
I'm creating a plugin that uses jQuery to modify some css, but what I can't figure out is how you can control the execution of the jQuery with WordPress plugin options (like checkboxes true/false). Can WordPress options be used as "variables" in jQuery? Or would every case require a unique .js file?
|
Variable can be passed to jQuery or any javascript using <code> wp_localize_script </code> . Example: <code> add_action( 'template_redirect', 'prefix_enqueue_vars' ); function prefix_enqueue_vars() { $script_vars = array( 'setting_1' => get_option( 'some_option' ), 'setting_2' => get_option( 'another_option' ), ); wp_enqueue_script( 'my_script', 'path/to/script.js', array( 'jquery' ), true); wp_localize_script( 'my_script', 'unique_name', $script_vars ); } </code> How to get the variables in your javascript: <code> jQuery(document).ready(function($) { $var_1 = unique_name.setting_1 $var_2 = unique_name.setting_2 }); </code> WordPress will output your variables between <code> <sript> </script> </code> tags before enqueuing the javascript file so they will be available to use. See wp_localize_script from Otto on WordPress for more information. Edit: Try adding the variables to a function that returns the value. I'm using the exact code below and it works. <code> wp_localize_script( 'cmb-scripts', 'MaxChar', array( 'charlimit' => c3m_get_the_size( $excerpt_length[0] ) ) ); </code> The function that returns the variables below: <code> function c3m_get_the_size() { global $post; global $prefix; $box_size = get_post_meta( $post->ID, $prefix.'box_size', true ); if ( $box_size == 'single-single' ) { $excerpt_length = 150; } elseif ( $box_size == 'single-double' ) { $excerpt_length = 150; } elseif ( $box_size == 'single-triple' ) { $excerpt_length = 150; } return $excerpt_length; } </code>
|
WordPress plugin options and jQuery
|
wordpress
|
I like to display only 20 lines of post with the read more link using <code> the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>' ) ); </code> But it shows full content . How can i strip it .please help me !
|
You need to add a more quicktag to your content See here: http://codex.wordpress.org/Customizing_the_Read_More
|
display 20 lines only with the_content
|
wordpress
|
Wordpress has wp_oembed_get , which I use to get rich media content with embed.ly . I've previously used oEmbed api calls such as this . As you can see it provides thumbnail_url, which I like to use instead of embedding the video. How can I do this with wordpress? Thanks!
|
Use the oembed_dataparse filter to modify the resulting HTML output by any given oembed call. Example: <code> add_filter('oembed_dataparse','test',10,3); function test($return, $data, $url) { if ($data->provider_name == 'YouTube') { return "<img src='{$data->thumbnail_url}'>"; } else return $return; } </code> Then putting this in a post: <code> [embed]http://www.youtube.com/watch?v=oHg5SJYRHA0[/embed] </code> Will give you a picture of Rick Astley instead of a flash video of him. :) Edit: Note that WordPress caches oEmbed results in postmeta. So after making your code, you'll have to go and Update a post for it to know to go re-get the oEmbed data and have code like this take effect. In case you want to do testing and such.
|
oEmbed, thumbnails and wordpress
|
wordpress
|
After spending most of the day looking for solutions and trying them out, I decided to explain my problem here. I am aware that this subject has been covered and as you will see I am using code that has been suggested here and over at ottopress, but I still cannot figure it out. I have a custom post type called 'review' (non-hierarchical) I have a custom taxonomy called 'reviewcats' (hierarchical) I have a whole bunch of terms under the taxonomy of which 3 are main and the rest children: featured applications (containing children) games (containing children) On my homepage template I am first showing the latest review (custom post type) that has the term 'featured' from the 'reviewcats' taxonomy. That review also contains the terms 'applications' and a child thereof. Under the Feature I would like to show the 10 most recent reviews (custom post type), but not the one from above, the one with the term 'featured' I have been trying with the code below (and many variations of it), but cannot get it right. Can anyone shed light on this dark matter for me please? Much appreciated! <code> $recentapps_query['tax_query'] = array( 'relation' => 'AND', array( 'post_type' => 'review', 'post_status' => 'publish', 'posts_per_page' => 10, ), array( 'taxonomy' => 'reviewcats', 'terms' => array('featured'), 'field' => 'slug', 'operator' => 'NOT IN', ), ); query_posts($recentapps_query); </code> if needed, the sandbox site is http://senl.in/jOaalP
|
Firstly, your tax query is a little jumbled. The first nested array should actually be at the 'root' of your <code> query_posts() </code> argument, with <code> tax_query </code> as a key among them; <code> array( 'post_type' => 'review', 'post_status' => 'publish', 'posts_per_page' => 10, 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'reviewcats', 'terms' => array( 'featured' ), 'field' => 'slug', 'operator' => 'NOT IN', ) ) ); </code> However , forgive me if I'm mistaken, but I think your query could be a lot simpler - simply exclude the 'featured' review you've just grabbed; <code> query_posts( array( 'post_type' => 'review', 'post_status' => 'publish', 'post__not_in' => array( $post->ID ) // $post *should* be the featured review, since it was the last post queried/worked on ) ); </code>
|
show 10 most recent custom post types excluding the one(s) from specific custom taxonomy
|
wordpress
|
I have a custom taxonomy template page in my theme. Essentially, when someone clicks on a term link into this taxonomy, I -ALWAYS- want to add a specific post-type to the query. I'm not entirely sure how to do this, I've found some functions that are included in PHP 5.3 that seem like they might do it, but I have 5.2 installed on my host. But, I essentially want to take the current $wp_query, add 'post-type' => 'my-custom-post-type' and then continue on with $wp_query in my loop. Is this possible? I'm probably over tired and over stressed and there's a much simpler way to do this and I just can't think of it =D Thanks! EDIT---- Ok, Clearly my methodology here is WAY off. Probably a direct result of being tired. I did manage to find code to manipulate $wp_query to add what I wanted; but it did not give the desired result: <code> function _my_method(&$item, $key) { if ($key == 'post_type') { $item = 'backend_data'; } } array_walk_recursive( $wp_query , '_my_method' ); </code> So, in the QUERY_VARS part of the array, now post_type has a value, backend_data. Except that farther on in the $wp_query array I can still see it querying every post type available. <code> [request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (35) ) AND wp_posts.post_type IN ('post', 'page', 'attachment', 'company', 'backend_data', 'ps_promotion') AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 1 AND wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10 [posts] => Array ( [0] => backend_data [1] => stdClass Object ( [ID] => </code> and then the two posts its pulling which are in 'posts'... it does however list backend_data again before it starts pulling post information. But I clearly don't know enough about the inner workings of wordpress and arrays to understand WTF it's doing at this point =D EDIT ----- Okay, now I'm just convinced my brain has gone mushy and there has got to be a more wordpressy way to do this cause php array hacking doesn't do the trick =D I tried throwing some wp_reset_query(); first before and then after my above function, and it still outputs the same thing with all post-types accounted for. So, I guess I added all this to my question for no reason :(
|
You can use <code> pre_get_posts </code> filter hook to check if you are on the taxonomy page and if so just add your custom post type to the query something like this: <code> function add_my_type( $query ) { if ( $query->is_tax('YOUR_TAXONOMY') ) { $query->set( 'post_type', array('post','YOUR_CUSTOM_POST') ); } } add_filter( 'pre_get_posts', 'add_my_type' ); </code>
|
On Taxonomy Template page, want to add Post_Type
|
wordpress
|
In the functions.php, I have the following code added: <code> add_post_type_support( 'page', 'excerpt' ); </code> This allows pages to have excerpts. The reason I want an excerpt is because I want to call only pages with excerpts to be one of 3 modules on the home page. On the front page, in my home.php file, these 3 modules will show the titles and excerpts of the pages in which I have added an excerpt. At anytime, the editor should be allowed to change the placement or page so that any existing page could theoretically become a module on the home page. For example, I have an About, New Patients and Services page, all three of which I have added text to the excerpt field (I will leave all other excerpt fields blank on pages which don't need to appear on the front page). On home.php, in the order I just listed, I want the title and excerpt of each page to show up as three columns. Here's how I intend to style it: http://i.stack.imgur.com/jOPb0.png It's possible these 3 modules will either need an order change or replaced by another page, which is why I'm looking for dynamic modules. I have created two custom fields, called <code> home_widget </code> and <code> order </code> . <code> home_widget </code> is equal to either <code> true </code> , whereas <code> order </code> is equal to the order they should appear on the page. This code is wrong, but I'm looking for similar logic: <code> <?php $pageExcerpt = get_the_excerpt(); if (is_page() && $pageExcerpt !== '') { the_excerpt(); } ?> </code> In other words, if a page exists AND it has an excerpt, then call the_excerpt() but do it in the order I define by custom field entry. This allows for dynamic insertion as needed. How do I write this code to work as I stated?
|
Initially, Wyck told me to study the WP_Query article on WordPress's site . This was very overwhelming to try and pick up, and I searched the web for articles that might give me a quicker answer, but I couldn't find anything that was relevant. This is similar but different than Wyck's answer, but I only figured it out by studying a new article just released on Smashing Magazine on How to Build a Media Site on WordPress . I would still prefer to query whether a page contains an excerpt or not, and only show that page, but this is a good solution in the interim. <code> <?php // Get the pages with excerpts $excerpt = new WP_Query( array( 'post_type' => 'page', // Tell WordPress which post type we want 'posts_per_page' => '3', // Show the first 3 'orderby' => 'meta_value', // Order by meta_key, defined on next line 'meta_key' => 'order', // Look for numerical value in this key 'order' => 'ASC', // Ascending order 'meta_query' => array( // Return only pages with home_widget meta key set to true array( 'key' => 'home_widget', 'value' => 'true', ) ) ) ); ?> <ul class="excerpt"> <?php //Start new loop looking for pages only with $excerpt from above while ( $excerpt->have_posts() ) : $excerpt->the_post(); ?> <li class="module"> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> <p><?php the_excerpt(); ?></p> </li> <?php endwhile; ?> </ul> </code>
|
I want Page titles and excerpts to show up on home.php in certain order
|
wordpress
|
I've added a role of "Customer" and I am working on customizing the Users Screen for that role. What I'd like to do is customize columns based on that particular role. Note: For example, take a look at the screenshot. How would I remove the reference to the posts column for only the customer role?
|
Thanks to Mike23 for the tip. Here's the code that I'm using to add a column to only the "customer" role: <code> if( $_GET['role'] == "customer" ) { add_filter('manage_users_columns', 'add_ecommerce_column'); add_filter('manage_users_custom_column', 'manage_ecommerce_column', 10, 3); function add_ecommerce_column($columns) { $columns['ecommerce'] = 'Ecommerce'; return $columns; } function manage_ecommerce_column($empty='', $column_name, $id) { if( $column_name == 'ecommerce' ) { return $column_name.$id; } } } </code> Any ideas or suggestions for improvement are very welcomed.
|
Customize Admin Users Screen based on Role
|
wordpress
|
Here's the code for a custom metabox. Very simply, how would I resize the textarea box? I'd like to add an expression such as cols="50" rows="5". <code> // Echo out the field echo '<p>Enter the location:</p>'; echo '<div class="customEditor"><input type="textarea" name="_location" value="' . $location . '" class="widefat" /></div>'; echo '<p>How Should People Dress?</p>'; echo '<input type="textarea" name="_dresscode" value="' . $dresscode . '" class="widefat" />'; </code> (Source: http://wptheming.com/2010/08/custom-metabox-for-post-type/ ) Thanks.
|
You could try styling it with CSS by adding an ID or a class to the textarea and inserting styles into the wp_admin head. Or, a quick way would be to do somehting like this : <code> echo '<textarea name="_dresscode" class="widefat" style="width:400px!important;height:80px!important;" >' . $dresscode . '</textarea>'; </code> If not, have you tried simply : <code> echo '<textarea name="_dresscode" class="widefat" cols="50" rows="5" />' . $dresscode . '</textarea>' </code>
|
Sizing textarea field in custom metabox
|
wordpress
|
I am using <code> archive-{post_type}.php </code> for queries of a custom post type. I want the system to use <code> archive.php </code> for category searches but it is defaulting to <code> category.php </code> which I am using for category searches (different categories) for regular posts. Does anyone have an idea of what could be going wrong?
|
I am not sure what you mean by category searches ? In <code> is_category() </code> branch of template hierarchy <code> category.php </code> precedes <code> archive.php </code> , it is intended and wanted behavior. If you want to change template behavior for specific category you will need to override that logic, likely in <code> template_redirect </code> hook or around that.
|
archive-{post_type}.php is defaulting to category.php vs. archive.php on category searches
|
wordpress
|
After commenting on one of my posts, WordPress redirects me to another random post. Only after, when checking the previous post, I can see that my comment was posted. Still, why is WordPress sending me to a random post after commenting? Here's my comments.php file and here's my website (please don't publish it anywhere else, as I'm launching it tomorrow). Feel free to test the comments, though. I'll clear then before I launch it. Any suggestions? PS: I'm using no plugins and the bug doesn't work on other themes. Also, I'm using pretty <code> /%postname%/ </code> permalinks.
|
You're doing something that is affecting the value of the main $post variable in an incorrect manner. The WordPress template consists of one main Loop. That Loop, on a single post page, shows the one and only Post (or Page). When the comments form runs, it expects the last post from the Loop to be the one you're commenting on. However, if you mess with the main Loop after the fact (like by doing another query_posts() or altering the global $post variable in any way), then you'll muck that bit up. This is what is happening on your posts. If you look at the source of http://joaoramos.org/sala-de-ser/ you'll see that that post's ID number is 635, but the comments form thinks it's 630. I'm surprised the comments go to the right pages. Specifically, what is happening here is that your sidebar is doing-it-wrong™. If you'll notice, the last entry in your sidebar is for http://joaoramos.org/via/ which, BTW, is post number 630. When you make secondary Loops, you should create new WP_Query objects instead of modifying the main one and your loop shouldn't modify any global variables, if possible. No quick fix to this one. Rewrite your sidebar to not muck up the main Loop. Edit: Didn't know about this one. Just add a call to wp_reset_postdata() after the sidebar loops run to fix up the global $post information back to what it should be.
|
Why is WordPress redirecting users to random posts after commenting?
|
wordpress
|
I have simple function to show an image: <code> function helloworld() { echo '<img src="'.$link.'" alt=".$alt." />'; } </code> I would like to pass strings link and alt to the function something like that: <code> <?php helloworld('link=www.google.com&alt=picture'); ?> </code> How can I achieve something like that?
|
I agree that this is more of a basic PHP question, but I can see where you're coming from. A lot of WordPress functions accept query string formatted parameters like you're trying to do, so it would be a good idea to know exactly how they do it. Shortcode functions are guilty in particular. First of all, you need to modify your <code> helloworld() </code> method to accept arguments. Then you pass them through a WordPress function that matches them against defaults. Then you'll have access to them elsewhere: <code> function helloworld( $args = '' ) { $defaults = array( 'link' => 'www.google.com', 'alt' = 'picture' ); wp_parse_args( $args, $defaults ); extract( $args, EXTR_SKIP ); echo '<img src="' . $link . '" alt="' . $alt . '" />'; } </code> Setting <code> $args = '' </code> in the function means that the parameter is optional. If nothing's passed in, your function will use the defaults you define instead. So if you call <code> helloworld('link=www.facebook.com') </code> you'd see <code> <img src="www.facebook.com" alt="picture" /> </code> . If you called <code> helloworld('alt=link') </code> you'd see <code> <img src="www.google.com" alt="link" /> </code> . Remember, the function will use whatever you list in the <code> $defaults </code> array if you don't override it with something else. The <code> extract() </code> function will pull out each element of the array and put it into its own variable. You don't need to do this, though. If you leave it out, you'd just referece <code> $args['link'] </code> instead of <code> $link </code> . It's really up to you.
|
Pass strings to plugin function
|
wordpress
|
What is the best method to retrieve the title tag of an external page using the http api? The snippet below will get the body but I can't find the right documentation about how to just get the tag. :/ <code> $url = 'http://wordpres.org'; $response = wp_remote_get( $url ); if( is_wp_error( $response ) ) { echo 'Something went wrong!'; } else { print wp_remote_retrieve_body( $response ); } </code> Edit: This code snippet gets both the screenshot and title of an external page (Thanks again @Bainternet). With a little editing this could be an easy way to display the link post format. <code> <?php $content = get_the_content(); $url = strip_tags($content); //assumes only a url is in the_content $width = '150'; $cleanurl = urlencode(clean_url($url)); $fullurl = 'http://s.wordpress.com/mshots/v1/' . $cleanurl . '?w=' . $width; // return title tag of an external page // stackexchange-url get_page_title($url){ if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC. '/class-http.php' ); $request = new WP_Http; $result = $request->request( $url ); if( is_wp_error( $result ) ) return false; if( preg_match("#<title>(.+)<\/title>#iU", $result['body'], $t)) { return trim($t[1]); } else { return false; } } $title = get_page_title($url); echo '<div class="grid_4 alpha"><a href="' . $url . '"><img src="' . $fullurl . '" width="' . $width .'px" /></a></div>'; echo '<div class="grid_10 omega"><h3>'; if ($title !== false){ echo $title;} echo '</h3><p>' . $content . '</p></div>'; echo '<div class="clear"></div>'; ?> </code>
|
here is a function i have for that: <code> function get_page_title($url){ if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC. '/class-http.php' ); $request = new WP_Http; $result = $request->request( $url ); if( is_wp_error( $result ) ) return false; if( preg_match("#<title>(.+)<\/title>#iU", $result['body'], $t)) { return trim($t[1]); } else { return false; } } </code> Usage: <code> $title = get_page_title('http://www.google.com'); if ($title !== false){ echo $title;} </code>
|
How to get title tag of an external page with http api?
|
wordpress
|
I'm using ALO EasyMail Newsletter plugin in order to send newsletters to subscribers. I have setup settings which is mainly the email address and try to send an email for subscribers but it doesn't send anything. Is there any special configuration for wordpress to do? Thanks
|
Sounds like a server config problem. Try looking for a custom SMTP plugin and set it up with that.
|
WP can't send newsletters
|
wordpress
|
I would like to create a visual recipe site, which lists how to make a dish in step by step through pictures.. Is it possible to create a custom page template where i can the following fields. 1.Dishname(title) 2.Introduction(Brief info) 3.Ingredients 4.upload photo input.. followed by add more pic Is it possible in wordpress, you have any effective ideas? please share :) here is a screenshot of what i have in my mind http://i.stack.imgur.com/rsWKg.png
|
Short answer, yes Wordpress can do this sort of things. You could create a custom post type called "Recepies", and a custom taxonomy called "Ingredients". Everything else is already included in the default WP setup, "Dishname" would be your post title, "Introduction" can be the "Excerpt" field, and photos are handled by the media gallery.
|
I want to create a Visual Recipe site on WordPress, any suggestions or tips on how i can do it?
|
wordpress
|
I am constructing a theme for Wordpress that uses PAGES for products for sale on a site. This Product will have properties like DESCRIPTION, PRICE that will be stored to custom fields. I was wondering if it is possible to retrieve the values from the custom fields and forward them to a form which is stored in another wordpress page. This form is a request for quotation form that the user fills out. Thank you.
|
When generating the form all you need is the post id of the product pages and you can use get_post_meta function to retive the information about that product , so basically you just need to pass the product post id. eg: <code> $price = get_post_meta($product_post_id,'price',true); </code>
|
How to retrive Custom Fields as Values for a Form field
|
wordpress
|
I guess the title says it all. Short of creating a page with a custom template that links all the posts with a given tag (this is NOT a scalable solution, particularly if you want to let a customer do this), how would you add a menu item that takes you to a tag archive?
|
When setting up custom menu click <code> Screen Options </code> (top right, near <code> Help </code> ) and check <code> Post Tags </code> there. You will get metabox that will allow to add links to tag archives as menu item.
|
What is the best way to create a menu item that links to all posts with a certain tag?
|
wordpress
|
Can someone help me disable the <code> Install Themes </code> link from the WordPress back-end?
|
You can essentially 'block' the capability <code> install_themes </code> using; <code> function __block_caps( $caps, $cap ) { if ( $cap === 'install_themes' ) $caps[] = 'do_not_allow'; return $caps; } add_filter( 'map_meta_cap', '__block_caps', 10, 2 ); </code>
|
Wordpress disable 'Install Themes' tab
|
wordpress
|
Just wondering if there is a way to remove WordPress's default function of adding a tag around an inserted image. I assume its a "remove_filter" function like you can do for WPAutoP, but all my searches only turned up links for gallery plugins, etc. Thanks in advance, Pete
|
This is not able to be changed through a filter. In WordPress 2.9.2 and lower, the setting can be changed in /wp-admin/options.php. The image_default_link_type field is set to "file" by default. If you set it to "none", then scroll to the bottom and save, it will disable media links. This option has been removed from options.php in WordPress 3. For versions 3.0 and higher you need to add the following to your theme's functions.php file or write it into a plugin: <code> update_option('image_default_link_type','none'); </code> Note: Getting rid of the link affects all media. If you upload .zip, .pdf, music or other types of media that you want people to download from your site you will have to manually add links to these. There is currently an open ticket on the trac for this: http://core.trac.wordpress.org/ticket/15924
|
Default Image Link Removal
|
wordpress
|
Currently I'm using this shortcode within a post http://pastebin.com/K7WC2Lk3 which works great, but somehow I can't add any text in front of this shortcode, without posting it the other way around. In example some dummy text [etalage] will always be shown as [etalage] some dummy text I've read to gather the value into a variable and return it, but I have to admit, I'm not entirely sure how to accomplish this best
|
Here's your updated shortcode function which puts output in a variable and returns it. Note that you have to use functions that return data rather than output directly, in this case <code> get_the_post_thumbnail() </code> is used in place of <code> the_post_thumbnail() </code> <code> function cor_etalage_add_shortcode() { $output = '<div id="etalage"><ul>'; $the_query = new WP_Query(array( 'post_type' => array( 'portfolio' ) )); while ($the_query->have_posts()) : $the_query->the_post(); $output .= '<li>'. get_the_post_thumbnail($post->ID,'etalage') .'</li>'; endwhile; wp_reset_postdata(); $output .= '</ul></div>'; return $output; } add_shortcode('etalage', 'cor_etalage_add_shortcode'); </code> EDIT oops, forgot to pass the post ID with <code> get_the_post_thumbnail </code> , updated.
|
Can't add text in front of shortcode
|
wordpress
|
I'm thinking of using a taxonomy archive template to list out my taxonomies and entries (I'm using a hierarchical structure) and then combining this with the WordPress pages module to apply static content to each taxonomy level. Each level will essentially have its own page and will list either its children or entries (posts). The idea I had was to create a page with the same slug as my taxonomy and then assign the taxonomy archive template to this page. Just wondered if anyone had done this before, or if its even possible.
|
Short answer : Yes its posible! long answer: Not the best way to do waht you are trying to do, when i need static content to go along with taxonomy terms i use the terms description field and in case that i need even more i just add my extra custom fields to the taxonomy term, here is a nice tutorial add extra fields to WordPress Custom taxonomies . this way the creation of the terms archive beacomes much more dynamic.
|
Is it possible to use pages to apply static content to each taxonomy level?
|
wordpress
|
When I click on preview a post, I get the following error: Catchable fatal error: Object of class WP_Error could not be converted to string in functions.php on line 288 The line 288 is as follows <code> echo get_category_parents($cat, TRUE, '' . $delimiter . ''); </code> Any ideas on this please?
|
The only way that function returns an instance of <code> WP_Error </code> is if <code> $cat </code> (in your example) has an empty value. You need to check the return before doing anything with it. Replacing that line with this should fix the problem: <code> echo is_wp_error( $cat_parents = get_category_parents($cat, TRUE, '' . $delimiter . '') ) ? '' : $cat_parents; </code>
|
What does this mean: Object of class WP_Error could not be converted to string
|
wordpress
|
I was wondering if there was a way to unregister a widget that gets declared in the functions.php file of a parent theme from a child theme, I understand that the child's function.php file gets loaded first so I don't know how to unregister it when it hasn't been created yet. Thanks all in advance!
|
Assuming the Parent Theme's Widget is registered at the <code> widgets_init </code> hook, all you need to do is wrap your <code> unregister_widget() </code> call inside of a function, hook that function into <code> widgets_init </code> , and give your hook a higher priority number than the Parent Theme's <code> widgets_init </code> -hooked function. Assuming the Parent Theme hooks into <code> widgets_init </code> without giving a priority number, the function will default to <code> 10 </code> . So, just give your hook call a priority of <code> 11 </code> or greater.
|
How to unregister a widget from a child theme
|
wordpress
|
I'm trying to unregister a post type from a child theme but I haven't been able to do so, the code in the funcions.php file on the parent theme is something like this: <code> add_action( 'init', 'mc_projects' ); function mc_projects() { register_post_type( 'project', array( // Default options.... ) ); } </code> What I tried to do in my child theme was to remove the mc_project action from the init hook like this: <code> remove_action('init', 'mc_projects', 11); </code> But it didn't work, even when I set the priority to some higher value, am I doing something wrong?
|
Try the following in your child theme functions file. <code> add_action( 'init', 'remove_mc_projects' ); function remove_mc_projects() { remove_action('init', 'mc_projects'); } </code>
|
Unregister post type from child theme
|
wordpress
|
Guys i have a custom file that is not part of the wordpress and its not a part of the plugins. How can i add it to the permalink solution? For example: Custom file name - example123.php Permalink solution - http://mysite.com/example
|
You should make a template out of your file and then in WP create a page named "Example" to which you assign this template.
|
Wordpress Custom File Permalink
|
wordpress
|
My question : how many custom fields or even taxonomies WordPress can handle without affecting performance? The reason I ask, is because I started building a custom theme and I might need to have around 10 to 20 custom fields, and thinking if this will affect the speed of the site. I understand that speed also depends on server/hosting and number of visits, cache techniques, etc... I also expect that a post with one custom field will be faster then one post with ten custom fields. But, let's say a site that haves around 10,000 visits a day with a post with one custom field will the speed difference be much more different from a site with the same 10 000 visits a day with a post with 10 custom fields. Just trying to figure it out how much of a difference a custom field can make. Also in terms of custom searching using wp_query and custom fields parameters will the speed be affected. Thank you.
|
In the case of custom fields- if you fetch them in a single query to the database, fetching one or ten is not going to differ much, it's the same relatively simple query in both instances. If you were to do a lot of complex meta queries on those fields you'd definitely see a performance hit. I think same for taxonomy, if you're doing complex taxonomy queries, that's a big hit. Simple queries to fetch terms are relatively cheap. Searching will certainly tax the server more if you've got ten times as much data, text searches are pretty expensive.
|
Custom Fields and performance
|
wordpress
|
I need to list the next seven days no matter what day it is. If its monday, it starts with today and lists 7 days, if its friday it starts with today and lists 7 days from today. Next I need to show any events for that day. IF there are no events for a given day it simply lists a default graphic. I am going to make a featured event for a each day and eventually set it up so that it just shows that one but for now I just want to list the next 7 days and any events contained within them. I have two piece that don't fit together very well. First: <code> <?php $cur_day = 'current_day'; $last = 'last'; $date = date('o-m-d'); $ts = strtotime($date); $dow = date('w', $ts); for ($i=0; $i<7; $i++, $ts+=86400){ ?> </code> This will list each of the next 7 days starting with today. <code> $event_query = new WP_Query( array( 'post_type' => 'event', // only query events 'meta_key' => 'event-date', // load up the event_date meta 'orderby' => 'meta_value', 'order' => 'asc', // ascending, so earlier events first 'meta_query' => array( array( // restrict posts based on meta values 'key' => 'event-date', // which meta to query 'value' => $event_date, // value for comparison 'compare' => '=', // method of comparison 'type' => 'NUMERIC' // datatype, we don't want to compare the string values ) // meta_query is an array of query ites ) // end meta_query array ) // end array ); // close WP_Query constructor call </code> This lists the next seven days but doesn't do well with the events... I am looking to duplicate this: http://www3.dmagazine.com/events with cpt's thanks PLEASE HELP
|
You should definitely do it in just a single query. then set up a simple loop, each iteration get that day's date. then loop through all posts and compare the date to the date meta field, and output if it matches. I think something like this should work... <code> $today = date("o-m-d"); $future = strtotime ( '+6 days' , strtotime ( $today ) ) ; $future = date ( 'o-m-d' , $future ); $event_query = new WP_Query( array( 'post_type' => 'event', 'meta_key' => 'event-date', 'orderby' => 'meta_value', 'order' => 'asc', 'meta_query' => array( array( 'key' => 'event-date', 'value' => array($today,$future), 'compare' => 'BETWEEN', 'type' => 'DATE' ) ) ) ); for ($i=0; $i<7; $i++){ $thedate = strtotime ( '+'.$i.' day' , strtotime ( $today ) ) ; $thedate = date ( 'o-m-d' , $thedate ); echo $thedate; // loop thru all posts and check $thedate against your date meta // and output if it matches // then rewind_posts(); to set it up for the next day } </code>
|
How do I list the next 7 days and any events (cpt) contained in those days
|
wordpress
|
hi i'm trying to insert a short code into a Text widget but all its doing it showing the code and not processing it. <code> <?php echo do_shortcode(' [stream embed=false share=false width=500 height=560 dock=true controlbar=bottom bandwidth=high autostart=false playlistfile=http://www.xxx.com/wp-content/uploads/videos/playlist.xml config=http://www.xxx.com/wp-content/uploads/videos/config_for_playlist.xml playlist=bottom repeat=none /] '); ?> </code>
|
the text widget doesn't do php.... Here's my fave solution http://wordpress.org/extend/plugins/php-code-widget/ It's from Otto, so ya know it's good. Based heavily on the text widget, but allows for php
|
Inserting shortcode [stream /] into a Text widget
|
wordpress
|
I am currently having some CSS problems with Google Chrome. Slider is overlapping with the buttons on the right side. My theme layout (CSS) works fine with Firefox, and IE but not in google chrome. Something to do with margins and alignments I think. Here's the link: http://tigerdm.com.au/
|
Not a WordPress question, but if you remove the width from #slideshow-wrapper on line 4 of gallery-slider.css it sort of fixes rendering.
|
Google Chrome CSS issues
|
wordpress
|
Just wondering if its possible to redirect existing posts which are permalinks of just %post_name% to %post_name%-%postid% ? Is there a plugin which can pick this up? Dont want to lose rankings on the content so would want it handled with legitimate 301 redirect. Appreciate any advice if someone has had to deal with this before? Many thanks :)
|
Have a look at the Redirection plugin.
|
301 Redirecting posts without %postid% (just %post_name%) in permalink to ones with %post_name%_%postid%
|
wordpress
|
I'd like to make a query that returns the children pages of various parent pages. Unfortunately the <code> post_parent </code> attribute of <code> WP_Query </code> accepts only one value. What do you suggest ?
|
POST does not have parents, but categories. Only PAGE can have parent. So, the question is, what do you want to get? In case of getting POSTS from different categories, just use <code> get_posts </code> and add multiple categories. As for pages, just use <code> get_page_children </code> .
|
How to make a query returning pages from multiple parents
|
wordpress
|
I have been using the IntenseDebate Comments plugin , but am unhappy with it and would like to uninstall. Supposedly due to the data synchronization feature , it shouldn't be a problem to just disable and remove it, but of course there's nothing on their support site about how to uninstall ... Does anyone with experience removing it have survival tips for me? Also, what will I lose in the process of uninstalling (e.g. Gravatar icons)?
|
There is a place to find this out on there site http://intensedebate.com/faq#li58
|
Uninstalling IntenseDebate
|
wordpress
|
I'm tired of typing in lists of counries in my "Countries" taxonomies. What's a good way to bulk import a long list of terms into Wordpress ?
|
Put list in PHP array, loop through it, use <code> wp_insert_term() </code> on each.
|
Is there a way to import terms into Wordpress?
|
wordpress
|
I'm curious if other PHP code files besides functions.php, WP template files and style.css in a child theme actually override the same file in a parent them? I am working with a client that has a theme with child theme support, however, there are no hooks or actions to unload for the functions that I wish to override. Looking for a clean way to perform this override whith customized code that won't be overwrote on upgrade.
|
It depends entirely on a) what functions and template files you're talking about, and b) how those functions are defined, or template files are called, in the Parent Theme. If the Parent Theme uses <code> get_template_part() </code> , then you're golden. If the Parent Theme uses <code> get_stylesheet_directory_uri() </code> or <code> STYLESHEETPATH </code> , then you can override, with caveats. If the Parent Theme uses <code> get_template_directory_uri() </code> or <code> TEMPLATEPATH </code> , then you're going to have a difficult time. With functions, if the Parent Theme wraps the functions in a <code> function_exists() </code> conditional, then you can simply override such functions by declaring them in the Child Theme. With hooks, you can simply <code> remove_action </code> or <code> remove_filter </code> .
|
Do all files in child theme override the parent?
|
wordpress
|
I'm creating an author.php page and I'd like to show comments as well as posts from a custom post type. I already have the list of posts but I'm looking into an efficient way of displaying the most recent comments from that author as well. So far I haven't found anything except widget and bloated plugins. I'd like to do that particularly in one stream (posts/comments) but I can understand if this is too challenging :) Thanks! Dennis
|
This function calls all comments by an author and strips every comment to a max-length. Adjust the comment excerpt length when calling the function in your template like <code> wpse19316_author_comments( 100 ); </code> . <code> function wpse19316_author_comments( $length ) { $final_length = (int) $length; $author_comments = get_comments( array( 'ID' => $GLOBALS['authordata']->ID ) ); foreach ( $author_comments as $comment ) { $comment_length = sublen( $comment->comment_content ); $comment_excerpt = $comment->comment_content; if ( $comment_length > $final_length ) $comment_excerpt = substr( $comment->comment_content, $final_length ); echo $comment_excerpt.'<br />'; } } </code>
|
Recent comments on author page?
|
wordpress
|
Hi I created a template within my theme files, just for displaying a map in a lightbox. I need to call this template page from a normal wordpress post, how can I do it? Say in my theme files I have a file called map-template.php From within my post I would like to call that map-template.php file and also pass the ID of the current post as a parameter. Thanks
|
So long as you have a standard page template header in your <code> map-template.php </code> , you can use the Custom Post Template plugin (which essentially allows you use templates on posts in the same way you do with pages). Update : Perhaps you might be better off using shortcode . For example; <code> This is my post content in the editor. And here is a map; [my-map] </code> And in <code> functions.php </code> ; <code> function __my_map_shortcode() { // output map } add_shortcode( 'my-map', '__my_map_shortcode' ); </code>
|
How to Call a static page in WordPress
|
wordpress
|
I found that my blog posts are inserted lot's of ad links, I'm using WordPress 2.9.2, is there a known security vulnerability in it? A screenshot : I post some codes on my blog, the ad links are inserted into them. I delete them by hand several days ago, and I found that they're back again!
|
Looks like you've been hacked. In all fairness, you're running a version that is over a year old - it's always best practice to upgrade as soon as you can. I would advise reading through the FAQ on the codex . I also stumbled across this rather concise step-by-step , though I would advise it's for the intermediate user (use of SQL and FTP is required).
|
Why was my blog post inserted lot's of ad links by others?
|
wordpress
|
I have a wp_nav_menu showing pages, but I'd also like to include a log in/out link, based on the current state of the user, which will redirect them to the home page. I've looked far and wide, but how can I implement this in a wp_nav_menu? Thanks, Dennis
|
Use the <code> wp_nav_menu_items </code> hook to add a filter which will allow you to add your login / logout link. Use <code> wp_loginout() </code> to display a status aware login / logout link. Codex page.
|
wp_nav_menu log in/out link?
|
wordpress
|
I am trying to customize behavior for different displays of pages; I know I can use the Template Hierarchy and Conditional Tags to accomplish this. In the process of debugging, though, I'd like to be able to access all the meta-information about a page without having to iterate through all the <code> is_* </code> functions. Is there a way to access this meta-information without rolling my own function (which would basically iterate through all the <code> is_* </code> functions). It would also be nice if this function had other information in it as well such as page-id, author, category, etc.
|
you can inspect $wp_query to see the query vars and returned data, including all of those conditionals: <code> <pre><?php print_r($wp_query); ?></pre> </code>
|
How do I acquire all the meta-information for a particular page I am on?
|
wordpress
|
I'm using Wordpress 3.1.3 as a full CMS, installed in the root directory of a domain. I have it setup using the built in options to have a static page as the home page, and then my blog at http://www.mydomain.com/blog . What I would like is to have my single blog posts, category pages, archive pages, and tag pages, and any other blog-related pages have the "prefix" of /blog/ in their link structure. So a post URL would be www.mydomain.com/blog/post-title Right now, I only have the category pages working correctly. This was accomplished by adding the following line to my .htacces file: RewriteRule ^category/(.+)$ http://www.mydomain.com/ $1 [R=301,L] Then, I set the Category Base to "blog" on the Permalinks Settings page in Wordpress. This gives category pages the URL of: www.mydomain.com/blog/category-name (without removing the category prefix in .htaccess, they had the URL category/blog/category-name). In an attempt to get this working for the other things I want it to work for, I set my Tag Base to "blog." I also made my Custom Permalink Structure: /blog/%postname% (as suggested by a few threads I've found searching on Google). These settings give the URLs for the single blog posts, tags pages, and archive pages the URL structure I'm looking for. However, it makes them all lead to 404 errors. I deleted my .htaccess file to ensure Wordpress was writing to it, and it is. If I remove the /blog/ from the permalink structure, everything works correctly, but I no longer have the URL structure I'm looking for. I'm at a loss as to what I should do. I keep reading threads and guides saying this is as simple as adding /blog/ to the permalink structure, but so far it hasn't been nearly that simple. I would be very grateful if anyone knows how I can get this to work. .htaccess contents: <code> <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> </code>
|
Go to Settings> Permalinks and add it to the permalink structures
|
How do I add /blog/ as a prefix to permalink structure for blog posts, tag pages, etc.?
|
wordpress
|
I am using WP Content Slideshow. I like the plugin, but am having an issue with it. I mailed the creator, but no response, so I am trying to troubleshoot what is causing the problem. You can see the issue on the homepage of elyconnect.com . The plugin uses the featured image for the image in the slideshow. I set the resolution for each image size correctly, but the images are "cropping" and I dont know why. I'm open to suggestions, or a recommendation for a better plugin if one exists.
|
I think on your example is the picture to small for crooping; if the image is smaller as the config on mediathek in WP, than it is not possible to crop the image. Your theme use the image from 300px width for this view and the css style defined 447px.
|
Is WP feature image function cropping images? WP Content Slideshow
|
wordpress
|
This is included in themes and plugins. <code> /* * @package WordPress * @subpackage Twenty_Ten * @since Twenty Ten 1.0 */ </code> What are they for? I've read that they are standard and so on, but what is the practical use for it?
|
These are PHPDoc tags - used to generate meaningful (and automated) code documentation
|
What are the package and subpackage comment for?
|
wordpress
|
what is a query for selecting a list of comment id's that have not had a reply yet so I can use it to iterate though each comment id and echo out the post it is on and the excerpt of the comment along with the author name, url and how many comments?
|
this should work... <code> <?php global $wpdb; $sql = "SELECT comment_ID FROM ". $wpdb->prefix ."comments WHERE comment_parent = 0 AND comment_ID NOT IN(SELECT comment_parent FROM ". $wpdb->prefix ."comments);"; $results = $wpdb->get_results($sql); ?> </code>
|
db query for retrieving comments without any reply
|
wordpress
|
I'm managing a movie related site.. I'm using yoast's simple taxonomies plugin to classify my content with Artists, Genre (action, horror, comedy, drama etc..), Director, Writer etc... On a specific page (template), I want to pull last 5 posts with only their titles from custom taxonomies.. how can I pull last 5 titles from Action, Comedy or Horror taxonomies as list? I will try to get an output like http://tutsplus.com/ Thanks
|
create additional loops in your template, selecting the taxonomy and term you'd like to limit display to for each. for instance, this will pull the last 5 posts from taxonomy "genre", term "action": <code> <?php $args = array( 'taxonomy'=>'genre','term'=>'action','posts_per_page'=>5 ); $action_films = new WP_Query( $args ); while( $action_films->have_posts() ) : $action_films->the_post(); echo '<li>'; the_title(); echo '</li>'; endwhile; ?> </code>
|
List Recent Post Titles from Custom Taxonomies?
|
wordpress
|
Does anyone know of any good wordpress themes that are compatible with the bbpress plugin ? I'm looking for something with a good layout, preferably a magazine/news type theme. Thanks :)
|
Best would be if you modify the bbpress theme a bit.Copy the entire folder "/bbpress/bbp-themes/bbp-twentyten" folder into your themes folder, rename it to something else, and modify your style.css to make it a custom child theme of whatever your current theme is. Now you can modify as you you wish. Another way :Copy all files of that folder inside ur theme. In your theme's function.php add the following line. add_theme_support( 'bbpress' ); Now you have your theme compatible with ur own bbpress page structure which you can modify as you wish. Hope that helps
|
Any Good WordPress Themes Compatible With The BBPress Plugin?
|
wordpress
|
I'm using wp_nav_menu and am trying to create custom output for the sub-level drop downs. I came across the "items_wrap" argument but there's really not much information as to what it is, how it works, and what kind of things can be done with it. What exactly is " %1$s " and " %2$s "? (Can anyone explain it in layman's terms?)
|
The parameter <code> 'items_wrap' </code> for <code> wp_nav_menu() </code> defaults to <code> '<ul id="%1$s" class="%2$s">%3$s</ul>' </code> . It is parsed with <code> sprintf() </code> : <code> $nav_menu .= sprintf( $args->items_wrap , esc_attr( $wrap_id ) // %1$s , esc_attr( $wrap_class ) // %2$s , $items // %3$s ); </code> The numbered placeholders – <code> %1$s </code> , <code> %2$s </code> , <code> %3$s </code> – refer to the arguments after the first argument in <code> sprintf() </code> . The percent sign marks a placeholder, the number the position and the type <code> s </code> means it should be treated as a string. Do not change the type unless you really know what you do. :) <code> $wrap_id </code> is the parameter <code> 'menu_id' </code> if you have it set, else it is <code> 'menu-' . $menu->slug </code> . <code> $wrap_class </code> is the parameter <code> 'menu_class' </code> if you have it set, else it is empty. <code> $items </code> is a string of the inner content of the menu. Let’s say you don’t need a <code> class </code> . Just omit the second string: <code> wp_nav_menu( array( 'items_wrap' => '<ul id="%1$s">%3$s</ul>' ) ); </code> If you don’t need the <code> class </code> and the <code> id </code> , and you want another container (because you used a stackexchange-url ("custom walker")): <code> wp_nav_menu( array( 'items_wrap' => '<div>%3$s</div>' ) ); </code> The main point is: You have to use the numbers for the replacements given in <code> wp_nav_menu() </code> . <code> %3$s </code> is always the list of items.
|
Any docs for wp_nav_menu's "items_wrap" argument?
|
wordpress
|
I'm developing a child theme of a premium template, this comes with a custom post type with the label name of "Projects" but I'd like to change it to something else, I know that if I go to the functions.php file of the main theme I can change it easily but I'd like to change it from my child theme so I don't have to edit any of the original files, is it possible? Thanks in advance!
|
There is a global array <code> $wp_post_types </code> . You can change <code> $wp_post_types[$post_type]->labels </code> after the parent theme has set the CPT. So … if the parent theme registers the CPT on <code> 'init' </code> like this: <code> add_action( 'init', 'register_my_cpt', 12 ); </code> Then you need a later priority: <code> add_action( 'init', 'change_cpt_labels', 13 ); </code> … or a later hook. I would use <code> wp_loaded </code> : <code> add_action( 'wp_loaded', 'change_cpt_labels' ); </code> Example for custom post type <code> place </code> changed to <code> location </code> <code> add_action( 'wp_loaded', 'wpse_19240_change_place_labels', 20 ); function wpse_19240_change_place_labels() { global $wp_post_types; $p = 'place'; // Someone has changed this post type, always check for that! if ( empty ( $wp_post_types[ $p ] ) or ! is_object( $wp_post_types[ $p ] ) or empty ( $wp_post_types[ $p ]->labels ) ) return; // see get_post_type_labels() $wp_post_types[ $p ]->labels->name = 'Locations'; $wp_post_types[ $p ]->labels->singular_name = 'Location'; $wp_post_types[ $p ]->labels->add_new = 'Add location'; $wp_post_types[ $p ]->labels->add_new_item = 'Add new location'; $wp_post_types[ $p ]->labels->all_items = 'All locations'; $wp_post_types[ $p ]->labels->edit_item = 'Edit location'; $wp_post_types[ $p ]->labels->name_admin_bar = 'Location'; $wp_post_types[ $p ]->labels->menu_name = 'Location'; $wp_post_types[ $p ]->labels->new_item = 'New location'; $wp_post_types[ $p ]->labels->not_found = 'No locations found'; $wp_post_types[ $p ]->labels->not_found_in_trash = 'No locations found in trash'; $wp_post_types[ $p ]->labels->search_items = 'Search locations'; $wp_post_types[ $p ]->labels->view_item = 'View location'; } </code>
|
Can I change a custom post type label from a child theme?
|
wordpress
|
We have a site http://ort.org.il built with WP 3.1.2. Its RSS address should be http://ort.org.il/feed/ , but nothing shows up there. I can see the feed in the View Source, but not in the browser, and not in one of our other applications, that reads the RSS from this site. What could be the problem, and how can I fix it?
|
The problem is an invalid UTF-8 character in the excerpt <code> <description> </code> . The text is cut off in the middle of a multi-byte character, rendering your complete feed invalid. You get a slightly hint when you look at it in Opera. Do you filter <code> 'bloginfo_rss' </code> or <code> 'get_bloginfo_rss' </code> ? Disable all plugins and look if the feed is still broken.
|
Site Rss not seen by browser
|
wordpress
|
In WordPress 3.1 a post can be reached a number of ways, for example each one of these takes you to the same post (where /id is the base) <code> http://myblog.com/id/1008 http://myblog.com/id/1008/my-slug http://myblog.com/my-slug </code> How can I tell WordPress to redirect all of these variations to <code> http://myblog.com/id/1008/my-slug </code> ?
|
Check whether the posts not being redirected actually have the correct permalink stored in the DB. There's a bug in which canonicals can't be properly guessed because the permalink structure was CHANGED after the post was created. Try either creating a new post with your current permalink structure, or editing the post_name DB field for them. (There's a plugin for updating the permalinks in DB) The question remains. ASSUMING it is still happening: How do we FORCE wordpress to REDIRECT to the canonical url? No just adding a link to it, but REDIRECTING to that page. I changed the permalinks structure of the site, and added a add_rewrite_rule in functions.php, so now the old <code> /02/20/2008/postname </code> addresses are accepted and canonicalized as <code> /blob/postname </code> correctly… and the page is found successfully. But no matter what I do, the canonical just stays as a link in the old URL'd page, still showing the wrong url in the adress bar. NO REDIRECT is performed. Ive worked with another website before, and I ended up (after days of trying tens of different pieces of code) using .htaccess redirects. I know .htaccess redirects will work, but now that I read everywhere that "It should" be doing it… I'm wondering: Should it? and more exactly "how do I FORCE it?
|
How can I force WordPress to redirect to canonical permalinks?
|
wordpress
|
I have to add a blog in my magento site.Is it possible to integrate wordpress into magento by which we are able to post blog in the wordpress and then display in the magento site. Thanks in advance Pramod
|
Here is an extension for this..that you can use http://www.magentocommerce.com/magento-connect/aheadworks/extension/1516/blog-extension-by-aheadworks or you can go with ... stackexchange-url ("Full Magento / Wordpress integration")
|
How I can add blog in my magento site?
|
wordpress
|
I was wondering if anyone knew how to have a different "featured post" based on it's category per category page? For example, if you are on the medical category page, you would see a medical post featured in a special div and so on.
|
assign the additional category 'featured' to the post in the category 'medical'. in your category template, use a query with <code> 'category__and' => array(3, 27) </code> example (assuming 'medical' is cat 3, and 'featured' is cat 27): <code> <?php $args = array( 'category__and' => array(3, 27), 'posts_per_page' => 1 ); $feature = new WP_Query( $args ); if( $feature->have_posts() ) : while( $feature->have_posts() ) : $feature->the_post(); ?> <div class="featured"> ANY POST OUTPUT <?php the_title(); ?> </div> <?php endwhile; endif; ?> </code>
|
Featured Posts for Category Pages
|
wordpress
|
I can easily link to my archives page by creating a link: <code> <a href="http://server.com/wordpress/archives.php">Archives</a> </code> . As I was editing my WP template, I noticed that there are a number of functions that WP uses to link to other pages. For example <code> get_the_category_list </code> returns a list of links. If I want to make my template more general, it would be nice not to hardcode the URL of my archives page and to use a WP function instead. In general, how should template designers create links to WP generated pages?
|
This link Wordpress Codex: Linking... provides detailed information on how to link different types of content. One nice feature that solves the above problem is to use a link of the form <code> /wordpress/archives.php </code> . This will transfer nicely (in most cases) to any particular server deployment. Further, looking in <code> wp-includes/link-template.php </code> gives you more insight to what kinds of tools are already available for creating links. Particularly helpful is <code> home_url() </code> which allows you to try to be as server agnostic as possible.
|
What is the canonical way to link to pages?
|
wordpress
|
I have a custom post-type 'videos' and on the first page I have the first video styled differently than the next videos on the page. Basically I show the first video in a large format, while the rest of the videos on the page are small. Question: On page 2, 3, etc of the video post-type, I do not want to have a large video on the top of the page, but rather follow my standard styling. What would be the best way to do this? Currently I am using rewrite rules to allow me a second template page for my 'paged' for the post-type. I would rather not use this approach anymore as it is more to maintain. If I used a check like if_paged.. then I find that I have to replicate a ton of code on my template. Hoping there is a simple way to identify the first post in the loop, style that, and then continue... open to any ideas thanks
|
In response to your comment, <code> $wp_query->current_post </code> in action. Note that it's zero-indexed: <code> <?php if (have_posts()) : while (have_posts()) : the_post(); if($wp_query->current_post==0): echo "this is the first post"; else: echo "this is post number " . ($wp_query->current_post + 1); endif; endwhile; endif; ?> </code>
|
What is the best practice to style archive page 2,3,etc differently than archive.php?
|
wordpress
|
I'm trying to add an Amazon advertising widget in a WordPress sidebar widget (self-hosted WordPress, v3.1.3). The widget code is basically an iframe. I've tried using the "Text" widget and pasting the iframe code in there, but when I save the widget, the iframe code disappears. I've come across this problem/limitation before and solved it using the IFrame Widget , but I want to use more than one iFrame in my sidebar, and the IFrame widget only supports one widget at a time. Am I missing something obvious? Is there a setting somewhere to allow iframe code in the widgets? Or is it normally allowed, and I've done something silly to my install? If not, any good workarounds?
|
Just create a widget that doesn’t filter your input. This is probably the most simple widget with user input you can build. Here is the widget I use in my plugin Magic Widgets. <code> /** * Simplified variant of the native text widget class. * * @author Thomas Scholz aka toscho http://toscho.de * @version 1.0 */ class Unfiltered_Text_Widget extends WP_Widget { /** * @uses apply_filters( 'magic_widgets_name' ) */ public function __construct() { // You may change the name per filter. // Use add_filter( 'magic_widgets_name', 'your custom_filter', 10, 1 ); $widgetname = apply_filters( 'magic_widgets_name', 'Unfiltered Text' ); parent::__construct( 'unfiltered_text' , $widgetname , array( 'description' => 'Pure Markup' ) , array( 'width' => 300, 'height' => 150 ) ); } /** * Output. * * @param array $args * @param array $instance * @return void */ public function widget( $args, $instance ) { echo $instance['text']; } /** * Prepares the content. Not. * * @param array $new_instance New content * @param array $old_instance Old content * @return array New content */ public function update( $new_instance, $old_instance ) { return $new_instance; } /** * Backend form. * * @param array $instance * @return void */ public function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'text' => '' ) ); $text = format_to_edit($instance['text']); ?> <textarea class="widefat" rows="7" cols="20" id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>"><?php echo $text; ?></textarea> <?php /* To enable the preview uncomment the following lines. * Be aware: Invalid HTML may break the rest of the site and it * may disable the option to repair the input text. ! empty ( $text ) and print '<h3>Preview</h3><div style="border:3px solid #369;padding:10px">' . $instance['text'] . '</div>'; /**/ ?> <?php } } </code> You register the widget with: <code> add_action( 'widgets_init', 'register_unfiltered_text_widget', 20 ); function register_unfiltered_text_widget() { register_widget( 'Unfiltered_Text_Widget' ); } </code> Now you get a new widget in <code> wp-admin/widgets.php </code> : I put just two cool Youtube videos as iframes and a <code> <hr> </code> into the widget. Output:
|
Adding iframe Content to Sidebar Widget
|
wordpress
|
On edit.php, the main content is a list of posts, with columns including the published date. I'd like to change the date format of the published date just on the admin page . In this case, I don't want to change what the users see; I want to change what the admin sees. I want to add the day of the week to the published/scheduled date, because I'm planning to publish "Every Tuesday, at least," and want to make sure I've scheduled posts correctly. After searching, the best route seems like it would be to create a custom field, but if there's a more subtle way to do this, I'd prefer to not install the custom field plugin. edit: thanks to Bainternet's comment, I see that I already have custom fields (the option was just hidden by default). And, I see custom fields are not what I want. The data already exists; I just want to format it differently on the screen.
|
stackexchange-url ("Add a column to the post edit screen") and format the date however you like. stackexchange-url ("Remove the default Date column"). EDIT here's the code to put inside your theme's <code> functions.php </code> file: EDIT 2 added additional code to add publish status and make the column sortable, this should now be a complete copy of the original date column. <code> function my_custom_columns( $columns ) { unset( $columns['date'] ); $columns['mydate'] = 'My Custom Date'; return $columns; } function my_format_column( $column_name , $post_id ) { if($column_name == 'mydate'){ echo get_the_time( 'l, F j, Y', $post_id )."<br>".get_post_status( $post_id ); } } function my_column_register_sortable( $columns ) { $columns['mydate'] = 'mydate'; return $columns; } function my_column_orderby( $vars ) { if ( isset( $vars['orderby'] ) && 'mydate' == $vars['orderby'] ) { $vars = array_merge( $vars, array( 'orderby' => 'date' ) ); } return $vars; } function my_column_init() { add_filter( 'manage_posts_columns' , 'my_custom_columns' ); add_action( 'manage_posts_custom_column' , 'my_format_column' , 10 , 2 ); add_filter( 'manage_edit-post_sortable_columns', 'my_column_register_sortable' ); add_filter( 'request', 'my_column_orderby' ); } add_action( 'admin_init' , 'my_column_init' ); </code> Thanks to Scribu for his tutorial on sortable columns
|
how to change "published date" format on edit.php (Posts page)?
|
wordpress
|
Okay = been working on the plugin I posted about stackexchange-url ("over here"), and having am having a couple troubles. I decided to go the route of writing a plugin from scratch. As I noted, its an customized ajax gallery / portfolio, and I'm trying to work its management into wp-admin. The goal is finally to do the query/sorting with wp, and deliver xml or json back to the httprequest via this plugin. First things first though - when the plugin is first activated I'm trying to create a new table, and insert some test data to it (I'm following the wordpress codex guidelines.) When the plugin is successfully activated, however, nothing is happening. I'm getting no errors (anymore), but the table is not getting inserted, and no data is being added. I realize the codex script is procedural and I'm using a class, but I think everything is scoped properly. Actually. I don't know if it is, specifically the <code> global $wpdb </code> . I'm still pretty new to php - it seems to have some scoping quirks that I don't quite grok yet. At any rate - this is what I've got so far. Very simple, but no go (yet). <code> <?php /* Plugin Name: B99 Portfolio Plugin URI: http://www.joshbosworth.com/ Description: B99 Portfolio data logic Version: 0.1 Author: Josh Bosworth Author URI: http://www.joshbosworth.com */ global $b99_pf_db_version; $b99_pf_db_version = "1.0"; if ( !class_exists( 'B99_Portfolio')){ require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); class B99_Portfolio { public function B99_Portfolio(){} public function __construct(){ add_action('admin_menu', array( &$this, 'b99_portfolio_admin_actions' )); } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // admin //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public function b99_portfolio_admin_actions(){ add_media_page( 'B99 Portfolio', 'B99 Portfolio', 'manage_options', 'B99_Portfolio', array( &$this, 'b99_portfolio_admin')); } public function b99_portfolio_admin(){ if (!current_user_can('manage_options')) { wp_die( __('You do not have sufficient permissions to access this page.') ); } include('b99-portfolio-admin.php'); } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // db table //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ var $table_name; public function b99_pf_install(){ global $wpdb; $this->table_name = $wpdb->prefix . "b99_pf"; $sql = "CREATE TABLE " . $this->table_name . " ( //changed to class var id mediumint(9) NOT NULL AUTO_INCREMENT, time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, title tinytext NOT NULL, cat tinytext DEFAULT NOT NULL, //changed from 'default' tag tinytext NOT NULL, note text NOT NULL, date tinytext NOT NULL, hr_path tinytext NOT NULL, lr_path tinytext NOT NULL, UNIQUE KEY id (id) );"; dbDelta($sql); add_option("b99_pf_db_version", $b99_pf_db_version); } public function b99_pf_install_data(){ global $wpdb; $title = 'Testing Furiously'; $cat = 'illustration,design'; $tag = 'sketch'; $note = 'Seriously Testing'; $date = 'june 2008'; $hr_path= 'hr/testing.furiously-hr.jpg'; $lr_path= 'lr/testing.furiously-lr.jpg'; $rows_affected = $wpdb->insert( $this->table_name, array( 'time' => current_time('mysql'), //changed table_name to class var 'title' => $title, 'cat' => $cat, 'tag' => $tag, 'note' => $note, 'hr_path'=>$hr_path, 'lr_path'=>$lr_path ) ); } } //end class } if( class_exists(B99_Portfolio)){ $b99_PF = new B99_Portfolio(); register_activation_hook(__FILE__, array(&$b99_PF, 'b99_pf_install')); register_activation_hook(__FILE__, array(&$b99_PF, 'b99_pf_install_data')); } ?> </code> Any advice would be most excellent. Frankly - and differing or contrary take on my overall plan here would be fine, too. Thanks in advance. btw. How the hell do I debug wordpress? I'm using netbeans / xampp... = update = Ok - was able to get xdebug up and running (thanks!). I have a couple more questions about this code. -Just general php - I'm a little puzzled over variable scope <code> $classvar // implied public modifier? private function someFunction(){ $classvar // let me get this straight - this is a new local var $classvar !=$this->classvar? // right? if so thats an important clarification... } </code> -$wpdb why <code> global $wpdb $rows_affected = $wpdb->insert(... </code> and not just <code> global $wbdb->insert(... </code> -register_activation_hook / wordpress db rebuild. I notice the activation hook gets run each time the admin page gets loaded, and not only when the plugin is 'activated' which seems like the logical behavior. And it seems as tho wp-query rebuilds, or at least runs dbDelta on the entire wordpress database each rebuild of the admin page also? Not that this seems wrong, but I'm not sure I understand why. I should note- I'm just using myPhpAdmin to see if the table is getting added into the db structure. Clearly I've spent my whole career working client side ;) Although I've made use of a lot of php features in the past, this may be the first time I've attempted anything but 'simple' server side routines or copy/pastes. At any rate - thanks for the help -
|
I see two problems- <code> $this->table_name = $wpdb->prefix . "b99_pf"; $sql = "CREATE TABLE " . $table_name . " ( </code> <code> $table_name </code> will be undefined, should be <code> $this->table_name </code> and in your query: <code> cat tinytext default NOT NULL </code> I don't think it'll like that <code> default </code> in there. EDIT - to answer your debug question- xdebug , xdebug and netbeans
|
How to properly create table in plugin
|
wordpress
|
How can I modify month names in "Archives" in my blog? I would like to translate english month names into my mother tongue. I'm using the english version of wordpress 3.1.3
|
if the translation is only for the archive widget, a filter function might work (to be added to functions.php of the theme): <code> add_filter('get_archives_link', 'translate_archive_month'); function translate_archive_month($list) { $patterns = array( '/January/', '/February/', '/March/', '/April/', '/May/', '/June/', '/July/', '/August/', '/September/', '/October/', '/November/', '/December/' ); $replacements = array( 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec' ); $list = preg_replace($patterns, $replacements, $list); return $list; } </code>
|
How to translate month names in "Archives"
|
wordpress
|
The page I am talking about is this: http://wordpress.org/extend/plugins/ It is simple and perfect in my opinion. Can anyone help me?
|
this should give you the same look unless your theme's css overwrites it: <code> <form name="loginformfooter" class="loginform" id="loginformfooter" action="<?php bloginfo('url'); ?>/wp-login.php" method="post"> <p><label>Username <input type="text" value="" maxlength="40" size="13" id="user_login" name="user_login" class="text"> </label> <label>Password <input type="password" maxlength="40" size="13" id="password" name="password" class="text"> </label> <input type="hidden" value="" name="re"> <input type="submit" value="Log in" id="submit" name="Submit" class="button-secondary"> (<a href="<?php bloginfo('url'); ?>/wp-login.php?action=lostpassword">forgot?</a>) or <a href="<?php bloginfo('url'); ?>/wp-login.php?action=register">Register</a></p> </form> </code>
|
How can I make a login just like on wordpress.org?
|
wordpress
|
I have created a page on which I would like to run queries exlusively for one custom post type in the same way I'm using Category.php, Author.php and index.php to run queries for regular posts. I can't seem to get anything to appear when I edit the page that is associated with the template I've created for this page, so I've edited the actual page template itself. This may or may not be related to the fact that I can't get this page to behave like index.php does, i.e. providing a running list of posts until someone does a more refined search such as by Category. I'm stumped - how can I get a page template to work just like index.php does, but for the custom post type only?
|
You want to use the template file <code> archive-{posttype}.php </code> to output an archive index of your Custom Post Type, and the template file <code> single-{posttype}.php </code> to output a single Custom Post. Refer to the Codex entry for Template Hierarchy .
|
Using Pages to handle calls for custom post types
|
wordpress
|
I am attempting to automate, as much as possible, the Settings API function calls for each setting in a Plugin. Looping through the options array, and outputting <code> add_settings_section() </code> and <code> add_settings_field() </code> is simple enough: <code> add_settings_section() </code> : <code> $oenology_hooks_tabs = oenology_hooks_get_settings_page_tabs(); foreach ( $oenology_hooks_tabs as $tab ) { $tabname = $tab['name']; $tabtitle = $tab['title']; $tabsections = $tab['sections']; foreach ( $tabsections as $section ) { $sectionname = $section['name']; $sectiontitle = $section['title']; $sectiondescription = $section['description']; // Add settings section add_settings_section( 'oenology_hooks_' . $sectionname . '_section', $sectiontitle, 'oenology_hooks_' . $sectionname . '_text', 'oenology_hooks_' . $tabname . '_tab' ); } } </code> And `add_settings_field(): <code> global $oenology_hooks; $oenology_hooks = oenology_hooks_get_hooks(); foreach ( $oenology_hooks as $hook ) { $hookname = $hook['name']; $hooktitle = $hook['title']; $hooktab = $hook['tab']; $hooksection = $hook['section']; add_settings_field( 'oenology_hooks_' . $hookname, $hooktitle, 'oenology_hooks_setting_callback', 'oenology_hooks_' . $hooktab . '_tab', 'oenology_hooks_' . $hooksection . '_section', $hook ); } </code> With <code> add_settings_field() </code> , I can easily write a generic callback, by passing the <code> $hook </code> variable to the callback, as the fifth parameter in the function call: <code> function oenology_hooks_setting_callback( $hook ) { $oenology_hooks_options = get_option( 'plugin_oenology_hooks_settings' ); $hookname = $hook['name']; $hooktitle = $hook['title']; $hookdescription = $hook['description']; $hooktype = $hook['type']; $hooktab = $hook['tab']; $hooksection = $hook['section']; $inputvalue = $hookname . '_hide'; $inputname = 'plugin_oenology_hooks_settings[' . $inputvalue . ']'; $textareaname = 'plugin_oenology_hooks_settings[' . $hookname . ']'; $textareavalue = $oenology_hooks_options[$hookname]; if ( 'Filter' == $hooktype ) { ?> <input type="checkbox" name="<?php echo $inputname; ?>" value="<?php echo $inputvalue;?>" <?php checked( true == $oenology_hooks_options[$inputvalue] ); ?> /> <span>Hide <?php echo $hooktitle; ?> content?</span><br /> <?php } ?> <span class="description"><?php echo $hooktype; ?> Hook: <?php echo $hookdescription; ?></span><br /> <textarea name="<?php echo $textareaname; ?>" cols="80" rows="3" ><?php echo esc_textarea( $textareavalue ); ?></textarea> <?php } </code> However, it appears that <code> add_settings_section() </code> does not have an analogous <code> $args </code> parameter; thus, I cannot use the same method to pass the <code> $section </code> variable to the callback. Thus, my question: is there any way to pass a variable to the <code> add_settings_section() </code> callback, or some other way to create a callback analogous to what I'm doing for <code> add_settings_field() </code> ? EDIT: @Bainternet nailed it! Here's my working code: <code> /** * Callback for add_settings_section() * * Generic callback to output the section text * for each Plugin settings section. * * @param array $section_passed Array passed from add_settings_section() */ function oenology_hooks_sections_callback( $section_passed ) { global $oenology_hooks_tabs; $oenology_hooks_tabs = oenology_hooks_get_settings_page_tabs(); foreach ( $oenology_hooks_tabs as $tab ) { $tabname = $tab['name']; $tabsections = $tab['sections']; foreach ( $tabsections as $section ) { $sectionname = $section['name']; $sectiondescription = $section['description']; $section_callback_id = 'oenology_hooks_' . $sectionname . '_section'; if ( $section_callback_id == $section_passed['id'] ) { ?> <p><?php echo $sectiondescription; ?></p> <?php } } } } </code>
|
if you look at the do_settings_sections function more specifically the line 1164 where the callback function is being executed : <code> call_user_func($section['callback'], $section); </code> you can see that the $section array is being passed to the callback function, so you can identify the callback by the <code> $section['id'] </code> hope this make since. Update here is an example, if your add_settings_section callback for all sections was named <code> oenology_hooks_section_callback </code> then you can identify it like this: <code> function oenology_hooks_section_callback($section_passed){ if ($section_passed['id'] == 'whatever_section_id'){ //do stuff } if ($section_passed['id'] == 'whatever_section_id_number2'){ //do other stuff } } </code> and by do stuff i mean do whatever you want to do with that section callback.
|
How to pass variable to add_settings_section() callback?
|
wordpress
|
I have a pretty extensive music collection and my friends are always borrowing my stuff. I would like to keep better track of my library so I'm building a sudo-checkout system using WP. The collection was already in WP using terms to sort everything. The main taxonomies are artist , year released , label , and genre . I want to add a new taxonomy called whereisit . The post type used is called album . Because of the way that other plugins interact with the site (I'm a music geek) I can't easily use post meta for inventory status term. If it matters at the moment I'm using Scribu's plugin to autogenerate taxonomy search fields. The question: How can I display a list of terms who's related posts also match another fixed term? For example: Show a list of terms for artists who's whereisit term is ihaveit . If all of the artist's albums have an whereisit term of idonthaveit , do not display the artist term in the list. Or more simply: If all of my albums by a particular artist are loaned out to someone else, don't display the artist's name in the Artist list. Would something like this have to be done through wpdb? Filtering a loop is easy enough, but translating that to a list is over my head. :) Edit: I replaced the terms inhouse with ihaveit , checkedout with idonthaveit , and the taxonomy named inventorystatus with whereisit for better clarity.
|
if i understand correctly you want to get a list of <code> albums </code> (posts) of a specific artist(taxonomy) and that are have <code> ihaveit </code> term. if so the its a simple query using <code> tax_query </code> : <code> $args = array( 'posts_per_page' => -1, //get all 'post_type' => 'album', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'artist', 'field' => 'slug', 'terms' => array( 'artist-slug' ) ), array( 'taxonomy' => 'whereisit', 'field' => 'slug', 'terms' => array('ihaveit') ) ) ); $query = new WP_Query( $args ); while($query->have_posts()) { $query->the_post(); //to your thing / loop here } </code>
|
How to create a list of terms who's posts also have a predefined external term?
|
wordpress
|
In a previous question I asked how to add a column to the Posts page in the Administration section, and got a working answer. But now I need to know how to delete an existing column (e.g. the Date column) so that my customized Date column replaces it.
|
<code> function my_manage_columns( $columns ) { unset($columns['date']); return $columns; } function my_column_init() { add_filter( 'manage_posts_columns' , 'my_manage_columns' ); } add_action( 'admin_init' , 'my_column_init' ); </code>
|
How to remove a column from the Posts page
|
wordpress
|
Has anyone written or can suggest a plugin that would replace the filter-by-month in the Post Administration screen with filter-by-week-number instead? e.g. a drop down option for "Week of 05/31-06/06, 2011"
|
here you go , its something i quickly cooked up and it seems to work fine: <code> <?php /* Plugin Name: admin-filter-by-week Plugin URI: http://en.bainternet.info Description: answer to Filtering posts on Post Administration Page by Week Number instead of by Month stackexchange-url 1.0 Author: Bainternet Author URI: http://en.bainternet.info */ add_filter( 'parse_query', 'week_admin_posts_filter' ); add_action( 'restrict_manage_posts', 'ba_admin_posts_filter_restrict_manage_posts' ); function week_admin_posts_filter( $query ) { global $pagenow; if ( is_admin() && $pagenow=='edit.php' && isset($_GET['weekly_archive-dropdown']) && $_GET['weekly_archive-dropdown'] != '') { $link = $_GET['weekly_archive-dropdown']; //http://en.bainternet.info/?m=2011&w=22 $pos = strpos($link, '?m='); if ($pos !== false) { $m = substr($link, $pos + 3); $wpos = strpos($m, '&w='); $w = substr($m, $wpos + 3); $m = substr($m, 0, $wpos + 3); $query->query_vars['year'] = $m; $query->query_vars['w'] = $w; $query->query_vars['post_status'] = array('publish','pending','draft','future','private'); } } } function hack_weekly_archives($w){ $types = "IN('publish','pending','draft','future','private')"; $w = str_replace("= 'publish'",$types,$w); return $w; } function ba_admin_posts_filter_restrict_manage_posts() { add_filter('getarchives_where','hack_weekly_archives'); ?> <select name="weekly_archive-dropdown"> <option value=""><?php echo esc_attr( __( 'Select Week' ) ); ?></option> <?php wp_get_archives( 'type=weekly&format=option&show_post_count=1' ); ?> </select> <?php remove_filter('getarchives_where','hack_weekly_archives'); } </code>
|
Filtering posts on Post Administration Page by Week Number instead of by Month
|
wordpress
|
What I'd like to do is have the entire row be a different color - for example, a light blue for draft posts. That way I can visually see at a glance what's a draft, what's scheduled, and what's published on a given time period (I am working on a system for scheduling posts out weeks in advance). It would seem the logical way to do this is to alter the row color, since there is a CSS class ("status-draft") for example. However, it appears that altering the row color doesn't work since the individual cells as well have overriding colors. Thoughts?
|
you mean something like this? then here you go: <code> add_action('admin_footer','style_posts_list'); function style_posts_list(){ ?> <style> .status-draft{background-color: #008866 !important;} .status-pending{background-color: #F53162 !important;} .status-publish{background-color: #FFF700 !important;} <?php } </code>
|
Is there a way to change the color of a row in Post Administration based on the type of post?
|
wordpress
|
For Example,Now I have 3 Categories Like Food,Transport,Technology.Under These Categories I have Many Posts.Now I Want To Show the Latest Post From Each Category.{How to get Recent Post From Each Category with Thumbnail?}Is This is Possible? I Think No Plugin for This One.If You have a Great Knowledge in Plugin Creation, this is the Greatest Challenge for you.Just try to Found New Things and Become a Great Founder. My Question is Not Clear Means Ask Me or Edit ... Thanks All...
|
I'm the developer of the List Category Posts WordPress plugin. The plugin uses a short code to get posts from a category and you can include thumbnails too. Give it a try and hopefully you'll find it useful.
|
How to get Recent Post From Each Category with Thumbnail?
|
wordpress
|
This seems like a simple thing to do, but I haven't been able to figure it out. What I'd like to do is add the time a post is scheduled to the date stamp on the list of posts. I know this means modifying the columns, and there's a way to do it that seems fairly simple. Has anyone done this, and can you suggest some code?
|
Try this: <code> add_filter('manage_posts_columns', 'posts_columns', 5); add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2); function posts_columns($defaults){ $defaults['your_date_col'] = __('Date'); return $defaults; } function posts_custom_columns($column_name, $id){ if($column_name === 'your_date_col'){ echo the_date(); } } </code>
|
How to add the time of a post to the list of posts on the administration page?
|
wordpress
|
What happened to the plugin in Wordpress plugin repository? The link doesn't work: http://wordpress.org/extend/plugins/wp-no-category-base/ and search for this plugin doesn't list it. Yes, I know I can download it from author's page, but I am intrigued why would folks at wordpress.org remove it from their list?
|
I am the author of the plugin. Try again, its back now.
|
What happened to WP No Category Base?
|
wordpress
|
Hi I would like to import tables through CSV, any particular plugins or functions that can help me do that? I would like to have them stand in their own table and then the user would be able to include them via shortcode and id e.g. [table id=1] Thanks
|
I know there are a few but the one that stands out is WP-Table Reloaded plugin which answers your requirements and has endless of customization options and features.
|
CSV Import Tables
|
wordpress
|
Hopefully, this is an easy question - I'm just a bit confused. I've got a custom widget with the usual structure: <code> class My_Widget extends WP_Widget { function My_Widget() { // widget actual processes } function form($instance) { // outputs the options form on admin } function update($new_instance, $old_instance) { // processes widget options to be saved } function widget($args, $instance) { // outputs the content of the widget } } register_widget('My_Widget'); </code> I's like to add my own custom function to it, so I can reuse it. Something like: <code> function item_width_cols_to_class( $cols_num = null ) { if( $cols_num ){ switch ( $cols_num ){ case '2': return "col140"; break; case '3': return "col220"; break; case '4': return "col300"; break; case '5': return "col380"; break; case '6': return "col480"; break; case '7': return "col540"; break; default: return ""; break; } } } </code> However, when I add that code to My_Widget class I got an error saying: <code> "Fatal error: Call to undefined function 'item_width_cols_to_class()'" </code> . I'd think it's possible to add custom functions to a widget as it extends the WP_widget class. Am I doing something wrong? :S Thanks for help, Dasha
|
Where did you call your <code> item_width_cols_to_class </code> "function"? You are using the function as a method inside the <code> My_Widget </code> class. Therefore, you have to call it with a reference to its non-existent object e.g. <code> $this->item_width_cols_to_class() </code> or <code> self::item_width_cols_to_class() </code> (static).
|
Add a custom function to widget code
|
wordpress
|
i want to do a research in Category List Area. I'll Explain Here... Now I have 4 Categories Like 1,2,3,4. First of all it needs to show in the category pages Horizontally.Next is, While Clicking on Any Category it will show the articles from only that category in this thumbnail format, this also should be in a format that allows for 40 or 50 potential articles to be shown this way.
|
In the category link URL, add he category ID. Then when you click the link, the page reads the <code> $_GET </code> variable and use this to fetch posts with that category. You can use <code> get_posts </code> .
|
How to Show Category List With Corresponding Links?
|
wordpress
|
How Can I add some js files from a plugin to a specific location with add_action I am Using this widget: http://www.designchemical.com/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-vertical-accordion-menu-widget/ It is adding its file here: After <code> <script type='text/javascript' src='http://new.dajewelers.com/wp-includes/js/l10n.js? ver=20101110'></script> <script type='text/javascript' src='http://new.dajewelers.com/wp- includes/js/jquery/jquery.js?ver=1.4.4'></script> </code> and before these lines: <code> <script type='text/javascript' src='http://new.dajewelers.com/wp-includes/js/jquery/ui.core.js?ver=1.8.9'></script> <script type='text/javascript' src='http://new.dajewelers.com/wp-includes/js/jquery/ui.widget.js?ver=1.8.9'></script> <script type='text/javascript' src='http://new.dajewelers.com/wp-includes/js/jquery/ui.tabs.js?ver=1.8.9'></script> <script type='text/javascript' src='http://new.dajewelers.com/wp-includes/js/jquery/ui.mouse.js?ver=1.8.9'></script> <script type='text/javascript' src='http://new.dajewelers.com/wp-includes/js/jquery/ui.resizable.js?ver=1.8.9'></script> </code> Its code is basically for accordion and I think it is not working because it is coming before JQuery.ui files. So I want it to come after UI Files. Please can some one figure out the problem or if same is problem then how to fix that. And this is wp code that is doing so <code> if(!is_admin()){ // Header styles add_action( 'wp_head', array('dc_jqaccordion', 'header') ); // Scripts wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jqueryhoverintent', dc_jqaccordion::get_plugin_directory() . '/js/jquery.hoverIntent.minified.js', array('jquery') ); wp_enqueue_script( 'jquerycookie', dc_jqaccordion::get_plugin_directory() . '/js/jquery.cookie.js', array('jquery') ); wp_enqueue_script( 'dcjqaccordion', dc_jqaccordion::get_plugin_directory() . '/js/jquery.dcjqaccordion.2.8.js', array('jquery') ); } </code> Here is the link where all this is : http://new.dajewelers.com Please tell if you have any idea. thanks in advance.
|
you have a $ undefined js error on line 191. wp_enqueue_script has a dependencies parameter, I think you need to pass the jquery-ui handle as a dependency with your accordion script so it loads first.
|
I add some js files from a plugin to a specific location
|
wordpress
|
I've added to the theme (twenty ten) a php template file in which I've written some javascript code. I then created a new page and set it to use that template. Then I installed and activated the 'wp-minify' plugin hoping for it to drop the blanks and comments. But when I look at the page's source code in the browser I see the code regularly. Your advice will be appreciated.
|
As far as i understand WP Minify plugin works on scripts and styles that are included in your page <code> <head> </code> tag as external files and not scripts and style that are in the <code> <body> </code> tag. if you are inserting scripts and style in the <code> <body> </code> tag manully you should insert it after you minify it and you can use many of the free online minify tools
|
Wp-minify doesn't seem to minify my JS code
|
wordpress
|
Almost all divs say wpl but can't find which plugin is. For example, <code> #wpl-likebox </code> . Here is a page that is using it: http://wpdevel.wordpress.com/2011/05/25/jquery-updates-in-wordpress-3-2/
|
It is a custom Plugin for WordPress.com.
|
Can anyone identify this like plugin (not facebook like)?
|
wordpress
|
I have a client who has the categories listed in the right-hand sidebar. He came to me today requesting a different "navigation" in the header for each category. So basically, if you click on Category 1, the navigation changes to a set of pages (that he has set) and so on. Is this even possible? I already have the built in menu feature activated, but I am really at a loss for this one.
|
You could set this in your theme using conditionals. Create a separate menu for each category using the WordPress menu feature (Appearances > Menus). Then in your theme, where you want the menu to display, determine which menu to display using the is_category('category-slug') and/or in_category('category-slug') conditionals and the wp_nav_menu function (http://codex.wordpress.org/Function_Reference/wp_nav_menu). For instance: <code> <?php if(is_category('first-category') || in_category('first-category)) { wp_nav_menu( array('menu' => 'First Category Nav' )); } else { wp_nav_menu( array('menu' => 'Default Nav' )); } ?> </code> That said, from a user-experience standpoint I'd recommend against switching out the main menu on a section-by-section basis. That will be very confusing for visitors. I'd recommend an additional category-specific menu instead, with consistent main navigation. Hope this helps!
|
Different Main Navigation per category
|
wordpress
|
I've been given a wordpress site to do some development work on (I didn't do any of the initial development on it). I've installed it locally and am running it with XAMPP on Windows 7. I generated the database from a mysqldump file and I made the changes to wp-config to link to the database. After also changing the URL values in the wp_options table (they were set to the path of the live site) I got it working so that all the posts and settings are are showing up in the wp-admin console. Also on the frontpage the blog item excerpts list is populating correctly and all the layout and images are loading fine. The problem is that when I click through to an article it returns a 404 object not found error. The URL path to the article page looks to be correct. Would really appreciate it if anyone had any suggestions on what may be wrong and what I need to do get the article display pages working. I figure it must still have something to do with an incorrect base URL path being set somewhere, but can't find any other places where it would need to be changed Thank you!
|
my first thought is that it is a permalinks issue. if it is, set your permalinks to default and the links should work correctly. also, be sure to search the database for (and replace) any other instances of the old live site's URL, particularly in wp_posts table. it's easy to forget to update guid and post_content [i.e., UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.livesiteurl.com', 'http://www.newsiteurl.com')]
|
article pages not displaying on local instance of wordpress site
|
wordpress
|
I'm using this bit of code to generate a menu: <code> <div id="menu"> <?php $args = array( 'depth' => 1, 'show_date' => '', 'date_format' => get_option('date_format'), 'child_of' => 0, 'exclude' => '426, 508', 'include' => '', 'title_li' => __(''), 'echo' => 1, 'authors' => '', 'sort_column' => 'menu_order, post_title', 'link_before' => '', 'link_after' => '', 'walker' => '' ); ?> <ul><div class="menu-button"><?php wp_list_pages( $args, 'sort_column=menu_order' ); ?></div></ul> </div> </code> It's generating the menu fine but one of the links I need it to goto another page. Is it possible to pick out that page by ID and tell it to goto a different address? If so, how can I do it?
|
I'm now using the Page Links To plugin to achieve this.
|
Pick out specific menu item from code
|
wordpress
|
I am designing a theme where the home page (i.e. <code> is_home() </code> ) should only display the latest blog post. I want to do something like <code> $wp_query->update_option('posts_per_page', 1) </code> every time I am on the home page. All other pages that display posts (like archives) should just follow the user defined option. This seems a bit unnecessary to do every single time since the option should just be set once, right? Is it possible within The Loop to just ignore the user-set option of <code> posts_per_page </code> and force <code> have_posts() </code> to just be set to one post? In general, where should this kind of "set-it-once" stuff go? I don't really think it should be a plug-in because it is theme specific. I also don't want to mess with the user's options which is why <code> update_option </code> isn't the best choice for this problem.
|
Alternate approach (if you want/need to keep this in functions.php and go via hooks instead of modifying template) would be something like this: <code> add_action( 'pre_get_posts', 'pre_get_posts_home' ); function pre_get_posts_home( $query ) { global $wp_query; if( $wp_query == $query && $query->is_home ) $query->set( 'posts_per_page', 1 ); } </code>
|
Where should I update_options in a theme?
|
wordpress
|
Here's the site I'm having problems with: http://www.ashleymosuro.com/newsite/about For some reason, my custom theme I created for the Jquery UI is being overridden by the google hosted stylesheet, and I have no idea where in my theme it is referencing the stylesheet. Wherever it is, I need to get rid of it. I'm trying to style the progress bars in the sidebar so that they are 20px high. I have done this in my custom theme stylesheet but it just keeps being overridden. Any suggestions? Thanks,
|
try and use the correct syntax in the stylesheet: <code> /* jQuery UI Progressbar 1.8.13*/ /* Progress bars on about page*/ .ui-progressbar.ui-widget.ui-widget-content.ui-corner-all { height:20px; text-align: left; } </code> (i don't know where the google css comes from. and excuse the way the code is presented; the 'code' button seems to be out-of-order)
|
Jquery UI Google CSS, from where?
|
wordpress
|
Wordpress 3.2 beta comes with twenty eleven. It has a Theme Option panel in the Appearance section: I would like to know what's the easiest (and extendible) way of adding more options to that panel. For instance, changing the color of other elements?
|
As you can see in source theme makes some use of Settings API , but doesn't include calls like <code> do_settings_fileds() </code> that would allow you to use add settings. I would probably try to unhook <code> twentyeleven_theme_options_add_page() </code> call and fork that and <code> theme_options_render_page() </code> to extend it with additional options. Also I think that unlike core Twenty Eleven wasn't declared to be ready yet. Things might change.
|
What's the easiest way of adding more options in the Theme Options of the twenty eleven theme?
|
wordpress
|
I've been using the Custom Field Template plugin for a while now, and I really like it. It's fantastic for adding quick custom field meta boxes in the wordpress back end. It handles TinyMCE, file uploads, repeating fields, date picker, etc. For really advanced stuff I do custom coding, but nothing beats rapid development with this plugin. There is only one problem with this powerful plugin: the developer is japanese and the documentation is almost non-existant. The docs on his site in english are poor, and other stuff I've found on the web is limited. The question: where is the best place for Custom Field Template documentation - especially for the more advanced features. I'm guessing that there is no place so lets begin creating the definitive source right here on wonderful Wordpress Answers. Here is what I found so far: Author's website (english version of Japanese) Multiple Fields & Groups with the WordPress Custom Field Template Plugin
|
Create a public gist or a repository. You can use multiple files per gist, everyone can comment or fork the project. It is like a wiki for developers. :)
|
Let's Create Custom Field Template Documentation
|
wordpress
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.