INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Category page showing posts from all categories I am trying to set up a category archive (editing category.php) that displays a list of posts from one single category. If I left the twentyten default code (get_template_part( 'loop', 'category' );) and i go to www.mysite.com/categoryname it correctly filters the posts only for the categoryname. If I try to use my custom query code, going to www.mysite.com/categoryname every post is displayed, despite of category. This is the loop code: <?php if (have_posts()) : ?> <?php $args = array( 'post_type' => 'post', 'posts_per_page' => 5, 'orderby' => comment_count, ); query_posts($args); while (have_posts()) : the_post();?> MY CUSTOM CONTENT <?php endwhile; ?> <?php else : ?> <?php endif; ?> thanks
That happens because you are overwriting the query with you $args, If you want to modify it and not overwrite it then use this format: //get the $query_string in to your $args array global $query_string; parse_str( $query_string, $args ); //modify whatever you want $args['post_type'] = 'post'; $args['posts_per_page'] = 5; $args['orderby'] = 'comment_count'; query_posts($args);
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "categories, pages" }
get_option() filtering and getting out of recursion `get_option()` provides couple of filters `'pre_option_'.$option` and `'option_'.$option`. However most times I tried to make use of these it usually explodes and not worth the trouble - either I need to check another option inside my filter, which triggers my filter, which triggers my filter... Another common case is that I need to get current option that I am filtering and I cannot do that because I am filtering it. Just curious - is there some practical logic to follow here? I know I could juggle my filter, but that is overhead that I don't like and filter removal is considered not too reliable by some. ;) For recent practical example - I want to filter `posts_per_rss` to my option, but provide WordPress value if my option is not set (for the record I know that recommended way to mess with it is via `post_limits`).
Usually I remove the filter, then add it back on afterwards; function _my_custom_option( $option ) { remove_filter( 'pre_option_name', '_my_custom_option' ); // do what you like with $option add_filter( 'pre_option_name', '_my_custom_option' ); return $option; } add_filter( 'pre_option_name', '_my_custom_option' );
stackexchange-wordpress
{ "answer_score": 10, "question_score": 4, "tags": "filters, options" }
Toggle nested comments I am trying to find a solution to toggle (hide/show) threaded comments. I need to see only comments 1,2,3 etc... and hide 1.1,1.2,1.3 etc... Clicking "show comments" will toggle and display the thread of comments. example: 1 --- \-----clicking "show more comments" shows \----- 1.1 \----- 1.2 \----- 1.3 \----- ... 2 --- \-----clicking "show more comments" shows \----- 2.1 \----- 2.2 \----- 2.3 \----- ...
< I used an ordered list to markup the comments. You probably need to tweak it to your own setup, and cache some variables for optimization, but the functionality is in there. $(document).ready(function() { // Toggle all $('#toggle-all').click(function() { var $subcomments = $('#comments').find('> li > ol'); if ($subcomments.filter(':hidden').length) { $subcomments.slideDown(); } else { $subcomments.slideUp(); } }); // Add buttons to threaded comments $('#comments').find('> li > ol') .before('<button class="toggle">Show more comments</button>'); // Toggle one section $('#comments').find('button.toggle').click(function() { $(this).next('ol').slideToggle(); }); }); I misread your question at first, that's why I added a "toggle all" button and left it in there as a free bonus.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "comments, jquery, threading" }
Delete some text and change html tag with Jquery Im looking a way to change the following HTML: <div class="votes">Rating: <strong>+5</strong> (from 5 votes)</div> and produce: <div class="votes"><div class="calculated-rating">+5</div></div> Thanks in advance.
<script type="text/javascript"> jQuery(document).ready(function(){ jQuery('.votes').each(function(){ votes = jQuery('strong',this).html(); jQuery(this).html('<div class="calculated-rating">'+votes+'</div>'); }); }); </script>
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "jquery" }
mod-rewrite exception? keep #hash in matching urls? Hey guys, My WordPress permalink structure is set to `/%postname%/. When I create a page with a name "FAQs" the permalink generated is "mydomain.com/faqs". When I link to this page in my code (hardcoded) like this... `<a href="<?php bloginfo('home'); ?>/faqs#b" title="FAQ's">FAQs</a>` (pay attention to the #b hash at the end) ...wordpress somehow automatically notices that there is a page `/faqs` and replaces `/faqs#b` just with `/faqs` (without the hash). Is there a chance I can write a kind of exception to my .htaccess file so WordPress doesn't do that? Any idea how I could make that work?
If your permalink structure is `/%postname%/` with a trailing slash, you need to pass the hash like this: `/faqs/#b` with the trailing slash.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "permalinks, url rewriting, urls, htaccess, mod rewrite" }
What's the .php file which generates the Custom Background page in the admin panel? What's the `.php` file which generates the `Appereance->Custom Background` page in Wordpress' admin panel? !enter image description here
`wp-admin/custom-background.php`
stackexchange-wordpress
{ "answer_score": 3, "question_score": -1, "tags": "php, wp admin" }
WordPress failure when logging out I have came across the WordPress logout error several times but I really never figured out the cause of it. In earlier days, it was generally that I was missing a nonce but now even with logout link generated by `wp_logout_url();`, I am greeted with the WP die screen: You are attempting to log out of SITE Do you really want to log out? What causes this to trigger at the first place? **Edit:** Like I mentioned it was happening randomly, I think I figured out something. IT works fine with link generated by `wp_logout_url();` but as soon as I use a `$redirect` parameter in `wp_logout_url( $redirect );`, I start facing the issue. Any light on the matter?
This message is raised by `wp_nonce_ays()` which is called by `check_admin_referer()`. Your browser has probably not sent a referer header, so WordPress could not validate the nonce. This may be a problem in your browser settings or your network connection.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "logout, nonce" }
Best way to arrange custom post types by Attributes -> Order metabox value? I have my front page setup to display a custom post type via: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() && false == $query->query_vars['suppress_filters'] ) $query->set( 'post_type', array( 'jwf_portfolio', 'attachment' ) ); $query->set( 'order', 'menu_order' ); return $query; } What's the most efficient way to have these ordered by the number value in the Order input in the Attributes metabox for each custom post? Currently I'm trying <?php query_posts( $query_string . '&orderby=menu_order' ); ?> <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> on my `index.php` and that's not cutting it.
This did it: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() && false == $query->query_vars['suppress_filters'] ) $query->set( 'post_type', array( 'jwf_portfolio', 'attachment' ) ); $query->set('orderby', 'menu_order'); $query->set('order', 'ASC'); return $query; } No need to mess with `index.php` now.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "custom post types, metabox, page attributes" }
How to rename 'Tag Base' with WPeC 3.8? In Wordpress>Settings>Permalinks there is an option at the bottom of the page to change the 'Tag Base'. I've entered 'testtag' in this option and saved, but my tag pages are still displaying as 'tagged' (eg www.example.com/tagged/tagcategory). wpsc-functions.php in the wp-ecommerce>wpsc-core folder... on line 319 'tagged' can be renamed which will change the URL's generated by things like the tag cloud, which in part solves the problem - but when you click on and request those new URL's it generates a 404 error. Does anyone have any ideas please on how I can rename this. I'm using WP 3.1 and Wordpress E-commerce Plugin 3.8. I've got a test site on www.chainsawdr.com. An example of a tag URL can be found by clicking a link in the tag cloud. Any tips or advice would be greatly appreciated. Thanks for reading ChainsawDR.com
Tags are a custom taxonomy called `product_tag` in WPEC 3.8+, they're not the same taxonomy as default WordPress tags so that's why tagbase has no effect. Line 315 in wpsc-core/wpsc-functions.php: register_taxonomy( 'product_tag', 'wpsc-product', array( 'hierarchical' => false, 'labels' => $labels, 'rewrite' => array( 'slug' => '/' . sanitize_title_with_dashes( _x( 'tagged', 'slug, part of url', 'wpsc' ) ), 'with_front' => false ) ) ); *Edit- I somehow skipped over the part of your question where you point out the above, however, changing the slug in this file and then flushing your rewrite rules WILL change the slug, but you're editing core files which is always bad. The question I suppose should then be "Is it possible to override something set elsewhere in a `register_taxonomy` call?"
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "permalinks, url rewriting, tags" }
How to echo tag description on loop-page.php using WPeC 3.8 I'm trying to display the 'Tag Description' on my tagged pages. I've added an if statement to loop-page.php already to only show custom text when a tagged page is being displayed... <?php } elseif ( is_tax ( 'product_tag' ) ){ ?><h1 class="entry-title"><?php the_title(); ?> print out this text on page</h1> ... but I don't know the code to output the tag description. Does anyone know the code to display the tag description? I want it to go after the H1 in the above code. I'm trying to output the description that is entered when you go into Wordpress Admin>Products>Product Tags>Description using WPeC 3.8. I'm using the Twenty10 theme, WPec 3.8 and WP 3.1 Thanks for your help ChainsawDR
get the term by its slug and echo out the descriptions elseif {is_tax ( 'product_tag' ) ){ $term_slug = get_query_var( 'term' ); $taxonomyName = get_query_var( 'taxonomy' ); $current_term = get_term_by( 'slug', $term_slug, $taxonomyName ); ?><h1 class="entry-title"><?php echo $current_term->description; ?></h1> <?php }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "tags" }
Accept a-z and 0-9 (restrict a-z to be lowercase without accents like ñ or ó) Using JQuery: While the user types, Im trying to find a way to restrict a field to only accept a-z and 0-9, restricting a-z be lowercase without accents like ñ or ó. <input type="text" value="" id="signup_username" name="signup_username"> Thanks in advance.
Jquery is my favorite js library anything you can think of already has a plugin, in your case check out **jQuery AlphaNumeric** <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "jquery" }
Posts cloud - Anyone? Okay... I turned every stone on the internet and I couldn't find plugin that I need. I want to have a dedicated page for each tag. When I click on a tag I want to get a page with "posts cloud" - all posts tagged with that tag. Post font should be proportional to "popularity" of a post... Is there such thing on earth?
Take a look at CloudClutter theme and see how its done <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin recommendation" }
Do not hyperlink menu heading How do I make a menu entry that's just plain text, not a link? My kludge workaround is linking to "/", but I'd prefer no link at all.
If this is for a dynamic menu you can use a 'Custom Links' and use a # for the URL then click add to menu. Once it's in the menu, remove the # from the URL in the menu and save the menu. It'll then be a text only no link item. (you can then add sub menu's that are linked) which is what I use this method for.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "menus" }
Best way of adding CSS which can be manipulated by the user via theme option panels? I thought about adding it as inline CSS with code from the `functions.php` (not really sure how to do it). Something like this: function addcss() { background: $this_is_the_css_value; } I would like to know that. But if there's is a better option (without adding inline CSS). I would like to know it too.
One way of doing this would be to create a "CSS" file from PHP. In other words, create a file, call it something like `style.css.php`, and at the beginning of the file put: <?php header("Content-type: text/css"); Then, link that file in the head of your theme file. Because the `style.css.php` file is a PHP file, anything you can do in a normal PHP file can be done in this file. As such, you can pull theme option values from the database and use them. For example: #header{ background: <?php echo get_option('my-header-background-color'); ?> } Of course, you need to get the options into the database first, but since your question didn't address that, I won't go into it here.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "php, functions, css" }
ignore_sticky_posts in WordPress 3.0.3? I am using WP 3.0.3 and I would like to exclude sticky posts from my query: This doesn't seem to work: <?php query_posts( 'posts_per_page=9&cat=-1,-2&ignore_sticky_posts=1' );?> To get JUST the sticky post I use the following: $sticky = get_option('sticky_posts'); $args = array( 'posts_per_page' => 1, 'post__in' => $sticky ); query_posts($args);
`ignore_sticky_posts` was introduced in WordPress 3.1. Before this version, you can use `caller_get_posts`, which will have the same effect (this option was used when you queried the posts via `get_posts()`, which uses the same `WP_Query` class in the background, but should ignore sticky posts). The name was a bit confusing, and thus changed in 3.1.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "sticky post" }
Show nav link highlighted OK so i have a main menu and a sub-menu How can i make a menu item active when viewing a single post. The sub-menu uses taxonomies so i know i need to make the taxonomy active when one of the posts has the taxonomy in use
So i ended up doing some jquery and lots of it. The downside is that i have to add the code each time i create a new menu. I am looking into re-creating this but do not want to bother with it right now. This is the link to the solution. It is very very temporary so if you wish to use it go ahead but there are better ways. You may be able to hook into the wp_nav_menu classes and add a active class to the current active item and then use some jquery to finish it off.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom taxonomy, navigation" }
Extend the wp_get_archives output with '?post_type=foo'? I've gotten my custom post types to display as it should in date based archives; the structure example.com/year/month/day (and above) works properly as long as it's extended with '?post_type=post_type_name'. With Bainternets solution I've also gotten wp_get_archives to properly list archives based on whether or not they contain my CPT. The problem is that wp_get_archives still returns the default archive permalinks, like this: > example.com/year/month/day but as I mentioned earlier, I need: > example.com/year/month/day?post_type=post_type_name Any suggestions on how to achieve this?
_From comment:_ Use the plugin Custom Post Type Archives. It is slightly more flexible than the argument `'has_archive' => TRUE` for `register_post_type()`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "custom post types, permalinks, customization, wp get archives" }
How to update WordPress from the latest trunk I read somewhere that I can set a constant in the wp-config.php to update WordPress from the latest trunk version and not the stable version. Stupid as I am, I can't find the site anymore where it was written. I know I could also update with SVN, but I thought the autoupdater was a smarter version.
< Sets you up for the nightlies, if that is what you are looking for. I've got it running on my dev install @ cdn.rvoodoo.com. Works great there
stackexchange-wordpress
{ "answer_score": 7, "question_score": 2, "tags": "wp config, automatic updates" }
Where is it better to start learning how to develop for Wordpress? I have already read this question and answer to it ( Where do I start from ). So I have slightly different question. If I basicaly have no knowledge of how the WordPress code is structured and I have some ideas for plugin I would like to write should I start at the same place where author of the answer sugested in the post linked above or there is some other path? Thanks to all who will contribute to this question. P.S. I have more than 3.5 years of experience with PHP and other web technologies.
The book Digging into WordPress is a good start. I bought this myself. I found it to be full of useful resources. If you want plugin development then Professional WordPress Plugin Development is a great book. Another book I bought and I used it to develop my first plugin. Other places to keep visit are Wordpress Codex WordPress StackExchange and the chat room
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "plugin development" }
Email friend for each Custom Post Type posts on a page I have a Custom Post Type called 'Property'. I display a list of CPT properties on a page: 10 per page with pagination. I would like to add an "Email friend" link to every property on the list, so a user can email that property url to multiple email addresses easily. Is there a plugin that can do this? Otherwise, what's the best approach for to do it? Many thanks, Dasha
I ended up using a simple "mailto" link. Not sure this is the best approach for this question, but it seems to work. If someone knows a better solution (ideally plugin or code) please feel free to add it. Thanks, Dasha
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, email" }
Already have htaccess but permalink settings not working. Getting 404 I have a .htaccess file <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> the config for the vhost looks like <VirtualHost *:80> ServerName elements DocumentRoot /works/web/elements <Directory /works/web/elements> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from 127.0.0.1 </Directory> </VirtualHost> But I am still getting 404 when I view pages, why is that?
The problem was not having mod_rewrite enabled ... Resolved it through sudo a2enmod rewrite
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "permalinks, mod rewrite" }
Make menu items open in new tab/page How do I make menu items open in a new tab/page instead of replacing the current page?
* Go to Appearance > Menu * click screen options (near top of page) * tick "Link target" Now, when you click a menu item drop down, you can choose what the link target is (you want to choose New window or tab)
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "menus" }
Adding existing links to custom navigation menus? When I visit _Appearance → Menu_ , I can add custom links, but not any links I've already created under _Links_. How can I do this?
You can't add link/blogroll type items to the main navigation - add them as custom links instead. [Update] To be more precise, you _could_ do it, but you would need to write some code that hooked into the menu creation/editing section, present a list of blogroll links in a metabox, allowed you to choose from them, and then added these links to your menu. Seems easier to just add the ones you want as custom links.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "menus, links" }
How to fix broken admin Thickbox? I have an installation of wordpress with the core wordpress files in a sub-directory as described here: < I've also changed wp-content to just content and moved it outside the wordpress core directory. Everything works fine except the media upload dialog does not load via Thickbox. It will load in the browser window and functions fine. So it seems it's just Thickbox that is not working. Any ideas on what I may have missed, or how to correct this problem?
**Update:** I fixed the issue myself. The problem was resulting from where I had removed jQuery output from the front end of my site (using my own version) improperly. It was not an issue with Wordpress itself. The function I was using to unset it removed it from the admin as well. I hadn't realized that some of the hooks that can be accessed in the functions.php file can affect the admin as well as the front-end.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "admin, thickbox" }
Can a plugin deactivate and delete itself once installed and activated? I have a unique plugin whose purpose is to set up a new WordPress site with a theme, default widgets, default plugins, custom menus, pages, posts, etc. The plugin does everything it needs to do when activated and never runs again. I'm looking for suggestions on how I might, as the last step in the activation routine, deactivate and delete the plugin. Any help, suggestions, or example references appreciated.
You can deactivate it with: deactivate_plugins( basename( __FILE__ ) ); I don't think you can delete it. It would be a big security risk, IMO. But if the folder has the correct (but insecure) permissions, you could use the PHP function rmdir
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugins, customization" }
Creating separate feeds for custom post types My site has a few custom post types, news, events, you-tube, etc. I'd like to create an rss feed for each post type as well as a main with all. I've experimented an bit and found how to combine them into one but I haven't determined how to segment each. Do I need to create separate feed-rss.php for the templates as well as a custom function? This is the function I'm currently using to combine them into one feed. //Custom post feeds function myfeed_request($qv) { if (isset($qv['feed']) && !isset($qv['post_type'])) $qv['post_type'] = array('post', 'youtube', 'event', 'news' ); return $qv; } add_filter('request', 'myfeed_request');
Look at this: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, posts, templates, rss, feed" }
Widgets with groups / sub widgets? Widget in a widget? I tried to find anything about adding a widget within a widget area. That widget should be a widget group / sub widget area. **I've found a plugin that does this:** * < * < **What I really want is to dynamically create something like this without the help from plugins:** * < Any bright ideas?
if you take a look at **Tabber Tabs Widget** plugin does it you will see that it creates a widget and a new "sidebar", now if you place widgets in that sidebar they will show only where you place the plugins widget. and if you look at what **Tabbed Widgets** plugin does, it creates a widgets that pulls a list of all registered widgets in to a dropdown and lets you choose which ones you want. both seem like nice ways to achieve that , depends on what you need.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "theme development, widgets" }
Is it possible for two WordPress plugins to share the same code base? So I have written my first WordPress plugin for production and in the next few days I will be starting up on another project where I might have to write two plugins for the same WP site because they do two distinct set of tasks. Now I was reviewing some of the code I had written for the first plugin I thought it would be great if the two plugins could share some of that code that I had written for the first plugin from my earlier project. At first I thought maybe I should just write one plugin that does it all but after some pondering I've come to the conclusion that I wanted my plugins to be small and do few tasks rather than having a bloated plugin that does too much. It would be hard to maintain later. So I was wondering if anyone has ever written a code base for that multiple plugins can share and how you accomplished this. Any relevant links would be appreciated.
Yes, you can easily set up plugins that share a code base. If you make use of global variables and constants, you will be able to read data stored in one plugin by the other. Also, remember that any function registered in one plugin, will be available to all other plugins (unless they're private class functions), as long as the plugin with the function is active.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, code" }
Can I specify that custom.css gets loaded at Appearance > Editor instead of style.css? I want to specify which css file gets loaded when the user clicks on "Appearance > Editor". However, its always loading style.css for some reason. Any way to enforce that a specific file gets loaded there?
This seems to be controlled by global `$file` variable, which is filled from request (GET or POST) by WordPress. So you will need to pass file you want in request or hook somewhere and override value of the variable. If latter be careful that you don't lock editing to single file altogether. See source for details.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "theme development" }
Pagenavi Plugin and Custom Post Type - Multipage results I having trouble with the results, the url and the pagination shows correctly, but when I'm on page 2 or 3 etc... there only show the results from the first page. this is my code. <?php $portfolioloop = new WP_Query( array( 'post_type' => 'portfolio', 'posts_per_page' => 12 ) ); ?> <?php while ( $portfolioloop->have_posts() ) : $portfolioloop->the_post(); ?> Code for the loop here <?php endwhile; // end of the loop. ?> <?php if (function_exists('wp_pagenavi')) { wp_pagenavi( array( 'query' => $portfolioloop ) ); } ?> WP Page Navi - Versión 2.74 Permalink structure - "/%postname%/"
you are quering the same posts over and over, and that is way you are getting the same posts, to fix it just add `'paged' => get_query_var('paged')` to your query arguments, so change: <?php $portfolioloop = new WP_Query( array( 'post_type' => 'portfolio', 'posts_per_page' => 12 ) ); ?> into: <?php $portfolioloop = new WP_Query( array( 'paged' => get_query_var('paged'), 'post_type' => 'portfolio', 'posts_per_page' => 12 ) ); ?> and just to make sure you are ok and to avoid errors add `wp_reset_postdata();` at the end of your code.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, pagination, plugin wp pagenavi" }
Multilingual WordPress plugins I've been using WPML to have multilanguage capabilities in my WordPress implementations. Now WPML has gone commercial, and I'm looking for a open source non-commercial replacement. My main concerns are: * It should be easy to use for the content administrator. * It should be fairly flexible. * It should let me decide the URL structure for each language (subdomain, folder, parameter, etc.) * It should perform relatively well (Specially the queries) * It should support all major WP features (eg: Custom post types, menus, widgets) I'm in the process of testing a few plugins, but I'd want to know if any of you have good advice.
I'd look into qTranslate. I haven't ever used it, but it's the only free alternative to WPML that I've ever seen. That being said, I'd suggest you just pony up the $30-80 for WPML. It's by far the best-maintained and cleanest multilingual plugin you can get and it's absolutely dirt cheap, considering what you get. And with their (very reasonable) pricing structure, what you're really paying for is DEDICATED SUPPORT. That's a pretty big deal in the open source world. Also, you're not looking for an open source replacement, you're looking for a free replacement. WPML is GPL licensed, so it's definitely open source.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 7, "tags": "plugin recommendation, multi language" }
Show scheduled posts in archive page I'd like my archive.php page's daily view (is_day) to display scheduled posts (post_status=future). For example, if I go to mysite.com/2011/05/20 I would see all posts scheduled to appear on May 20. The archive page's loop starts with: if ( have_posts() ) the_post(); and ends with: rewind_posts(); get_template_part( 'loop', 'archive' ); Do I need to make a second loop, or can I modify this single loop to show scheduled posts? If so, how? Thank you.
Keep things simple - leave your archive templates alone and place this in your `functions.php`; add_action( 'pre_get_posts', function ( $wp_query ) { global $wp_post_statuses; if ( ! empty( $wp_post_statuses['future'] ) && ! is_admin() && $wp_query->is_main_query() && ( $wp_query->is_date() || $wp_query->is_single() ) ) { $wp_post_statuses['future']->public = true; } }); Essentially, it says; > If we're on a date archive, or viewing a single post, make future posts publicly visible. As a result, WordPress behaves normally when you view archives for any given date, except now it also includes posts 'from the future'!.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 1, "tags": "loop, archives, post status" }
Load entire NextGEN gallery from single thumbnail? I'm using Alex Rabe's NextGEN Gallery in a lot of client sites as a centralized image repository, and am finding I often need to load an entire gallery into a lightbox (invoked via a single thumbnail), without displaying more than a single thumbnail on page. Thus, I could have a series of four thumbnails on a page, each thumbnail opening a different set of pictures in a lightbox when clicked. **Any idea how I could do this? Thanks.**
Output all images of each gallery in your HTML. Use an anchor tag that links to the fullsize image around each thumbnail. Depending on the lightbox plugin you prefer to use, group all images from the same gallery (often done using the `rel` attribute in HTML). At that point, just hide all but one thumbnail per gallery. Hook your lightbox plugin to the galleries. Check it out: <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "templates, ajax, gallery, plugin nextgen gallery" }
Show greetings on first time visitors? This seems pretty straightforward using cookies in straight HTML. In wordpress, how do I do this? AFAIK, wordpress only provides cookies functions for logging/logged in users. How about when I don't want the user to log in to show my greetings?
if you are not looking at coding it yourself then WP Greet Box(< could be used to achieve this. This plugin automatically loads a greeting message based on the referrer and it even allows you to customize the greetings, set time out to auto close the greeting etc. The only problem I see(from your question) is that this plugin greets all visitors not just new. If the visitor closes it, it won't be shown again. First time visitors based on cookies aren't reliable anyway, clear the cache and you become first time visitor again!
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "cookies" }
How do I check if I linked to a post before I delete it? If I want to "safely" delete a post. I want to make sure that no link exists (within my blog) to "to-be-deleted" post. How do I do that?
After reading this thread I saw that I might need this also sometimes. So here is the result: ### The internal link checker plugin It adds a meta box at your post edit screens that shows links to all posts who link internally to the currently displayed post. If you want to alter the output (add something for eg.), please use the provided filter. An example of how to use the filter can be found at the readme file. The Plugin is GPL2 licensed. Maybe I'll also put it in the official repo to allow installation from inside your self hosted blog. **Edit:** Done. * **Grab it for free over at github** ...or at... * **WordPress.org - Extend** ...or in our own * **WPSE Plugin Repository**
stackexchange-wordpress
{ "answer_score": 6, "question_score": 15, "tags": "posts, links, wpse plugin" }
Custom Post Types - Current section heading above the loop? On the site I am currently developing I have used custom post types for the different types of content it contains (News, Podcasts, Press Releases etc). How would I go about showing the label (plus a bit of text) for each section above the loop? For example: **Press Releases** Some text under the heading. * Press Release 1 * Press Release 2 * Press Release 3 * Press Release 4 * Press Release 5 Any idea how I would go about achieving this? Thanks!
If the template page in question is the archive index for the custom post type, you can simply create a custom template file, `archive-{post-type}.php`, and add in the Title and custom text. If you don't want to create a custom template file, you can use this boolean as a conditional in your existing `archive.php` template file, for creating custom output: <?php is_post_type_archive( $post_types ); ?> To retrieve the Title for a Post Type archive: <?php post_type_archive_title( $prefix, $display ); ?> To retrieve the current Post Type (for use in PHP): <?php get_post_type( $post ) ?> To retrieve all Post Type information (e.g. to output Title, Description, etc. if configured): <?php get_post_type_object(); ?>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom post types" }
I have a custom post type with many posts. How do I split the list into multiple pages? I have about 100 posts, and I want to create pages that only show 10 on each. How would I go about this?
You need to add the following query argument: `posts_per_page` global $query_string; query_posts( $query_string . '&posts_per_page=10' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types" }
Comment formatting with comment_content I'm displaying a comment outside the comment template, getting it with `get_comments()` and echoing the `comment_content`. My problem is that the comment loses the formatting (paragraphs, line breaks, etc...). In my template I'm using TinyMCEComments (TinyMCE on comment form). Someone pointed me to this solution, but is not working for me. <?php echo wpautop($comment->comment_content);?>
applying the 'the_content' filter could work: <?php echo apply_filters('the_content', $comment->comment_content); ?>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "formatting, comments" }
Style reply form different than comment form Is there a way to display (css and html) in a different way the "reply" form and the main "comment" form?
Well, it is the same form, but it is moved to another place in the DOM tree. So you could create one style for just `.comments #respond`, and one for `.comments .comment #respond` for the moved reply form.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 6, "tags": "html, forms, css, comments" }
How to fix this PHP warning in WP-Admin after upgrading to 3.1.2? I just upgraded from 3.0 to 3.1.2 and in the comments column under Posts in the WP Admin, this error keeps appearing for every row: > Warning: number_format() expects parameter 1 to be double, string given in /path/mysite/wp-includes/functions.php on line 155 Can someone tell me how to fix this?
The "Comments" column is not a default/core column in the "Posts" page. Perhaps it is being generated by your Disqus Plugin? Try temporarily disabling the Disqus Plugin, and see if the PHP notices go away. EDIT: actually, it _is_ a default column. But I still suspect Disqus is causing the PHP warning.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, customization, upgrade, warnings" }
Mega WordPress Applications WPMU or otherwise I'm a small-timer, so I was amazed at this question: Ideal WP multisite server setup for up to 1000 sites?. I know that WordPress is a highly flexible platform, but what types of entities/businesses would need or use this type of setup? In situations like this is there much redundant content? How do you begin designing something like this? Are there lessons in this for the small-timers?
Let's see how many use cases I can come up with in 20 seconds (grin) 1. School and university sites where every student gets a blog 2. Community sites (BuddyPress) where every member gets a blog (i.e. Dieting sites like SparkPeople.com) 3. News organizations where the many personalities get a blog (i.e. CBS, CNN, etc.) 4. Businesses trying to emulate the Etsy.com business model, where every site has a store plugin and paypal chained payments gateway 5. Businesses trying to emulate wordpress.com where free blogs are offered and upgrades are available for a fee 6. Businesses that create mini-sites for every affiliate product they promote, on an automated basis 7. Businesses that offer website hosting as a service - instead of a raw hosting account, subscribers get a multisite account pre-configured as a CMS for their business vertical, with access to support and features not available via wordpress.com
stackexchange-wordpress
{ "answer_score": 5, "question_score": 4, "tags": "multisite" }
Method to retrieve category names and IDs only as an array? I'm building a category picker select list. I just need to populate an array of categorys like so: $myCats = array("null" => "None (default)", "1" => "Uncategorized", "2" => "Second Category", etc..) Does WP have an existing method call I can use to pull this data alone? I may need to exclude some categories from the listing too.
Can't you use wp_dropdown_categories? wp_dropdown_categories('show_option_none=Select category&exclude=1,2,3&selected=6');
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "plugin development" }
Force all users in MU to change their passwords I'm looking for a solution to notify/force all users in an MU network to change their passwords. Any ideas of a solution out there as a plug-in?
You can use PassExpire force all users to change password at next login. Or set it to expires user passwords after 60 (Variable) days and requires a password change on login. Note: This is community wiki answer for this Question (as @tony-zeoli has already answered his own question).
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "password, reset" }
Creating an Archive using a Custom Taxonomy I recently adjusted the twentyten theme to display archives in a three column grid. In doing so, it seems that the archive has lost the ability to display posts from the specified taxonomy. For instance, a taxonomy type is 'Flowers', with a specific flower being 'Rose'. When the 'Rose' archive is displayed, it simply lists all posts. I believe I have narrowed the problem to this line: `query_posts('cat=0&posts_per_page=12&paged='.$paged);` I understand that it is just listing all 'uncategorized' posts, but I am at a loss with how to have display a specific taxonomy archive as would normally be done for a category archive. Any ideas? I am guessing it isn't as hard as I am making it, but I have searched for hours with no luck. Thanks in advance!
you can add the current term to you query so if its category, tag or custom taxonomy you will get the posts with the current term, try changing this: query_posts('cat=0&posts_per_page=12&paged='.$paged); with this: $term_slug = get_query_var( 'term' ); $taxonomyName = get_query_var( 'taxonomy' ); query_posts(array('posts_per_page' => 12, 'paged' => $paged, $taxonomyName => $term_slug));
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "custom taxonomy, customization, archives" }
Custom Field IF/ELSE PHP Ok so i am trying to use WordPress's custom fields and have them working but now i have some php code i need help with. <a href="<?php echo get_post_meta( $post->ID, '_ct_text_4dc9e9f74d000', true ); ?>">Go To Store!</a> The above code is what i have for right now. Is there a way to setup a if and else statement so if there is a value in the custom field then show that but else show N/A if there is no value present
You mean something like this? $customhref = get_post_meta( $post->ID, '_ct_text_4dc9e9f74d000', true ); if ( $customhref ) { ?> <a href="<?php echo $customhref; ?>">Go To Store!</a> <?php } else { echo 'N/A'; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "php, custom field" }
Is there a filter for editor-style.css file? I need to add multiple css files from a css framework to my editor-style.css file. The point is that i don't want to update the editor-style.css file anytime there's a new update from either my theme or the css framework. Is there a filter or hook **to add more than one stylesheet**? (I'm aware of `@import`, but didnt try to use it here.)
add_editor_style( $stylesheet ); <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "css, editor, wysiwyg, add editor style" }
My custom posts that are assigned to categories, are not called on a category search using a Category Menu I used the Custom Post UI plugin to create a custom post type called 'business_sold'. I assigned each custom post to one of six categories and an additional one called 'All'. I used a standard WP widgetized menu to list the 'Business Sold' categories, but my custom posts are not called on a search of any category. I can see that WP has recognized the category assignment. Single-business_sold.php is working fine, but neither category-business_sold or archive-business_sold are working. I cannot figure out what I'm doing wrong. Can anyone help me please?
Category archive by default it search for posts and not your custom type, you need to tell WordPress to search for your custom type, paste this code in your theme's functions.php file: function cpt_Search_category_Filter($query) { $post_type = array('post','business_sold'); if ($query->is_search || $query->is_category) { $query->set('post_type', $post_type); }; return $query; }; add_filter('pre_get_posts','cpt_Search_category_Filter'); and you should be fine.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types" }
Creating a podcast directory site - how to allow user to upload "large" files? I wish to create a podcast directory site. For which, I'd like the users of my site to be able to upload audio files which are "large" (e.g: more then 2 or 8 MB), and to make that upload "easily" go to the correct field in a relevant plugin (such as "podcasting") Any suggestions will be welcomed.
Just to add to what other have said, beyond changing your php.ini settings, upload size is limited mainly by the browser/connection. There are more reliable browser bases solutions that use java/flash or a combination of tech that allow for uploads reliably up to 100MB. 1. < 2. < 3. < 4. <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "uploads, user access, podcasting" }
Should I use wpdb prepare? I'm new to SQL and am wondering if I need to use `wpdb->prepare` for the following query to a table I've created global $wpdb; $tablename = $wpdb->prefix . "my_custom_table"; $sql = "SELECT * FROM " . $tablename . " ORDER BY date_created DESC"; $resulst = $wpdb->get_results( $sql , ARRAY_A ); Do I need to use `prepare` here? How would I do that? Cheers
It's best practice to always use `prepare` but the main use of it is to prevent against SQL injection attacks, and since there is no input from the users/visitors or they can't effect the query then that is not an issue in your current example. But like I said before it's best practice to use it and once you start using it you never stop, so in your example you can use it like so: global $wpdb; $tablename = $wpdb->prefix . "my_custom_table"; $sql = $wpdb->prepare( "SELECT * FROM %s ORDER BY date_created DESC",$tablename ); $results = $wpdb->get_results( $sql , ARRAY_A ); to read more about how to use it head to **the codex**
stackexchange-wordpress
{ "answer_score": 45, "question_score": 36, "tags": "plugin development, mysql, wpdb" }
Can I run a second wordpress site as a subdomain without using multisite? I have an two wordpress sites that I would like to host on the same domain. One is already up and running, the other is sitting in waiting. Can I get the second as a subdomain, or simple within a folder, to run on the same domain (different DB) without converting to multisite?
Point the subdomain to the same directory as the main site, and define different settings in your **wp-config.php** per `$_SERVER['HTTP_HOST']`: Example from my local setup: switch ( $_SERVER['HTTP_HOST'] ) { case 'zzl.dev': $table_prefix = 'zzl_'; $table_name = 'zzl'; break; case 'wpbuch.dev': $table_prefix = 'wpbuch_'; $table_name = 'wpbuch'; break; default: $table_prefix = 'wp_'; $table_name = 'wpdev'; break; } $sub = '/wp-content/' . $_SERVER['HTTP_HOST']; const WP_CONTENT_DIR = __DIR__ . $sub; const WP_CONTENT_URL = ' . $_SERVER['HTTP_HOST'] . $sub; const DB_NAME = $table_name; You can change much more variables in the switch: all `DB_*` definitions, `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` (to share the plugin list between different sites), `WPLANG` and so on.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 1, "tags": "multisite" }
Post Type Description for 'Posts' On the site I'm currently developing I am using 'Custom Post Type UI' to manage my custom post types. Within this I can manage the description for any of the new custom post types that I have created. How would I go about editing the description of the default 'posts' post type? I am outputting this description under the heading in each section. Thanks!
you can use `global $wp_post_types` to edit the description for example: add_action('init' , 'edit_post_description'); function edit_post_description(){ global $wp_post_types; $wp_post_types['post'] ->description = 'type your description here...'; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom post types" }
Rename "post" to "article" throughout the admin back end > **Possible Duplicate:** > Is there a way to change 'Posts' to be 'Portfolio' is the WP backend? Is there a way to accomplish this by the functions.php file ? I tried: add_filter( 'gettext', 'change_post_to_article' ); add_filter( 'ngettext', 'change_post_to_article' ); function change_post_to_article( $translated ) { $translated = str_ireplace( 'Post', 'Article', $translated ); return $translated; } but it does not change all the entries for "post". I still have "Post tags" for example. Any suggestion?
This is essentially a duplicate of this question: How to rename default posts-type Posts
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts" }
Using underscores instead of hyphens in the permalink What's the best way to ensure that post and page slugs use underscores instead of hyphens, without needing to edit the slug manually (or updating the page manually) Current permalink: www.<domain>.com/2011/05/this-is-a-test-post/ Desired permalink www.<domain>.com/2011/05/this_is_a_test_post/ One approach I've tried is to hook into `sanitize_title`, but this seems to only be called when the post is updated, so not very practical for a blog of several thousand post. Is there any way to force each post to update? I need this to preserve compatibility as an old MovableType site is moved into WordPress - using .htaccess isn't really an option
IMO hooking into sanitize_title is probably the best way to go here. Check out this plugin by Mark Jaquith which does something similar: < As for updating the old posts, I would just write a simple script that would generate sql to manually update everything. (code not tested) <?php function sanitize_title_with_underscores( $title ) { return str_replace( '-', '_', sanitize_title_with_dashes( $title ) ); } $posts = get_posts( array( 'numberposts' => -1 ) ); foreach ( $posts as $post ) { global $wpdb; $id = absint( $post->ID ); $name = sanitize_title_with_underscores( $post->post_name ); print "\n" . "UPDATE $wpdb->posts SET post_name = '{$name}' WHERE ID = {$id};" } ?> Probably not the most elegant solution, but for something that only needs to be done once, it should work rather well.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 4, "tags": "permalinks" }
How do i edit the plugin files in DataBase via phpMyAdmin? I need guidance to edit the WordPress plugin and theme files via phpmyadmin If I want to edit a particular plugin file or remove a plugin completely from database, I could able to find them ,but I can able to find the data tables for options , comments, links etc. I don't know how to edit/remove a particular plugin or theme there. Could anybody let me know how to find a particular plugin or the entire ' plugins ' folder in data base? Thank you!
Plugins and themes are no in the database, they are physical files under wp-content directory, and that is why you CAN'T find them in the database nor edit them from phpmyadmin. However WordPress has a built in editor for plugins and themes files. For themes its under appearances -> editor and for plugins its under plugins-> editor.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "plugins, database, phpmyadmin" }
Exclude current post but keep the same posts-per_page amount Okay I have a custom loop within the main loop of the page that shows 4 posts but obviously excludes the current main post. I'll show you: <?php $my_query = new WP_Query( "cat=3&posts_per_page=4" ); if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post(); if($post->ID == $mainPost) continue; ?> <?php get_template_part('workThumb'); ?> <?php endwhile; endif; wp_reset_postdata(); ?> However I want to show 4 posts in this loop but obviously if it contains the current post then it only shows 3. However if I increase the posts_per_page to 5 then on pages when it doesn't include the current post it shows 5 posts, which I don't want. I hope this makes sense. Any ideas?
change your query to: <?php $my_query = new WP_Query( array("cat" => 3, "posts_per_page" => 4, "post__not_in" => array($mainPost))); <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization, loop" }
Wordpress Rotating Background Images I would like to be able to create a rotating background image that resizes with the browser window. I would like to also be able to set a certain amount of images to rotate per page or at the least start at a random number. Here is an example > < Is there a plugin for this? I am assuming it's Jquery. Thanks.
You can use CSS3 `background-size` to make your background-images stretch to cover the area of the box. If you then create a containing box positioned absolutely over the whole page, you can put your slides in there. At that point it is just a matter of fading them in and out, something which can be easily done via a jQuery plugin like Cycle. **Here's an example:< As you can see all you need to do to add slides is create a new child `div` for `#slideshow`. In WordPress this can be done by looping over your gallery images. Related reading: * Supersized – Full Screen Background/Slideshow jQuery Plugin * Advanced jQuery background image slideshow
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "jquery, images" }
Posts URL structure like site.com/category/the-post-title I'm new with `wordpress` and I would like to understand better if it's possible to create pages with an url based on the `category` and then the `post title`, so: something like ` or ` (the post id) or ` does exist some plug-in do this or should I consider other ways like `url_rewrite` to do this?
Yes, any of those are possible and configurable under `Settings > Permalinks`. Have a look at the Permalinks page for other possibilities. One thing to note though, it's suggested to add a number at the beginning of your permalinks to reduce the number of rewrite rules WordPress has to generate to resolve all of your URLs. The permalink strings for your examples would be: /%category%/%postname% /%category%/%post_id% /%category%/%post_id%/%postname%
stackexchange-wordpress
{ "answer_score": 12, "question_score": 8, "tags": "categories, url rewriting, urls, plugins url" }
Count the posts number for every category I'd like to count the number of posts created for every category, so: 12 Works (12 posts in works category) 36 Pictures (36 posts in pictures category) 17 Furnitures (17 posts in furnitures category) How can I do that?
You can use wp_list_categories() function and set show_count to 1 (true) <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "categories, sort" }
Why is my custom sidebar always open on the widgets screen in Admin? I've created a custom sidebar with this code in my theme's functions.php: register_sidebar(array( 'name' => __('Article - Below Content'), 'id' => 'zg-article-footer', 'description' => 'Use this sidebar to place widgets that will appear directly underneath the Article' )); When I navigate to Appearance > Widgets in my Admin, this sidebar is always the first one on the top of my list of sidebars, and it's always "open" (that is, you can see the description and the list of widgets attached to it). None of my other sidebars are open, and WP Admin doesn't seem to remember my last-opened sidebar. Is there an argument I should use when registering the sidebar that will tell it to default to closed? Or is there an option somewhere else entirely?
This is default behavior. I believe that sidebars are listed by ID in `Dashboard -> Appearance -> Widgets`, and that the sidebar with ID `0` is always open in the default view.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "sidebar, register sidebar" }
Debugging / displaying errors in WP_Widget->form() I'm finding that if I have errors in my code that's being called by my custom widget's form() method, I don't see any error display - the only indication I have is that in Admin > Appearance > Widgets the sidebars are all gone. What can be done to: a) avoid completely destroying all sidebars in Admin whenever your code has an error b) get more information about what is causing the error or exception?
Since the question was asked in May, the WP core team released the Admin Debug Bar, and its ancillary plugin Debug Bar Console is exactly the balm to ease any WP Programmer's pain.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "widgets, errors" }
how to show the syntax of a shortcode I want to show the syntax in some posts about how to run a shortcode. I mean, something like this [myshortcode] but without running it, is that possible?
If you use double brackets, WordPress will not execute the shortcode but just display it with single brackets. So `[[gallery]]` becomes _[gallery]_ in your post.
stackexchange-wordpress
{ "answer_score": 24, "question_score": 11, "tags": "shortcode" }
How to query custom post types with multiple keys? I recently upgraded WordPress from 3.0.x to 3.1.2. I had set it up to use custom post types before the upgrade. I need make a list of events that are occurring that started in the past until they occur. For example, if an event started today at Noon, it should show up in this list until it ends, which could be tomorrow at 6:00 PM. Can someone tell me how to modify this query so it will get custom posts that occur between the start and end date (multiple keys)? $args = array ('post_type' => 'events', 'meta_key' => 'end_date_value', 'meta_compare' => '>', 'meta_value' => $current_time, 'orderby' => 'meta_value', 'order' => 'ASC' );
Here is example from Codex on using `BETWEEN` with new format of meta query, which covers multiple fields as well: $args = array( 'post_type' => 'product', 'meta_query' => array( array( 'key' => 'color', 'value' => 'blue', 'compare' => 'NOT LIKE' ), array( 'key' => 'price', 'value' => array( 20, 100 ), 'type' => 'numeric', 'compare' => 'BETWEEN' ) ) ); $query = new WP_Query( $args ); See Custom Field Parameters for details.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, get posts" }
removing the list container <ul> from the custom menu output any suggestions on how to get rid of **_ul_** tag wrapped around **_li_** tags in custom menu here at < the custom menu is outputted with nested tags around like <ul id="menu-home" class="navLeft"><li><a href=" <li><a href=" </ul> I am trying to take out the tags and already passed the container => false parameter before outputting custom menu as mentioned at wordpress codex, below is code again. $args = array( 'menu' => 'home_menu', // 'sort_column' => '', 'container' => 'false', //'container_id'=>'myID', 'menu_class' => 'navLeft', 'walker' => new my_walker() ); wp_nav_menu( $args );
The `container` argument controls what is one level higher - around `<ul>`. What you need is `items_wrap` argument that controls the list wrap and defaults to `<ul id="%1$s" class="%2$s">%3$s</ul>`. Removing the ul wrap in Codex gives following example: wp_nav_menu( array( 'items_wrap' => '%3$s' ) );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "menus" }
Disable Individual Plugins (specifically in Custom Post Types) on a per-post basis? The title pretty much says what I'm trying to accomplish, but more specifically I have a plugin that I made and it creates a custom post type, lets call them `newpages`. On these pages I have used `template_redirect` to take over the design of the pages, but some plugins appear, but I don't want to remove all of the plugins from loading, just a couple. So I was wondering if it's possible to use something like custom fields to disable certain plugins on a per-post basis. Can anybody point me in the right direction? Thanks!
I don't see why not. 1. Hook to `template_redirect` (you already did). 2. Conditionals should work at this point, so use `is_single()` / `is_singular()` / etc to check for what you need. 3. Use `remove_action()`/`remove_filter()` to unhook unwanted functionality.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, custom post types, plugin development" }
How to build a multi-taxonomy, multi-term query based on user input Thanks to Otto's excellent post on advanced taxonomy queries, I (mostly) understand how to create multi-taxonomy and multi-term queries. However, what I don't know is how to build those dynamically based on user input. I'd really like to end up with something like Amazon.com has on their site, with check boxes next to the various terms for a taxonomy in the sidebar (and multiple lists of terms, each with a taxonomy heading). Something like this: !Taxonomy with list of terms and check boxes to select those terms How should I go about building something like this? Displaying the content dynamically (content changes when a box is checked) would be great, but I'd certainly settle for having a "submit" button.
I am a little fuzzy on specifics of technical side, but I think general outline would be following: 1. **Interface** \- you will need to either submit this as form by button or JavaScript. 2. **Query variables** \- you will need to register custom variable(s) via `query_vars` filter so your custom data is not discarded from URL. 3. **Query** \- modify query to make complex query, using custom data submitted.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "multi taxonomy query" }
Get something out from taxonomy I like to use the new taxonomy to make a little CRM, really simple contact - name - tel - email - company Fine, the secretary will enter all the name in the database of the cms (WordPress), and i will have all those in, able to display it like a list or whatever i like 1) first question, do i reinvent the wheel, is it already done... Now, with all those nice contact... i have a page, or a list of really good product.. and all those contact can benefit to see it in there mail, much like a newsletter, but simpler... 2) question, how can i get all those email, and have wp to send the wp page/link to those email... plugin, code ? thanks in advance for the light on that
I used < a while back and have nice features for contact administration
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "taxonomy, email, export" }
W3 Total Cache Minify + cforms II = POST /wp-content/plugins/cforms/lib_ajax.php 500 (Internal Server Error) Enabling minify is causing cforms (ajax enabled forms) to produce the following error on submit, whereby it hangs: **POST dearearth.net/wp-content/plugins/cforms/lib_ajax.php 500 (Internal Server Error)** Current minify settings: < Form page: < Any suggestions on how to get past this (aside from disabling minify altogether)? Thanks!
I believe its a bug which is currently being attended to. Read the article below, which describes the current versions problems. W3 Total Cache Minify Bug Make sure that you've upgraded to the latest version in case its been resolved.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin w3 total cache" }
How do I add Login fields and registration link to the header? I want to have a login username and password field in the header, and a registration link beside it. I want the registration link to go away once the user is logged in and the login fields to be replace with a logout link. I have found these two snippets but they don't help me achieve what I want.
wp_login_form(); // Codex: // or: wp_loginout(); // Codex: if ( ! is_user_logged_in() ) // Codex: wp_register('', ''); // Codex:
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "login, user registration" }
Change page title in admin area Is there someway to change the title in wp-admin? Been looking all over google but no one seem to mention it. I simply want to get rid of "-- WordPress" and possibly change the "‹" into some other symbol. Any ideas?
add_filter('admin_title', 'my_admin_title', 10, 2); function my_admin_title($admin_title, $title) { return get_bloginfo('name').' &bull; '.$title; } You could also do a `str_replace` on `$admin_title` to remove "— WordPress" and change "‹". Look at the top of the `wp-admin/admin-header.php` file to see what is going on by default.
stackexchange-wordpress
{ "answer_score": 29, "question_score": 14, "tags": "wp admin, title" }
Podcast Guest List So what I want to do is too have a function similar to a category or tag, but a little more robust. It's **for a podcast** to _list of guests for each episode_. Ideally this would do a few things: ### Guest Data For _each_ guest (added to an episode), display their: * name, * photo, * twitter id, * url. ### Guest Page Clicking on their photo or name would the visitor to a page _like the authors page_ , where more info on that guest could be stored: * a short bio, * all the episodes that guest has appeared on, * etc... ### Meta Box on pod cast edit screen: The management of this would ideally be managed like categories are now, through checkboxes and names listed on the write page to select from. Further management, (adding bio, photos, ect) would be done in another panel like posts are. My first thought was custom post types or custom taxonomies, but I'm not sure which method is more feasible. Any ideas? Thanks.
So what I did was make a custom post type for guests profiles, and use "posts 2 posts" to connect them to specific episodes. The plugin has functions to both list the connected guests on episode pages, and list all episodes associated with that guest on their profile pages. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, custom taxonomy, podcasting" }
HelpDesk solution for Wordpress Is there a help desk solution plugin (free or paid) for Wordpress? Ideally a visitor would be able to create a ticket from the WP site and the admin would see it via email and in the admin portal of WP. Also offer the option for invoicing per ticket. **Edit:** The plugin has to play well with my theme without having to alter anything with the exception of adding shortcodes for the helpdesk
I have been looking at the WordPress Advanced Ticket System plugin. The free version has an admin interface to submit tickets but front end ticket submission requires the paid version.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, plugin recommendation" }
ShortCut on meta boxes There any way to run a shortcut that is in a meta box? I'm trying to execute the shortcut but does nothing, is that if the code comes from the wordpress editor does not have any problem
use `do_shortcode()` on your meta box content: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "metabox" }
What are allowedposttags and allowedtags? I have been going crazy trying to google up what these globals are. What are allowedposttags and allowedtags? What is the difference between the two? Is there a list of all WP Globals and an explanation of what they are? For MCE Editor - to allow users not logged in to use lists and underline + strikethrough add following: add_action('init', 'my_html_tags_code', 10); function my_html_tags_code() { global $allowedposttags, $allowedtags; //$allowedposttags["ol"] = array(); //$allowedposttags["ul"] = array(); $allowedtags["ol"] = array(); $allowedtags["ul"] = array(); $allowedtags["li"] = array(); $allowedtags["span"] = array( "style" => array() ); }
These are arrays that are used by the wp_kses library. Basically they are white lists of html tags and attributes that WordPress allows in posts and comments. If memory serves correctly, "allowedposttags" is used for sanitizing post_content while "allowedtags" is used for comments.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "tags" }
Complex widget form UI - examples and best practices I'm contemplating a widget with quite a number of options, which will make for a lengthy widget form. To improve the user experience with this form, I'd like to divide it into sections. I don't feel like re-inventing the wheel, so what are some examples of widgets that have fairly complex forms (especially those which are divided into multiple sections) **all the while remaining usable and easy to parse visually**? I should add that I'm looking for examples that could be considered "best practices", _not messy kitchen sink forms that are difficult to use_. I realize this is probably subjective. Thanks for your input!
How about native Thickbox with the native jQuery tabs for example: the widget it self is simple and only has a link !enter image description here but one you click on it the thickbox pops up and shows all of the options grouped by tabs: !enter image description here let me know what you think I'll fetch the code for you.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 5, "tags": "widgets, customization, forms, user interface" }
Specific css on homepage, different one for other pages Is there a way to have specific css on the homepage and use a different one for all the other pages?
Yes there is. You can add this to your themes header. <?php if(is_home()){ // we are on the home page echo '<link rel="stylesheet" src="your_stylesheet" />'; } ?> You can also use other conditional tags to find out if you are on nearly every type of WordPress page. Conditional Tags Following on from the comments below, this would be better used like this <?php if(is_home()){ // we are on the home page echo '<link rel="stylesheet" src="your_home_stylesheet" />'; }else { echo '<link rel="stylesheet" src="your_default_stylesheet" />'; } ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "css" }
How to Add Custom Fields to a Custom Post Type? Ok, so I have registered a few custom post types and a few taxonomies. Now, for the life of me, I cannot figure out the code I need to add a Custom Field to my Custom Post Type. I need a drop down and a single line text area. But I also need to have separate fields for post types. So, say post type one has 3 fields and post type 2 has 4 fields but the fields are different. Any tips would help I have looked at the codex and found something but cannot make sense of what I need to add to my `functions.php` file
This is probably more complicated than you think, I would look into using a framework: * < If you want to write your own , here are some decent tutorials: * < * < * <
stackexchange-wordpress
{ "answer_score": 23, "question_score": 30, "tags": "custom post types, custom taxonomy, custom field" }
How can I automatically duplicate a site's pages onto network site? Basically there are sub-sites that inherit all the pages. But I have worked out ways for each page to be unique to their location, by creating a shortcode that pulls in the Blog Description. The point is I am not trying to spam the web, but this site needs to reach different people in different towns. And I don't want to repeat all the content each time. I have installed threewp broadcast and multipost MU and tested them out, but when you add a site you have to go through each time you add each page to the new site. There are 50+ pages. Essentially I want to make sure the main site is right, then add a new site and have all the pages automatically added. I can go through and mess with the settings on each site to give it the right homepage and all that but adding the pages individually is a pain... ideas?
I think that is possible with the plugin WordPress MU Sitewide Tags: (< With that plugin you can republish content from all sites OR a selection and you can choose to publish it to the main site OR to a new subsite.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "multisite, automation" }
How can I de-register ALL styles all at once? And same with Javascript? How can I get all enqueued styles or scripts and then deregister them all at once?
I hope you know what you are doing. You can use the `wp_print_styles` and `wp_print_scripts` action hooks and then get the global `$wp_styles` and `$wp_scripts` object variables in their respective hooks. The "registered" attribute lists registered scripts and the "queue" attribute lists enqueued scripts on both of the above objects. An example code to empty the scripts and style queue. function pm_remove_all_scripts() { global $wp_scripts; $wp_scripts->queue = array(); } add_action('wp_print_scripts', 'pm_remove_all_scripts', 100); function pm_remove_all_styles() { global $wp_styles; $wp_styles->queue = array(); } add_action('wp_print_styles', 'pm_remove_all_styles', 100);
stackexchange-wordpress
{ "answer_score": 27, "question_score": 9, "tags": "wp enqueue script, wp enqueue style" }
How to disable or protect against disposable email accounts? Now im getting a couple of disposable email accounts in users table, how can I avoid this nasty situation?
You might need this plugin: <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "user registration" }
How to display a public profile page for registered users with custom slug? I have a website where users can register, login and their edit profile, they can comment but not post. What I am looking for is a way to display a user profile page (where I display the gravatar and the info about the user) clicking on the username. The url must be something like "www.mywebsite.com/user/username". I know about author.php, but I don't know how to link even if the user has no posts and is not an author. **UPDATE:** I managed to solve it. Instead of linking using `<?php the_author_posts_link(); ?>` I did an href linking to `www.mysite.com/user/<?php echo $user_info->display_name; ?>` To rename the slug I installed the Edit author slug plugin, it makes the author slug editable under Settings > permalinks. To customize the user profile, just edit authors.php as you like.
Every registered user can have profile, they don't need to have posts. To change Wordpress author's profile permalink, paste the following code in your functions.php: function change_author_permalink_base() { global $wp_rewrite; $wp_rewrite->author_base = "user"; } add_filter( 'init', 'change_author_permalink_base' ); After pasting the code, visit Settings->Permalink Structure under your wordpress admin, to flush the rewrite rules. This is a required step, otherwise you may get 404 on author profiles. Then code your author.php. As far as linking is concerned this is totally your design decision. If you want to link the profiles from user's comment, you can either add the new link or just link comment author name to their profile. Remember the profile is available only if the user is registered as Wordpress user.
stackexchange-wordpress
{ "answer_score": 11, "question_score": 7, "tags": "permalinks, users, author, profiles" }
How to get_term_children output in alphabetical order? How do i get output of this in alphabetical order <?php $termID = 5; $taxonomyName = 'area'; $termchildren = get_term_children( $termID, $taxonomyName ); echo '<ul>'; foreach ($termchildren as $child) { $term = get_term_by( 'id', $child, $taxonomyName ); echo '<li><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>'; } echo '</ul>'; ?>
`get_term_children()` only outputs the term IDs, and you later get details for each term using `get_term_by()`. You can combine these queries in one using `get_terms()` with the `child_of` argument: get_terms( $taxonomyName, array( 'child_of' => $termID ) ); By default this sorts by name. However, it is possible that the `child_of` argument undoes the sorting. In that case you can sort it again using `usort()`. See an example at this answer for a related problem.
stackexchange-wordpress
{ "answer_score": 16, "question_score": 7, "tags": "terms" }
Excluding Pages not working I was trying to set up a few pages the other day that would hold an authors information (only to be accessed from the author snippet at the bottom of posts), and obviously these pages are showing up in the `<?php wp_list_pages('title_li='); ?>` , I made sure of my page order (0-5 are the pages that must be there, and I set up the special pages to start with an id of 44 just in case they added some pages), and then tried `<?php wp_list_pages('title_li=&exclude=44'); ?>`. However, 0-5 show up, as well as 44. Any thoughts on why this is still occurring?
it sounds from your text that you are using the number you gave it under 'page attributes' 'order'; use the page ID instead for the 'exclude'.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, pages, list" }
Sort Custom Post Type Archive by Taxonomy Term What is the best method (as of 3.1 or 3.2 beta) to sort a custom post type archive by a given taxonomy term? I'm trying to make a staff page and I want to sort employees by department. So the taxonomy would be `staff` and the terms to sort would be `sales` and `support`. I tried `query_posts` and `WP_Query` but perhaps I messed up the arg array...
Good question - I'm fairly sure you can't do this just using wp_query. You'll need to either add a posts_groupby filter, or just query the database directly. This previous question and answer might be helpful Using wp_query is it possible to orderby taxonomy?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 5, "tags": "custom taxonomy, custom post type archives" }
Display last login time I am using this script to get the last time a user logged in function get_last_login($user_id) { $last_login = get_user_meta($user_id, 'last_login', true); echo human_time_diff($last_login) . " " . __('ago'); } I am calling it in author.php with `<p>Last login: <?php get_last_login($userdata->ID); ?></p>` I am trying to output like "last login X days ago" but I can't get it working. $last_login output is `2011-05-13 18:00:06` but the final output I get is `last login 15108 days ago`
Are you formatting the `mysql2date()` input string as `'Y-m-d H:i:s'`, as specified in the Codex? Also, why not use this same format as `$date_format`? EDIT: 1. What output do you get for `$last_login?` 2. The second argument in `human_time_diff()` is optional. Why not just omit it? That way, if you get valid output from `$last_login`, you should get valid output from `human_time_diff()`. EDIT: The `human_time_diff()` function expects a _UNIX timestamp_ for its first argument. Try wrapping `$last_login` in `mktime()`, e.g.: $last_login_unix = mktime( $last_login ); human_time_diff( $last_login_unix ); EDIT: Might want to use `strtotime()` instead of `mktime()`: $last_login_unix = strtotime( $last_login ); human_time_diff( $last_login_unix );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "login, date time" }
How to "orderby" the first array in a meta_query that uses multiply keys? My query is currently sorting by end date. How can I make it so it will sort by the start date? $args = array ('post_type' => 'events', 'meta_query' => array( array( 'key' => 'start_date', 'value' => $min_date, 'compare' => '>' ), array( 'key' => 'start_date', 'value' => $max_date, 'compare' => '<' ), array( 'key' => 'end_date', 'value' => $current_date, 'compare' => '>' ) ), 'orderby' => 'meta_value', 'order' => 'ASC' );
try adding: 'meta_key' => 'start_date'
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query, sort, meta query" }
What is the link to my default "archive" page? I'm using twentyten and have overloaded home.php to do some custom stuff. However, I would still like to have a page that lists all of my recent posts, archive-style. I can get to an archive page for any given category with myblog/category/category-name. But I'd like to get to an archive that just lists all recent posts, regardless of category. Like myblog/archive Am I assuming too much? I know I can create a custom page template and then create a custom page and apply that template. I just thought that wordpress had a built-in "archives" page, no?
No, there is no "full archive" page like you describe created by default. This would basically be the twentyten index page set to display "your latest posts." If you don't want to access the archives via some sort of filter (category, author, year, month etc.) then you will need to create your own archive template and page like you described above. you could also use the twentyten index.php as the basis for your new template. So you can create the archive page, set it to use your new template and use the url myblog/archive like you wanted.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 6, "tags": "templates, archives, links" }
Add class to navigation link of page On my Wordpress site I have a three level navigation. In the second level of every main navigation item is a "toolkit" page. I would like to highlight this page in the navigation. Is there anyway that I can add a class to a page, so that I could style its navigation link separately? Is there a plugin out there that would allow me to do this? I'm hoping it would be something like in the Page Editor screen is a custom field that allows me to input a class. The class is then generated when calling the WP_List_Pages function. Then with some simple CSS and can change the background of all those links. Thanks in advance.
You could also simply use css: `#menu-item-ID` (where "ID" is the unique ID of the page/post/category/whatever).
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "css, navigation" }
Hooks: admin_footer and admin_print_footer_scripts not working? Tried them both and they don't seem to be working, am I missing something? add_action('admin_footer', 'jupload_scripts'); wp_register_script('jquery-ui', ' array('jquery'), '1.8.6'); wp_enqueue_script( 'jquery-ui' ); }
As per Wordpress Codex its best to register and queue your scripts with the hook dedicated for them, even if you want your script to be added to footer. So the correct way of doing it will be: function jupload_scripts() { wp_enqueue_script( 'jquery-ui', ' array('jquery'), '1.8.6', true ); } add_action( 'admin_print_scripts', 'jupload_scripts' );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "wp admin, admin" }
Allow anonymous users to post to my site for moderation I'm in need of the ability to allow anyone (they don't have to login) to fill out a form with email and a textarea and submit it to my site. This form would be treated as a post and appear somewhere for me to moderate. If i hit publish, it would be published to my site like any other post i wrote. Is there a plugin that allows me to do this or do i need to code it myself, if the latter, how would i go about doing that? Thanks in advance!
This might work for you? <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "posts, users, moderation" }
Can't filter wp_get_attachment_link Can't figure out why this won't work: function my_get_attachment_link($html){ $postid = get_the_ID(); $html = str_replace('<a','<a rel="shadowbox['.$postid.']"',$html); return $html; } add_filter('wp_get_attachment_link','my_get_attachment_link',10,1); Just trying to hook up all the images on a single post view to a lightbox script. FYI, this didn't work either: < What could be jamming it up?
Your code only works if you are actually _calling`wp_get_attachment_link()` somewhere in your template_. If you're not calling the function, then the `apply_filters()` _inside the function_ will never get called, and therefore your code will have nothing into which to hook.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "functions, attachments, links, filters" }
Hook any php file into the wordpress api Say I just have a dumb .php file sitting on my WP server and I wanted it to access WP info through the API, how would I go about doing that? For example if I wanted to call bloginfo('url'); As I have scored myself a downvote (with no explanation) I will expound upon why I am interested in this. Sure I can access WP API from all the built-in pages. But let's say I have a page that has little to do with WP. Seems like a lot of overhead to create say a custom template page and then hook it into an actual post, all so that I can have access to a few WP API calls. I ended up using something like this: require $_SERVER['DOCUMENT_ROOT'].'/wp-blog-header.php';
You mean something like this? <?php require 'path/to/wordpress/wp-blog-header.php'; bloginfo('url'); ?>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "hooks, api" }
Create Child Taxonomies Is there a way to use the `register_taxonomy` function to create child taxonomies to a specific parent taxonomy in a hierarchical structure? For example: Let's say I'm creating a theme for selling cars where users can activate it and it automatically creates a hierarchical taxonomy called "Make". Is there any way to have it automatically create a few different vehicle "make" taxonomies, say Toyota, Lexus, etc.?
I think you mean you want to create terms in your taxonomy? Have a look at this answer for detecting when a theme is activated. Then use wp_insert_term to insert the terms into your taxonomy.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom taxonomy, taxonomy" }
How to add CSS Class to previous_post_link or get previous/next post link URL How can I add a CSS Class to the `previous_post_link` output or just get the URL and create the HTML markup myself
You can use the more native function that is "below" the `previous_/next_post_link();`: # get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) $next_post_obj = get_adjacent_post( '', '', false ); $next_post_ID = isset( $next_post_obj->ID ) ? $next_post_obj->ID : ''; $next_post_link = get_permalink( $next_post_ID ); $next_post_title = '&raquo;'; // equals "»" ?> <a href="<?php echo $next_post_link; ?>" rel="next" class="pagination pagination-link pagination-next"> <?php echo $next_post_title; ?> </a>
stackexchange-wordpress
{ "answer_score": 9, "question_score": 8, "tags": "pagination, navigation" }
Show list of categories even if they have no posts Is there a way to show a list of all categories available even if there are no posts associated with them. So if there is a post in that category then it echos a link and if not it just echos out the name of the category? I'm using wp_list_categories() to show them...
There's an argument called `hide_empty` which is true by default. $args = array('hide_empty' => FALSE); wp_list_categories($args); Codex: `wp_list_categories()`
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "categories" }
Display all posts from selected category This is going to be tough to explain. I have created a custom theme and have a file called: categories.php, in this file i have: <?php $args = array('hide_empty' => FALSE); wp_list_categories($args); ?> This displays all my categories as links, even the ones without a post associated with them. My permalink structure is this /%category%/%postname%/ so when i click a category name i go to < This is fine but what i'm struggling with is what file i have to create and what i have to put in said file so it displays all the posts from the clicked category? Thanks
if category.php does not exist, make a copy of archive.php or index.php and save it as category.php; then, before the start of the loop, add: `<?php global $query_string; query_posts( $query_string . '&posts_per_page=-1'); ?>`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories" }
videos not showing on my tag pages i am using the Smart Youtube plugin for wordpress to show youtube videos. This works fine on my main site. But when i click on a view by a certain tags, none of the video show up in the blog entries. so when i view: ** it works fine and when i view an individual post like: ** , it works fine but when i view ** it only shows the blog entry heading (and not the video). if i click into the post it shows it fine on the individual page. Is there anyway to see videos on a page by tags?
edit tag.php (or archive.php if tag.php does not exist) and look for `the_excerpt();` \- exchange it with `the_content();` codex the_excerpt() codex the_content()
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "tags, videos, youtube" }
How to disable empty <p> tags in comment_text() Im not sure if you guys have encountered this problem, but WordPress appends empty `<p>` tags before and after the body of text from the `comment_text()` function. Strangely, when you `echo get_comment_text()` or `echo $comment->comment_content` (same thing) the empty `<p>` tags disappear before and after the body of text. This is entirely exclusive to a call to `comment_text()`. If you'd like to recreate it the problem, give your `<p>` tags top and bottom padding. Anyway to fix this?
If you look in `wp-includes/default-filters.php` you'll see all of the functions each comment is run through before it's output. I'd guess it's the last one, wpautop, which adds p tags in place of line breaks: add_filter( 'comment_text', 'wptexturize' ); add_filter( 'comment_text', 'convert_chars' ); add_filter( 'comment_text', 'make_clickable', 9 ); add_filter( 'comment_text', 'force_balance_tags', 25 ); add_filter( 'comment_text', 'convert_smilies', 20 ); add_filter( 'comment_text', 'wpautop', 30 ); You can `remove_filter( 'comment_text', 'wpautop', 30 );` to confirm, but you'll lose paragraphs entirely.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "comments" }
Show info to author only I'm writing my own plugin. works like this: function myfunc (){ $a = 'hello'; // the sentence what Am looking for: if ( user is logged and is the author of current post / page ){ $a= 'author'; } return $a; } Wondering how I can do that sencence / function?
Just compare display names: $currentuser = get_currentuserinfo(); if ( get_the_author() == $currentuser->displayname ) { // current user is the post author; do something } The `get_the_author()` function returns `displayname`, which should be able to be compared against the `displayname` parameter that is a part of the `$currentuser` object.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts, admin, author" }
Custom Canonical URLs I am moving my site from olddomain.com to newdomain.com. I want to keep all of the content at olddomain.com but I want the canonical version in google to be recognized as newdomain.com/whatever-post/ instead of the same thing at olddomain.com. How can I modify the rel=canonical in the section of olddomain.com to make this change?
Unfortunately, there's no filter in the `rel_canonical()` function. But you can remove that function from wp_head altogether and write your own. Try adding this to the functions.php at your old domain: remove_action( 'wp_head', 'rel_canonical' ); add_action( 'wp_head', 'new_rel_canonical' ); function new_rel_canonical() { if ( !is_singular() ) return; global $wp_the_query; if ( !$id = $wp_the_query->get_queried_object_id() ) return; $link = get_permalink( $id ); $link = str_replace( 'olddomain.com', 'newdomain.com', $link ); echo "<link rel='canonical' href='$link' />\n"; } Obviously, just replace olddomain.com and newdomain.com in the second to last line with your actual domain names!
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "seo" }
How to get child category list post in one template? Here is what I want to have My category Structure in WP admin Cat Parent -Cat Child 1 -Cat Child 2 -Cat Child 3 -Cat Child 1 This what I want to have in one template: It show the list of post in Cat Parent Children Category Cat Child 1 -Post1 Child 1 -Post2 Child 1 -Post3 Child 1 -So on... . Cat Child 2 -Post1 Child 2 -Post2 Child 2 -Post3 Child 2 -So on... . Cat Child 3 -Post1 Child 3 -Post2 Child 3 -Post3 Child 3 -So on... . Does anyone have done it before or anyone have an idea on how to code this? Thanks
get the child categories, using get_categories(); then loop through them with a foreach loop, using WP_Query() : <?php $cats = get_categories('child_of='.get_query_var('cat')); foreach ($cats as $cat) : $args = array( 'posts_per_page' => 3, // max number of post per category 'category__in' => array($cat->term_id) ); $my_query = new WP_Query($args); if ($my_query->have_posts()) : echo '<h3>'.$cat->name.'</h3>'; while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php /*general loop output; for instance: */ ?> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a> <br /> <?php endwhile; ?> <?php else : echo 'No Posts for '.$cat->name; endif; endforeach; ?>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "categories, posts" }