question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
We're building a plugin that displays posts, and we also want to display the image gallery when it is used in a post. However, we need to limit the number of photos displayed? Is that possible?
There's two ways you can go about this, but both involve creating a function that does pretty much the same as the existing gallery shortcode function... You can either.. Hook onto <code> post_gallery </code> and manipulate the incoming data(you can use the gallery shortcode function as a base for the filter if necessary) Unregister the gallery shortcode and register a new gallery shortcode with modifications(again you can use the existing function as a base if necessary) I did something similar in stackexchange-url ("this thread"), and i'm only referring to it because i'm going to take the same approach for the example that follows. Example filter for the gallery shortcode <code> add_filter( 'post_gallery', 'my_post_gallery', 10, 2 ); function my_post_gallery( $output, $attr) { global $post, $wp_locale; static $instance = 0; $instance++; // We're trusting author input, so let's at least make sure it looks like a valid orderby statement if ( isset( $attr['orderby'] ) ) { $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); if ( !$attr['orderby'] ) unset( $attr['orderby'] ); } extract(shortcode_atts(array( 'order' =&gt; 'ASC', 'orderby' =&gt; 'menu_order ID', 'id' =&gt; $post-&gt;ID, 'itemtag' =&gt; 'dl', 'icontag' =&gt; 'dt', 'captiontag' =&gt; 'dd', 'columns' =&gt; 3, 'size' =&gt; 'thumbnail', 'include' =&gt; '', 'exclude' =&gt; '' ), $attr)); $id = intval($id); if ( 'RAND' == $order ) $orderby = 'none'; if ( !empty($include) ) { $include = preg_replace( '/[^0-9,]+/', '', $include ); $_attachments = get_posts( array('include' =&gt; $include, 'post_status' =&gt; 'inherit', 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'order' =&gt; $order, 'orderby' =&gt; $orderby) ); $attachments = array(); foreach ( $_attachments as $key =&gt; $val ) { $attachments[$val-&gt;ID] = $_attachments[$key]; } } elseif ( !empty($exclude) ) { $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); $attachments = get_children( array('post_parent' =&gt; $id, 'exclude' =&gt; $exclude, 'post_status' =&gt; 'inherit', 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'order' =&gt; $order, 'orderby' =&gt; $orderby) ); } else { $attachments = get_children( array('post_parent' =&gt; $id, 'post_status' =&gt; 'inherit', 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'order' =&gt; $order, 'orderby' =&gt; $orderby) ); } if ( empty($attachments) ) return ''; if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $att_id =&gt; $attachment ) $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; return $output; } $itemtag = tag_escape($itemtag); $captiontag = tag_escape($captiontag); $columns = intval($columns); $itemwidth = $columns &gt; 0 ? floor(100/$columns) : 100; $float = is_rtl() ? 'right' : 'left'; $selector = "gallery-{$instance}"; $output = apply_filters('gallery_style', " &lt;style type='text/css'&gt; #{$selector} { margin: auto; } #{$selector} .gallery-item { float: {$float}; margin-top: 10px; text-align: center; width: {$itemwidth}%; } #{$selector} img { border: 2px solid #cfcfcf; } #{$selector} .gallery-caption { margin-left: 0; } &lt;/style&gt; &lt;!-- see gallery_shortcode() in wp-includes/media.php --&gt; &lt;div id='$selector' class='gallery galleryid-{$id}'&gt;"); $i = 0; foreach ( $attachments as $id =&gt; $attachment ) { $link = isset($attr['link']) &amp;&amp; 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); $output .= "&lt;{$itemtag} class='gallery-item'&gt;"; $output .= " &lt;{$icontag} class='gallery-icon'&gt; $link &lt;/{$icontag}&gt;"; if ( $captiontag &amp;&amp; trim($attachment-&gt;post_excerpt) ) { $output .= " &lt;{$captiontag} class='gallery-caption'&gt; " . wptexturize($attachment-&gt;post_excerpt) . " &lt;/{$captiontag}&gt;"; } $output .= "&lt;/{$itemtag}&gt;"; if ( $columns &gt; 0 &amp;&amp; ++$i % $columns == 0 ) $output .= '&lt;br style="clear: both" /&gt;'; } $output .= " &lt;br style='clear: both;' /&gt; &lt;/div&gt;\n"; return $output; } </code> Modify that function to impose whatever restrictions you like(it's just a base).. You can find the hook i'm using in <code> wp-includes/media.php </code> inside the gallery shortcode callback function(see line 763). http://core.trac.wordpress.org/browser/tags/3.0.1/wp-includes/media.php#L745 Hope that helps.. :)
How to customise the output of the WP image gallery shortcode from a plugin?
wordpress
I'm working on a voting plugin for my site and I want to create 2 tables: one that stores votes and another that stores voter ips. In Codex it suggests to use an if statement to see if the table has already been created when installing the plugin but how can I alter the code if I'm creating 2 tables? This is my if statement in the plugin install function, currently set to check if 1 table already exists. <code> ... $table_name1 = $wpdb-&gt;prefix . "voters_ip"; $table_name2 = $wpdb-&gt;prefix . "vote_posts"; $installed_ver = get_option( "postvote_version" ); if($wpdb-&gt;get_var("show tables like '$table_name'") != $table_name1) { //unsure how to add both tables $sql = "CREATE TABLE " . $table_name1 . " ( id bigint(20) NOT NULL AUTO_INCREMENT, vote_post_id bigint(20) NOT NULL, voter_ip varchar(100) NOT NULL, UNIQUE KEY id (id) );"; $sql = "CREATE TABLE " . $table_name2 . " ( id bigint(20) NOT NULL AUTO_INCREMENT, vote_post_id bigint(20) NOT NULL, up int(11) NOT NULL, ddown int(11) NOT NULL, UNIQUE KEY id (id) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); add_option("postvote_version", $postvote_version); } .... </code> What is the correct way to check if both tables exist?
Basic programming techniques you should have learned before building a plugin: You can concatenate checks with &amp;&amp; (and) and || (or). You can (and should) guard each <code> CREATE </code> query with its own check SQL syntax you should have looked into before writing queries on your own: IF NOT EXISTS On a related note, please make sure that you delete these tables when the plugin is uninstalled/deleted . PS: No offense intended, but it does look like you copy pasted without knowing what the code does. Please be aware that by doing this in a plugin you risk other people's installations!
Creating two database tables via plugin
wordpress
I ran a search that did not yield that many results. Is it possible, and how can each sub-blog of a multi-site installation be given its own domain name?
Shortly after, I was able to find Otto's tutorial on the topic. WordPress 3.0: Multisite Domain Mapping Tutorial
How To Provide Sub-Blogs Their Own Domain Names?
wordpress
Does anyone know how to style the visual editor so that when specific shortcodes are used they are replaced with an image within the visual editor? I have found that many users screw up the shortcode text or delete it by mistake when using the visual editor so I would like for shortcodes to be replaced with paceholder images within the visual editor. HTML editor would still show the codes though.
I have not a working solution at hand, but what I would do is to analyze how this is done for the more seperator. In the HTML editor, there is <code> &lt;!-- more --&gt; </code> , in the visual editor, an image is displayed instead. This is done by extending the tinyMCE editor - which is the base of the visual editor in wordpress - with a plugin. To learn more about tinymce plugins, you find more examples and documentation in the moxiecode wiki: Creating a plugin for TinyMCE (3.x) . You find example code within the following file: <code> wp-includes/js/tinymce/plugins/wordpress/editor_plugin.dev.js </code> It works basically by replacing content (e.g. the shortcode <code> [mycode] </code> ) with some predefined HTML that contains the image. Before the content get's posted, it is replaced again with the original HTML. You can make use of regular expressions in the process. The more link is showing this quite well.
Styling Shortcodes in Visual Editor
wordpress
I need to apply an add_filter from my functions.php but only if the user has opened media-upload.php from my custom function. Is it possible to send a variable when opening media-upload.php that I could then test for existence of before executing add_filter? Example: Here is my code in which I'm opening the media uploader from my custom icon... <code> //Custom upload launcher for custom attachments function wpe_customImages($initcontext) { global $post; ?&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function() { var fileInput = ''; jQuery('#customAttachments').click(function() { fileInput = jQuery(this).prev('input'); formfield = jQuery('#upload_image').attr('name'); post_id = jQuery('#post_ID').val(); tb_show('', 'media-upload.php?post_id='+post_id+'&amp;amp;type=image&amp;amp;TB_iframe=true'); return false; }); }); &lt;/script&gt; &lt;?php return $initcontext. '&lt;input type="hidden" id="post_ID" value="'. $post-&gt;ID .'" /&gt; Product Images:&lt;a id="customAttachments" href="javascript:;" class="mceButton mceButtonEnabled" onmousedown="return false;" onclick="return false;"&gt; &lt;img src="'.get_bloginfo('template_directory') .'/img/upload-icon.gif"" /&gt;&lt;/a&gt;'; } add_filter('media_buttons_context', 'wpe_customImages'); </code> Inside the above code, would it be possible to set a global variable or some marker that I can test for in order to execute my add_filter code? <code> if(isset($myMarker)){ add_filter("attachment_fields_to_save", "rt_image_attachment_fields_to_save", null , 2); } </code>
From the looks of your code, clicking on the <code> #customAttachments </code> field is firing a jQuery event that calls a <code> tb_show() </code> method to load the <code> media-upload.php </code> file with certain GET parameters already set ( <code> post_id </code> , <code> type </code> , <code> TB_iframe </code> ). What you could do is add another GET parameter and check if that's set in order to execute your <code> add_filter() </code> code. So: <code> tb_show('', 'media-upload.php?post_id='+post_id+'&amp;amp;type=image&amp;amp;TB_iframe=true'); </code> Becomes: <code> tb_show('', 'media-upload.php?post_id='+post_id+'&amp;amp;type=image&amp;amp;TB_iframe=true&amp;amp;myMarker=true'); </code> Then you can use: <code> if(isset($_GET['myMarker'])){ add_filter("attachment_fields_to_save", "rt_image_attachment_fields_to_save", null , 2); } </code>
Conditional add_filter?
wordpress
I have script in my functions.php that seeks to locate the media directory of the site in which the theme is installed. This is pretty simple unless the site is an MU site. In that case, the media directory is based on the blog_id. However, my code below is returning the main site id rather than the blog_id of the site in which its being run... <code> function get_image_list() { global $current_site; $dir=is_multisite() ? 'wp-content/blogs.dir/'.$current_site-&gt;blog_id.'/files/' : 'wp-content/uploads/'; $url=is_multisite() ? get_bloginfo('url').'/wp-content/blogs.dir/'.$current_site-&gt;blog_id.'/files/' : get_bloginfo('url').'/wp-content/uploads/'; </code> In this case, the actual blog_id is 3, however, its returning a value of 1 for $current_site-> blog_id The error is... <code> cannot open wp-content/blogs.dir/1/files/ </code>
Compare <code> $current_site-&gt;id </code> with <code> $current_site-&gt;blog_id </code> . According to the in-line documentation, <code> blog_id </code> should be working ... but check to see if there's a major difference there (your system might have a plug-in or something else causing a problem). Update - Ignore last It seems like <code> $current_site </code> is a global variable defined by your site or network and will always return the same <code> blog_id </code> as your network dashboard - in this case, "1." What you need to use instead is <code> $current_blog </code> : <code> function get_image_list() { global $current_blog; $dir=is_multisite() ? 'wp-content/blogs.dir/'.$current_blog-&gt;blog_id.'/files/' : 'wp-content/uploads/'; $url=is_multisite() ? get_bloginfo('url').'/wp-content/blogs.dir/'.$current_blog-&gt;blog_id.'/files/' : get_bloginfo('url').'/wp-content/uploads/'; </code> That should get you the right information.
Error getting correct blog_id on MU from functions.php
wordpress
When I check "view source > frame info" on the window produced by the jQuery code below, it cuts off the querystring at the &amp;type=image. I'm url encoding the ampersands properly, right? <code> Address: ...wp-admin/media-upload.php?post_id=28&amp;type=image&amp; function wpe_customImages($initcontext) { global $post; ?&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function() { var fileInput = ''; jQuery('#wpe-uploadAttachments').click(function() { fileInput = jQuery(this).prev('input'); formfield = jQuery('#upload_image').attr('name'); post_id = jQuery('#post_ID').val(); tb_show('', 'media-upload.php?post_id='+post_id+'&amp;amp;type=image&amp;amp;TB_iframe=true&amp;amp;wpe_idCustomAttachment=true'); return false; }); </code>
As you have asked wether or not you have done the url encoding for the ampersands right, then my answer is: No. You are calling a javascript function, you're not outputting something as x(ht)ml. You therefore do not need to encode <code> &amp; </code> as <code> &amp;amp; </code> . The function is expecting a URL not a string that contains an xml encoded url. But that's probably nit-picking. The reason why this does not work is, that tb_show() cut's away anything after the first <code> TB_ </code> it finds in that URL, and only the part of the URL before that string is preserved for the iframe src. So you need to move the <code> TB_iframe=true </code> to the end of the parameter. This should do the trick: <code> tb_show('', 'media-upload.php?post_id='+post_id+'&amp;amp;type=image&amp;amp;wpe_idCustomAttachment=true&amp;amp;TB_iframe=true'); </code> BTW, wordpress is open source. You can just look to find the tb_show() function in source and look why something is happening or not. This can help to find out specific stuff. I didn't do anything else :)
Querystring data gets truncated
wordpress
I need more control over the category listing output, so I'm using get_categories (http://codex.wordpress.org/Function_Reference/get_categories), instead of wp_list_categories (http://codex.wordpress.org/Template_Tags/wp_list_categories). This function returns a flat array of objects ordered by a certain attribute. How can I build a hierarchical list from it like wp_list_categories() does?
The most ideal solution for walking over the data is to use the WordPress walker class. http://codex.wordpress.org/Function_Reference/Walker_Class You won't find many an example around the web for using it, but one was given by Scribu here. http://scribu.net/wordpress/extending-the-category-walker.html You can also look to the classes WordPress uses to extend the walker as further examples. http://core.trac.wordpress.org/browser/tags/3.0.1/wp-includes/classes.php Hope that helps..
Reproducing hierarchical list output from wp_list_categories, using get_categories()
wordpress
Working on a site for a client: http://esteyprinting.jasinternetmarketing.com/ I added an HTML table to header.php to include the "Call us at..." and the social media icons. It renders fine in most browsers but IE7 screws up that table. I ran it through the W3C validator and that part of the code is fine. You can see what I mean by putting the above URL into: http://ipinfo.info/netrenderer/ Any ideas for how to solve the problem? Thanks! Jim
Write a stylesheet just for ie7 and link it in wordpress like so: <code> &lt;!--[if IE 7]&gt;&lt;link rel="stylesheet" type="text/css" href="&lt;?php bloginfo('stylesheet_directory'); ?&gt;/css/ie7.css" /&gt;&lt;![endif]--&gt; </code> in the file add this <code> #header table {float:right;} #header table tr td p {margin-top:45px;} </code>
Adding HTML to the Header, Screws up in IE7
wordpress
Within wordpress 3.0 you have the ability to create a custom header image with a very slick built in cropping tool. I found out that the code being utilized for this is located within wp-admin/custom-header.php. What I am looking to do is including this same functionality within my own custom post type so that I can create many header images and rotate through them while also adding additional fields to each post. Does anyone know how to do this? Here is the code from the custom-header.php file. <code> &lt;?php /** * The custom header image script. * * @package WordPress * @subpackage Administration */ /** * The custom header image class. * * @since 2.1.0 * @package WordPress * @subpackage Administration */ class Custom_Image_Header { /** * Callback for administration header. * * @var callback * @since 2.1.0 * @access private */ var $admin_header_callback; /** * Callback for header div. * * @var callback * @since 3.0.0 * @access private */ var $admin_image_div_callback; /** * Holds default headers. * * @var array * @since 3.0.0 * @access private */ var $default_headers = array(); /** * Holds the page menu hook. * * @var string * @since 3.0.0 * @access private */ var $page = ''; /** * PHP4 Constructor - Register administration header callback. * * @since 2.1.0 * @param callback $admin_header_callback * @param callback $admin_image_div_callback Optional custom image div output callback. * @return Custom_Image_Header */ function Custom_Image_Header($admin_header_callback, $admin_image_div_callback = '') { $this-&gt;admin_header_callback = $admin_header_callback; $this-&gt;admin_image_div_callback = $admin_image_div_callback; } /** * Set up the hooks for the Custom Header admin page. * * @since 2.1.0 */ function init() { if ( ! current_user_can('edit_theme_options') ) return; $this-&gt;page = $page = add_theme_page(__('Header'), __('Header'), 'edit_theme_options', 'custom-header', array(&amp;$this, 'admin_page')); add_action("admin_print_scripts-$page", array(&amp;$this, 'js_includes')); add_action("admin_print_styles-$page", array(&amp;$this, 'css_includes')); add_action("admin_head-$page", array(&amp;$this, 'help') ); add_action("admin_head-$page", array(&amp;$this, 'take_action'), 50); add_action("admin_head-$page", array(&amp;$this, 'js'), 50); add_action("admin_head-$page", $this-&gt;admin_header_callback, 51); } /** * Adds contextual help. * * @since 3.0.0 */ function help() { add_contextual_help( $this-&gt;page, '&lt;p&gt;' . __( 'You can set a custom image header for your site. Simply upload the image and crop it, and the new header will go live immediately.' ) . '&lt;/p&gt;' . '&lt;p&gt;' . __( 'If you want to discard your custom header and go back to the default included in your theme, click on the buttons to remove the custom image and restore the original header image.' ) . '&lt;/p&gt;' . '&lt;p&gt;' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you&amp;#8217;d like and click the Save Changes button.' ) . '&lt;/p&gt;' . '&lt;p&gt;&lt;strong&gt;' . __( 'For more information:' ) . '&lt;/strong&gt;&lt;/p&gt;' . '&lt;p&gt;' . __( '&lt;a href="http://codex.wordpress.org/Appearance_Header_SubPanel" target="_blank"&gt;Documentation on Custom Header&lt;/a&gt;' ) . '&lt;/p&gt;' . '&lt;p&gt;' . __( '&lt;a href="http://wordpress.org/support/" target="_blank"&gt;Support Forums&lt;/a&gt;' ) . '&lt;/p&gt;' ); } /** * Get the current step. * * @since 2.6.0 * * @return int Current step */ function step() { if ( ! isset( $_GET['step'] ) ) return 1; $step = (int) $_GET['step']; if ( $step &lt; 1 || 3 &lt; $step ) $step = 1; return $step; } /** * Set up the enqueue for the JavaScript files. * * @since 2.1.0 */ function js_includes() { $step = $this-&gt;step(); if ( ( 1 == $step || 3 == $step ) &amp;&amp; $this-&gt;header_text() ) wp_enqueue_script('farbtastic'); elseif ( 2 == $step ) wp_enqueue_script('imgareaselect'); } /** * Set up the enqueue for the CSS files * * @since 2.7 */ function css_includes() { $step = $this-&gt;step(); if ( ( 1 == $step || 3 == $step ) &amp;&amp; $this-&gt;header_text() ) wp_enqueue_style('farbtastic'); elseif ( 2 == $step ) wp_enqueue_style('imgareaselect'); } /** * Check if header text is allowed * * @since 3.0.0 */ function header_text() { if ( defined( 'NO_HEADER_TEXT' ) &amp;&amp; NO_HEADER_TEXT ) return false; return true; } /** * Execute custom header modification. * * @since 2.6.0 */ function take_action() { if ( ! current_user_can('edit_theme_options') ) return; if ( empty( $_POST ) ) return; $this-&gt;updated = true; if ( isset( $_POST['resetheader'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); remove_theme_mod( 'header_image' ); return; } if ( isset( $_POST['resettext'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); remove_theme_mod('header_textcolor'); return; } if ( isset( $_POST['removeheader'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); set_theme_mod( 'header_image', '' ); return; } if ( isset( $_POST['text-color'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); $_POST['text-color'] = str_replace( '#', '', $_POST['text-color'] ); if ( 'blank' == $_POST['text-color'] ) { set_theme_mod( 'header_textcolor', 'blank' ); } else { $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['text-color']); if ( strlen($color) == 6 || strlen($color) == 3 ) set_theme_mod('header_textcolor', $color); } } if ( isset($_POST['default-header']) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); $this-&gt;process_default_headers(); if ( isset($this-&gt;default_headers[$_POST['default-header']]) ) set_theme_mod('header_image', esc_url($this-&gt;default_headers[$_POST['default-header']]['url'])); } } /** * Process the default headers * * @since 3.0.0 */ function process_default_headers() { global $_wp_default_headers; if ( !empty($this-&gt;headers) ) return; if ( !isset($_wp_default_headers) ) return; $this-&gt;default_headers = $_wp_default_headers; foreach ( array_keys($this-&gt;default_headers) as $header ) { $this-&gt;default_headers[$header]['url'] = sprintf( $this-&gt;default_headers[$header]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); $this-&gt;default_headers[$header]['thumbnail_url'] = sprintf( $this-&gt;default_headers[$header]['thumbnail_url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); } } /** * Display UI for selecting one of several default headers. * * @since 3.0.0 */ function show_default_header_selector() { echo '&lt;div id="available-headers"&gt;'; foreach ( $this-&gt;default_headers as $header_key =&gt; $header ) { $header_thumbnail = $header['thumbnail_url']; $header_url = $header['url']; $header_desc = $header['description']; echo '&lt;div class="default-header"&gt;'; echo '&lt;label&gt;&lt;input name="default-header" type="radio" value="' . esc_attr($header_key) . '" ' . checked($header_url, get_theme_mod( 'header_image' ), false) . ' /&gt;'; echo '&lt;img src="' . $header_thumbnail . '" alt="' . esc_attr($header_desc) .'" title="' . esc_attr($header_desc) .'" /&gt;&lt;/label&gt;'; echo '&lt;/div&gt;'; } echo '&lt;div class="clear"&gt;&lt;/div&gt;&lt;/div&gt;'; } /** * Execute Javascript depending on step. * * @since 2.1.0 */ function js() { $step = $this-&gt;step(); if ( ( 1 == $step || 3 == $step ) &amp;&amp; $this-&gt;header_text() ) $this-&gt;js_1(); elseif ( 2 == $step ) $this-&gt;js_2(); } /** * Display Javascript based on Step 1 and 3. * * @since 2.6.0 */ function js_1() { ?&gt; &lt;script type="text/javascript"&gt; /* &lt;![CDATA[ */ var text_objects = ['#name', '#desc', '#text-color-row']; var farbtastic; var default_color = '#&lt;?php echo HEADER_TEXTCOLOR; ?&gt;'; var old_color = null; function pickColor(color) { jQuery('#name').css('color', color); jQuery('#desc').css('color', color); jQuery('#text-color').val(color); farbtastic.setColor(color); } function toggle_text(s) { if (jQuery(s).attr('id') == 'showtext' &amp;&amp; jQuery('#text-color').val() != 'blank') return; if (jQuery(s).attr('id') == 'hidetext' &amp;&amp; jQuery('#text-color').val() == 'blank') return; if (jQuery('#text-color').val() == 'blank') { //Show text if (old_color == '#blank') old_color = default_color; jQuery( text_objects.toString() ).show(); jQuery('#text-color').val(old_color); jQuery('#name').css('color', old_color); jQuery('#desc').css('color', old_color); pickColor(old_color); } else { //Hide text jQuery( text_objects.toString() ).hide(); old_color = jQuery('#text-color').val(); jQuery('#text-color').val('blank'); } } jQuery(document).ready(function() { jQuery('#pickcolor').click(function() { jQuery('#color-picker').show(); }); jQuery('input[name="hidetext"]').click(function() { toggle_text(this); }); jQuery('#defaultcolor').click(function() { pickColor(default_color); jQuery('#text-color').val(default_color) }); jQuery('#text-color').keyup(function() { var _hex = jQuery('#text-color').val(); var hex = _hex; if ( hex[0] != '#' ) hex = '#' + hex; hex = hex.replace(/[^#a-fA-F0-9]+/, ''); if ( hex != _hex ) jQuery('#text-color').val(hex); if ( hex.length == 4 || hex.length == 7 ) pickColor( hex ); }); jQuery(document).mousedown(function(){ jQuery('#color-picker').each( function() { var display = jQuery(this).css('display'); if (display == 'block') jQuery(this).fadeOut(2); }); }); farbtastic = jQuery.farbtastic('#color-picker', function(color) { pickColor(color); }); &lt;?php if ( $color = get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) ) { ?&gt; pickColor('#&lt;?php echo $color; ?&gt;'); &lt;?php } ?&gt; &lt;?php if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this-&gt;header_text() ) { ?&gt; toggle_text(); &lt;?php } ?&gt; }); &lt;/script&gt; &lt;?php } /** * Display Javascript based on Step 2. * * @since 2.6.0 */ function js_2() { ?&gt; &lt;script type="text/javascript"&gt; /* &lt;![CDATA[ */ function onEndCrop( coords ) { jQuery( '#x1' ).val(coords.x); jQuery( '#y1' ).val(coords.y); jQuery( '#width' ).val(coords.w); jQuery( '#height' ).val(coords.h); } jQuery(document).ready(function() { var xinit = &lt;?php echo HEADER_IMAGE_WIDTH; ?&gt;; var yinit = &lt;?php echo HEADER_IMAGE_HEIGHT; ?&gt;; var ratio = xinit / yinit; var ximg = jQuery('img#upload').width(); var yimg = jQuery('img#upload').height(); if ( yimg &lt; yinit || ximg &lt; xinit ) { if ( ximg / yimg &gt; ratio ) { yinit = yimg; xinit = yinit * ratio; } else { xinit = ximg; yinit = xinit / ratio; } } jQuery('img#upload').imgAreaSelect({ handles: true, keys: true, aspectRatio: xinit + ':' + yinit, show: true, x1: 0, y1: 0, x2: xinit, y2: yinit, maxHeight: &lt;?php echo HEADER_IMAGE_HEIGHT; ?&gt;, maxWidth: &lt;?php echo HEADER_IMAGE_WIDTH; ?&gt;, onInit: function () { jQuery('#width').val(xinit); jQuery('#height').val(yinit); }, onSelectChange: function(img, c) { jQuery('#x1').val(c.x1); jQuery('#y1').val(c.y1); jQuery('#width').val(c.width); jQuery('#height').val(c.height); } }); }); /* ]]&gt; */ &lt;/script&gt; &lt;?php } /** * Display first step of custom header image page. * * @since 2.1.0 */ function step_1() { $this-&gt;process_default_headers(); ?&gt; &lt;div class="wrap"&gt; &lt;?php screen_icon(); ?&gt; &lt;h2&gt;&lt;?php _e('Custom Header'); ?&gt;&lt;/h2&gt; &lt;?php if ( ! empty( $this-&gt;updated ) ) { ?&gt; &lt;div id="message" class="updated"&gt; &lt;p&gt;&lt;?php printf( __( 'Header updated. &lt;a href="%s"&gt;Visit your site&lt;/a&gt; to see how it looks.' ), home_url( '/' ) ); ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;h3&gt;&lt;?php _e( 'Header Image' ) ?&gt;&lt;/h3&gt; &lt;table class="form-table"&gt; &lt;tbody&gt; &lt;tr valign="top"&gt; &lt;th scope="row"&gt;&lt;?php _e( 'Preview' ); ?&gt;&lt;/th&gt; &lt;td &gt; &lt;?php if ( $this-&gt;admin_image_div_callback ) { call_user_func( $this-&gt;admin_image_div_callback ); } else { ?&gt; &lt;div id="headimg" style="max-width:&lt;?php echo HEADER_IMAGE_WIDTH; ?&gt;px;height:&lt;?php echo HEADER_IMAGE_HEIGHT; ?&gt;px;background-image:url(&lt;?php esc_url ( header_image() ) ?&gt;);"&gt; &lt;?php if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this-&gt;header_text() ) $style = ' style="display:none;"'; else $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"'; ?&gt; &lt;h1&gt;&lt;a id="name"&lt;?php echo $style; ?&gt; onclick="return false;" href="&lt;?php bloginfo('url'); ?&gt;"&gt;&lt;?php bloginfo( 'name' ); ?&gt;&lt;/a&gt;&lt;/h1&gt; &lt;div id="desc"&lt;?php echo $style; ?&gt;&gt;&lt;?php bloginfo( 'description' ); ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;th scope="row"&gt;&lt;?php _e( 'Upload Image' ); ?&gt;&lt;/th&gt; &lt;td&gt; &lt;p&gt;&lt;?php _e( 'You can upload a custom header image to be shown at the top of your site instead of the default one. On the next screen you will be able to crop the image.' ); ?&gt;&lt;br /&gt; &lt;?php printf( __( 'Images of exactly &lt;strong&gt;%1$d &amp;times; %2$d pixels&lt;/strong&gt; will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); ?&gt;&lt;/p&gt; &lt;form enctype="multipart/form-data" id="upload-form" method="post" action="&lt;?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?&gt;"&gt; &lt;p&gt; &lt;label for="upload"&gt;&lt;?php _e( 'Choose an image from your computer:' ); ?&gt;&lt;/label&gt;&lt;br /&gt; &lt;input type="file" id="upload" name="import" /&gt; &lt;input type="hidden" name="action" value="save" /&gt; &lt;?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ) ?&gt; &lt;input type="submit" class="button" value="&lt;?php esc_attr_e( 'Upload' ); ?&gt;" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;form method="post" action="&lt;?php echo esc_attr( add_query_arg( 'step', 1 ) ) ?&gt;"&gt; &lt;table class="form-table"&gt; &lt;tbody&gt; &lt;?php if ( ! empty( $this-&gt;default_headers ) ) : ?&gt; &lt;tr valign="top"&gt; &lt;th scope="row"&gt;&lt;?php _e( 'Default Images' ); ?&gt;&lt;/th&gt; &lt;td&gt; &lt;p&gt;&lt;?php _e( 'If you don&amp;lsquo;t want to upload your own image, you can use one of these cool headers.' ) ?&gt;&lt;/p&gt; &lt;?php $this-&gt;show_default_header_selector(); ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php endif; if ( get_header_image() ) : ?&gt; &lt;tr valign="top"&gt; &lt;th scope="row"&gt;&lt;?php _e( 'Remove Image' ); ?&gt;&lt;/th&gt; &lt;td&gt; &lt;p&gt;&lt;?php _e( 'This will remove the header image. You will not be able to restore any customizations.' ) ?&gt;&lt;/p&gt; &lt;input type="submit" class="button" name="removeheader" value="&lt;?php esc_attr_e( 'Remove Header Image' ); ?&gt;" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php endif; if ( defined( 'HEADER_IMAGE' ) ) : ?&gt; &lt;tr valign="top"&gt; &lt;th scope="row"&gt;&lt;?php _e( 'Reset Image' ); ?&gt;&lt;/th&gt; &lt;td&gt; &lt;p&gt;&lt;?php _e( 'This will restore the original header image. You will not be able to restore any customizations.' ) ?&gt;&lt;/p&gt; &lt;input type="submit" class="button" name="resetheader" value="&lt;?php esc_attr_e( 'Restore Original Header Image' ); ?&gt;" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php endif; ?&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;?php if ( $this-&gt;header_text() ) : ?&gt; &lt;h3&gt;&lt;?php _e( 'Header Text' ) ?&gt;&lt;/h3&gt; &lt;table class="form-table"&gt; &lt;tbody&gt; &lt;tr valign="top" class="hide-if-no-js"&gt; &lt;th scope="row"&gt;&lt;?php _e( 'Display Text' ); ?&gt;&lt;/th&gt; &lt;td&gt; &lt;p&gt; &lt;?php $hidetext = get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ); ?&gt; &lt;label&gt;&lt;input type="radio" value="1" name="hidetext" id="hidetext"&lt;?php checked( ( 'blank' == $hidetext || empty( $hidetext ) ) ? true : false ); ?&gt; /&gt; &lt;?php _e( 'No' ); ?&gt;&lt;/label&gt; &lt;label&gt;&lt;input type="radio" value="0" name="hidetext" id="showtext"&lt;?php checked( ( 'blank' == $hidetext || empty( $hidetext ) ) ? false : true ); ?&gt; /&gt; &lt;?php _e( 'Yes' ); ?&gt;&lt;/label&gt; &lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top" id="text-color-row"&gt; &lt;th scope="row"&gt;&lt;?php _e( 'Text Color' ); ?&gt;&lt;/th&gt; &lt;td&gt; &lt;p&gt; &lt;input type="text" name="text-color" id="text-color" value="#&lt;?php echo esc_attr( get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) ); ?&gt;" /&gt; &lt;span class="description hide-if-js"&gt;&lt;?php _e( 'If you want to hide header text, add &lt;strong&gt;#blank&lt;/strong&gt; as text color.' );?&gt;&lt;/span&gt; &lt;input type="button" class="button hide-if-no-js" value="&lt;?php esc_attr_e( 'Select a Color' ); ?&gt;" id="pickcolor" /&gt; &lt;/p&gt; &lt;div id="color-picker" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php if ( defined('HEADER_TEXTCOLOR') &amp;&amp; get_theme_mod('header_textcolor') ) { ?&gt; &lt;tr valign="top"&gt; &lt;th scope="row"&gt;&lt;?php _e('Reset Text Color'); ?&gt;&lt;/th&gt; &lt;td&gt; &lt;p&gt;&lt;?php _e( 'This will restore the original header text. You will not be able to restore any customizations.' ) ?&gt;&lt;/p&gt; &lt;input type="submit" class="button" name="resettext" value="&lt;?php esc_attr_e( 'Restore Original Header Text' ); ?&gt;" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;?php endif; wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?&gt; &lt;p class="submit"&gt;&lt;input type="submit" class="button-primary" name="save-header-options" value="&lt;?php esc_attr_e( 'Save Changes' ); ?&gt;" /&gt;&lt;/p&gt; &lt;/form&gt; &lt;/div&gt; &lt;?php } /** * Display second step of custom header image page. * * @since 2.1.0 */ function step_2() { check_admin_referer('custom-header-upload', '_wpnonce-custom-header-upload'); $overrides = array('test_form' =&gt; false); $file = wp_handle_upload($_FILES['import'], $overrides); if ( isset($file['error']) ) wp_die( $file['error'], __( 'Image Upload Error' ) ); $url = $file['url']; $type = $file['type']; $file = $file['file']; $filename = basename($file); // Construct the object array $object = array( 'post_title' =&gt; $filename, 'post_content' =&gt; $url, 'post_mime_type' =&gt; $type, 'guid' =&gt; $url); // Save the data $id = wp_insert_attachment($object, $file); list($width, $height, $type, $attr) = getimagesize( $file ); if ( $width == HEADER_IMAGE_WIDTH &amp;&amp; $height == HEADER_IMAGE_HEIGHT ) { // Add the meta-data wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); set_theme_mod('header_image', esc_url($url)); do_action('wp_create_file_in_uploads', $file, $id); // For replication return $this-&gt;finished(); } elseif ( $width &gt; HEADER_IMAGE_WIDTH ) { $oitar = $width / HEADER_IMAGE_WIDTH; $image = wp_crop_image($file, 0, 0, $width, $height, HEADER_IMAGE_WIDTH, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file)); if ( is_wp_error( $image ) ) wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); $image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication $url = str_replace(basename($url), basename($image), $url); $width = $width / $oitar; $height = $height / $oitar; } else { $oitar = 1; } ?&gt; &lt;div class="wrap"&gt; &lt;?php screen_icon(); ?&gt; &lt;h2&gt;&lt;?php _e( 'Crop Header Image' ); ?&gt;&lt;/h2&gt; &lt;form method="post" action="&lt;?php echo esc_attr(add_query_arg('step', 3)); ?&gt;"&gt; &lt;p class="hide-if-no-js"&gt;&lt;?php _e('Choose the part of the image you want to use as your header.'); ?&gt;&lt;/p&gt; &lt;p class="hide-if-js"&gt;&lt;strong&gt;&lt;?php _e( 'You need Javascript to choose a part of the image.'); ?&gt;&lt;/strong&gt;&lt;/p&gt; &lt;div id="crop_image" style="position: relative"&gt; &lt;img src="&lt;?php echo esc_url( $url ); ?&gt;" id="upload" width="&lt;?php echo $width; ?&gt;" height="&lt;?php echo $height; ?&gt;" /&gt; &lt;/div&gt; &lt;p class="submit"&gt; &lt;input type="hidden" name="x1" id="x1" value="0"/&gt; &lt;input type="hidden" name="y1" id="y1" value="0"/&gt; &lt;input type="hidden" name="width" id="width" value="&lt;?php echo esc_attr( $width ); ?&gt;"/&gt; &lt;input type="hidden" name="height" id="height" value="&lt;?php echo esc_attr( $height ); ?&gt;"/&gt; &lt;input type="hidden" name="attachment_id" id="attachment_id" value="&lt;?php echo esc_attr( $id ); ?&gt;" /&gt; &lt;input type="hidden" name="oitar" id="oitar" value="&lt;?php echo esc_attr( $oitar ); ?&gt;" /&gt; &lt;?php wp_nonce_field( 'custom-header-crop-image' ) ?&gt; &lt;input type="submit" class="button-primary" value="&lt;?php esc_attr_e( 'Crop and Publish' ); ?&gt;" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;/div&gt; &lt;?php } /** * Display third step of custom header image page. * * @since 2.1.0 */ function step_3() { check_admin_referer('custom-header-crop-image'); if ( $_POST['oitar'] &gt; 1 ) { $_POST['x1'] = $_POST['x1'] * $_POST['oitar']; $_POST['y1'] = $_POST['y1'] * $_POST['oitar']; $_POST['width'] = $_POST['width'] * $_POST['oitar']; $_POST['height'] = $_POST['height'] * $_POST['oitar']; } $original = get_attached_file( $_POST['attachment_id'] ); $cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); if ( is_wp_error( $cropped ) ) wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication $parent = get_post($_POST['attachment_id']); $parent_url = $parent-&gt;guid; $url = str_replace(basename($parent_url), basename($cropped), $parent_url); // Construct the object array $object = array( 'ID' =&gt; $_POST['attachment_id'], 'post_title' =&gt; basename($cropped), 'post_content' =&gt; $url, 'post_mime_type' =&gt; 'image/jpeg', 'guid' =&gt; $url ); // Update the attachment wp_insert_attachment($object, $cropped); wp_update_attachment_metadata( $_POST['attachment_id'], wp_generate_attachment_metadata( $_POST['attachment_id'], $cropped ) ); set_theme_mod('header_image', $url); // cleanup $medium = str_replace(basename($original), 'midsize-'.basename($original), $original); @unlink( apply_filters( 'wp_delete_file', $medium ) ); @unlink( apply_filters( 'wp_delete_file', $original ) ); return $this-&gt;finished(); } /** * Display last step of custom header image page. * * @since 2.1.0 */ function finished() { $this-&gt;updated = true; $this-&gt;step_1(); } /** * Display the page based on the current step. * * @since 2.1.0 */ function admin_page() { if ( ! current_user_can('edit_theme_options') ) wp_die(__('You do not have permission to customize headers.')); $step = $this-&gt;step(); if ( 1 == $step ) $this-&gt;step_1(); elseif ( 2 == $step ) $this-&gt;step_2(); elseif ( 3 == $step ) $this-&gt;step_3(); } } ?&gt; </code>
If I understand you right, you're looking for custom header support for custom post types. By default WordPress does not offer such a thing for custom post types. The features that are offered for CPTs are listed here: Arguments for register post type() . So this is not easily possible.
Duplicate Custom Header Functionality into the post edit screen
wordpress
I have created a page that uses custom posts: http://www.africanhealthleadership.org/resources/toolkit/ Each tool (Preparation, Assessment, etc.) is a custom post. On the WP Admin, each tool is a category; each category has a "description" field. I would like to output those descriptions on the Toolkit page. I tried using this and nothing displayed: <code> &lt;?php echo category_description( $category ); ?&gt; </code> Right now, the descriptions are hard-coded in to the page. The one for preparation begins "Preparation tools establish..." Thank you for any ideas! Jeff Here is the loop that spits out the custom post type: <code> &lt;?php query_posts( array( 'post_type' =&gt; 'portfolio', 'toolkit' =&gt; 'preparation' ) ); //the loop start here if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; &lt;?php the_content(); ?&gt; &lt;?php endwhile; endif; wp_reset_query(); ?&gt; </code> And Here is the code from functions.php <code> add_action('init', 'portfolio_register'); function portfolio_register() { $labels = array( 'name' =&gt; _x('Toolkit', 'post type general name'), 'singular_name' =&gt; _x('Tool', 'post type singular name'), 'add_new' =&gt; _x('Add New Tool', 'tool'), 'add_new_item' =&gt; __('Add New Tool'), 'edit_item' =&gt; __('Edit Tool'), 'new_item' =&gt; __('New Tool'), 'view_item' =&gt; __('View Tool'), 'search_items' =&gt; __('Search Toolkit'), 'not_found' =&gt; __('Nothing found'), 'not_found_in_trash' =&gt; __('Nothing found in Trash'), 'parent_item_colon' =&gt; '' ); $args = array( 'labels' =&gt; $labels, 'public' =&gt; true, 'publicly_queryable' =&gt; true, 'show_ui' =&gt; true, 'query_var' =&gt; true, 'menu_icon' =&gt; get_stylesheet_directory_uri() . '/article16.png', 'rewrite' =&gt; true, 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, 'menu_position' =&gt; null, 'supports' =&gt; array('title','editor','thumbnail') ); register_post_type( 'portfolio' , $args ); } register_taxonomy("toolkit", array("portfolio"), array("hierarchical" =&gt; true, "label" =&gt; "Tool Categories", "singular_label" =&gt; "Tool", "rewrite" =&gt; true)); </code>
To get the taxonomy term for this particular post, then what you need is <code> wp_get_post_terms($post-&gt;ID, 'yourtaxonomyname') </code> This will return an array of terms in the specified taxonomy for the post specified. The codex page is: http://codex.wordpress.org/Function_Reference/wp_get_post_terms If you're after a specific term in a taxonomy get_term($taxonomy_name, $term_id). You can also get all terms for a taxonomy using get_terms() Here's an example of how to use it. <code> $terms = wp_get_post_terms($post-&gt;ID,'toolkit'); foreach ($terms as $term) { echo $term-&gt;description; } </code>
How to display category information from a custom post
wordpress
I'm calling media-upload.php via a custom icon click inside the content editor and I would like to add a custom meta value for all images that are uploaded when the media-upload.php is called from my custom function. For example, for each of the images that are uploaded, I want to insert a value into wp_postmeta of _customAttachment = 1 like so: <code> update_post_meta($post['ID'], '_customAttachment', true); </code> I know how I can pass the current post-id to the media-upload.php (via querystring parameters), but I have no idea how to attach my update_post_meta filter to the save/upload trigger in media-upload.php Is there a filter for this?
Yes, you can add fields, an example <code> function rt_image_attachment_fields_to_save($post, $attachment) { // $attachment part of the form $_POST ($_POST[attachments][postID]) // $post['post_type'] == 'attachment' if( isset($attachment['rt-image-link']) ){ // update_post_meta(postID, meta_key, meta_value); update_post_meta($post['ID'], '_rt-image-link', $attachment['rt-image-link']); } return $post; } // now attach our function to the hook. add_filter("attachment_fields_to_save", "rt_image_attachment_fields_to_save", null , 2); </code> see more on this post
Can I add custom meta for each image uploaded via media-upload.php?
wordpress
Does anyone happen to know how to create a simple "attach/browse" button that can be placed into a metabox which upon clicking it would open a lightbox where the user would be able to view all the media files, tick the ones he wants to attach and click an "attach" button on the bottom. After clicking "attach" the post metabox would update with all the files he selected...
For the part of opening a lightbox, browse for something and then performing something on an action within: Wordpress has this already build in. For what you ask is basically the thickbox that opens up like in the post editor when you browse for an image in the gallery. You find all the code you need for that already in wordpress. The only thing you need to do is to collect the rather more complex chunk of code, package it up in a plugin on it's own and modify it to fit your needs. Those components are not very re-useable on their own, so there is no API which could have made this easier for you. Well, that's not really true, you can use <code> tb_show() </code> to display the thickbox for stackexchange-url ("example"). But overall, this is not trivial. You probably are looking for something that is easier to adopt. I don't know. I once tinkered with thickbox &lt;-> post editor communication (which might be more complex with what you need), and there is a lot to think about to do things. But for the scenario you describe, it's often needed, to signal the page that is opening the thickbox to update something after the selection in the popup has been made. For the metabox, you should find enough code-snippets how to create one, so I'm pretty sure that there is already code for that.
Attach Files Metabox
wordpress
I have certain names in my category title (that need to stay there for other reasons). I am displaying all category titles with the blog name prefixed, but on categories that already have this name I would like to automatically remove the blog name from the single_cat_title. i.e. "My Blog My Blog Category" is what is showing using but where single_cat_title allready has the blogname as part of the title, I would like to only show "My Blog Category". Can one do this with single_cat_title as I have used it everywhere and manually replacing these would be problemattic?
There is a filter with the same name ( <code> single_cat_title </code> ) you can make use of to replace a particular word all the time: <code> add_filter('single_cat_title', function($title) { return str_replace('word to replace', '', $title); }) ; </code> This should basically do the job.
how do I filter single_cat_title to remove all instances of a particlular word
wordpress
how to make permalink available for search result page /?s=one+two+ok to /search/one-two-ok/ thank
That kind of search request should already work(query it directly in your address bar), the component you're missing is redirecting the non-pretty search requests.. For doing the redirect, you should find the following plugin still works.. http://txfx.net/wordpress-plugins/nice-search/ Hope that helps..
Search result permalink
wordpress
I've added a new page under "Pages" in the wordpress admin, and added several custom fields. I'd also like to be able to add an upload image field to the page editor - is there some way to do this via custom-fields? Or is there a different direction I need to take if I need this ability?
For anyone who wants to know more about file uploading, here's a quick primer covering the major topics and pain points. This is written with WordPress 3.0 on a Linux box in mind, and the code is just a basic overview to teach the concepts--I'm sure some folks here could offer advice for improvement on the implementation. Outline Your Basic Approach There at least three ways to associate images with posts: using a post_meta field to store the image path, using a post_meta field to store the image's media library ID (more on that later), or assigning the image to the post as an attachment. This example will use a post_meta field to store the image's media library ID. YMMV. Multipart Encoding By default, WordPress' create &amp; edit forms have no enctype. If you want to upload a file, you'll need to add an "enctype='multipart/form-data'" to the form tag--otherwise the $_FILES collection won't get pushed through at all. In WordPress 3.0, there's a hook for that. In some previous versions (not sure of the specifics) you have to string replace the form tag. <code> function xxxx_add_edit_form_multipart_encoding() { echo ' enctype="multipart/form-data"'; } add_action('post_edit_form_tag', 'xxxx_add_edit_form_multipart_encoding'); </code> Create the Meta Box and Upload Field I won't go far into creating meta boxes as most of you probably already know how to do it, but I'll just say that you only need a simple meta box with a file field in it. In the example below I've included some code to look for an existing image, and display it if one exists. I've also included some simple error/feedback functionality that passes errors using a post_meta field. You'll want to change this to use the WP_Error class... it's just for demonstration. <code> function xxxx_render_image_attachment_box($post) { // See if there's an existing image. (We're associating images with posts by saving the image's 'attachment id' as a post meta value) // Incidentally, this is also how you'd find any uploaded files for display on the frontend. $existing_image_id = get_post_meta($post-&gt;ID,'_xxxx_attached_image', true); if(is_numeric($existing_image_id)) { echo '&lt;div&gt;'; $arr_existing_image = wp_get_attachment_image_src($existing_image_id, 'large'); $existing_image_url = $arr_existing_image[0]; echo '&lt;img src="' . $existing_image_url . '" /&gt;'; echo '&lt;/div&gt;'; } // If there is an existing image, show it if($existing_image) { echo '&lt;div&gt;Attached Image ID: ' . $existing_image . '&lt;/div&gt;'; } echo 'Upload an image: &lt;input type="file" name="xxxx_image" id="xxxx_image" /&gt;'; // See if there's a status message to display (we're using this to show errors during the upload process, though we should probably be using the WP_error class) $status_message = get_post_meta($post-&gt;ID,'_xxxx_attached_image_upload_feedback', true); // Show an error message if there is one if($status_message) { echo '&lt;div class="upload_status_message"&gt;'; echo $status_message; echo '&lt;/div&gt;'; } // Put in a hidden flag. This helps differentiate between manual saves and auto-saves (in auto-saves, the file wouldn't be passed). echo '&lt;input type="hidden" name="xxxx_manual_save_flag" value="true" /&gt;'; } function xxxx_setup_meta_boxes() { // Add the box to a particular custom content type page add_meta_box('xxxx_image_box', 'Upload Image', 'xxxx_render_image_attachment_box', 'post', 'normal', 'high'); } add_action('admin_init','xxxx_setup_meta_boxes'); </code> Handling the File Upload This is the big one--actually handling the file upload by hooking into the save_post action. I've included a heavily-commented function below, but I'd like to note the two key WordPress functions it uses: wp_handle_upload() does all the magic of, well, handling the upload. You just pass it a reference to your field in the $_FILES array, and an array of options (don't worry too much about these--the only important one you need to set is test_form=false. Trust me). This function doesn't, however, add the uploaded file to the media library. It merely does the upload and returns the new file's path (and, handily, the full URL as well). If there's a problem, it returns an error. wp_insert_attachment() adds the image to the media library, and generates all of the appropriate thumbnails. You just pass it an array of options (title, post status, etc), and the LOCAL path (not URL) to the file you just uploaded. The great thing about putting your images in the media library is that you can easily delete all the files later by calling wp_delete_attachment and passing it the item's media library ID (which I'm doing in the function below). With this function, you'll also need to use wp_generate_attachment_metadata() and wp_update_attachment_metadata(), which do exactly what you'd expect they do--generate metadata for the media item. <code> function xxxx_update_post($post_id, $post) { // Get the post type. Since this function will run for ALL post saves (no matter what post type), we need to know this. // It's also important to note that the save_post action can runs multiple times on every post save, so you need to check and make sure the // post type in the passed object isn't "revision" $post_type = $post-&gt;post_type; // Make sure our flag is in there, otherwise it's an autosave and we should bail. if($post_id &amp;&amp; isset($_POST['xxxx_manual_save_flag'])) { // Logic to handle specific post types switch($post_type) { // If this is a post. You can change this case to reflect your custom post slug case 'post': // HANDLE THE FILE UPLOAD // If the upload field has a file in it if(isset($_FILES['xxxx_image']) &amp;&amp; ($_FILES['xxxx_image']['size'] &gt; 0)) { // Get the type of the uploaded file. This is returned as "type/extension" $arr_file_type = wp_check_filetype(basename($_FILES['xxxx_image']['name'])); $uploaded_file_type = $arr_file_type['type']; // Set an array containing a list of acceptable formats $allowed_file_types = array('image/jpg','image/jpeg','image/gif','image/png'); // If the uploaded file is the right format if(in_array($uploaded_file_type, $allowed_file_types)) { // Options array for the wp_handle_upload function. 'test_upload' =&gt; false $upload_overrides = array( 'test_form' =&gt; false ); // Handle the upload using WP's wp_handle_upload function. Takes the posted file and an options array $uploaded_file = wp_handle_upload($_FILES['xxxx_image'], $upload_overrides); // If the wp_handle_upload call returned a local path for the image if(isset($uploaded_file['file'])) { // The wp_insert_attachment function needs the literal system path, which was passed back from wp_handle_upload $file_name_and_location = $uploaded_file['file']; // Generate a title for the image that'll be used in the media library $file_title_for_media_library = 'your title here'; // Set up options array to add this file as an attachment $attachment = array( 'post_mime_type' =&gt; $uploaded_file_type, 'post_title' =&gt; 'Uploaded image ' . addslashes($file_title_for_media_library), 'post_content' =&gt; '', 'post_status' =&gt; 'inherit' ); // Run the wp_insert_attachment function. This adds the file to the media library and generates the thumbnails. If you wanted to attch this image to a post, you could pass the post id as a third param and it'd magically happen. $attach_id = wp_insert_attachment( $attachment, $file_name_and_location ); require_once(ABSPATH . "wp-admin" . '/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $file_name_and_location ); wp_update_attachment_metadata($attach_id, $attach_data); // Before we update the post meta, trash any previously uploaded image for this post. // You might not want this behavior, depending on how you're using the uploaded images. $existing_uploaded_image = (int) get_post_meta($post_id,'_xxxx_attached_image', true); if(is_numeric($existing_uploaded_image)) { wp_delete_attachment($existing_uploaded_image); } // Now, update the post meta to associate the new image with the post update_post_meta($post_id,'_xxxx_attached_image',$attach_id); // Set the feedback flag to false, since the upload was successful $upload_feedback = false; } else { // wp_handle_upload returned some kind of error. the return does contain error details, so you can use it here if you want. $upload_feedback = 'There was a problem with your upload.'; update_post_meta($post_id,'_xxxx_attached_image',$attach_id); } } else { // wrong file type $upload_feedback = 'Please upload only image files (jpg, gif or png).'; update_post_meta($post_id,'_xxxx_attached_image',$attach_id); } } else { // No file was passed $upload_feedback = false; } // Update the post meta with any feedback update_post_meta($post_id,'_xxxx_attached_image_upload_feedback',$upload_feedback); break; default: } // End switch return; } // End if manual save flag return; } add_action('save_post','xxxx_update_post',1,2); </code> Permissions, Ownership and Security If you have trouble uploading, it might have to do with permissions. I'm no expert on server config, so please correct me if this part is wonky. First, make sure your wp-content/uploads folder exists, and is owned by apache:apache. If so, you should be able to set the permissions to 744 and everything should just work. The ownership is important--even setting perms to 777 sometimes won't help if the directory isn't properly owned. You should also consider limiting the types of files uploaded and executed using an htaccess file. This prevents people from uploading files that aren't images, and from executing scripts disguised as images. You should probably google this for more authoritative info, but you can do simple file type limiting like this: <code> &lt;Files ^(*.jpeg|*.jpg|*.png|*.gif)&gt; order deny,allow deny from all &lt;/Files&gt; </code>
How can I add an image upload field directly to a custom write panel?
wordpress
I am setting up Wordpress for a school. They want to enable teachers to have their own section of the site where they can create posts in different categories (assignments, events, etc). I know that Wordpress supports multiple authors and that I can show posts by those authors out of the box by going to <code> http://domain.com/authors/{username} </code> . However, instead of just showing all of the posts from different categories in one loop, I would like to allow the user to view posts by category and they can choose from a link menu. Can anyone point me in the right direction on how to do this? Is there a way to create a url that would filter posts by author AND category?
You should consider to make use of an author template . It will allow you to control how the author page is displayed, so you can add what you pictured into there. You can then register a rewrite endpoint to create the multiple areas of the author page. In the template just check on which "subpage" you are and display the tabs and listing accordingly. That's basically doing WP_Query then which is pretty well documented, so should be an easy start.
How to set up sub-categories for author pages?
wordpress
I currently have a webside called storelocator.no. Here you can search for a brand, and you can see what stores sells this brand. Clicking a store, you will see what brands this store has. Currently I am using custom database for this. But now that WP has custom post types, I'm considering if I should create a custom post type for a store and one custom post type for a brand. I still have to make the connection between store and brand -> A store can have many brands, a brand can be in many stores. I also have to connect certain users up to a store or brand (store owner or brand owner), sΓ₯ that they can maintain infromation. Normal users can also sign up, so that they can add extra stores / labels into the system. Currently I have over 7.000 brands registered, and I will in due time have mane stores in the system. My questions is this: Should I stick to custom tables? Or should I take advantage of WP Custom post types? Would the site be slower using custom post types if I have several thousands entries? Oh, another thing. A user is never backend in WP to register data., Everything is done from front end.
I'll go with hakre's solution using RewriteAPI. I did not know it existed and it looks like it is what I need.
Custom post types or not custom post types?
wordpress
I just discovered this wonderful message board :-) Hopefully someone can help me with a Wordpress issue I can't figure out.. I added a hook to my plugin file to insert the post id of the immediate posts I publish, in a table named "post_votes" - used to keep track of up &amp; down votes for posts. <code> function post_votes($post_ID) { $wpdb-&gt;insert( $wpdb-&gt;prefix . 'post_votes', array( 'post_id' =&gt; $post_ID ) ); return $post_ID; } add_action ( 'publish_post', 'post_votes' ); </code> so the code above should add a post id in the post_id row (in post_votes table).. however I get, Fatal error: Call to a member function insert() on a non-object for <code> $wpdb-&gt;insert( $wpdb-&gt;prefix . 'post_votes', array( 'post_id' =&gt; $post_ID ) ); </code>
This is more or less a programming question. $wpdb is not available everywhere. It's a global variable. If you want to use it inside your own functions, just add <code> global $wpdb; </code> at the first line of the function. For general programming questions, this might be another discovery for you: stackexchange-url ("stackoverflow.com"),it is about programming in specific. Regardless being PHP (as with wordpress plugins) or javascript stuff. But for your wordpress problem, here is the code in full: <code> function post_votes($post_ID) { global $wpdb; $wpdb-&gt;insert( $wpdb-&gt;prefix . 'post_votes', array( 'post_id' =&gt; $post_ID ) ); return $post_ID; } add_action ( 'publish_post', 'post_votes' ); </code>
INSERT in table row fatal error
wordpress
On a site with premium user account subscriptions, I'd like to be able to limit logins to one computer at a time. The most straightforward way to accomplish this would be to limit by IP, but I haven't had any luck finding a plugin to accomplish this. Does anybody know of one I can use to get this functionality? Related: stackexchange-url ("Login security question - Does WP show me if I'm logged in from multiple locations?")
As already suggested in a comment above of mine, technically a (cookie based) session is limited to one IP at a time by using the Safer Cookies (Wordpress Plugin). This does not prevent to allow another login with the same username and password because it is a feature of wordpress to allow you to login multiple times with your credentials and therefore with multiple IPs. What you would like to achieve is to prevent multiple logins at all then. According to Otto, this is not trivial. Stacy writes, that the Wishlist Member (Wordpress Plugin) has such a functionality built in: IP-Login Protection. So probably that plugin or part thereof is a solution to your issue. IANAL, but that plugin is violating the GPL license as it restricts you to make use of your wordpress derivate. I would not use it. But probably there is another plugin out there available, or it's quite easy to extend Login LockDown (Wordpress Plugin) to bind the whole session to the last valid IP recorded.
Limiting sessions to one IP at a time
wordpress
How can one determine, from functions.php, the blog-id of the site (or alternately, the path to the media directory)?
For the current site, you can use the <code> $current_site </code> global variable and look at the blog_id member variable, e.g. <code> $current_site-&gt;blog_id </code>
How to get blog-id of an MU site from functions.php
wordpress
What is the call to determine, from a theme's functions.php whether the site is an MU site or not? Updated with answer: <code> $dir = is_multisite() ? 'wp-content/blogs.dir/'.$current_site-&gt;blog_id.'/files/' : 'wp-content/uploads/'; </code>
Try the <code> is_multisite() </code> conditional, more documentation here: http://codex.wordpress.org/Function_Reference/is_multisite You may find the <code> is_main_site() </code> conditional useful as well. Just note that <code> is_main_site() </code> will always be true if <code> is_multisite() </code> is false.
How to test for MU via functions.php?
wordpress
A friend of mine has a WordPress site using the Theisis theme. Recently he added a bit of problematic PHP code to the footer via the Theme (not into a PHP file). The PHP code is erroring out causing the site to WSOD (White Screen of Death). Because the footer is on every page, he can't get back in to remove the PHP code to fix the site. I'm not super familiar with WordPress (use mostly Drupal myself) so I'm not 100% sure how to help him. I'd guess the PHP snippet got stored in the database and needs to be manually removed from there. But I don't know the WordPress schema all that well. Can someone point me in the right direction? Where in the database would this code be store so I can remove it?
Use FTP to rename the Thesis theme folder and then WP will use the default theme and you will be able to get back into admin. If he edited the theme file via the theme editor in WP admin, then replace the file he edited in the Thesis folder from a fresh copy and try and reactivate the theme. If that doesn't work and the added code was saved to the Thesis theme options, use a plugin called Clean Options to clear out the old Thesis theme options and start over: http://wordpress.org/extend/plugins/clean-options/
Remove problem PHP code entered into footer via Theme
wordpress
Bear with me. I promise there's a question when I'm done :) In WordPress, you can upload images while editing a post and have the option to insert them into the content (or not). Regardless, the image appears to be "attached" to the post when viewing the Media manager. Does WordPress place any references into the database to differentiate an image that's been attached and also inserted into the post content? Or conversely, an image that's been attached to a post but has NOT been inserted into the post content? Why do I want to know this? I would like to allow the user to upload images that will be written above the post content (a row of images) by simply uploading them via the post attachment wizard. But they may also upload some images that they only want to appear in the content, so they will click "insert into post" in that case. Unless I have some way of differentiating images that have actually been inserted vs images that have merely been attached, they will get duplicate images, one in the post and one at the top of the post. Any thoughts on how to do this? I suppose an alternate approach would be to add a checkbox to the attachments editor to flag an image for display as a post header attachment, then do a lookup for images attached to the post with the special flag.
I used nextgen gallery plugin to do something like this. Actually I've used only half of that: the end user uploads images through the plugin's interface but the actual display inside the post is done with a custom shortcode. I don't think there is a way to tell if an attachment has been inserted in the post, short of examining the post content source.
How can you determine whether an image is merely attached or has actually been inserted into a post?
wordpress
Is there a built-in filter to add a custom icon and function to the WordPress "Uploads/Insert" toolbar? This is the toolbar that's located just above the content editor. The existing icon I want to replicate is shown in the blue circle of the image below. I'd like to add a custom icon that loads the "Add an Image" wizard and passes a special parameter to the upload function such that the attached images get a special meta attribute they would not ordinarily get when uploaded via the standard icon. Update: With the help of tnorthcutt's answer below, I've managed to hook into the media icon filter. From here, I should be able to attach a jQuery click event to the image or href and trigger the opening of the media-upload.php, passing a parameter to process the uploads as special... <code> //Upload custom images function addMediaIcon($initcontext) { return $initcontext. ' &lt;a id="myID" href="javascript:;" onmousedown="return false;" onclick="return false;" title="tooltip"&gt; &lt;img src="wp-admin/images/media-button-image.gif" onclick="javascript:alert()" title="" /&gt; &lt;/a&gt;'; } add_filter('media_buttons_context', 'addMediaIcon'); </code>
I'm inclined to say that this is possible. For instance, the Gravity Forms plugin adds an image here. Start with looking at the media_buttons_context hook.
Can I add an icon & function to the "Upload/Insert" toolbar at the top of the content editor?
wordpress
I was looking through the crawl results of my SEO Moz app and saw that there are somehow many copies of certain pages that have titles that are the exact same except for a number added to them. An example is in the image. How could this be happening?
These are attachment URLs. They are created for all images in your post. You have a gallery with 17 images, so for each image an URL with the structure <code> [post_url]/[attachment_name] </code> is created. <code> /2010/07/2011-honda-odyssey-official-details-photos-and-specs/ </code> is the post URL, <code> 2011_hondy_odyssey-2 </code> is the name of one of the images in it (created based on the file name when you upload it). You can style these pages by modifying the <code> attachment.php </code> template file.
Duplicate content with incremental titles. How is this happening?
wordpress
So a few days ago I added the following code to Geek for Him and obviously missed the nested comments portion. This is implemented on many other sites of mine, without Standard Theme of coarse and working fine. Am I missing something? Check out the link here - geekforhim dot com is the site A comment is made, I comment (highlight works) someone comments below me and it's highlighted also. Any help would be greatly appreciated. <code> .commentlist li.bypostauthor, li.comment-author-admin { background-color: #E0E0E0 !important; } </code> So I have figured out that fi I add a background to <code> #comments ul.children { background:none repeat scroll 0 0 #FFFFFF; margin:10px 0 0 25px; padding:0; } </code> it works, but its very ugly. Any cleaner ideas? See image below on what seems to messed up I have noticed that the comments themselves are one. What I mean by this is that 4 nested comments below one all equal one comment. This is not correctly coded in my mind and probably a bug fix? Any ideas or workarounds do let me know. UPDATED With the guidance below I was able to figure out what I was after. Thanks to t31os!!
The background is transparent, so it just inherits the styling of the parent comment.. Style the comment class.. <code> #comments li.comment { background-color: #fff /* Default styling */ } </code> Then do the more specific styling as you go down.. <code> #comments li.odd { /* whatever */ } /* Style odd numbered comments */ #comments li.even { /* whatever */ } /* Style even numbered comments */ #comments li.bypostauthor { /* whatever */ } /* Style author comments */ </code> The more specific rules go later, so you get a cascading effect with your styles.. NOTE: CSS selectors with IDs typically have precedance over those with classes (even if they come first), the more specific your CSS rule, the higher priority it has over others competiting to style a given element. Eg. <code> #comments li.comment { /* This rule will be given priority */ } .someclass li.comment { } </code> If you're a Firefox user, Firebug helps understand what styling an element is inheriting and from what style(strongly urge you to give it a try if you use Firefox). This is really more a question of how to use CSS to style nested elements with the selectors available than one specific to WordPress. That said, if you get stuck working out what rules to put where, post up your comment CSS so we can see how you're building and ordering your CSS rules(styles). I hope my answer helps.. EDIT: To answer your question in the comments. Try targetting the div that encases the comment and follows the containing <code> &lt;li&gt; </code> instead.. <code> #comments li.comment .comment-container {} #comments li.odd .comment-container {} </code> And so on... see if that helps... :)
Highlight Author Comments issues
wordpress
Is there a method or API that WordPress uses to encode the URLs similar to how it generates part of the URL when using the title in the URL? I am writing a plugin that generates URLs and would like to use the same method as everything else is. For instance, I type "This is my blog post" in the title and "this-is-my-blog-post" gets generated.
On a lower level, the function <code> sanitize_title_with_dashes() </code> converts to lowercase, replaces spaces and non-alphanumeric characters with dashes, and urlencodes whatever you pass to it. <code> &lt;?php echo sanitize_title_with_dashes( 'This is my blog post' ); // this-is-my-blog-post </code>
Encoding Method for URLs?
wordpress
I'm trying to set up a portfolio page on my wordpress website, and I would like the following construct: /blog/ where I blog all kinds of things, including portfolio entries /portfolio/ where I show just posts from my portfolio category some regular /pagename/ pages (about, contact, etc) I want the portfolio section to have a separate style (and even html probably) than a regular category overview. So if someone clicks one of the categories in my blog they still see the normal /category/randomcategory/ overview page. This means I can't just change the category php page and/or the css, because the portfolio page is different from the regular view. Is there a way to set up my page so that it shows the posts in the category portfolio the way I want?
The page of posts example pulls posts from one category, it uses a custom field to designate the category, which in turn makes the page template re-usable on other pages with other categories to, if you so choose.. You can style that template however you like.. Hope that helps..
Use a wordpress page to display a certain category
wordpress
I found several plugins/themes for creating a job board with WordPress, but only one solution which is free (see here ) Are there any other free solutions for doing that? Thanks.
Plug-ins Job Listing Job Manager WP Careers WP Job Board - Premium (This has a similar name to the one you linked to, but they seem to be completely different systems) Themes JobRoller - Premium Job Board - Premium JobPress - Premium Tapp Jobs - Premium As you can see, a lot of available solutions are premium plug-ins or themes. The pricing seems fairly reasonable ($25-$40 for a good solution), but if you're really strapped with your project budget the free plug-ins might serve as a good base for building your own replacement. Once again, though, I have no criteria with which to judge any of these alternatives since you never explained exactly what you were looking for. All of these options will help you build a job site, but without a better understanding of what you're trying to accomplish, I have no idea which, if any, would be the best route for you.
Creating a job board using WordPress (for free)?
wordpress
Standard WordPress sites, at least of the versions of WP I've tested, store files uploaded via the Media Manager under wp-content/uploads/ Where do these same files get stored in MU sites and how can you obtain a reference to this folder via script from functions.php? Is the location different depending on which version of WP or WPMU is installed?
Have a look at the following page and see if that answers the question for you... ;) https://core.trac.wordpress.org/browser/tags/3.0.1/wp-includes/ms-default-constants.php
Where do files uploaded via Media Manager get stored in MU?
wordpress
So the default url to display a list of posts by a particular author looks like this: <code> http://domain.com/author/{username} </code> I am wondering how to change the 'author' in that url to something else? I am working on a website for a charter school and they would like to allow each teacher to have a list of posts by "classroom". So the desired url would be <code> http://domain.com/classroom/{username} </code>
You might wish to try.. http://wordpress.org/extend/plugins/custom-author-base/ Hope that helps.. ;)
Override default url for author pages?
wordpress
I'm using the similar posts plugin <code> http://wordpress.org/extend/plugins/similar-posts/ </code> , and I want the similar posts to show on the same line instead of as a list... like link 1, link 2, link 3, link 4 instead of link 1 link 2 link 3 link 4 I posted this on the wordpress forum and on the plugin's official site days ago and still no answer... please help me! (I know very little about coding, so try to be specific, and if you give me code explain what each line does so I can learn please) thanks! Added info: I'm using mostly default settings for the plugin, I think the only change I made was to set it to only consider tags. I would think there would be something I could change on the output settings tab, but I have no idea what. I've got it set to display after the content because I couldn't figure out what file to put <code> &lt;?php similar_posts(); ?&gt; </code> and that's really where I wanted it anyways so it worked out perfectly. Oh, I am using the default theme Twenty Ten. Follow the link to wordpress forums in my chosen answer below for the missing parts of the discussion.
I've responded to your thread on the WP forums, see here.. http://wordpress.org/support/topic/simple-question-about-similar-posts-plugin You can do what you want from the plugin's settings page.. EDIT: Following the CSS suggestion, if you wanted to try this method. Leave the fields as they were Update the <code> &lt;ul&gt; </code> field to now read <code> &lt;ul id="my_special_id"&gt; </code> Update your theme's style.css file with the below. Example CSS. <code> #my_special_id, #my_special_id li { display:inline; } #my_special_id li a { margin-right: 5px; } </code> Which should result in the list items displaying side by side. The margin is to push the items away from one another, else they'll look like one long sting.. The <code> {link} </code> text is basically just a placeholder for output produced by the plugin, not much different to how a shortcode works...
Similar posts formatting
wordpress
Ok, I'm using the TagCloudShortCode plugin. I have a problem with how my tag pages display.... I want them to display the way they show on my main page, with the image and more button... how do I change the way it displays? I want it to display like this <code> http://www.top-iphone-apps.info/ </code> but it displays like this <code> http://www.top-iphone-apps.info/?tag=free </code> (I know very little about coding, so try to be specific, and if you give me code explain what each line does so I can learn please) thanks! Update... I fixed it by changing this in the index.php file <code> &lt;?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?&gt; &lt;div class="entry-summary"&gt; &lt;?php the_excerpt(); ?&gt; &lt;/div&gt;&lt;!-- .entry-summary --&gt; </code> to <code> &lt;?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?&gt; &lt;div class="entry-content"&gt; &lt;?php the_content( __( 'Continue reading &lt;span class="meta-nav"&gt;&amp;rarr;&lt;/span&gt;', 'twentyten' ) ); ?&gt; &lt;?php wp_link_pages( array( 'before' =&gt; '&lt;div class="page-link"&gt;' . __( 'Pages:', 'twentyten' ), 'after' =&gt; '&lt;/div&gt;' ) ); ?&gt; &lt;/div&gt;&lt;!-- .entry-content --&gt; </code> basically copying the stuff from the else statemnt. It worked, but I know it's a sloppy way of fixing it, so if anyone can tell me the better way of doing it I'd appreciate it.
First, the root of your issue is that WordPress has two very different template tags to output posts: <code> the_content() </code> and <code> the_excerpt() </code> . There are a lot of nuances with these and many get details wrong, I did my best to get everything right in post at my blog if you are interested that Make sense of WordPress excerpts and teasers . In this specific case you want <code> the_content() </code> , but theme uses <code> the_excerpt() </code> . Simply editing it as in your follow-up in question is not really sloppy, actually it is the only (non-messy) way to change one of these to another. Problem is you will lose your edits next time you update Twenty Ten (or WordPress, since Twenty Ten is part of package). The slightly more complex, but solid and upgrade proof way is to create child theme for Twenty Ten and apply your tweaks there. Create child theme, see Child Themes in Codex. It uses Twenty Ten as example, should be easy to follow. Switch to your child theme, at start it would be identical to Twenty Ten. Create file <code> loop-tag.php </code> in your child theme's folder. Copy content of Twenty Ten <code> loop.php </code> to that <code> loop-tag.php </code> you created. Apply your edits to <code> loop-tag.php </code> (you can probably just throw out extra stuff if you feel like it, this file will only load for tag archive pages).
How can I change how my tag pages display?
wordpress
I want to add 2 more rows (for voting up or down) to my default wordpress posts table. Would those rows be deleted when I update my WP version, or cause any other problem? An alternative would be to create a separate table but it's much faster and easier to query from 1 in my case.
First, I assume you're referring to columns, not rows. To answer your question, no, the upgrade process will not remove the extra columns from the posts table. That said, WordPress has the wp_postmeta table that should be used to store extra data about posts rather than adding columns to the posts table. I would suggest using the postmeta table instead of modifying the core database.
Adding new row to wp_post table
wordpress
The code below adds a custom input field to the attachments editor. How can I convert the text input to a checkbox and get/set the value of the checkbox on load and save? Note: <code> "input" =&gt; "checkbox" </code> does not work :( <code> function image_attachment_fields_to_edit($form_fields, $post) { $form_fields["imageLinksTo"] = array( "label" =&gt; __("Image Links To"), "input" =&gt; "text", "value" =&gt; get_post_meta($post-&gt;ID, "_imageLinksTo", true) ); return $form_fields; } function image_attachment_fields_to_save($post, $attachment) { if( isset($attachment['imageLinksTo']) ){ update_post_meta($post['ID'], '_imageLinksTo', $attachment['imageLinksTo']); } return $post; } add_filter("attachment_fields_to_edit", "image_attachment_fields_to_edit", null, 2); add_filter("attachment_fields_to_save", "image_attachment_fields_to_save", null, 2); </code>
Set the 'input' to 'html' and write out the html for the input: <code> function filter_attachment_fields_to_edit( $form_fields, $post ) { $foo = (bool) get_post_meta($post-&gt;ID, 'foo', true); $form_fields['foo'] = array( 'label' =&gt; 'Is Foo', 'input' =&gt; 'html', 'html' =&gt; '&lt;label for="attachments-'.$post-&gt;ID.'-foo"&gt; '. '&lt;input type="checkbox" id="attachments-'.$post-&gt;ID.'-foo" name="attachments['.$post-&gt;ID.'][foo]" value="1"'.($foo ? ' checked="checked"' : '').' /&gt; Yes&lt;/label&gt; ', 'value' =&gt; $foo, 'helps' =&gt; 'Check for yes' ); return $form_fields; } </code> Saving works just as you did above, but you're checking against a checkbox value instead, so you'll need to update to true if isset() and update to false if not.
How to add a checkbox element to attachments editor with example
wordpress
I need to show some info only to admins visiting a page, so I need a conditional tag to identify them. So far I have found: <code> &lt;?php if ( current_user_can('manage_options') ): ?&gt; </code> is this the correct function?
Yes, that's good. You can be a little safer using <code> &lt;?php if(current_user_can('manage_plugins') ); ?&gt; </code>
How to tell if the user is an admin?
wordpress
I really need your help. in my single.php I had to get the next post in the same category (which i already have by: $in_same_cat = true; $excluded_categories = ''; $previous = false; $next_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);) now I need the next next post and also in the opposite direction previous previous post thanx
surprisingly,I found the answer myself... I am using the same function as I used for next/previous post (get_adjacent_post() ) but sending the the next/previous post which I already found as a parameter <code> $in_same_cat = true; $excluded_categories = ''; $previous = true; $previous_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous); $previous_previous_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous,$previous_post); $previous = false; $next_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous); $next_next_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous,$next_post); </code> but...we haven't finished yet.. we need to add this code to the function declaration in wp-includes/link-template.php <code> function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true,$mypost = null) { global $wpdb; //if specific post wasnt sent to function it takes the global one and checks if its empty before using it. if ( empty( $mypost ) ) { global $post; if(empty( $post )) return null; $mypost=$post; } //... </code>
get next next post in single.php
wordpress
What do you think of killing jQuery in the public facing WP site? Isn't it useless and making for slower page loading? What's the best way to get rid of it?
jQuery is loaded by the theme that you use and not by WordPress. The theme must be modified to not load jQuery. Useless? not sure. It is very useful. Many themes' UI elements and even design elements may depend on jQuery.
What do I need jQuery for?
wordpress
How is plugin network activate different from normal activation by implementation? What is done/not done in network activation that is done/not done in activation?
Network activation will activate a plug-in for every site in a network whereas regular activation will only activate a plug-in for the site you're currently on. As far as implementation goes, there is one other important difference: If your plug-in is built to do something when it's activated (via <code> register_activation_hook() </code> ), this will fire automatically when you activate a plug-in normally, but it will not fire for a network-activated plug-in until you visit the admin screen for each blog. So if major database updates are tied in to <code> register_activation_hook() </code> they won't occur until you log in to the other sites.
How Is Network Activate Different From Activate (by Implementation)?
wordpress
I've got a custom post type called wine, this will be the main type, I also have a custom post type called review, I want to be able to associate multiple reviews with a wine and have this controlled in the review edit screen. On the Wine template I need to be able to link to the page listing all the reviews for that wine so the review needs to know the wine's $post-> id Thanks, Mark
I would add a custom taxonomy called "wine" as well. You can use this taxonomy to associate reviews about the same wine and also to associate the "wine" custom post with the taxonomy. Then you can run a query to get all "review" posts that share the "pinot" term in the "wine" taxonomy, for example. This makes it easier to group posts, custom posts, and pages without needing to know <code> $post-&gt;ID </code> for anything. Justin Tadlock has written a fantastic explanation of custom taxonomies if you need a place to start ...
Link a custom post type child to a parent using dropdown
wordpress
I am trying to show a list of posts that are related to category X and tag Y. I've tried the following code: <code> $args = array( 'posts_per_page' =&gt; 4, 'tag_id' =&gt; $tag_id, 'cat' =&gt; $cat_id, ); query_posts($args); </code> but it doesn't work correctly and returns all the posts in the co\ategory. Would love to hear any insight you might have
Edit: See below for proper way to query category and tag intersections. <code> global $wp_query; $args = array( 'category__and' =&gt; 'category', 'tag__in' =&gt; 'post_tag', //must use tag id for this field 'posts_per_page' =&gt; -1); //get all posts $posts = get_posts($args); foreach ($posts as $post) : //do stuff endforeach; </code>
how to query posts by category and tag?
wordpress
OK I need to query posts using the following criteria: category_name=office, meta_key=featured_post, meta_value=Yes and order these results using a second custom field which has a numerical value meta_key=prop_order I have the following query which pulls the correct posts, but doesn't order them by the second custom field. <code> &lt;?php $recent = new WP_Query("category_name=office&amp;meta_key=featured_post&amp;meta_value=Yes&amp;posts_per_page=3&amp;orderby=date&amp;order=ASC"); while($recent-&gt;have_posts()) : $recent-&gt;the_post(); ?&gt; </code> However since I'm already using a custom field in the query I can't use orderby=meta_value. I found the following SQL query on the forums but can't get it working. <code> &lt;?php global $wpdb; global $post; $querystr = " SELECT * FROM $wpdb-&gt;posts LEFT JOIN $wpdb-&gt;postmeta AS proporder ON( $wpdb-&gt;posts.ID = proporder.post_id AND proporder.meta_key = 'prop_order' ) LEFT JOIN $wpdb-&gt;term_relationships ON($wpdb-&gt;posts.ID = $wpdb-&gt;term_relationships.object_id) LEFT JOIN $wpdb-&gt;term_taxonomy ON($wpdb-&gt;term_relationships.term_taxonomy_id = $wpdb-&gt;term_taxonomy.term_taxonomy_id) WHERE $wpdb-&gt;term_taxonomy.term_id = 3 AND $wpdb-&gt;term_taxonomy.taxonomy = 'category' AND $wpdb-&gt;posts.post_status = 'publish' AND $wpdb-&gt;wpostmeta.meta_key = 'featured_post' AND $wpdb-&gt;wpostmeta.meta_value = 'Yes' ORDER BY proporder.meta_value ASC "; $pageposts = $wpdb-&gt;get_results($querystr, OBJECT); ?&gt; </code> Any help would be greatly appreciated! Thanks Dave
Thanks for your input guys. Didnt realise i'd never posted back on this! Thanks to Ethan and a few other foums heres the working code: <code> &lt;?php global $wpdb; global $post; $querystr = " SELECT * FROM $wpdb-&gt;posts LEFT JOIN $wpdb-&gt;postmeta AS proporder ON( $wpdb-&gt;posts.ID = proporder.post_id AND proporder.meta_key = 'prop_order' ) LEFT JOIN $wpdb-&gt;postmeta AS propfeatured ON( $wpdb-&gt;posts.ID = propfeatured.post_id AND propfeatured.meta_key = 'featured_post' ) LEFT JOIN $wpdb-&gt;term_relationships ON($wpdb-&gt;posts.ID = $wpdb-&gt;term_relationships.object_id) LEFT JOIN $wpdb-&gt;term_taxonomy ON($wpdb-&gt;term_relationships.term_taxonomy_id = $wpdb-&gt;term_taxonomy.term_taxonomy_id) WHERE $wpdb-&gt;term_taxonomy.term_id = 4 AND $wpdb-&gt;term_taxonomy.taxonomy = 'category' AND $wpdb-&gt;posts.post_status = 'publish' AND propfeatured.meta_value='Yes' ORDER BY proporder.meta_value ASC "; $pageposts = $wpdb-&gt;get_results($querystr, OBJECT); //print_r($querystr); ?&gt; &lt;?php foreach ($pageposts as $post): ?&gt; &lt;?php setup_postdata($post); ?&gt; &lt;!-- some post stuff here --&gt; &lt;?php endforeach; ?&gt; </code> where 'prop_order' and 'featured_post' are the custom fields and posts are returned that match featured_post='Yes' and then they are ordered by 'prop_order' in ASC order. hope this helps!
Query posts by category AND custom field, then ORDERBY another custom field - help!
wordpress
I'm sorry for this scholar question, but I'm totaly confused with search in Wordpress. What is the difference beetwen <code> searchpage.php </code> , <code> searchform.php </code> and <code> search.php </code> ? Could anybody tell me how it all works? Thanks.
Your question is most likely referring to a specific theme, but I'll answer it for the current default Twenty Ten (Wordpress Theme) as it's well documented. You find it in the <code> wp-content/themes/twentyten </code> directory. The main search template in there is <code> search.php </code> . It is the template file to display the search page. Which means either only the search form or when called for a search, the search results as well. <code> searchform.php </code> is a template part , so a fragment to hold the search form. The default theme does not ship with it by default, but if it exists it will load it instead of a hardcoded search form. Here is the default search from: <code> &lt;form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" &gt; &lt;div&gt;&lt;label class="screen-reader-text" for="s"&gt;' . __('Search for:') . '&lt;/label&gt; &lt;input type="text" value="' . get_search_query() . '" name="s" id="s" /&gt; &lt;input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" /&gt; &lt;/div&gt; &lt;/form&gt;' </code> That is done in the wordpress function <code> get_search_form() </code> which is part of the core package and used by many themes including Twenty Ten. <code> searchpage.php </code> is something specific to another theme I guess, as it is not used within the default theme and worpdress core. I assume by name, that it's having the same or a similar meaning as <code> search.php </code> but being specific to some other theme.
Search in Wordpress - Difference of searchpage.php, searchform.php and search.php?
wordpress
I would like to be able to grant my editors the power to change the menu, can this be done? The appearance tab doesn't appear to be an option at all, can I make it so?
add this to your theme's <code> functions.php </code> : <code> // add editor the privilege to edit theme // get the the role object $role_object = get_role( 'editor' ); // add $cap capability to this role object $role_object-&gt;add_cap( 'edit_theme_options' ); </code>
allow editors to edit menus?
wordpress
How to query Post with current date month with custom field: Here is my code <code> &lt;?php global $wp_query; $event_month = get_post_meta($wp_query-&gt;post-&gt;ID, 'eventdate', true); //format in db 11/17/2010 $event_month = date("n"); //A numeric representation of a month, without leading zeros (1 to 12) $today= getdate(); ?&gt; &lt;?php query_posts('meta_key='.$event_month .'&amp;meta_compare&amp;meta_value=' .$today["mon"]);?&gt; &lt;?php while (have_posts()): the_post(); ?&gt; &lt;div class="event-list-txt"&gt; &lt;h4&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" title="&lt;?php the_title(); ?&gt;" rel="bookmark"&gt; &lt;?php the_title(); ?&gt; &lt;/a&gt;&lt;/h4&gt; &lt;?php the_content(); //Display the content?&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;?php wp_reset_query();?&gt; </code> but it doesn't display the output.. .what I want to display is the event list for the month.. for example if it's November it will display the event list for November and when the month of December comes it will show the event list of December and so on.. . The event list date comes with custom field format like this 11/17/2010 compare to current date here are the additional expected output current date is November and the event list should be like this: <code> +-----------------------+-------------+ | Event Name | Date | +-----------------------+-------------+ | ABC Market opening | 11/18/2010 | | ABC Market Seminar | 11/25/2010 | | ABC Market Promo | 11/29/2010 | +-----------------------+-------------+ </code> thanks guys
<code> meta_key </code> value should be name of custom field. I doubt you have fields named after each month, so it's likely should be <code> eventdate </code> . <code> meta_compare </code> should have value that specifies a comparison operator, or just be omitted and it will default to <code> = </code> in that case. From this you can't really query full event date on equals condition to month alone. I am not sure but as I see it you will have either to add separate field for month/year (without day) or do much more complex query with <code> posts_where </code> filter. See Time Parameters , Custom Field Parameters in Codex for more documentation.
query_posts meta_key with current date
wordpress
I'm using this function to be able to retrieve several data, from outside the Loop: <code> function get_post_data($postId) { global $wpdb; return $wpdb-&gt;get_results("SELECT * FROM $wpdb-&gt;posts WHERE ID=$postId"); } </code> ... and then, this to display the date a post was published: <code> &lt;?php global $wp_query; global $thePostID; $thePostID = $wp_query-&gt;post-&gt;ID; $data = get_post_data($thePostID); echo $data[0]-&gt;post_date; ?&gt; </code> wich displays something like "2010-06-14 22:36:03" in my sidebar, but I'd like to format it like just "June, 2010" Can it be done?
I'm using something like this: <code> date('F, Y', strtotime($data[0]-&gt;post_date)); </code>
Formating the display of a post's date, outside the Loop
wordpress
I'm making a blog where only on specific pages I want to show different sidebar, I will add some widgets to those sidebar, which I don't want to show in default sidebar. I've found a coding method to do this , but I would like to use a plugin, and not edit code myself. I need to give the control of adding/removing sidebar/widgets in client hands. So is there any plug-in to do this easily?
A client of mine recently used a plug-in similar to Widget Context to accomplish this. Rather than create different sidebars you just define what contexts you want your widgets to show up in. So if you have a set of widgets you want to show up on a specific page, you mark them to only show up on that page. But it allows you to continue using widgets that show up on every page/post if you want. The convenience of this plug-in is that you don't have to code anything, and it's got a fairly intuitive UI you can put in the hands of your own clients.
How to Show Different Sidebars on Specific Pages?
wordpress
The shared server that I used for hosting my WordPress website was hacked recently, and many of the <code> index.php </code> files, plugin files and uploads were deleted, with my MySQL databases untouched. But after having restored all of it from my local backups, I'm having some weird problems. My homepage http://inversekarma.in does not fully load - the sidebar and footer are missing. If I view the page source, it ends at the point where the code for my sidebar starts. I am not able to login to the dashboard. It throws a 500 error. Please help me fix this issue! P.S.: I have another WordPress blog on the same domain, at <code> http://inversekarma.in/photos </code> , which is working perfectly without any of the above issues, after I restored the files from my backup.
Had you just overwrote site from backup? Not a good way since it may easily leave broken files or even backdoors. It is best to erase site completely, then copy clean WordPress archive and copy of your files from backup there. If possible it's best to restore database from pre-hack backup as well. If these are not possible I suggest you find someone who handles such cases professionally. There is now way to comprehensively advice on hacking case "in theory".
Weird problems after recovery from security breach
wordpress
I'm intending to use the default "post tags" taxonomy to provide a common set of tags across posts and 2 custom post types (to allow for collection/aggregation by tag). I'd like to rename the "post tags" taxonomy to something else - like "general tags' - to make it a bit clearer, especially when this taxonomy is attached to other custom post types. So, is there any way of doing this within Wordpress, or do I do it via SQL. Also, anyone know if there is an expectation that this taxonomy exists with the nane "post tags"
The information about taxonomies is stored in the global <code> $wp_taxonomies </code> array. If you register a new taxonomy, it is added as an object with different properties, including the labels to use in the UI. The standard tags and categories are also registered there on each page load, with the <code> create_initial_taxonomies() </code> function that fires on <code> init </code> . Since it is a simple array of objects, we can modify it and see what happens. The properties we are interested in are <code> labels </code> and <code> label </code> . <code> add_action( 'init', 'wpa4182_init'); function wpa4182_init() { global $wp_taxonomies; // The list of labels we can modify comes from // http://codex.wordpress.org/Function_Reference/register_taxonomy // http://core.trac.wordpress.org/browser/branches/3.0/wp-includes/taxonomy.php#L350 $wp_taxonomies['post_tag']-&gt;labels = (object)array( 'name' =&gt; 'WPA 4182 Tags', 'menu_name' =&gt; 'WPA 4182 Tags', 'singular_name' =&gt; 'WPA 4182 Tag', 'search_items' =&gt; 'Search WPA 4182 Tags', 'popular_items' =&gt; 'Popular WPA 4182 Tags', 'all_items' =&gt; 'All WPA 4182 Tags', 'parent_item' =&gt; null, // Tags aren't hierarchical 'parent_item_colon' =&gt; null, 'edit_item' =&gt; 'Edit WPA 4182 Tag', 'update_item' =&gt; 'Update WPA 4182 Tag', 'add_new_item' =&gt; 'Add new WPA 4182 Tag', 'new_item_name' =&gt; 'New WPA 4182 Tag Name', 'separate_items_with_commas' =&gt; 'Separata WPA 4182 tags with commas', 'add_or_remove_items' =&gt; 'Add or remove WPA 4182 tags', 'choose_from_most_used' =&gt; 'Choose from the most used WPA 4182 tags', ); $wp_taxonomies['post_tag']-&gt;label = 'WPA 4182 Tags'; } </code> I haven't checked it everywhere, and you'll probably have to change it in your theme yourself, but this seems to do what you want:
Can the default "post tags" taxonomy be renamed?
wordpress
I've tried everything: Peter's Login Redirect , Redirection , some unworking javascript hacks, routemap PHP Class (which is really impressive, but I'm not sure that's very useful in this case). I'm using Theme My Login , but its redirection settings just wouldn't respond. (Still need it, though). Any ideas?
You can use the WordPress function <code> wp_redirect() </code> . If you want a redirect after login or logout, check the plugin Adminimize, it has an option for this. Two examples for a redirect in a custom plugin or <code> functions.php </code> of the theme (the following example uses the variable <code> $pagenow </code> ): <code> function fb_redirect_1() { global $pagenow; if ( 'plugins.php' === $pagenow ) { if ( function_exists('admin_url') ) { wp_redirect( admin_url('edit-comments.php') ); } else { wp_redirect( get_option('siteurl') . '/wp-admin/' . 'edit-comments.php' ); } } } if ( is_admin() ) add_action( 'admin_menu', 'fb_redirect_1' ); </code> An alternative with <code> $_server </code> , checks the URL too: <code> function fb_redirect_2() { if ( preg_match('#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI']) ) { if ( function_exists('admin_url') ) { wp_redirect( admin_url('edit-comments.php') ); } else { wp_redirect( get_option('siteurl') . '/wp-admin/' . 'edit-comments.php' ); } } } if ( is_admin() ) add_action( 'admin_menu', 'fb_redirect_2' ); </code>
How to redirect after login, the working way?
wordpress
I've setup a custom post type and a custom taxonomy for that post type, but I'm having one problem - on the custom taxonomy permalink pages, the content of the custom post that should be there is not being displayed. However, looking at the page source, I can see that there is a div that should contain the post content. Any suggestions on how to get the entire content to be displayed? Edit: The Custom Post Types UI plugin was used for the creation of the custom post types and the custom taxonomies. Edit 2: Turns out it was a Thesis problem. Design Options > Display Options > Archives was set to "titles only", which kept the content of the posts from being displayed.
By default, a custom post type isn't included in the standard query. You'll need to manually create a query in your taxonomy page for that post type.
Trick to get custom post types to show up on a custom taxonomy page?
wordpress
Currently, it is up to any plugin's author as to where to put a link to the plugin's option page. I have seen at least the following "solutions": Plugin list Dashboard menu Plugins menu Appearance menu Tools menu Settings menu Tools menu Top level In my opinion, this is very bad style (globally, not necessarily individually). In addition to the mass of links in many different locations, Wordpress does not sort them or anything. As it is now, plugin developers can put anything anywhere in the menues and we probably want it that way; but there really should be a unified way of registering an options page such that is recognised and placed as such. Please see here , too. The old ways could remain valid, but I'd suggest recommending to use the standardised (and easy) way. I have lately thought about writing a plugin that provides such an frontend, that is offers a function for other plugin authors that registers an options page and cares for placing links to it in the appropriate places. The notion of appropriateness could be hardcoded in a first version and be left to the user in subsequent iterations. I can even image a screen were users can put pages registered by plugins (not necessarily only option pages) were it suits them; if the user thinks this plugin's options should be there, so be it. What do you think? In particular: As a plugin author, would you delegate to such a plugin? Do you think I should build it? Should I rather implement the feature directly into Wordpress, hoping that the main hackers approve and incorporate it?
There will never be such thing as a restriction of where a plugin can place a link that will display a certain page the plugin is registering. It's just in your scenario that a plugin is registering a settings page and the link normally is named settings as well. As there is no convention or suggestion what plugin authors can/should do, I see it even more probelmatic to restrict this. I doubt that a restriction would be technically effective and on the social side, it will only create problems for those who want/need to circumvent some more restricted approach. This has various reasons and you are totally right, this can be a problem because it's not easy to locate all the plugins settings. For the plugins I code that actually have a settings page, I prefer them to add in the plugin listing - at least as well. I know that some users look there if they don't locate stuff within the menu. So it would be nice if core provides an additional routine plugin authors could call to register their settings page. For plugins that don't do that, the plugin listing could display a greyed out - no settings - or else remark. Because I know that not all plugin authors do announce their settings page at least in the plugins listing, I've create a quicksearch plugin for the admin that let's you browse the menu quickly: Admin Quicksearch (Wordpress Plugin) - It let's you search the plugin listing quickly as well.
Unified Approach for Placing Option Pages
wordpress
I need to prevent uploading bmp image for user. How can it be possible?
I have found the solution from here . And its working! WordPress has a set of restricted filetypes it will allow you to upload via the media library. Whilst this is a great security feature, there may be times where you’d like to add other files that are restricted by default, or maybe even the opposite where you’d only like to allow a few extensions to be uploaded. Fortunately, WordPress makes this dead easy with a small snippet of PHP code. If you’d like to add or remove a specific filetype that can be uploaded to wordpress via the media library, you can insert this PHP code in your theme functions.php file: <code> function my_myme_types($mime_types){ //Adjust the $mime_types, which is an associative array //where the key is extension and value is mime type. return $mime_types; } add_filter('upload_mimes', 'my_myme_types', 1, 1); </code> Here is an example of what you can do to add and remove a new filetype (in this example, I’m adding an extension that already exists, but the concept is the same): <code> function my_myme_types($mime_types){ $mime_types['avi'] = 'video/avi'; //Adding avi extension unset($mime_types['pdf']); //Removing the pdf extension return $mime_types; } add_filter('upload_mimes', 'my_myme_types', 1, 1); </code> You can also reset the allowed filetypes by creating a new array within the function and returning these values: <code> function my_myme_types($mime_types){ //Creating a new array will reset the allowed filetypes $mime_types = array( 'jpg|jpeg|jpe' =&gt; 'image/jpeg', 'gif' =&gt; 'image/gif', 'png' =&gt; 'image/png', 'bmp' =&gt; 'image/bmp', 'tif|tiff' =&gt; 'image/tiff' ); return $mime_types; } add_filter('upload_mimes', 'my_myme_types', 1, 1); </code> If you’d like to see what filetypes are currently supported by wordpress, check out the function get_allowed_mime_types located in the wp-includes/functions.php file.
How can I prevent uploading bmp image?
wordpress
In Wordpress, whenever a post is password protected the backend admin area appends the text in bold "- Password protected" after the post title. What I am looking for is a way to remove this text and instead have it utilize an icon (link below) which should be appended before the title text. How can this be done? I want to use an Icon from the Aesthetica Icon Set by http://dryicons.com :
Try this (don't forget to replace icon URL): <code> add_filter( 'display_post_states', 'password_protected_icon' ); function password_protected_icon( $post_states ) { $text = __('Password protected'); $pos = array_search( $text, $post_states); if( false !== $pos ) $post_states[$pos] = '&lt;img src="http://i.stack.imgur.com/aIDa6.png" title="'.htmlspecialchars($text).'"/&gt;'; return $post_states; } </code>
How to replace "Password Protected" text with icon in Admin
wordpress
I'm using the Custom Post Type UI plugin to create my custom taxonomies. I have a portfolio that is made up of projects (custom post type) with 2 custom taxonomies of technologies and clients. The clients taxonomy has a custom rewrite slug of <code> portfolio/clients/ </code> , while the technologies taxonomy has a custom rewrite slug of <code> portfolio/ </code> Rewrites: <code> portfolio/html </code> &lt;- page displays all projects using HTML <code> portfolio/clients/client-a </code> &lt;- page displays all projects for client A Now when I try to make a landing page for clients that has a url slug of <code> /portfolio/clients </code> I get the 404 page. I'm pretty sure this is because of conflicting url rewrites of the technologies taxonomy. I'm guessing as it searches for it in the technology taxonomy, it doesn't exist then it spits out the 404 page. So how do I get the url rewrite slug to work so that when I hit <code> /portfolio/clients </code> , it doesn't send back the 404 page and it uses the correct page template?
You seem to need "partial verbose rewrite rules". Verbose rewrite rules means all the pages are put on top because WordPress can't figure out the difference between a page and a post. Here it thinks it can, because all URLs of the form <code> portfolio/([^/]+)/ </code> are from your <code> portfolio </code> taxonomy, except this one <code> portfolio/clients/ </code> . You will have to put that one on top of the rewrite rules, so it matches before the more generic portfolio taxonomy. You could probably also force all of the rewrite rules to be verbose, but that will impact the performance if you have lots of pages. This answer is written with my just-gained understanding of rewrite rules, so I hope it is a good way to do it and the example code doesn't contain too many errors. A page does not generate just one rewrite rule, it generates a group: <code> (pagename)/trackback/?$ </code> <code> (pagename)/feed/(feed|rdf|rss|rss2|atom)/?$ </code> <code> (pagename)/(feed|rdf|rss|rss2|atom)/?$ </code> <code> (pagename)/page/?([0-9]{1,})/?$ </code> <code> (pagename)/comment-page-([0-9]{1,})/?$ </code> <code> (pagename)(/[0-9]+)?/?$ </code> You don't have to create these yourself, you can re-use the power of <code> WP_Rewrite </code> . Look at its <code> page_rewrite_rules() </code> method: if we are in verbose mode, it gets a list of all pages (via <code> page_uri_index() </code> ) and their attachments, overwrites the <code> %pagename% </code> rewrite tag, and generates the rewrite rules for this page. We can do this too: <code> // We only generate them for this page $page_uri = 'portfolio/clients'; // Returns site root + '%pagename%' $page_structure = $wp_rewrite-&gt;get_page_permastruct(); // Everywhere you see %pagename% in the structure used to generate rules // in the next step, replace it with our fixed page name $wp_rewrite-&gt;add_rewrite_tag('%pagename%', "({$page_uri})", 'pagename='); // This generates the group given above $page_rewrite_rules = $wp_rewrite-&gt;generate_rewrite_rules($page_structure, EP_PAGES); </code> This will give us the rules for the pages, but not yet for attachments used in the page. If you also want them, you repeat the step for each attachment, but with <code> add_rewrite_tag('%pagename%', "({$attachment_uri})", 'attachment=') </code> (see <code> page_rewrite_rules() </code> for more details). Good, we got the rules, but now you need to add them to the complete rewrite structure in some way. You could do this with <code> add_rewrite_rule() </code> , but you must call it for every rule generated in the <code> $page_rewrite_rules </code> array. For this reason, many people hook into the <code> rewrite_rules_array </code> filter , since you can just modify the array there. <code> add_filter('rewrite_rules_array', 'add_verbose_portfolio_clients_page'); function add_verbose_portfolio_clients_page($rewrite_rules) { global $wp_rewrite; // The previous code snippet comes here, where we generate $page_rewrite_rules // Our rules have priority, they should be on top $rewrite_rules = array_merge($page_rewrite_rules, $rewrite_rules); return $rewrite_rules; } </code> After you included this filter, you should flush the rewrite rules (once, not one every page load, as it is quite heavy). You can do this by calling <code> flush_rewrite_rules() </code> , or by visiting the "Permalinks" settings page.
custom taxonomy and pages rewrite slug conflict gives 404
wordpress
When a user tries to share a page with an embedded video on it only the title of the pages shows up on their facebook status and not the flash video player. This happens while sharing with the addthis button or if the url is posted directly to the facebook page. Any idea how I can make facebook pickup the embedded flash video?
That really depends on how the video is embedded into the page. Facebook can only handle specific formats and if it sees something it doesn't expect, it defaults to a failsafe "show nothing" standard. If the embedded video is well-recognized standard (i.e. YouTube's default player) it should work just fine. If it's your own self-hosted video player, though, this won't work. Facebook won't embed other people's Flash objects on their site. Update 11/18 Facebook, as smart as it is, still needs a considerable amount of help to determine what content lives on the page. It can do a quick scraping of <code> &lt;img /&gt; </code> tags to give you page thumbnails, but it doesn't scan for <code> &lt;object&gt; </code> s or <code> &lt;embed&gt; </code> s because these could be anything from a YouTube video (that you'd like shared on Facebook) to an intrusive Flash application (that Facebook doesn't want on their site). To make things easier, YouTube actually uses a specific Facebook application to allow you to share videos that will be automatically embedded into Facebook. In addition to linking directly to this application, every YouTube video page includes additional meta information in their header that Facebook uses to scrape up the video and embed it into the page. Here's an example from the video you linked to earlier: <code> &lt;meta property="fb:app_id" content="87741124305" /&gt; &lt;meta property="og:title" content="Cubed: Manny Pacquiao&amp;amp;#39;s Punchout" /&gt; &lt;meta property="og:description" content="Manny Pacquiao is training hard for his upcoming fight with Miguel Cotto, but you might be surprised how he got to the top. Check out this clip." /&gt; &lt;meta property="og:type" content="video" /&gt; &lt;meta property="og:url" content="http://www.youtube.com/watch?v=IvCCuuuJhd4" /&gt; &lt;meta property="og:image" content="http://i2.ytimg.com/vi/IvCCuuuJhd4/default.jpg" /&gt; &lt;meta property="og:site_name" content="YouTube" /&gt; </code> The application linked is the YouTube application on Facebook. You can also see some specific information included here: title, description, type, url, image, site_name. All of this helps Facebook figure out what to do when you "share" the page to your friends and network. The AddThis button doesn't add any of this information to your header. It can't, really, because it's built to allow simple sharing of pages, not to power sharing for video websites like YouTube. So as I said before, it "depends on how the video is embedded into the page." Facebook can only handle videos in specific formats, tagged in a specific way, that originate from specific sites/applications. To replicate the embedded video feature that YouTube has, you'll need to: Create your own Facebook app to power things Add the same kind of meta information to your header If you want (and I would recommend this), the easier route would be to just scrape the <code> &lt;meta&gt; </code> tags YouTube uses. So if you add a video, use the same YouTube app Id, the same <code> &lt;meta&gt; </code> properties, and you should be good to go.
sharing video on facebook from wordpress
wordpress
Recently I tried to update my plugin to WP server. The update to trunk folder went fine, but when I created a folder with a new version under tags folder and tried to upload it, only the immediate children files of this folder where uploaded successfully and the sub folders weren't. Eventually I figured out that the svn info file "thinks" that this sub folder already exists in the server even though it doesn't, so I used Tortoise delete function and a few times and then added it and click commit. Finally after more than an hour of trial and error, I succeeded. That was really frustrating because I know that people already received an update notification and some of them might have updated and received an error message that crashed their admin! My questions are: Should I switch to working with command line instead of Tortoise? will it be safer? Is there a way to postpone the version update notification until I confirm somehow that I have completed the upload of the new version successfully?
Question 1: Should I switch to working with command line instead of Tortoise? will it be safer? No, tortoise SVN does everything you need to do pretty well and without the need for you to learn every command line command. I've used it plenty of time, and I never had problems that were related to it, the problems were related to me using it ;) BTW: Tortoise SVN contains the same code under the hood as the command line client, so both are exactly the same kind of safe. But you can download SVN for the commandline as well and even use both in parallel. But that's not really something helpful for you, I guess. Just take Tortoise SVN as it is much easier to use. I think you missed to svn-add the subdirectories. As long as you do not add those, they won't get committed. It's just that they were not under version control so SVN did not know that those should be committed. Question 2: Is there a way to postpone the version update notification until I confirm somehow that I have completed the upload of the new version successfully? Normally there is no need to do so. Only for the very first version, the ZIP package is created automatically by the wordpress website. For any additional version, you need to tag a release before the new plugin.zip is generated. So as long as you do not tag your next release, nobody will get notified about the new version. Further Question 1: So basically I can upload the new version without incrementing the version in the main plugin file and the readme file and only when I see it the update was successful, I can update only those 2 files after incrementing the version. That's soemthing you can do as well. In the end you should update the readme.txt and the plugin file headers otherwise this won't be user-friendly might create a wrong view. I normally change those two files in my development trunk directly directly after I tagged the last release, so not at the end. This works very well for me. So this is quite the opposite then in your question. Just tag for your next release and you are fine. The tagging will signal wordpress.org plugin repository that a new version is available. Until then, only the development version get's upated after each commit if I remember that right. And that's nothing problematic as it is the development version. Those normally do not get downloaded, and they are not announced with the update feature. This should answer your other question as well: Update notifications aren't send out unless you tag. Further Question 2: Creating a branch is for major versions, right? No, that's unrelated. You can create a tagged version as a minor or bugfix release as well. The following principle is common: <code> MyPlugin version 1.0.0 </code> This is the first major release. <code> MyPlugin version 1.1.0 </code> This is a feature release within the first major release. <code> MyPlugin version 1.1.1 </code> This is the first bugfix release for the first feature release in your first major release. This is common. The wordpress.org plugin repository does not support this out of the box very well, it's just counting up, regardless which position this is. To fine-tune that, you can tag (within plugin headers) your plugin as being stable: <code> * Stable tag: 1.1 </code> So on wordpress.org you can have one stable version only but next to that you can have countless of other versions as well. And you can (and should) tag them, too. Probably each time you fixed a bug or added a feature. So you normally count up release numbers. If you're creating a beta, you can add that behind, which is normally understood by users pretty well: <code> MyPlugin version 1.0.1-beta </code> This works as well. For a real life example you can take a look on the table at the bottom ob this plugin page on my homepage . That's a wordpress plugin that is also released on wordpress.org. The according line-up can be found here: http://wordpress.org/extend/plugins/better-http-redirects/download/
How to handle the Plugin Version on Update using Tortoise SVN and the worpdress.org Plugin Repository?
wordpress
Using <code> /%category%/%postname%/ </code> for the permalink I get a URL string of all the categories that the specific post is included in. I would like the categories in the url to be filtered down to only one branch of the categories structure, and starting not from the root parent category. I have a travel blog and I have this category structure: places β€Ί countryName β€Ί regionName β€Ί cityName ex: www.mytravelblog.com/places/indonesia/java/jakarta/myPostName/ I would like to skip the root category in the URL or even just use the smallest child ex: www.mytravelblog.com/jakarta/myPostName Is it possible? (WP 3.0.1)
This should be possible. First, you're lucky that <code> www.mytravelblog.com/jakarta/myPostName/ </code> already works, it shows you the post and doesn't redirect you to the longer version (at least it seems to work on my side). That means you only have to work on the generated link, and not mess with the way incoming URLs are handled or "canonicalized". The result of <code> get_permalink() </code> , which you want to modify, is filtered through <code> post_link </code> . So you can probably do something like this: <code> add_filter( 'post_link', 'remove_parent_cats_from_link', 10, 3 ); function remove_parent_cats_from_link( $permalink, $post, $leavename ) { $cats = get_the_category( $post-&gt;ID ); if ( $cats ) { // Make sure we use the same start cat as the permalink generator usort( $cats, '_usort_terms_by_ID' ); // order by ID $category = $cats[0]-&gt;slug; if ( $parent = $cats[0]-&gt;parent ) { // If there are parent categories, collect them and replace them in the link $parentcats = get_category_parents( $parent, false, '/', true ); // str_replace() is not the best solution if you can have duplicates: // myexamplesite.com/luxemburg/luxemburg/ will be stripped down to myexamplesite.com/ // But if you don't expect that, it should work $permalink = str_replace( $parentcats, '', $permalink ); } } return $permalink; } </code>
Filtering categories in the permalink structure
wordpress
I have a custom post type for slideshows that creates a paginated post and each slide is a separate page. The data for each slide is saved in the custom fields and each slide has a title set saved in the custom field with key <code> slide{$i}-title </code> ( <code> $i </code> being the slide number, for example <code> slide1-title </code> ). Currently the url of each subsequent page is the number appended to the post permalink (which is the standard way paginated page urls are formatted) like this: http://example.com/post-title/2/ for page/slide 2 and http://example.com/post-title/3/ for page/slide 3. How can I change this so that each page's url is appended with the slide title instead of the incremental number? For example: http://example.com/post-title/slide-2-title/ for page/slide 2 and http://example.com/post-title/slide-3-title/ for page/slide 3.
Modifying the URL structure always consists of two parts: one two modify the URLs you generate with your code, and one to handle the incoming URLs of the new structure. I will focus on the second, and maybe least understood, part. The incoming URLs are matched to different rewrite rules , which are regular expressions that can match the URL. These expressions can have capture groups which capture a part of the URL to send it to different query variables, which are (for example) used to construct the database query. If you create a custom post type <code> slideshow </code> , one of the rewrite rules will look like this: slideshow/([^/]+)(/[0-9]+)?/?$ => index.php?slideshow=$matches[1]&page=$matches[2] This means we match a URL that starts with <code> slideshow/ </code> , then anything up that is not <code> / </code> , and optionally (the <code> ? </code> ) a <code> / </code> and any number of digits. The first match is sent to the <code> slideshow </code> query variable, the second match to the <code> page </code> variable. For example, <code> slideshow/nature/2 </code> will set <code> slideshow </code> to <code> nature </code> and <code> page </code> to <code> 2 </code> . I wrote stackexchange-url ("a plugin that might be helpful in understanding and debugging your current rules"). You would like to match a structure like <code> slideshow/nature/slide-2-canyon/ </code> . The regex for this looks like: slideshow/ // Start with 'slideshow/' ([^/]+) // Then anything that is not '/' (/slide- // Then 'slide-' ([0-9]+) // A page number (-([^/]+))? // Slide title: '-' and anything that is not '/'. Optional so you don't have to add it )?/?$ // Which could be followed by a '/' We want to capture the slideshow name and the page number. You count the opening '(' to get the match indexes, so our full rewrite rule looks like this: slideshow/([^/]+)(/slide-([0-9]+)(-([^/]+))?)?/?$ => index.php?slideshow=$matches[1]&page=$matches[3] Now, we just need to add this to the rewrite rules. Make sure you put it at the top, as a similar rule is used to match for attachments of a post, and your custom rule would never be hit if it is at the bottom of the list. <code> add_rewrite_rule( 'slideshow/([^/]+)(/slide-([0-9]+)(-([^/]+))?)?/?$', 'index.php?slideshow=$matches[1]&amp;page=$matches[3]', 'top' ); </code> It is enough to only call this line once, and then <code> flush_rewrite_rules() </code> . Or, if you don't want to mess with plugin activation hooks, call the <code> add_rewrite_rule() </code> on every <code> init </code> , but then load the "Permalink" settings page to flush the rules. As long as you don't flush the rules on every page load, because it is an expensive calculation. The only thing left for you is generating page links of the new format. <code> wp_link_pages() </code> seems to offer no filters to modify its output, so I would study how it works and duplicate it with your page format (it's not hard, and you only need half of the function if you choose only one output format).
Changing the URL Structure of a Paginated Custom Post
wordpress
I have a wp query that works great - it returns a list of featured posts. WP_Query("category_name=office&amp;meta_key=featured_post&amp;meta_value=Yes&amp;posts_per_page=3"); However I want to add a 2nd custom key to the query (a custom order field) then order by the numerical value of the meta value of this key.. is it possible to use 2 meta_key values in a WP_Query? If not is it possible using an SQL query statement?
The query value parameters can be set to true ( returns single result) or false ( an array). http://codex.wordpress.org/Function_Reference/get_post_meta For instance http://www.mattvarone.com/wordpress/query-multiple-meta-values/
Query 2 meta key values and a category
wordpress
I'm setting up a plugin with a nested shortcode, i.e. <code> [ct_training_group] [ct_training] [/ct_training_group] </code> Here's the catch: I use the <code> [ct_training] </code> code outside of the parent as well as within it, and want to output something slightly different in each case. When it is inside a group, I need to omit the <code> &lt;ul&gt; </code> and <code> &lt;/ul&gt; </code> that I would wrap the <code> [ct_training] </code> shortcode in when it is called on its own. I figure the easiest way to do this would be to pass a variable from the parent to the child. Is there any graceful way to do this where I wouldn't need to mess with globals or such? Thanks.
I assume you just pass the content of <code> ct_training_group </code> to another call of <code> do_shortcode() </code> ? You can't pass extra parameters to it, so if you don't want to use global state variables, you could always replace the current shortcode handler for <code> ct_training </code> with one that doesn't add the extra <code> &lt;ul&gt; </code> . It seems there is no cache for the handlers, so there will not be a performance penalty. <code> add_shortcode('ct_training', 'ct_training_full'); function ct_training_full($attr, $content) { return '&lt;ul&gt;' . ct_training_item($attr, $content) . '&lt;/ul&gt;'; } function ct_training_item($attr, $content) { return '&lt;li&gt;CT Training&lt;/li&gt;'; } add_shortcode('ct_training_group', 'ct_training_group_handler'); function ct_training_group_handler($attr, $content) { $output = '&lt;h3&gt;CT Training group&lt;/h3&gt;'; $output .= '&lt;ul&gt;'; // Redefine the sub-code add_shortcode('ct_training', 'ct_training_item'); $output .= do_shortcode($content); // Reset the sub-code add_shortcode('ct_training', 'ct_training_full'); $output .= '&lt;/ul&gt;'; return $output; } </code>
Pass variable to nested shortcode
wordpress
I have been trying to get this worked out for over a year and have tried numerous ways and have not been able to get it to work. I'd really appreciate it if someone could help me with this. Here's what I'm trying to do... I need to create 15 custom metaboxes for the Write screen on my custom post type for Slideshows (lom_slideshow). Each metabox will be the same except for the number of slide (Eg, Slide 1, Slide 2...). I would like the metaboxes to save each field into the seperate Custom Field. Here are the fields that need to be in each metabox: Number/Text Field Title: Slide Number Custom Field Key: slide1-number Checkbox Title: Hide This Slide Custom Field Key: slide1-hide Radio toggle Title: Slide Type Custom Field Key: slide1-slidetype Values: Image Slide or Video Slide Text Field Title: Slide Title Custom Field Key: slide1-title Image (this one could work several ways and I don't really care how it works as long as it does) Title: Slide Image Custom Field Key: slide1-image How it will function: as long as it does one of the following things I'll be happy... A) A dropdown list of all the image attachment associated with the post. B) A list of thumbnails for all the attached images associated with the post. C) An image upload field to upload an image and attach it to the post. WYSIWYG Title: Slide Description Custom Field Key: slide1-desc Type: wysiwyg Textarea Title: Video Embed Code Custom Field Key: slide1-embed Slide 2 will be the same but the all the Custom Field Values will be appended with "slide2-" instead of "slide1-" The only other consideration is that I'd like them to be in the main content column and only visible on my Slideshow custom post type (lom_slideshow). Like I said I have tried this numerous time and never got it right. I have gotten close in the past and have gotten the whole thing working except I couldn't get multiple instances of the WYSIWYG to show up on the page. I no longer have that code because I have changed it numerous times since then. I ultimately decided on using the More Fields Plugin to do this instead of my own code and tested it with 5 meta boxes for development, but then when I tried to implement it with the 15 boxes I needed the plugin wreaked havoc on my database tables. I really don't want another plugin. I'm actually looking for someone to just tell me how to code it. I don't need links to tutorials because I am confident that I have tried them all unless it was published in the last hour or so. For some background here was what I was originally trying to do: stackexchange-url ("Help Creating a Slideshow Custom Post Type with Custom Meta Boxes?") EAMann provided me with a very comprehensive answer however it was outside my skill set and I couldn't implement it. I have simplified my request down to this question here in hopes of finally being done with this.
Solve a complex Problem (rationally) To solve complex problems, there is a kind of standardized/well known approach: Divide your complex problem into a set of smaller problems. Smaller problems are easier to solve. If you have solved each smaller problem you most often have solved your complex problem already. Locate and Divide into Parts So far for the theory. Let's check your needs. I line-up in my own words what you described above: Handle a set of options in multiple instances (slide-1 to slide-N). Store values in post meta values. A Metabox in multiple instances (slide-1 to slide-N). A Slideshow Editor (Form) within the Metabox (again multiple Instances) A Basic Form to edit the Data (e.g. using simple HTML Form Elements) The technical problem to solve, having multiple WYSIWYG editors. Your more complex Image Input. So how to code that? I think the most important part is that before you start to actual coding, you make up your mind what you really want to achieve and how to divide the problem into the smaller parts. The list above might not be complete it's just what I could read from your question. And the format is quite unspecific. It's just more or less a repetition from what you wrote but a bit ordered into single points. So check if those are your needs and extend that list to all you see fit. When done, the next step is to look how those needed stuff could be expressed in simple words and as a list of features of your plugin A Plugin for this: SlideshowPlugin. A Slideshow that consists of Slides. An Editor to edit a Slideshow. A place to store and retrieve the Slideshow data from. Looks quite simple now, right? I probably might have missed something here, so double check on your own before you continue. As written, before starting to code just make up your mind in simple wording and terms. Don't even think about which parts are problematic and which are not or how to code some detail like the naming of HTML Input elements. I know that's hard if you already tried for such a long time now to restart from scratch because there are many ideas in your mind's back that come up again. Grab a pencil and some paper. This often helps to make up someone's mind. As you can see I did not specify the need of a Metabox or a Custom Post Type here. It's too specific to learn about the parts of your problem first. Metabox or Custom Post Type is very concrete, possibly something how to code the plugin already. So I kept this out for the moment and tried to short but precisely describe the needs. The Metabox or similar is something which might play a role in the Design. Let's see. Design your Plugin After you know what you need/want to achieve, you can make up the mind about how to design the plugin. This could be done by drawing a little picture. Just Identify the parts from your Feature List and set them in relation to each other. As you can see, you actually do not need to do fine arts ;) : Excuse my bad writing, I hope this can be read. In any case, you can create your own image, this is just an example. Designs can vary, so if you would not draw it the same way, that's just normal. I like to do the beginning of the design step on paper because it helps to get a better view on the problem from above and it's much faster on paper then on the computer. So now you could compare your list with your design and check if all features from the list are covered by the parts you have in the design. Looks good so far for my list and my image, so I continue, but don't skip this step. Otherwise you do not know if you have missed something. And as you start to code soon, it's much more hard to change something that's already coded than an image or a list. Separation of Problems in the Design Now this plugin becomes more concrete in ones mind. After some little design, it's probably the right time to start coding. As we have the list on top, I could go through and think about each point on it's own and cross-check with the Design so that I know how the parts are in relationship to each other. Because if every single part is done, the plugin is ready without making up the mind on the whole thing at once, which was the original problem. I do the coding now a bit in comment style and some sample code. It's a first implementation idea and the code is untested. It's just to get the hands dirty for me and for you to probably have an example of how - but not must - this can be written. I tend to be too specific sometimes already, so mind me. When I write code, I re-write it quite often while creating it, but I can not make this visible while creating the sample code. So bear this in mind. If you see something to be done simpler, choose your route. You need to change and extend your code later on, so this is really only some example code. Plugin Just a class that handles the basic operation like registering hooks and providing the Slideshow with it's Slides and the Metaboxes for the Editor. This is where everything starts. Plugins are started at a single point of code. I call that bootstrap: <code> &lt;?php /** Plugin Headers ... */ return SlideshowPlugin::bootstrap(); class SlideshowPlugin { /** @var Slideshow */ private $slideshow; /** @var SlideshowMetaboxes */ private $metaboxes; /** @var SlideshowPlugin */ static $instance; static public function bootstrap() { $pluginNeeded = (is_admin() &amp;&amp; /* more checks based your needs */ ); if (!$pluginNeeded) return; } if (NULL === self::$instance) { // only load the plugin code while it's really needed: require_once('library/Slideshow.php'); require_once('library/SlideshowSlide.php'); require_once('library/Store.php'); require_once('library/Metaboxes.php'); require_once('library/Metabox.php'); require_once('library/Form.php'); // ... self::$instance = new SlideshowPlugin(); } return self::$instance; } private function addAction($action, $parameters = 0, $priority = 10) { $callback = array($this, $action); if (!is_callable($callback)) { throw new InvalidArgumentExeception(sprintf('Plugin %s does not supports the %s action.', __CLASS__, $action)); } add_action($action, $callback, $parameters, $priority); } public function __construct() { $this-&gt;addAction('admin_init'); } /** * @return bool */ private function isEditorRequest() { // return if or not the request is the editor page } /** * @-wp-hook */ public function admin_init() { // register anything based on custom post type and location in the admin. // I don't care about the details with CPT right now. // It's just that editorAction is called when we're on the slideshow // editor page: if ($this-&gt;isEditorRequest()) { $this-&gt;editorAction(); } } private function getPostID() { // ... code goes here to get post id for request return $postID; } private function getSlideshow() { is_null($this-&gt;slideshow) &amp;&amp; ($postID = $this-&gt;getPostID()) &amp;&amp; $slideshow = new Slideshow($postID) ; return $slideshow; } private function getMetaboxes() { is_null($this-&gt;metaboxes) &amp;&amp; ($slideshow = $this-&gt;getSlideshow()) &amp;&amp; $this-&gt;metaboxes = new SlideshowMetaboxes($slideshow) ; return $this-&gt;metaboxes; } private function editorAction() { $metaboxes = $this-&gt;getMetaboxes(); } } </code> So this plugin class is already quite complete. I did not specify how to retrieve the postID but it's already encapsulated in a function on it's own. Next to that I did not code to check whether or not this is the right page to display the editor, but there's already some stub code for that. In the end, the editorAction() is called if the request is on the actual custom post type editor page and in there, the Metaboxes are aquired. That's it. Plugin should be pretty complete now. It has the slideshow and takes care of the Metaboxes. Compared with the design, those are the parts which are linked with the plugin. Compare with the image: The decision whether or not the Editor is to be displayed. The connection between the plugin and the slideshow. The plugin has a slideshow already. The connection to the Metaboxes. The plugin has the Metaboxes already. Looks complete. Job done on that part. Slideshow and Slides A Slideshow is 1:1 mapped to a post. So it needs to have the Post ID. The Slideshow can take care of holding the data, so it's basically a Datatype. It stores all the values you need there. It's a compound datatype in the sense that it consist have 0 to N slides. A Slide again is another Datatype that holds the information for each Slide. The slide then is used by a metabox and probably a form. I additionally choosed to implement the storage and retrieval of the slideshow data as well into those datatypes (the box labeled Store in the design). That's somehow dirty as it mixes datatypes and actual objects. But as the Store is connected to Slideshow and Slides only in the Design I connected them with each other. Probably too close for the future, but for a first implementation of the design, I think it's a valid approach for the moment. As this is the first approach it won't take much time after it will get refactored anyway so even with some issues I'm quite confident that the direction is right: <code> class SlideshowSlide { private $slideshow; private $index; public $number, $hide, $type, $title, $image, $wysiwyg, $embed public function __construct($slideshow, $index) { $this-&gt;slideshow = $slideshow; $this-&gt;index = $index; } public function getSlideshow() { return $this-&gt;slideshow; } public function getIndex() { return $this-&gt;index; } } class Slideshow implements Countable, OuterIterator { private $postID; private $slides = array(); private function loadSlidesCount() { $postID = $this-&gt;postID; // implement the loading of the count of slides here } private function loadSlide($index) { $postID = $this-&gt;postID; // implement the loading of slide data here $data = ... ; $slide = new SlideshowSlide($this, $index); $slide-&gt;setData($data); // however this is done. return $slide; } private function loadSlides() { $count = $this-&gt;loadSlidesCount(); $slides = array(); $index = 0; while(($index &lt; $count) &amp;&amp; ($slide = $this-&gt;loadSlide($index++))) FALSE === $slide || $slides[] = $slide ; $this-&gt;slides = $slides; } public function __construct($postID) { $this-&gt;postID = $postID; $this-&gt;loadSlides(); } public function count() { return count($this-&gt;slides); } public function getInnerIterator() { return new ArrayIterator($this-&gt;slides); } private function touchIndex($index) { $index = (int) $index; if ($index &lt; 0 || $index &gt;= count($this-&gt;slides) { throw new InvalidArgumentExpression(sprintf('Invalid index %d.', $index)); } return $index; } public function getSlide($index) { $index = $this-&gt;touchIndex($index); return $this-&gt;slides[$index]; } } </code> The Slideshow and Slide classes are also quite complete but lacks actual code as well. It's just to show my idea of having the properties / methods and some handling stuff as well on how the retrieval of data could be implemented. Metabox The Metabox needs to know which Slide it represents. So it needs to know the Slideshow and the concrete Slide. The Slideshow can be provided by the Plugin, the Slide could be represented by the index (e.g. 0 ... N where N is count of slides in the slideshow - 1). <code> class Metabox { public function __construct(SlideshowSlide $slide) { } } </code> The Metabox class is actually extending the plugin class somehow. It does some of the work that could be done by the plugin class as well, but as I wanted to have it represent the slide in context of the plugin while being able to have multiple instances, I choosed this way. The Metabox now needs to take care of the request logic: It represents one Metabox which is actually somehow output but it's also input as it needs to deal with form input. The good thing is, it actually does not deal with the details because form output and input are done by the form objects. So probably if I would have coded this class to an end, I would have removed it completely. I don't know right now. For the moment it represents the Metabox on the editor page for one specific slide. Metaboxes <code> class Metaboxes private $slideshow; private $boxes; public function __construct(Slideshow $slideshow) { $this-&gt;slideshow = $slideshow; $this-&gt;editorAction(); } private function createMetaboxes() { $slides = $this-&gt;slideshow; $boxes = array(); foreach($slides as $slide) { $boxes[] = new Metabox($slide); } $this-&gt;boxes = $boxes; } private function editorAction() { $this-&gt;createMetaboxes(); } </code> I only wrote some little code here so far. The Metaboxes class acts as a manager for all metaboxes. The representative of the Slideshow as Metabox represents a slide. That stub code does not much but instantiating one Metabox per Slide. It can and must do more in the end. You probably might want to make use the of the Composite Pattern here, so to do an action on a Metaboxes object will do the same action on every Metabox it carries. Comparable with the instantiation, where it creates new Metaboxes. So you don't need to deal with individual Metaboxes later on, just with the Metaboxes object. Just an Idea. Form The Form is probably the most complex thing you have in terms of dealing with stuff and lines of code. It needs to abstract your data to be processed via the Browser. So it must be able to handle multiple instances. You can achieve this by prefixing form element names (as they need to be unique) with a genreal prefix (e.g. "slide"), then an identifier (the slide index, I name it index here as you want to be able to change the number e.g. to have a sort key) and then the actual value identifier (e.g. "number" or "hide"). Let's see: A form knows about it's prefix, the slide's number and all fields it contains. This pretty much maps to the Slideshow and Slide datatypes spoken about above. Some little stub-code: <code> /** * SlideForm * * Draw a Form based on Slide Data and a Form definition. Process it's Input. */ class SlideForm { /** @var Slide */ private $slide; private $prefix = 'slide'; public function __construct(Slide $slide) { $this-&gt;slide = $slide; } private function inputNamePrefix() { $index = $this-&gt;slide-&gt;getIndex(); $prefix = $this-&gt;prefix; return sprintf('%s-%d-', $prefix, $index); } private function inputName($name) { return $this-&gt;inputNamePrefix().$name; } private function printInput(array $element) { list($type, $parameters) = $element; $function = 'printInput'.$type; $callback = array($this, $function) call_user_func_array($callback, $parameters); } private function printInputText($value, $name, $label, $size = 4) { $inputName = $this-&gt;inputName($name); ?&gt; &lt;label for="&lt;?php echo $inputName ; ?&gt;"&gt; &lt;?php echo htmlspecialchars($label); ?&gt;: &lt;/label&gt; &lt;input type="text" name="&lt;?php echo $inputName; ?&gt;" size="&lt;?php echo $size; ?&gt;" value="&lt;?php echo htmlspecialchars($value); ?&gt;"&gt; &lt;?php } private function printInputCheckbox($value, $name, $label, ... ) { ... } private function printInputRadio($value, $name, $label, ... ) { ... } private function printInputImage($value, $name, $label, ... ) { ... } private function printInputWysiwyg($value, $name, $label, ... ) { ... } private function printInputTextarea($value, $name, $label, ... ) { ... } // ... private function mapSlideValueTo(array $element) { $slide = $this-&gt;slide; list($type, $parameters) = $element; list($name) = $parameters; $value = $slide-&gt;$name; array_unshift($parameters, $value); $element[1] = $parameters; return $element; } /** * @return array form definition */ private function getForm() { // Form Definition $form = array( array( 'Text', array( 'number', 'Number' ), array( 'Checkbox', array( 'hide', 'Display', 'Hide This Slide' ), ), array( 'Radio', array( 'type', 'Type', array('Image', 'Video') ), ), array( 'Text', array( 'title', 'Title', 16 ), ), // ... ); return $form; } public function printFormHtml() { $form = $this-&gt;getForm(); foreach($form as $element) { $element = $this-&gt;mapSlideValueTo($element); $this-&gt;printInput($element); } } public function processFormElement($element) { list($type, $parameters) = $element; list($name) = $parameters; $inputName = $this-&gt;inputName($name); $map = array( 'Text' =&gt; 'String', 'Checkbox' =&gt; 'Checkbox', 'Radio' =&gt; 'Radio', ); // I would need to continue to code there. throw new Exception('Continue to code: Process Form Input based on Form Definition'); } public function processForm() { $form = $this-&gt;getForm(); foreach($form as $element) { $this-&gt;processFormElement($element); // &lt;- this function needs to be coded } } // ... } </code> This class is quite large now because it takes care of three things at once: Form Definition Form Output Rendering Form Input Processing It is wiser to split this up into the three parts it represents. I leave that up to you. It does already show how you can encapsulate the forms functionality into smaller tasks so it's easier to comply with your needs. E.g. in case the Image Input element form output needs tweaks, it can be easily extended / polished. Same for WYSIWYG. You can change the implementation later on as it won't interfere for you slideshow and slide datatypes much. The principle behind this is also called Separation of Concerns , and that is just about how I started my answer: Divide the problem into smaller problems. Those separated problems are easier to solve. I hope this helps for the moment. In the end I didn't come back to Custom Post Types even. I know they must go inside the plugin, but with a new design it's probably easy to find the place where to write the code to. What's left? Split the code into multiple files. One class per file. You can merge them together later easily, but for development, keep things apart as you want to solve the smaller problems / parts on their own. Testing: You need to test the functionality of the parts on their own. Is the slide doing what it should do? Gladly you can make use of Unittests if you write classes, for PHP there is PHPUnit. This helps you to develop the code while knowing that it does exactly what it does. This helps to solve the simple problems in a unit of each own and you can more easily change your code later on as you can run tests all the time. Testing #2: Sure you need to test your plugin as a whole as well so you know that it is doing what you're looking for. Can you imagine how that can be done automatically so you can repeat the test with the same quality all the time?
Multiple Custom Metabox Help
wordpress
I would like to collect main info about post like Title etc. in moment when post was written and it's going to be published and perform some actions on this data. What's the hook for that? Thanks!
The function is <code> wp_insert_post() </code> , and as you can see there are some hooks you can use to modify data. <code> wp_insert_post_data </code> is a filter that gets all data right before it will be inserted into the database, so you modify it there and don't need to do anything to get it saved. At the end of the function you can see the <code> save_post </code> action and its equivalent <code> wp_insert_post </code> , which are more appropriate if you want to do something (instead of change something). These functions are fired when a post is saved, not only when it is published. For the publish action, look at <code> wp_transition_post_status() </code> , which has three hooks: <code> transition_post_status </code> , called with the new and old statuses, and the post data <code> {$old_status}_to_{$new_status} </code> , like <code> draft_to_publish </code> , called with the post data <code> {$new_status}_{$post-&gt;post_type} </code> , like <code> publish_page </code> , called with the post ID and post data
Getting Post details when post is published
wordpress
I am working on an aggregator at the moment for an opt-in blog service. Essential a handful of people submit their WP blogs to the aggregator for, well, aggregation. I am currently using a slightly hacked version of http://feedwordpress.radgeek.com/ What I want to be able to do is for each bit of syndicated content shoot off to the post in question and grab the latest comments and comment count. Anyone have any opinions on the best way to do this?
grab the rss feeds for the posts grab the comments rss feed for each of these posts make it cache if you want to do multiple runs also handy for debugging bad feeds don't do this code in a wordpress install but on a standalone place where you install magpierss/ Use a token that stores the latest date in each rss feed read for the next time you do an "aggregation" a) Possibly re-combine it in a new RSS feed and publish that one for subscription. b) Possibly re-post each post in the new twitter feed header: <code> require_once 'magpierss/rss_fetch.inc'; define("MAGPIE_CACHE_DIR", "/home/yoursite/cache"); define("MAGPIE_CACHE_ON", true); </code> simple loop based on a file based storage of cache and last-datetime-counter: <code> $rss = fetch_rss('http://whateversite/rss.php'); $filename = "/your_path_to_datetime_token/timedatetoken.txt" ; $fp = fopen($filename, 'r'); $lastdate = fread($fp, filesize($filename)); fclose($fp); $wroteLastDate = false; // read feed foreach ($rss-&gt;items as $item) { $published = $item['date_timestamp']; if ($published &gt; $lastdate) { if ($wroteLastDate == false) { $fp = fopen($filename, 'w'); fwrite($fp, $published); fclose($fp); $wroteLastDate = true; } $title = $item[title]; $url = $item[link]; $guid = $item[guid]; $description = $item[description]; $description = strip_tags($description); // now store it somewhere or e.g. post it to your owb blog via xmlrpc } } </code> So the same loop needed for the comments which is the form /feed , so you call with each post you find above ($url) a new exact the same loop but then for ($url)/feed. These are the comments, same loop, same procedure. The line "// now store it somewhere or e.g. post it to your owb blog via xmlrpc" now means you could call your own aggregator blog xmlrpc to add either a new post or a new comment to an existing post. 1) adding a new post is pretty default, you could call this function: <code> function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories=array(867)) { $categories = implode(",", $categories); $XML = "&lt;title&gt;$title&lt;/title&gt;" . "&lt;category&gt;$categories&lt;/category&gt;" . $body; $params = array('','',$username,$password,$XML,1); $request = xmlrpc_encode_request('blogger.newPost',$params); $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); curl_setopt($ch, CURLOPT_URL, $rpcurl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 1); curl_exec($ch); curl_close($ch); } </code> and the blog is entered in your aggregator blog. Now for the comment: you have to check that the post is already present in your blog before adding a comment via XMLRPC. So first do the check, then do the comment (and actually maybe do that even before adding a new post). Add a new comment via: wp.newComment (http://codex.wordpress.org/XML-RPC_wp) I you are close to the aggregator application database you can skip XMLRPC and do instead of XMLRPC direct database calls to validate e.g. if the post is already present, grab the id, then check if the comment is present, if not store it, if updated, update it, if deleted, then delete it (to be completely in sync). (you need to delete comments and posts on your side to prevent people calling you to delete a post or comment because of all kinds of reasons, sometimes years later) --> leading to a decision on how long you want to keep aggregated posts and comments for external display. I would run this scheduled rss checker and updater as a seperate application and not in the same application as where the presentation layer is to make it scalable etc... IMHO
Any tools for quickly grabbing comments / comment count?
wordpress
Is there a simple way to use the post thumbnail when calling <code> previous_post_link() </code> and <code> next_post_link() </code> ?
This could be acheived by using the <code> get_previous_post() </code> and <code> get_the_post_thumbnail() </code> functions. Then just pass the thumbnail value into the second parameter of <code> previous_post_link() </code> . <code> $prevPost = get_previous_post(); $prevThumbnail = get_the_post_thumbnail( $prevPost-&gt;ID ); previous_post_link( '%link', $prevThumbnail ); </code>
Showing Thumbnail from Previous and Next Posts
wordpress
What is the best way to get an experienced WordPress developer take a look at my plugin and give constructive criticisms? I have written code to solve some of my questions on this site, and I think they could be useful to others too. However, since they would by my first public WordPress plugins, and I have seen many not-so-great examples in the public WordPress directory, I would like to know "where I stand", and how I can improve my plugins. I have read stackexchange-url ("the list of best practices"), and still need to apply some of them, but I would also like an answer to the more general question "Is this a good way to solve this problem?" I just re-read the related discussion on <code> wp-hackers </code> (I did not realize that the participants were also so involved in this site, and that the "best practices" question is a direct result of it). I'm not sure my needs would be covered by such a system, and I agree with Paul's concerns: When I read the original comments on this thread last week I though the purpose was to put together a peer review process where plugin developer can offer advice to other plugin developers as review of their code. I originally took this advice as something along the lines of "Well, your code works but this set of routines you've written would be better served if you just hooked into this WP filter and tried this technique (see xxx plugin as an example)". The goal I thought was to share WP plugin development knowledge and make any mediocre plugin developer a better developer. Like myself. This would be a different scope than doing a point-by-point checklist review, it would be more of a "mentorship". It seems there are many people willing to do this, and (even better) many of them participate here on this site, so how can we transform all of that energy into something concrete? My current example are three plugins I wrote to stackexchange-url ("solve my "image resize" problem"). I wrote long introductory comments to each plugin, which (I hope) makes it easier to understand my intentions without reading the full code. Is there anything else I can do to make it easier for others to take a look at it? Please ignore my current concrete request. Not only is it too early for them, but I changed my mind and don't want to spoil the general discussion with my specific situation.
The easiest way is a two step approach: Release your plug-in to the public. Once it's live, you'll start getting feedback from end users in addition to developers. If you want, release it as a "beta" version and heavily emphasize that in the readme file. Ask. There are veteran WordPress developers everywhere: here, on the WP-Hackers list, at WordPress jobs , stalking @wordpress on Twitter, etc. It's just a matter of throwing your plug-in out there and asking for feedback. In general, follow the same steps as you would getting a Core patch looked at by a developer: Write it Document it Contact a developer (either broadly through one of the above channels or directly if you can) and ask for feedback As far as transforming the kind of "mentorship" that occurs on this site into something more concrete, that would be an organic process. As you've already mentioned, efforts to create a kind of plug-in review process before actually reviewing anything seem to have stalled. The only way to get anything off the ground is to actually start doing it. So don't just talk about finding a veteran developer and getting feedback, go out, find one, get your feedback, and write down how the process went. Then it can be repeated with future plug-ins and future developers. But you've got to start somewhere ...
Getting a peer review for my new plugin?
wordpress
I have a main page where i want to show up the latest post content of two or more blogs.. for now I have this code : <code> &lt;?php // Include WordPress Blog 1 define('WP_USE_THEMES', false); require('./blog1/wp-load.php'); ?&gt; &lt;?php query_posts('showposts=3');?&gt; &lt;?php while (have_posts()): the_post(); ?&gt; some of my blog 1 stuff.. . &lt;?php endwhile; ?&gt; &lt;?php wp_reset_query();?&gt; &lt;?php // Include WordPress Blog 2 define('WP_USE_THEMES', false); require('./blog2/wp-load.php'); ?&gt; &lt;?php query_posts('showposts=3');?&gt; &lt;?php while (have_posts()): the_post(); ?&gt; some of my blog 2 stuff.. . &lt;?php endwhile; ?&gt; &lt;?php wp_reset_query();?&gt; </code> blog no. 1 is showing it's content but blog no. 2 doesn't show up the content.. .how can I reconstruct them both to work in one page which is my main page... are this possible to reconstruct?
I highly doubt you can get it to work that way reliably. WordPress relies a lot on global variables and so there is no way you can keep two WordPress instances active and sane at the same time. My suggestion would be to use RSS feeds of posts from those two blogs (with RSS widget or <code> fetch_feed() </code> ) or direct SQL queries.
Multiple WordPress outside wordPress installation?
wordpress
I'm designing a custom magazine theme, where categories are used for different sections, and I created a custom "edition" taxonomy. The editor will create a new term in that taxonomy for each new edition published, i.e. the number of the issue. How can I query the latest "edition", so I can combine it with each category and then publish only the posts that belong to the newest edition? Something along the lines on: ?edition=34&amp;cat=studies
The latest edition should always be the term in that taxonomy with the highest term_id, right? Query get_terms and find the latest edition, then use that term to build the rest of your query... <code> $edition = get_terms('edition','orderby=none&amp;order=DESC&amp;number=1'); $latest_edition = $edition[0]-&gt;slug; </code> Then you can either modify the current query, if that's what you want to do: <code> global $wp_query; $wp_query-&gt;set('edition',$latest_edition); </code> Or use it to build new queries: <code> $studiesposts = get_posts('category_name=Studies&amp;edition='.$latest_edition); </code> If you have your permalink structure set up, it should also work to build urls for new links, like this: <code> http://yourdomain.com/edition/34/category/studies </code>
Get the latest taxonomy/category?
wordpress
this is shortcode in template: <code> function shortcode_frame_left( $atts, $content = null) { return '&lt;span class="frame alignleft"&gt;'. do_shortcode($content) . '&lt;/span&gt;'; } add_shortcode('frame_left', 'shortcode_frame_left'); </code> this is how using in post content: <code> [frame_left] &lt;a href="YOUR-URL"&gt;&lt;img src="YOUR-URL" /&gt;&lt;/a&gt; [/frame_left] </code> I am trying to use this shortcode in template file for displaying post thumbnails. What i try: <code> if (has_post_thumbnail()) { apply_filters( 'the_content', "[frame_left]".the_post_thumbnail()."[/frame_left]"); } </code> and <code> if (has_post_thumbnail()) { $thumbnail = '[frame_left]'. the_post_thumbnail() . '[/frame_left]'; echo do_shortcode("$thumbnail"); } </code> What am i doing wrong?
<code> the_post_thumbnail() </code> echos the thumbnail and returns nothing. You probably want to use <code> get_the_post_thumbnail() </code> which returns it as a string. Your code currently is equivalent to this: <code> if (has_post_thumbnail()) { // Echo the thumbnail the_post_thumbnail(); // Apply the filter but do nothing with the result. apply_filters( 'the_content', "[frame_left]"."[/frame_left]"); } if (has_post_thumbnail()) { // Echo the thumbnail the_post_thumbnail(); $thumbnail = '[frame_left]' . '[/frame_left]'; // Echo the &lt;span&gt; with an empty content echo do_shortcode("$thumbnail"); } </code>
Using shortcode in template file
wordpress
I'm adding an action witht he following line: <code> add_action( 'admin_init', 'fb_init_scripts'); </code> And my function looks like this: <code> function fb_init_scripts() { //Only use these scripts in admin interface if (is_admin() ) { wp_enqueue_script('jquery-ui','http://ajax.googleapis.com/ajax/libs/jqueryui/1.7/jquery-ui.min.js',array('jquery')); } } </code> In this instance, is it pointless to use <code> is_admin() </code> to controll if I'm in admin panel, since I'm running this function in <code> admin_init </code> ?
Yep, pointless. <code> admin_init </code> only fires in admin area (and couple more files related to AJAX functionality) so additional <code> is_admin() </code> check is not necessary. It often comes up in examples for hooks that fire both on front-end and admin area.
Should I use is_admin() inside 'admin_init' hook callback
wordpress
If possible, how can installed plugins (meaning the files have been placed in wp-content/plugins directory) be activated from other plugins?
This is how I did it in some web apps: <code> function run_activate_plugin( $plugin ) { $current = get_option( 'active_plugins' ); $plugin = plugin_basename( trim( $plugin ) ); if ( !in_array( $plugin, $current ) ) { $current[] = $plugin; sort( $current ); do_action( 'activate_plugin', trim( $plugin ) ); update_option( 'active_plugins', $current ); do_action( 'activate_' . trim( $plugin ) ); do_action( 'activated_plugin', trim( $plugin) ); } return null; } run_activate_plugin( 'akismet/akismet.php' ); </code>
How To Activate Plugins via Code?
wordpress
I am curious to know if setting 'WPLANG' in wp-config.php just effects the admin language or does it have other consequences? I run a blog in a foreign language but use English in my admin. I initially set the WPLANG to the foreign language a while ago and used a plugin (admin in English) to keep the English admin interface whilst using an .mo file to translate the theme. I now use 'WPML' to manage the translations. I was wondering whether my WPLANG setting is still relevant and what it really means to the site? Thanks
WPLANG effects the whole site not just the admin section, you can use it in conjunction with WPML. It basically sets what language you have translations for but you must include a languages folder inside wp-include with the appropriate .mo and .po files. You can also set WPML to use the default languages directory ( which is set up by defining the language(s) in wp-config as I said above).
Does changing 'WPLANG' in wp-config.php just effect the admin language or does it have other consequences?
wordpress
These are some very basic questions, so I apologize for asking them, but it's hard to understand exactly how some things work without spending dozens of hours experimenting with them. I'm more than willing to learn WP if it can do these things, but I just need some yes / no / brief explanation answers to know what WP is capable of. I know WP is some sort of blogging system, but can I use it to create blog posts on my own domain? If so, can only the web admin make them, or can any user of the site make them? If WP can create a blog on my own domain, is it as easy as tossing some server-side script files into a directory on my site and then creating the blog posts from within my browser? If so, will it manage blog accounts by itself, or do I have to create an account/login/password/etc system? If WP can create a blog system on my domain that all users can use, is the CPU usage that WP will create going to end up costing me $100/mo if there are only about 20 active bloggers on my site, or will the CPU-usage bills caused by WP be insignificant? Does WP have any forum-like functionality, or is it strictly blog posts + comments + facebook "likes" / Digg votes / etc.? Does my web site's host (HostGator) have to support WP in any way (whether it be with server-side files that I can't myself put on the server [other than PHP and MySQL , which HG offers), or whether it be the case that some site hosts do not allow the use of WP, etc.)? I know HostGator does not allow warez, music sites, gaming, et al. sites, but they shouldn't have a problem with me using WP, right? Like I said, if it sounds like what I'm looking for, I'm more than happy to buckle down and learn it. I just need to know what WP "is." I apologize again for my profound ignorance.
Yes, you can run WordPress with your own domain if you purchase hosting for it. WordPress has system of Roles (which can be further enhanced via plugins), you can let users register and allow to perform actions accordign to their role. Essentially yes. You copy WordPress files to server and initiate brief installation procedure . First account will be created during installation (if I remember right latest WordPress version will ask to specify login/password). CPU usage will be proportional to pageviews and amount of functionality you implement in your WP site. WordPress has no forum functionality natively. There are third party plugins to implement/integrate it and sister project bbPress (but it currently goes through some rough patch and is being heavily refactored). WordPress is tailored to be highly compatible with different hosting environments. Hostgator not only supports but explicitly recommends WordPress for blogging sites.
What exactly is WordPress?
wordpress
Is there any simple way to have wordpress, php or apache rewrite all urls which involve <code> /wp-admin </code> to <code> /admin </code> ? I have added this entry to my .htaccess file: <code> RewriteRule ^admin /wp-login.php [L] </code> However although <code> domain.com/admin </code> will correctly show the login page all pages after you login show the URL as <code> /wp-admin </code> which I want to always show <code> /admin </code> . Any thoughts on this?
To answer you question as a apache URL layout configuration via mod_rewrite (the apache module that handles URL rewriting), this could be helpful: <code> RewriteRule ^admin/(.*)$ /wp-admin/$1 [QSA,L] </code> (untested configuration directive, check the docs in case this does errors) This will basically translate any request to /admin/... into /wp-admin/... . If that's the only thing you would like to know, I must admit that this is slightly off-topic for worpdress@se as this is acutally a question how to configure the apache webserver. A better place might be serverfault. Keep in mind that this only rewrites the URLs that get requested. Wordpress would know nothing about this and it does still output links to /wp-admin/ on the admin then. There is a hook for any admin URL that you might want to rewrite then as well: <code> return apply_filters('admin_url', $url, $path, $blog_id); </code> You would need to replace the <code> domain/wp-admin/ </code> part with <code> domain/admin/ </code> with a filter on your own.
How to redirect/rewrite all /wp-login requests
wordpress
My permalinks are: /%postname% I currently use Custom Post Permalinks to rewrite my permalinks. It work well, but... I dlike to have some url like: www.mysite.com/permalinks_of_my_custom_posts.php > > www.mysite.com/mario-games.php If I use the plugin to do that I have to write /%list-mario%.php and it's ok,slug is rewrite... Well ... not so much because if I write another custom posts and do the same way, for exemple : /%list-firemen-games.php , it's ok, I have my www.mysite.com/firemen-games.php BUT, www.mysite.com/mario-games.php has became unaccessible. But, (many butt there sorry :D) If I write something before the slug, for example: /test/%list-mario%.php , my url is ok and it work ... So I have www.mysite.com/test/mario-games.php and www.mysite.com/firemen-games.php and I want www.mysite.com/mario-games.php and www.mysite.com/firemen-games.php and other ... It s like when I want multiple url like www.mysite.com/mario-games.php a var is erased by another and only the last work. An other solution would be to have some page.php ... Thanks for your help !
The reason adding second permalinks like that makes the first type inaccessible is because WordPress is interpretting both <code> list-firemen-games </code> and <code> list-mario </code> as <code> list-firemen-games </code> post types. To WordPress, the regular expression that is registered looks exactly the same (both look something like <code> ([^/]+)\.php/? </code> ), so when it pulls that regular expression, it's going to match that pattern against the first entry it finds in the rewrite rules; in this case, <code> list-firemen-games </code> . The reason it was working when you added <code> test </code> to the permalink is because now the regex for <code> list-mario </code> looks like <code> test/([^/]+)\.php/? </code> . If you want both types to have the same permastruct, but want to differentiate firemen from mario, I suggest using a custom taxonomy for the post type.
custom posts permalinks url rewriting
wordpress
I want to trigger a function in a plugin when a new sub-blog is created in a multisite set up of WordPress. Is it possible? If so, to which action/filter should I hook? The motivation here is to modify the new sub-blog blog it has a preset arrangment of settings, theme, plugin options, plugin activations, content set up, etc. If there aren't action/hooks for this purpose are there any other ways to accomplish this?
U guess you can use the activate_blog hook
How To Modify New Sub Blog Immediately When Super Administrator Creates It?
wordpress
I am working on a script to convert all posts in a given category to use a postmeta flag instead (testing of MySQL has shown me that on a site as large as mine this will lead to a meaningful decrease in query time). When converting posts I want to just fetch all posts in the category, add the postmeta then remove the category, which will let me just reload that function until there are no more posts in the category. I can't find a good function for removing a term from a post though. I want to give it the post id and the term taxonomy+ID and have it handled for me. I am also interested in plugins that can do the conversion for me if anyone knows of one. I couldn't find any that did cat-> postmeta, unlike the opposite which can be handled by Scribu's plugin.
Hmmm, can't remember or find fitting function either. There is <code> wp_set_object_terms() </code> that is used in multiple wrappers like <code> wp_set_post_categories() </code> . It can overwrite categories for a post. So you can get post categories, check for unwanted one and write it back excluding unwanted in that case.
Best way to programmatically remove a category/term from a post
wordpress
I have a loop pulling in two different custom post types. I have that loop showing the thumbnails of posts. Each post type used to have its own seperate loop and I had set up some png overlays to sit on top of the thumbnails. I had a play button icon over the thumbnails of the posts in the Video post type, and a stack of pictures icon over the slideshows post type thumbs. Now that I have combined the two loops I need a conditional statement to determine the post type and apply the appropriate overlay. Here is the code I have that puts the play button over every thumb. How do I change this to a conditional that would apply the btn-play.png over video thumbs and <code> &lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/images/btn-ss.png" class="play" /&gt; </code> over slideshow thumbs? <code> &lt;?php $new = new WP_Query(array ('post_type' =&gt; array('video', 'slideshow'), 'posts_per_page' =&gt; '5')); ?&gt; &lt;?php while ($new-&gt;have_posts()) : $new-&gt;the_post(); ?&gt; &lt;!-- BEGIN .post-container --&gt; &lt;div class="post-container"&gt; &lt;div class="post-thumb"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" rel="bookmark" title="&lt;?php printf(__('Permanent Link to %s', 'framework'), get_the_title()); ?&gt;"&gt; &lt;?php if ( (function_exists('has_post_thumbnail')) &amp;&amp; (has_post_thumbnail()) ) { /* if post has post thumbnail */ ?&gt; &lt;?php the_post_thumbnail('thumbnail-ws'); ?&gt; &lt;?php } else { ?&gt; &lt;?php get_the_image( array( 'custom_key' =&gt; array( 'Thumbnail' ), 'width' =&gt; 100 ) ); ?&gt; &lt;?php } ?&gt; &lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/images/btn-play.png" class="play" /&gt;&lt;span&gt; &lt;?php the_title('&lt;h2&gt;', '&lt;/h2&gt;'); ?&gt; &lt;?php the_excerpt(); ?&gt; &lt;/span&gt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; </code> Any help incorporating this conditional statement would be greatly appreciated. Just in case anyone is wondering about my code, which probably isn't optimal: I have two tiers of thumbnails so all the old posts where I hadn't specified a Thumbnail will use Justin Tadlock's "get the image script". Also, the weird setup with the span tags is because I have the title and excerpt show on mouseover (with css, no js).
You can do: <code> if( 'video' == $post-&gt;post_type ) $play_button = '/images/btn-play.png'; elseif( 'slideshow' == $post-&gt;post_type ) $play_button = '/images/btn-ss.png'; </code> Then render the button with: <code> &lt;img src="&lt;?php echo get_bloginfo('template_directory') . $play_button; ?&gt;" class="play" /&gt; </code> Hope that helps!
Conditional PNG Overlay in Custom Post Type Loop Depending on Post Type
wordpress
The user profile page has the following fields: Username First Name Last Name Nickname Display name Contact Info E-mail Website AIM Yahoo IM Jabber / Google Talk How can more fields be added to this section. Field such as Phone number, address, or anything else.
Hi @Raj Sekharan: You need to use the <code> 'show_user_profile' </code> , <code> 'edit_user_profile' </code> , <code> 'personal_options_update' </code> and <code> 'edit_user_profile_update' </code> hooks. Here's some code to add a Phone number : <code> add_action( 'show_user_profile', 'yoursite_extra_user_profile_fields' ); add_action( 'edit_user_profile', 'yoursite_extra_user_profile_fields' ); function yoursite_extra_user_profile_fields( $user ) { ?&gt; &lt;h3&gt;&lt;?php _e("Extra profile information", "blank"); ?&gt;&lt;/h3&gt; &lt;table class="form-table"&gt; &lt;tr&gt; &lt;th&gt;&lt;label for="phone"&gt;&lt;?php _e("Phone"); ?&gt;&lt;/label&gt;&lt;/th&gt; &lt;td&gt; &lt;input type="text" name="phone" id="phone" class="regular-text" value="&lt;?php echo esc_attr( get_the_author_meta( 'phone', $user-&gt;ID ) ); ?&gt;" /&gt;&lt;br /&gt; &lt;span class="description"&gt;&lt;?php _e("Please enter your phone."); ?&gt;&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php } add_action( 'personal_options_update', 'yoursite_save_extra_user_profile_fields' ); add_action( 'edit_user_profile_update', 'yoursite_save_extra_user_profile_fields' ); function yoursite_save_extra_user_profile_fields( $user_id ) { $saved = false; if ( current_user_can( 'edit_user', $user_id ) ) { update_user_meta( $user_id, 'phone', $_POST['phone'] ); $saved = true; } return true; } </code> That code will add a field to your user screen that looks something like this: There are also several blog posts available on the subject that might be helpful: Adding and using custom user profile fields Adding Extra Fields to the WordPress User Profile Or if you prefer not to roll-your-own there are plugins that add said features such as the following (although I'm sure there are others): Cimy User Extra Fields
How To Add Custom Form Fields To The User Profile Page?
wordpress
I'm trying to use the media uploader thing from WP (the form from the pop-up with crunching and all that), and can't figure out how. Is there any plugin out there that uses it? It would be easier to understand...
The plugin Image Widget uses it. http://wordpress.org/extend/plugins/image-widget/
Any plugin out there that uses WP's internal image uploader?
wordpress
im using the media finder plugin which works fine in 2.9 wordpress, but since the 3.0 wordpress, the json sans eval library which the plugin uses works no more. not sure what was involved in the upgrade from 2.9 to 3.0 core wise with json. here is a screenshot what firebug in firefox spits out, the actual json is parsed, but its not displayed. (media finder lets you search vid the media manager in your post) so since json eval sans is non validating, not sure if wp 3.0 doesnt like that. here is the url to the plugin http://wordpress.org/extend/plugins/media-finder/ here is the screen shot of the error in the plugin http://imgur.com/RFGXm.jpg anyone can assist would be a life saver, or even what is involved in converting the code from json sans eval to json2.js which wp is packed with now the code that would need to be converted to json2 would be the line xhr = $.post(ajaxurl, params, function(data) { data = jsonParse(data);
When I comment out the line: <code> @header('Content-type: application/json; charset=UTF-8'); </code> it works for me p.s. there is also a closing php opening tag in it without the word php there is a closing php tag at the bottom which can be gone there is a notice on an undefined index. better would be to use $charset = get_option('blog_charset'); I have no idea if this: http://wordpress.org/support/topic/plugin-json-api-content-length-header has something do with it, or this: http://core.trac.wordpress.org/ticket/11537 or this: http://wordpress.org/support/topic/wordpress-gone-wild?replies=3 , did not dive in it.
wordpress 3.0 json issue
wordpress
Is it possible to specify the category people can choose to subscribe to in the Subscribe2 (Wordpress Plugin) widget?
there is an addon for subscribe2 that allows that called TT Subscribe2 Front End Plugin
Subscribe2 widget with choosing categories?
wordpress
I'm creating a custom post type, "gallery", in which the admin should be able to upload images (these images would be attached to the post). The thing is that the "editor" meta box is disabled for this post type. And I need a way to add the image upload pop-up box to it, just like posts have. How can I do that? or maybe it's better to create my own uploader? if so, how could I attach the uploaded images to the post (gallery) that's being created? how do attachments work? are they custom post types too?
At the top of <code> wp-admin/edit-form-advanced.php </code> I see the following code that seems related to the media uploader: <code> if ( post_type_supports($post_type, 'editor') || post_type_supports($post_type, 'thumbnail') ) { add_thickbox(); wp_enqueue_script('media-upload'); } </code> You'll need to add these yourself. <code> add_thickbox() </code> enqueues both a script and a style, so make sure you hook into <code> print_styles </code> , as <code> print_scripts </code> will be too late to also print a style. <code> add_action('admin_print_styles-post-new.php', 'wpa4016_add_media_upload_scripts'); add_action('admin_print_styles-post.php', 'wpa4016_add_media_upload_scripts'); function wpa4016_add_media_upload_scripts() { if ($GLOBALS['post_type'] == 'wpa4016') { add_thickbox(); wp_enqueue_script('media-upload'); } } </code> Now we need to add the upload buttons. I see <code> the_editor() </code> , the function that displays the editor, has a parameter <code> $media_buttons </code> , and if we set to to <code> true </code> it basically executes <code> do_action('media_buttons') </code> . This in turn calls <code> media_buttons() </code> , which calls <code> _media_button() </code> for each media type (image, video, audio, ...). So we do this ourselves! <code> add_action('edit_form_advanced', 'wpa4016_edit_form_advanced'); function wpa4016_edit_form_advanced() { if ($GLOBALS['post_type'] == 'wpa4016') { echo _media_button(__('Add an Image'), 'images/media-button-image.gif?ver=20100531', 'image'); } } </code> Attachments are indeed custom posts of type <code> attachment </code> , with their <code> post_parent </code> set to the post they're attached to. Images have two meta fields: <code> _wp_attached_file </code> contains the filename, <code> _wp_attachment_metadata </code> contains an array with image EXIF data and pointers to different sizes of the same image. You can create these yourself, using <code> wp_insert_attachment() </code> , but I believe you still have to handle the upload yourself then.
Attaching media to custom posts without editor
wordpress
Is there any way to measure the time it takes for plugins to load and in which pages they load (without figuring out the entire code)? In addition, I would like to find out which plugins load files in which pages and find the ones that load on irrelevant ones.
Yes, Plugins effect site loading time. There are many poorly written Plugins that make unnecessary database queries and load numerous files to the page. The extra JavaScript and CSS files are not that big of deal unless you are using numerous plugins. I have worked on large sites that had 30 or 40 active plugins and the server would crash during any high traffic periods so it can be an issue. To see what extra files are being loaded you can simply view source or use the net tab on Firebug. Another good way to find external files loaded by plugins is to use W3 Total Cache's minify help wizard. The wizard scans your theme and plugins and recommends the ones to combine and minify and for what page to load them on. To monitor Plugin database queries and cpu time you can add the following code to the bottom of your footer.php: <code> &lt;!--&lt;?php echo $wpdb-&gt;num_queries; _e('queries'); ?&gt;. timer_stop(1); _e('seconds'); ?&gt;.--&gt; </code> This will allow you to view the source of each page and see how many queries are being made and how long it takes to make them. Ex: Of course this won't tell you what Plugin is responsible for the queries but allows you to do testing while disabling and activating different combinations.
Do Plugins effect site loading time?
wordpress
I have a WP Multisite installation. On the main blog all subscribers are appearing in the post author dropdown on the post edit screen. I think this happened after an upgrade to 3.0.1. The new user role is set to Subscriber, so it's not like all the new signups are being made contributors or authors. Does anyone know if the problem I'm experiencing is a bug? Or am I missing something really obvious? We have hundreds of subscribers so it's really a pain to try to find the right one to assign a post author. Any help / hacks would be much appreciated. Thank you. ALSO.... when I look at edit-form-advanced.php , I see this: <code> if ( post_type_supports($post_type, 'author') ) { $authors = get_editable_user_ids( $current_user-&gt;id ); // TODO: ROLE SYSTEM if ( $post-&gt;post_author &amp;&amp; !in_array($post-&gt;post_author, $authors) ) $authors[] = $post-&gt;post_author; if ( ( $authors &amp;&amp; count( $authors ) &gt; 1 ) || is_super_admin() ) add_meta_box('authordiv', __('Author'), 'post_author_meta_box', $post_type, 'normal', 'core'); } </code> Is there anything I can change in there to fix this?
This is a bug. It has been reported in trac and will hopefully be fixed with the release of WordPress 3.1 soon. If you really want to dive into it, you could apply the patch that is with the ticket. http://core.trac.wordpress.org/ticket/14094
How to Remove Subscribers from the Post Author Drop Down
wordpress
I recently committed version 2 of my new plugin to the Plugin Directory, but now when you install the plugin for the first time, you get this error on activation: "The plugin does not have a valid header." You can workaround it by browsing to the plugin section of wp-admin and activating from there with no errors, but this is still not ideal. As far as I can tell, the header looks fine, and is pretty much the same as version 1.0. Which leave me to wonder why I get this error? Here is the plugin: http://wordpress.org/extend/plugins/export-to-text/
From what you write, it looks to me that you accidentially copied/tagged the whole <code> /trunk </code> directory in your SVN while tagging/branching. As the wordpress plugin directory just grabs the full directory that got tagged, the zip package was invalidated. You can recover from that. I once made the same mistake. Just do a full checkout on your local machine in another directory (not the working copy in which you develop your plugin). That check downloads everything, the current trunk and all tags. Then go inside the tags directory and locate the tag in which you accidentially created the mess. SVN-Delete it and commit that change. You probably can revert the accidental change as well, but I think deleting the directory of the concrete tag is more straight forward. Next time you tag your plugin, tag the working copy and not the trunk directory. If you're using SVN on the commandline: Tags - Chapter 4. Branching and Merging If you're using Tortoise SVN: Branching / Tagging - Chapter 4. Daily Use Guide
Why do I get this "plugin does not have a valid header" error?
wordpress
I don't care about having images catalogued by date, I actually hate the subdirectories it creates by year and by month when you upload an image. Is there a way to store them all in the same folder?
Uncheck this box: Setting/Media [ ] Organize my uploads into month- and year-based folders
Image archive without date
wordpress
I have a blog hosted at wordpress.com. How do I integrate it with Google Analytics?
You can't. GA requires javascript, and wordpress.com doesn't allow it.
Can I integrate Google Analytics with my blog, hosted at wordpress.com?
wordpress
I'm trying to set up a sidebar area that'll do two things: Display a drop-down of posts in a given custom post types. Display post metadata (content and custom fields) if selected post The thing that's getting me is two-fold: Having the selected post metadata display in the sidebar once selected via the dropdown Having the content refresh via ajax or jquery so it doesn't refresh the entire page
Hi @Norcross: What you are looking for is a bit involved but I wrote it anyway. Unfortunately it took longer than I planned so I've run out of gas on going in depth to explain it but I did document the code so hopefully that will help you follow it and you can download a copy of the code here . The Widget in Use on the Website: Note in my example I wrote a generic function to grab all the meta keys and meta values associated with a post to have something to display; that's what you see on the screen. The Widget Configuration in the Admin Console: The Code Here's the code. This can be used in your theme's <code> functions.php </code> file or as a standalone file in a plugin or theme you are developing: <code> &lt;?php /* Plugin Name: List_Custom_Post_Type_Posts_with_AJAX class Version: 0.1 Author: Mike Schinkel Author URI: http://mikeschinkel.com Shows how to create a widget with a dropdown list of posts for a given post type and then retrieve HTML specific to the selected post via AJAX to insert into the page. Yes, the name of the class is insanely long in hopes that you'll be forced to think about what would be a better name. This can be used in your theme's functions.php file or as a standalone file in a plugin or theme you are developing. */ class List_Custom_Post_Type_Posts_with_AJAX extends WP_Widget { /* * List_Custom_Post_Type_Posts_with_AJAX() used by the Widget API * to initialize the Widget class */ function List_Custom_Post_Type_Posts_with_AJAX() { $this-&gt;WP_Widget( 'list-custom-post-type-posts-with-ajax', 'List Custom Post Type Posts with AJAX', // Widget Settings array( 'classname' =&gt; 'list-custom-post-type-posts-with-ajax', 'description' =&gt; 'Widget to List List Custom Post Type Posts with AJAX.', ), // Widget Control Settings array( 'height' =&gt; 250, // Set the form height (doesn't seem to do anything) 'width' =&gt; 300, // Set the form width 'id_base' =&gt; 'list-custom-post-type-posts-with-ajax', ) ); } /* * widget() used by the Widget API to display a form in the widget area of the admin console * */ function form( $instance ) { global $wp_post_types; $instance = self::defaults($instance); // Get default values // Build the options list for our select $options = array(); foreach($wp_post_types as $post_type) { if ($post_type-&gt;publicly_queryable) { $selected_html = ''; if ($post_type-&gt;name==$instance['post_type']) { $selected_html = ' selected="true"'; $post_type_object = $post_type; } $options[] = "&lt;option value=\"{$post_type-&gt;name}\"{$selected_html}&gt;{$post_type-&gt;label}&lt;/option&gt;"; } } $options = implode("\n",$options); // Get form attributes from Widget API convenience functions $title_field_id = $this-&gt;get_field_id( 'title' ); $title_field_name = $this-&gt;get_field_name( 'title' ); $post_type_field_id = $this-&gt;get_field_id( 'post_type' ); $post_type_field_name = $this-&gt;get_field_name( 'post_type' ); // Get HTML for the form $html = array(); $html = &lt;&lt;&lt;HTML &lt;p&gt; &lt;label for="{$post_type_field_id}"&gt;Post Type:&lt;/label&gt; &lt;select id="{$post_type_field_id}" name="{$post_type_field_name}"&gt; {$options} &lt;/select&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="{$title_field_id}"&gt;Label:&lt;/label&gt; &lt;input type="text" id="{$title_field_id}" name="{$title_field_name}" value="{$instance['title']}" style="width:90%" /&gt; &lt;/p&gt; HTML; echo $html; } /* * widget() used by the Widget API to display the widget on the external site * */ function widget( $args, $instance ) { extract( $args ); $post_type = $instance['post_type']; $dropdown_name = $this-&gt;get_field_id( $post_type ); // jQuery code to response to change in drop down $ajax_url = admin_url('admin-ajax.php'); $script = &lt;&lt;&lt;SCRIPT &lt;script type="text/javascript"&gt; jQuery( function($) { var ajaxurl = "{$ajax_url}"; $("select#{$dropdown_name}").change( function() { var data = { action: 'get_post_data_via_AJAX', post_id: $(this).val() }; $.post(ajaxurl, data, function(response) { if (typeof(response)=="string") { response = eval('(' + response + ')'); } if (response.result=='success') { if (response.html.length==0) { response.html = 'Nothing Found'; } $("#{$dropdown_name}-target").html(response.html); } }); return false; }); }); &lt;/script&gt; SCRIPT; echo $script; echo $before_widget; if ( $instance['title'] ) echo "{$before_title}{$instance['title']}{$after_title}"; global $wp_post_types; // Dirty ugly hack because get_pages() called by wp_dropdown_pages() ignores non-hierarchical post types $hierarchical = $wp_post_types[$post_type]-&gt;hierarchical; $wp_post_types[$post_type]-&gt;hierarchical = true; // Show a drop down of post types wp_dropdown_pages(array( 'post_type' =&gt; $post_type, 'name' =&gt; $dropdown_name, 'id' =&gt; $dropdown_name, 'post_status' =&gt; ($post_type=='attachment' ? 'inherit' : 'publish'), )); $wp_post_types[$post_type]-&gt;hierarchical = $hierarchical; echo $after_widget; // Create our post html target for jQuery to fill in echo "&lt;div id=\"{$dropdown_name}-target\"&gt;&lt;/div&gt;"; } /* * update() used by the Widget API to capture the values for a widget upon save. * */ function update( $new_instance, $old_instance ) { return $this-&gt;defaults($new_instance); } /* * defaults() conveninence function to set defaults, to be called from 2 places * */ static function defaults( $instance ) { // Give post_type a default value if (!get_post_type_object($instance['post_type'])) $instance['post_type'] = 'post'; // Give title a default value based on the post type if (empty($instance['title'])) { global $wp_post_types; $post_type_object = $wp_post_types[$instance['post_type']]; $instance['title'] = "Select a {$post_type_object-&gt;labels-&gt;singular_name}"; } return $instance; } /* * self::action_init() ensures we have jQuery when we need it, called by the 'init' hook * */ static function action_init() { wp_enqueue_script('jquery'); } /* * self::action_widgets_init() registers our widget when called by the 'widgets_init' hook * */ static function action_widgets_init() { register_widget( 'List_Custom_Post_Type_Posts_with_AJAX' ); } /* * self::get_post_data_via_AJAX() is the function that will be called by AJAX * */ static function get_post_data_via_AJAX() { $post_id = intval(isset($_POST['post_id']) ? $_POST['post_id'] : 0); $html = self::get_post_data_html($post_id); $json = json_encode(array( 'result' =&gt; 'success', 'html' =&gt; $html, )); header('Content-Type:application/json',true,200); echo $json; die(); } /* * self::on_load() initializes our hooks * */ static function on_load() { add_action('init',array(__CLASS__,'action_init')); add_action('widgets_init',array(__CLASS__,'action_widgets_init')); require_once(ABSPATH."/wp-includes/pluggable.php"); $user = wp_get_current_user(); $priv_no_priv = ($user-&gt;ID==0 ? '_nopriv' : ''); add_action("wp_ajax{$priv_no_priv}_get_post_data_via_AJAX",array(__CLASS__,'get_post_data_via_AJAX')); } /* * get_post_data_html($post_id) * * This is the function that generates the HTML to send back to the client * Below is a generic want to list post meta but you'll probably want to * write custom code and use the outrageously long named hook called: * * 'html-for-list-custom-post-type-posts-with-ajax' * */ static function get_post_data_html($post_id) { $html = array(); $html[] = '&lt;ul&gt;'; foreach(get_post_custom($post_id) as $name =&gt; $value) { $html[] = "&lt;li&gt;{$name}: {$value[0]}&lt;/li&gt;"; } $html[] = '&lt;/ul&gt;'; return apply_filters('html-for-list-custom-post-type-posts-with-ajax',implode("\n",$html)); } } // This sets the necessary hooks List_Custom_Post_Type_Posts_with_AJAX::on_load(); </code> Also, if you want to read a good article about coding Widgets, Justin Tadlock has a good one called: The complete guide to creating widgets in WordPress
Display custom post data in sidebar w/ dropdown
wordpress
<code> &lt;?php query_posts(array('showposts' =&gt; 1000, 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'page', 'orderby' =&gt; 'title', 'order' =&gt; 'ASC', 'meta_key' =&gt; featured_product, 'meta_value' =&gt; 1)); ?&gt; &lt;?php query_posts(array('showposts' =&gt; 1000, 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'page', 'orderby' =&gt; 'title', 'order' =&gt; 'ASC')); ?&gt; </code> I have 2 queries, first to show meta key with featured_product eq 1. So I want to exclude all the featured products on the second query. How can i do that please? Thanks!
I've never had any luck getting the meta compare to work either--but I came up with a workaround for this exact situation (having "featured" items at the top of the page). First, you probably shouldn't be using query_posts for both queries. You should use a custom query for at least the first one. Then, while you're running that loop, keep the ids of any "featured" posts in a variable. When you run your second loop, you can use the "post__not_in" arg to exclude the featured ones. Like so: <code> // Set up a custom query $featured_query = new WP_query(); // Your query args $featured_args=array( 'post_type'=&gt;'post', 'meta_key'=&gt;'featured_product', 'meta_value'=&gt;'1' ); // Run it $featured_query-&gt;query($featured_args); if ($featured_query-&gt;have_posts()) { while ($featured_query-&gt;have_posts()) { $featured_query-&gt;the_post(); // Remember the featued ID $featured_post_id = get_the_ID(); // Render your featured post here } } // Set up the args for your main query $args = array( 'post_type' =&gt; 'post', 'post__not_in' =&gt; array($featured_post_id) // Don't show the featured post ); // Now run your main query and so on... </code>
query_posts exclude a meta key
wordpress
I've created a custom post type, and have successfully added a few entries. I can call these entries out with <code> query_posts() </code> to show on the front page, but <code> the_permalink() </code> on each of them just sends me to a "Page not found" 404. Am I missing something? I'm currently running on <code> http://localhost </code> , so the results of <code> the_permalink() </code> from the front page custom post type loop sends the user to <code> http://localhost/PU/PU2010/website/cartoons/einstein-on-california </code> . functions.php <code> function createCartoonPostType() { register_post_type( 'cartoon', array( 'label' =&gt; 'Cartoon', 'public' =&gt; true, 'hierarchical' =&gt; true, 'supports' =&gt; array( 'title', 'editor', 'thumbnail', 'comments' ), 'rewrite' =&gt; array( 'slug' =&gt; 'cartoons' ) ) ); } add_action( 'init', 'createCartoonPostType' ); </code> According to this, I should be able to just create <code> single-cartoon.php </code> , correct? single-cartoon.php <code> &lt;?php get_header(); ?&gt; &lt;div class="container_20"&gt; &lt;div class="grid_14"&gt; &lt;div class="bodybox"&gt; &lt;?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?&gt; &lt;?php the_title(); ?&gt; &lt;?php endwhile; ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="grid_6"&gt; &lt;?php get_template_part( 'social', 'box' ); ?&gt; &lt;?php get_sidebar(); ?&gt; &lt;/div&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php get_footer(); ?&gt; </code> loops-cartoons.php (frontpage loop) <code> &lt;?php query_posts( 'post_type=cartoon&amp;posts_per_page=1' ); ?&gt; &lt;div class="cartoons-box"&gt; &lt;ul class="cartoons-list"&gt; &lt;?php if ( ! have_posts() ) : ?&gt; Sorry, no posts. &lt;?php else : while ( have_posts() ) : the_post(); ?&gt; &lt;li&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" class="preview-image"&gt; &lt;?php the_post_thumbnail( 'featured' ); ?&gt; &lt;/a&gt; &lt;/li&gt; &lt;?php endwhile; endif; ?&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php wp_reset_query(); ?&gt; </code>
Did you go to Admin -> Settings -> Permalinks after setting up the post type? The permalink structure hasn't been added until you've done that. It could be the cause of your problem. The permalinks page fires <code> $wp_rewrite-&gt;flush_rules(); </code> each time the page is visited, so it's not even necessary to save.
single-type.php not working, delivering 404
wordpress
Hey, I've been trying to get a pending count to appear on the admin sidebar, for pending posts, like the little bubble that appears for pending comments: Offtopic : Am I the only one that thinks this should be core behaviour? Where should I suggest this feature? Anyhow, I found this plugin , but I noticed it didn't always worked. Sometimes the notifier appears on Pages or other item. The code it uses to add the pending count goes something like this: <code> $menu[5][0] .= " &lt;span class='update-plugins count-$pending_count'&gt;&lt;span class='plugin-count'&gt;" . number_format_i18n($pending_count) . '&lt;/span&gt;&lt;/span&gt;'; </code> So, clearly the problem is the hard-coded 5 there, but how can I update it so it always points to Posts? I'll be glad to commit this change to the plugin if we know the answer. Thanks!
@ign Replace the line of code you posted with the following.. <code> foreach( $menu as $menu_key =&gt; $menu_data ) : if( 'edit.php' != $menu_data[2] ) continue; $menu[$menu_key][0] .= " &lt;span class='update-plugins count-$pending_count'&gt;&lt;span class='plugin-count'&gt;" . number_format_i18n($pending_count) . '&lt;/span&gt;&lt;/span&gt;'; endforeach; </code> ..that should avoid the need to know the specific key.. (let me know if any problems).. Hope that helps.. :)
Modifying admin sidebar contents to show pending posts indicator
wordpress
I would like to take the titles of recent posts or content related posts from one website and display them in the widget area of another website. I'm sure there must be a way to do this, perhaps some adaptation to the standard 'recent posts' widget? I did something similar before using an rss feed from one site and displaying their titles in a module on another. However this was in a non-wordpress site and I am not quite sure how to achieve the same result here. Ideally I would like to do it without using an rss feed and also be able to control specifically which posts are shown, perhaps being able to define them manually or by other criteria than just 'recent'.
There are three ways you can accomplish this: two are very code intensive, the other is already built-in. RSS Hand's down, the easiest way to do what you want to do is with an RSS widget. WordPress already has an RSS widget built-in to core, so all you need to do is specify the feed and voila! The widget displays the title by default, but you can also add the post's content, author, and publication date. Tweaking the front-end display to fit your layout is left up to CSS, just like any other widget. This method doesn't require you to have access to the other site at all and (other than styling the CSS) doesn't require any coding whatsoever. Custom Code If you have direct database access (which you say yo do), you can add a script to the one site that loads content from the other. You can do this one of two ways: Include the WordPress bootstrap file ( <code> wp-blog-header.php </code> ) and load up WordPress within the second site. Then you can use the standard WordPress query functions to retrieve posts and do with them whatever you want. Use direct database queries to quickly pull information out of the database. You're looking at the <code> wp_posts </code> table for anything with <code> post_type=post </code> and <code> post_status=publish </code> . Just get the title and content, then do whatever you need to do. I actually used this method on a client site. They had an existing PHP/MySQL-driven home page and wanted to add links to an external WordPress blog. If you go to their site, you'll see a list of blog posts on the front page - the front page is generated by a proprietary CMS that queries the WordPress database to find, parse, and display a list of recent posts. XML-RPC WordPress has a fantastic XML Remote Procedure Call system built-in to core. This system allows for external applications (desktop applications, iPhone apps, other websites) to remotely interact with WordPress by sending and receiving XML-formatted messages. There's even an XML-RPC method that does exactly what you want: <code> metaWeblog.getRecentPosts </code> . So, turn XML-RPC 'on' for the site you want to request posts from. Then send a <code> metaWeblog.getRecentPosts </code> request to <code> http://yoursite.com/xmlrpc.php </code> that specifies the following parameters: ID of the blog you’re working with (usually 0 for a single site) WordPress username WordPress password Number of posts you want to return WordPress will log you in, run a query to fetch the posts, and return an XML object containing a list of recent posts (as many as you specified) that each contain the following: dateCreated - Post publication date userid – ID of the post author postid – ID of the post itself description – Post content title – Post title link – Post permalink permaLink – Post permalink categories – Array of post categories mt_excerpt – Post excerpt mt_text_more – Read More text mt_allow_comments – Whether comments are open or closed mt_allow_pings – Whether pings are open or closed mt_keywords – Array of post tags wp_slug – Post slug wp_password – Post password wp_author_id – ID of the post author wp_author_display_name – Display name of the post author date_created_gmt – Post publication date (as GMT time) post_status – Post publication status custom_fields – Array of custom fields sticky – Whether or not the post is marked as "sticky" I wrote a tutorial specific to the MetaWeblog API (which is implemented by WordPress) some time ago. I've also written one that explains how to use the XML-RPC API from within WordPress to make calls to an external WordPress system. That might help to get you started. If you want to fetch a specific post rather than just "recent" posts, there's a method call for that, too. Just call <code> metaWeblog.getPost </code> and specify the ID of the post you want and your WordPress username and password. This method will return a single post as an XML object containing the same data as I listed above.
Is there plugin to show recent posts from one website in the widget area of another?
wordpress
I have created a custom post type and added some custom metaboxes to the page edit screen. My objective was to provide specific metaboxes which a user can edit which in turn would allow a user to modify specific content areas of a websites homepage. Everything described above works perfectly except that I seem to be unable to set the page created from this custom post type as the "static page" within the wordpress admin "settings" area. It seems the dropdown which lets your select a static page only shows pages located within the default wordpress "page" post_type. How would I be able to change these settings to achieve my goal?
Unless a solution can be provided on this topic I will assume for the time being that the best way to get this to work is to just create a "home.php" file within ones template and query the post ID directly. I have accepted this as the answer for the time being but if anyone finds a solution after this answer is accepted please post it and I will accept that as the correct answer.
How to add a post from a custom post type as the static page?
wordpress
I'm using the query_posts for "Page" item rather than "Post". I want to have the ability to make the "featured" page always on the top, we could add a custom field called "featured_product", if it's eq "1" then display the post as the very first one. Here is the basic code for the query. Someone help please!? <code> &lt;?php query_posts(array('showposts' =&gt; 1000, 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'page', 'orderby' =&gt; 'title', 'order' =&gt; 'ASC')); ?&gt; &lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; ... &lt;?php endwhile; else: ?&gt; ... &lt;?php endif; ?&gt; </code>
In your query posts array add this: <code> 'meta_key' =&gt; (meta key name in database), 'meta_value' =&gt; 1 </code> To make it at the top use two queries. One for the top first post and one for the rest of the posts/pages. so your whole query will look like this: <code> &lt;?php query_posts(array('showposts' =&gt; 1, 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'page', 'orderby' =&gt; 'title', 'order' =&gt; 'ASC', 'meta_key' =&gt; featured, 'meta_value' =&gt; 1); ?&gt; &lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; ... &lt;?php endwhile; else: ?&gt; ... &lt;?php endif; ?&gt; &lt;?php wp_reset_query(); ?&gt; &lt;second query goes here as you have it in your post&gt; </code> Replace "featured" with your key name.
wordpress query_posts featured page always on top
wordpress
I currently use <code> query_posts </code> to show these custom posts but I'm pretty sure that I should uses <code> get_posts() </code> to write it correctly. <code> &lt;?php query_posts( array( 'type-mario' =&gt; 'games', 'showposts' =&gt; 10 ) ); ?&gt; &lt;p&gt;Mario games&lt;/p&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;div id="post-&lt;?php the_ID(); ?&gt;" &lt;?php post_class(); ?&gt;&gt; &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;?php wp_reset_query(); ?&gt; </code> Thanks for your advice.
Hi Elium2009 : Using your code, I think this is what you were looking for? (note that <code> WP_Query() </code> is just the more direct version of <code> get_posts() </code> ): <code> &lt;?php $posts = WP_Query(array( 'taxonomy' =&gt; 'type-mario' 'term' =&gt; 'games', 'posts_per_page' =&gt; 10 )); ?&gt; &lt;p&gt;Mario games&lt;/p&gt; &lt;?php while ( $posts-&gt;have_posts() ) : $posts-&gt;the_post(); ?&gt; &lt;div id="post-&lt;?php the_ID(); ?&gt;" &lt;?php post_class(); ?&gt;&gt; &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;?php wp_reset_query(); ?&gt; </code> Hope this helps?
How to call a custom post with get_posts() instead of query_posts()?
wordpress
I would like to make a portfolio page where each entry (a post) would be fetched using Ajax. This way I would have an image gallery, but in which I not only would have images but also the description of the work, if it's for sale, the url to the shop, and whatever other random fields. A gallery is not good enough because there is no clean way of displaying text belonging to each image's post.
Absolutely! There are a number of themes on the market that do load posts via AJAX. Take a look at any of them to get an idea of how they work. A particularly good example is K2 - K2 loads entire pages of posts via AJAX if you click on the previous posts link. To really get your hands dirty, check out this awesome tutorial on loading posts via AJAX. Just keep in mind, AJAX is all about using JavaScript to request data from a server - your server in this case is running WordPress and is built to produce posts based on specific requests. All you need to do is add the JavaScript layer to request them on demand.
Can I load posts via Ajax?
wordpress
Any post install tips after installing Wordpress 3.0.1? which would be useful for any wordpress installation , where we will use wordpress as a CMS for a website. and blog page will not as a home page.
01 Database Security 01.01 change your database prefix during install or after install this is security by obscurity but helps with automated scripts that could run over all databases to inject bad code in your content like scripts, iframes or display: bits 01.02 install a database backup plugin to automate the backup e.g. http://wordpress.org/extend/plugins/wp-db-backup/ Read More: http://codex.wordpress.org/WordPress_Backups 02 Operating System Security 02.01 change all your files to 644 and directories to 755. 02.02 only access your backend via secure means e.g. never use ftp. 02.03 move the wp-config.php one level up so that it does not sit in your webroot directory. E.g. with MediaTemple: move it one level up to the HTML directory. Chmod this file to 400 for starters. 02.04 install an intrusion detection system. At least something like wordpress file monitor to check for potential changes (use hash option): http://wordpress.org/extend/plugins/wordpress-file-monitor/ Read More: http://codex.wordpress.org/WordPress_Backups Read More: http://codex.wordpress.org/Hardening_WordPress 02.05 If possible use svn to install the initial site and upgrade it, may also be handy in case of zero day breaches you need to act upon 03 WordPress Security 03.01 Install login lockdown (http://wordpress.org/extend/plugins/login-lockdown/) or related plugins that minimize the amount of allowed retries on logging in. 03.02 Choose a strong password, use a password tool for storing it. 03.03 Preferably perform all administration via https Read More: http://codex.wordpress.org/Administration_Over_SSL 03.04 Never use Admin as username, change it directory from the start to something else, you can change it via the database: <code> update tableprefix_users set user_login='newuser' where user_login='admin';, </code> 03.05 Hide the version WordPress is using or possibly hide the fact that your using WordPress at all, see e.g.: stackexchange-url ("Steps to Take to Hide the Fact a Site is Using WordPress?") 03.06 Remove notifications about new updates, see: stackexchange-url ("Best Collection of Code for your functions.php file") 04 Anti Spam 04.01 enter your Akismet key for starters. You can get your key after signing up with wordpress.org. 04.02 install a Captcha tool See also: stackexchange-url ("Why do I get comment spam even with Akismet and Captcha?") 05 Usability and URL Hacking 05.01 Set a Permalink for your blogs. Create one that will not cause performance issues. See: stackexchange-url ("Performance of my permalink structure?"). Remember that you will have to live with it for a long time. 05.02 adjust your titles to have a meaningful names. See: stackexchange-url ("Best Collection of Code for your functions.php file") for an example, change to your own likings. 05.03 Give your blog a meaningful title and subtitle 06 Functional Installation 06.01 Add Users to your weblog, use strong passwords 06.02 Add a contact form, see: stackexchange-url ("Contact Form on WordPress Sites?") 06.03 install tinymce advanced: http://wordpress.org/extend/plugins/tinymce-advanced/ this gives you needed table editing, etc... 06.04 configure the blog in blogging tools or write documentation how to do this e.g. in windows live writer 06.05 Modify the login logo and link, see: stackexchange-url ("Best Collection of Code for your functions.php file") 06.06 Remove pings to your own blog: stackexchange-url ("Best Collection of Code for your functions.php file") 06.07 Display content only for specific users, see: stackexchange-url ("Best Collection of Code for your functions.php file") 06.08 delete the hello post and comment 06.09 delete the hello dolly plugin, see: stackexchange-url ("Initialization Script for "Standard" Aspects of a WordPress Website?") 06.10 write an about page 06.11 add your FTP details for upgrading: stackexchange-url ("How can I stop WordPress from prompting me to enter FTP information when doing updates?") (possibly further secure this) 07 SEO and Metrics 07.01 Add Analytic Tools like Google Analytics, Wp Stats, Statcounter to your theme. There are also plugins available to auto include the scripts for these. 07.02 WP Stats gives you shortlinks. Handy to include the short link code in your post to have users twitter them etc... 07.03 Register your blog on Technorati 07.04 install a twitter plugin to sync your posts with your twitter account 07.05 Remove not needed words in titles automatically, see: stackexchange-url ("Best Collection of Code for your functions.php file") 07.06 install any of the hundreds of SEO plugins 08 Performance 08.01 install one cache plugin (or more). see e.g.: stackexchange-url ("What are the best practices for using a caching plugin on a shared host?") there are a lot of options, you might also think of widget caching or in specific cases needing to write your own cache. 08.02 install wp smush it to automatically shrink your images: http://wordpress.org/extend/plugins/wp-smushit/ 08.03 disable revision or limit them: stackexchange-url ("Best Collection of Code for your functions.php file") (this is performance and scaling in the broadest sense) 08.04 for a while check the amount of queries and performance, see: stackexchange-url ("Best Collection of Code for your functions.php file") 08.05 If you do not need XMLRPC, remove it, see: stackexchange-url ("Best Collection of Code for your functions.php file") 09 Design 09.01 Install a theme. Depending on your needs make a decision on what you seek in a theme, think of useability by disabled, SEO and maintainability by non technical people OR create your own theme. It's not that hard. 10 Useless 10.01 Remove the filter to translate WoRdPrEsS back to WordPress, see: stackexchange-url ("Best Collection of Code for your functions.php file")
Any post install tips after installing Wordpress 3.0.1?
wordpress
My <code> category.php </code> lists articles on the first page, and on the bottom I have a pager. When I click page 2, the index.php page is loaded and the url looks like this: <code> http:// www.mysite.com/some-category/page/2 </code> . Why isn't category.php page loaded when URL has <code> /page/2/ </code> ? My permalink structure looks like this: <code> /%category%/%postname%/ </code> If it helps to see the code, here it is: <code> &lt;?php /** * Template Name: Article List - Category * * Displays articles from magazine * * @package WordPress * @subpackage Norwegian_Fashion * @since Norwegian Fashion 1.0 */ get_header(); // Get current page. Is used for pagination. $page = (get_query_var('paged')) ? get_query_var('paged') : 1; ?&gt; &lt;div id="mainArea"&gt; &lt;div id="articleList"&gt; &lt;ul&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;li&gt; &lt;div class="photo"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt; &lt;?php the_related_image_scaled('h=180') ?&gt; &lt;/a&gt; &lt;/div&gt; &lt;div class="info"&gt; &lt;span class="date"&gt;&lt;?php the_date(); ?&gt;&lt;/span&gt; | by &lt;span class="byline"&gt;&lt;?php the_custom_author(); ?&gt;&lt;/span&gt; &lt;header&gt; &lt;h1&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h1&gt;&lt;/header&gt; &lt;div class="intro"&gt;&lt;?php the_intro('num_words=25'); ?&gt;&lt;/div&gt; &lt;div id="post_metadata"&gt; &lt;div class="keywords"&gt; &lt;?php the_tags('Keywords: ', ','); ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="commentsCount"&gt;&lt;?php comments_number('no comments','1 comment','% comments'); ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;?php endwhile; ?&gt; &lt;/ul&gt; &lt;?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;aside&gt; &lt;div id="sidebar"&gt; &lt;ul&gt; &lt;?php //dynamic_sidebar( 'frontpage' ); ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/aside&gt; &lt;?php get_footer(); ?&gt; </code>
I found he answer. The problem was that my URL looked like this: <code> www.mysite.com/wp-category/ </code> . This was wrong. The right way was this: <code> www.mysite.com/category/wp-category/ </code> . Now it works. I thought that since I was using the following permalink: <code> /%category%/%postname%/ </code> , did not need the extra <code> /category/ </code> in my URL. But now I know.
Having problems with paging
wordpress