INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
How to automatically highlight syntax of code in a post? I post my codes from different programing languages. Now, I want to highlight syntax of codes with different colors. But, doing it manually is time consuming. Is there any plugin or method which could do this automatically? Strictly, it should be done in CSS way.
There's a whole bunch of plugins that do that. After some reading i decided to go with Syntax Highlighter Evolved.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "themes, posts, design, css" }
How to catch/what to do with a WP Error Object I am running some of the WP functions directly inside a plugin, including wp_insert_post(), if something goes wrong, this returns a WP Error object, what is the correct method to catch this error? Either using built in WP functions or PHP exceptions or whatnot..
1. Assign return of the function to the variable. 2. Check the variable with `is_wp_error()`. 3. If `true` handle accordingly, for example `trigger_error()` with message from `WP_Error->get_error_message()` method. 4. If `false` \- proceed as usual. Usage: function create_custom_post() { $postarr = array(); $post = wp_insert_post($postarr); return $post; } $result = create_custom_post(); if ( is_wp_error($result) ){ echo $result->get_error_message(); }
stackexchange-wordpress
{ "answer_score": 31, "question_score": 21, "tags": "plugins, errors" }
Split WP install between 2 databases? Is it possible for Wordpress to work from two databases? The reason I ask is that we're approaching our 100mb limit for database size on our host (1and1) but have up to 100 databases, so what I was hoping to do is essentially 'add on' another database for when the limit is reached?
Yes, but that is out of _quick and easy_ realm. See HyperDB in Codex and repository for starters.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "database, mysql, server" }
How Can You Exclude Categories From Your RSS Feeds? I've searched and found posts that have asked and answered how to merge different categories into an RSS feed. **What I need to know is how to exclude specific categories from the RSS feed?** Specifically, I use WP to post blog articles and to post portfolio items onto my site. I want to exclude the portfolio category from appearing in the RSS feed, making only blog posts available.
It's been broken since 3.1, see: < and also < **NOTE:** Otto's suggested fix in that thread doesn't work for me. Ticket suggests patch will go in for 3.1.1 and i can confirm that currently filters on `pre_get_posts` or `parse_query` fail for feeds(unfortunately).
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "categories, rss" }
Users moderate own comments Im putting together a portfolio site and have come across something that i would like to implement, but im unsure of how i can set around doing it. Basically as the site stands now (in development) the user never has (or will have) to access wp-admin to change any of their details, they can do that via a user-profile page. Each user has a portfolio/bio page with a comments form at the bottom, what im wanting to do is make it so that any comments left on this bio page are moderated by that pages owner, ie perfect solution would be: 1) Bio page owner is notified via email that they have a new comment. 2) Bio page owner logs in and goes to user-profile page to review and then accept/decline comment, upon accepting it is then published. Anyone have any previous experience in this, or know of a working site/plugin that i could take a look at, or just any general advice on what im trying to do. Best regards
< This plugin is great for fine tuned control of content. I have not, however, tried what you are requesting. So I can only suggest it as something to look into.... I'm not sure if it gives such fine tuned control over comments....
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "comments, review" }
WordPress: query pages except remove one page I'm currently running this query to get pages (not posts) from the site section: query_posts("post_type=page&post_parent=6"); I'd like to remove one page, 271, from this query. Based on this stack I tried: query_posts("p=-271&post_type=page&post_parent=6"); Unfortunately this had the opposite of the intended result, showing only page 271 and not the other pages in the loop. Placing the _p=-271_ at the end of the query had the same unsuccessful result. How can I reverse this to show all the other pages except page 271?
**Update:** You must use exclude the page using `post__not_in` paremeter. Rewrite your query using the array parameters query_posts(array( 'post__not_in'=>array('271'), 'post_parent'=>6, 'post_type'=>'page' ) ); See this page for reference.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "loop, pages" }
index2.php in root causing 404 error I put up a quick splash page with `index.php` and added a link in that splash page to index2.php and when I go to `index2.php`, I get a _"page not found"_ error. Getting rid of the splash is not an option right now. Is there anything I can do to get this to work?
Try to just use a index.html file and use `<META HTTP-EQUIV="Refresh" CONTENT="5; URL= in your `<head>` section. Let's see if the easy stuff works. _edit:_ to be on the save side, always display a link to the index.php file with some descriptive text like "if your browser doesn't redirect you automatically, please click _here_ "
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "404 error" }
Possible to add "Template" selector to posts? I would like to apply layout templates to my posts, just like I can do with pages. For example, I have a template-wide.php that does not include sidebars and adds a special "wide" class to the content div. At present, I can only use this template for pages. Is it possible to make it available to posts as well?
Use the Custom Post Template Plugin.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "theme development" }
Is there a way to display content from a post meta box in the sidebar? I'd like to display content from a custom meta box that appears for a particular custom post type in the sidebar, when a single post of that type is being displayed. I know how to normally display that content in the post content area, but I'm assuming that using that same code in a widget won't work, since the sidebar is outside of the loop (right?). Any suggestions?
Well, you could access the `$post` variable with `global $post` and then access it's meta values with `get_post_meta($post->ID)` or something close to that. If you just want that to be accessed when you are viewing a single post, you can use if(is_singular('my_custom_post_type')) //do your stuff
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "sidebar, custom field" }
Output author and description if description is not empty Is it possible to only display the author's name and description (aka bio) _if_ the description contains text? This code doesn't work (it doesn't return the name or description) but hopefully it can be edited to accomplish this goal: <?php $authorDesc = the_author_meta($post->ID, 'description', true); if (!empty($authorDesc)) { ?> <em>by <?php the_author(); ?></em> <span><?php the_author_meta('description'); ?></span> <?php } ?>
<?php $authordesc = get_the_author_meta( 'description' ); if ( ! empty ( $authordesc ) ) { ?> <a href="<?php echo get_author_posts_url( get_the_author_meta( 'id' ) ); ?>"><?php the_author(); ?></a> <?php echo wpautop( $authordesc ); }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "author" }
Sort pages in loop by admin's page attributes order field? Is it possible to sort pages in the loop using the admin's order field (under page attributes)?
Yes, use the `orderby` and `order` clause in your query posts. query_posts( array('orderby'=>'menu_order', 'order' => 'ASC' ) ); See: WP_Query#Order for reference
stackexchange-wordpress
{ "answer_score": 29, "question_score": 11, "tags": "admin, loop, sort" }
How can I modify RSS item titles to be either the title or a custom meta field? I'd like to optionally replace some RSS item titles with a headline meta field I've added to certain post types. I have the post types showing up in the feed using: function myfeed_request($qv) { if (isset($qv['feed']) && !isset($qv['post_type'])) $qv['post_type'] = array('post', 'interviews', 'reviews'); return $qv; } add_filter('request', 'myfeed_request'); But I've searched around and can't figure out how to replace the title. Any ideas?
Something like this (not tested): add_filter('the_title_rss', 'custom_feed_title'); function custom_feed_title($title) { $headline = get_post_meta(get_the_id(), 'headline', true); if (!empty($headline)) return $headline; return $title; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "custom field, rss, post meta, title" }
How to add TinyMCE to a front-end textarea? I would like to let the user edit their comments using TinyMCE. Is there any way of doing this?
I've used this plugin before: Tiny MCE for Comments. The plugin page says it's only been updated to WP 2.8.4, so not sure if it's working for more recent versions. Try it and see!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "visual editor" }
How to remove class attributes from custom menu markup? Just playing around with adding "custom menu" support to my theme. I'm super excited about it. HOWEVER, Check this out > <ul id="menu-my-main-menu" class="menu"> <li id="menu-item-12" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-12"> <a href=" </li> </ul> Worst case of "class-itus" I think I've ever seen. Is this something "I" did unintentionally or is this the default? How can I control or remove the class attribs on these menus?
You can use the `nav_menu_css_class` filter to remove the classes that you want from your menu-item. See the example below, to remove ALL the CSS classes that are appended to you menu items: add_filter('nav_menu_css_class','remove_nav_menu_classes'); function remove_nav_menu_classes($classes) { return array(); } Do a `print_r($classes)` if you want to know which classes are active in your menu.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "theme development, menus" }
Character encoding issue after changing servers I recently moved my WordPress-based site from DreamHost VPS to a Linode VPS running Debian + LEMP. After getting the site up again, I noticed many erroneous characters in posts; characters like " and - were being replaced with gibberish. After doing some looking, it seemed clear that the issue was something related to character encoding. I found a guide that suggested editing `wp-config.php` and commenting out the lines: `define('DB_CHARSET', 'utf8');` and `define('DB_COLLATE', '');` I did this and it fixed the problem, but I'm wondering if that was the best way to go about it. Thank you for any advice.
After spending the entire day working on this, I finally found a guide that worked perfectly: * < Before that, I tried following @Rarst's information, tried exporting the database and manually cleaning it, tried the UTF-8 Sanitize Plugin with a modified version from here < (which actually worked pretty well, but didn't fix all the characters. And was probably a terrible idea). Anyway, if any of you ever encounter this problem, check out the first link I posted. The procedure was pretty simple and basically came down to replacing `SET NAMES latin1` with `SET NAMES utf8` after exporting the database, then making sure to import the new cleaned database explicitly as UTF8.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 5, "tags": "server, wp config, encoding" }
How do I rewrite attachment urls when permalink structure contains %category%? I'm trying to change the permalinks to my attachments in the same way as this question, and the given solution works great except for one problem: if the permalinks settings on my site contain %category%, the solution doesn't work at all and I get a "This page isn't redirecting properly" error. The only way I can get this solution to work properly is by using the provided "Day and Name", "Month and Name", and "Numeric" permalink settings. What do I add to the solution so that still use %category% in my custom permalink settings?
It seems like what I want is something that WordPress's internal permalink code isn't prepared to deal with. After reading this writeup by Otto, I've come to understand that having my permalinks start with %category% could create a performance issue down the road and I would have to create a function that further alters the WordPress permalink rules in order to get the attachment permalinks working with %category%. As a result, I've decided to start all my posts with the year. This allows me to use the solution found here for attachment permalinks, and I'll avoid performance headaches in the future.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "permalinks, url rewriting, attachments" }
custom post type - use default or create new? I'm building a website that will only have one post type called Work. This post type will need a field as well. Should I just use the default post type (post) and use custom fields or hide the default post type and create a brand new one called Work? If the former, is there a way to change "Post" to "Work" in the dashboard?
There is no need to create a new post type and remove the regular post, just rename post to work, add_filter('gettext','rename_post_to_work'); function rename_post_to_work( $input ) { if( is_admin() && 'post' == $input || 'Post' == $post_type ) return 'Work'; return $input; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types" }
Check is category parent or not from its ID question is simple (i don't know is aswer too ;) I just want to check that, does a category has child (or is ancestor) from its cat-id with a function. Eg. `function check_category ($catid){ ............ ...//true if is ancestor, false if not return $result; } ` Note: I can only pass cat-id parameter for function because i need to use it in functions.php Thanks in advance...
You can do something like this: function category_has_parent($catid){ $category = get_category($catid); if ($category->category_parent > 0){ return true; } return false; } and use it like this: if (category_has_parent('22')){ //true there is a parent category }else{ //false this category has no parent } ## Update: to check the other way around (if a category has children) you can use get_categories $children = get_categories(array('child_of' => id,'hide_empty' => 0)); if (count($children) > 1){ //has childern }else{ //no children }
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "categories, functions" }
Multisite wide post type? Is it possible to have a multisite wide post type without duplicating the posts? That is a post type that is the same no matter what blog you are on? _Theoretical example:_ StackExchange has many sites (blogs) but wants their site-wide news post type, I'll call it `sitewide_news`, to be the same on every blog. If they happen to be in blog id 4 and make a change or add a new post it will show up in 3 or 8 as if they made the change there. In other words only one database entry exists. Thanks!
I've been using this plugin, which works really, really well.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "custom post types, multisite" }
What is theme-editor.tmp? What is theme-editor.tmp? It is located under wp-content.
.tmp-files are temporarly files created by incomplete Wordpress- or plugin actions. These files appear also in general computing. In this case, they are often created during plugin updates that are performed from the Wordpress backend (wp-admin). If the plugin upgrade fails for some reason, or termitated by the user, the .tmp files may not be deleted by the system. The .tmp files can be deleted safely under normal circumstances – since they are usually the forgotten residue of some incomplete WordPress actions. However, it might be a good idea to backup the files to a local folder before you delete them, just in case..
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "customization" }
Is there a plugin that let you edit Posts and Comments in a front-end page? Basically, I need a plugin that let you edit posts and comments the same way you do in StackExchange sites (questions and replies)? Because by default Wordpress sends you to the back-end.
Yes, try the Front-end Editor by Scribu!
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "editor" }
Can I apply a WP theme to a specific custom page template? One section of my website is going to be completely different visually than the rest of the pages, is there a way to apply a WP Theme to specific page templates ?
In fact there is, using `template_redirect`, which you would put in the functions.php file - Here's what I use: function uniquename_default_template() { if(get_post_type() == 'posttype') : /* You could use is_single() instead of get_post_type() == '' or any type of conditional tag) */ include(TEMPLATEDIR . 'path/to/theme/file.php'); /* You could use TEMPLATEDIR to get a file from a template folder, or PLUGINDIR to get a file from the plugins directory - doesn't support HTTP requests */ exit; endif; } add_action('template_redirect', 'uniquename_default_template'); The above code checks for a `post_type` called `posttype`, if it is, it will include the PHP file specified in the include statement by redirecting the template using the `template_redirect` function.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "themes, templates, pages, customization" }
I need to have two 1-5 star rating fields, only editable by admins. Which plugin should I use? I need the following: two different 1-5 star rating fields, for one of my custom content types. The ratigs will be stablished by the admin, so I dont need a real voting system. The fields are more like indicators than polls. I tried gd-star ratings but its aimed at community voting and rating systems which is not at all what I want. I know this would be uite easy to code, but if there is a plugin for this I would like to know. Thank you guys!
Take a look at * Easy Review Builder for WordPress * Review Ratings they both work as shortcode.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "plugins, plugin recommendation, rating" }
Do we still need to include a "if (have_posts())" in templates? I include this logic in my template all the time if ( have_posts() ): //show content else: //show content not found endif; But recently I began to doubt its necessity, WordPress will turn to 404.php when no post found, it seems no need to add this logic in normal templates, `else` will never be triggered, is it?
When I look at `WP::handle_404()`, I think that the `404.php` template will not be loaded, even if there are no posts, if: * We are on the homepage * It is a search * It is a taxonomy term that exists, but has no posts attached to it (and it's not paged) * It is an author that exists, which has written no posts (yet) (and it's not paged) So in these template files, `have_posts()` can be useful.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 6, "tags": "posts, loop" }
custom tabs in media uploader I've managed to add a custom tab to the media uploader, but for some reason it doesn't come with the same layout - it doesn't load the media-uploader-header that contain all the other tabs: add_filter('media_upload_tabs', 'my_media_upload_tabs_filter'); function my_media_upload_tabs_filter($tabs) { unset($tabs["type_url"]); unset($tabs['library']); $newtab = array('ell_insert_gmap_tab' => __('Google Map','insertgmap')); return array_merge($tabs,$newtab); } add_action('media_upload_ell_insert_gmap_tab', 'media_upload_ell_gmap_tab'); function media_upload_ell_gmap_tab() { return wp_iframe('media_upload_ell_gmap_form', $errors ); } function media_upload_ell_gmap_form() { ?> <h2>HTML Form</h2> <?php } Thanks.
found it. in the automattic SVN for media.php i found the media_upload_header() function, and the only thing left to do is to echo it in the last function: function media_upload_ell_gmap_form() { echo media_upload_header(); ?> <h2>HTML Form</h2> <?php } that's it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "admin, uploads, media, thickbox, tabs" }
What is a subpage in WordPress? Can someone explain what a subpage is in wordpress? Does it look any different from a regular page? What is its purpose and what does it do? Thank you
The only difference between a page and a subpage is that a subpage contains it's parent in the URL, as will any pages that sit as children to the child page... For illustration. **Regular page:** example.com/a-page/ **Subpage:** example.com/a-page/a-child-page/ **Sub Subpage:** example.com/a-page/a-child-page/another-child/ and so on... Aside from the URL there's no other differences i can think of.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "pages, hierarchical" }
Uploaded images not displaying in network site I have a network of sites and have recently added another site. When I upload an image it uploads to the correct directory but is showing a broken image link when viewed within the library or on the site. I checked the site's setting and everything looks correct. file actually uploads to blogs.dir\7\files\2011\03\1551-oct-cable.png broken image link location e.x. < I really have no idea where to go on this one.
Looks like I needed <rule name="WordPress Rule 1" stopProcessing="true"> <match url="^index\.php$" ignoreCase="false" /> <action type="None" /> </rule> <rule name="WordPress Rule 2" stopProcessing="true"> <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" /> <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" appendQueryString="false" /> </rule> Also here's a bit more information I was able to find. <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "images, uploads, media library, multisite" }
Exclude a category name using cat name I'm trying to exclude a category because I have a post that i have in multiple post. How do I like for example I have a post in the categories lastest news and pictures but I want to exclude latest news and show only the pictures name. I tried using $category = get_the_category(); echo $category[0]->cat_name; but that's no help. any help is appreciated.
actually I fingered it out this code worked. <?php //edit below for categories you want excluded $exclude = array("Latest News", "Uncategorized"); //how do you want the list separated? just a space is okay $separator = " | "; //don't edit below here! $new_the_category = ''; foreach((get_the_category()) as $category) { if (!in_array($category->cat_name, $exclude)) { $new_the_category .= '<a href="'.get_bloginfo(url).'/'.get_option('category_base').'/'.$category->slug.'">'.$category->name.'</a>'.$separator; } } echo substr($new_the_category, 0, strrpos($new_the_category, $separator)); ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories" }
How can I get page slug How can I get the slug of a page or post?
Inside of your loop you can do: global $post; echo $post->post_name;
stackexchange-wordpress
{ "answer_score": 23, "question_score": 24, "tags": "theme development" }
How to 301 private posts rather than 404? How do I 301 redirect private pages, rather than 404 them? If a post is private, WordPress filters it out in the SQL query, so there are no $post variables to work with. I'd like for this code to work, but doesn't: add_action('wp','redirect_stuffs', 0); function redirect_stuffs(){ global $post; if ( $post->post_status == "private" && !is_admin() ): wp_redirect(" exit(); endif; } I don't know where that is set earlier than `wp`, other than the fact that I know it's a user role issue. If I could set a non-logged in user to have that capability, it would probably fix the issue: $publicReader -> add_cap('read_private_posts'); The problem with add_cap is that only logged-in users have capabilities.
Sorry guys, I found my answer: add_action('wp','redirect_stuffs', 0); function redirect_stuffs(){ global $wpdb; if ($wpdb->last_result[0]->post_status == "private" && !is_admin() ): wp_redirect( home_url(), 301 ); exit(); endif; } Posts/Pages are removed from the sitemaps, but the page still shows up on the site so that it can get 301'd.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "wp redirect, post status, capabilities" }
Is it possible to customize the layout of Gallery Shortcode? Is it possible to customize how my gallery shortcode works. eg. have a div for showing the image then a list of thumbnails at the bottom or side? Or perhaps I can create a custom template file to loop through my page's gallery images?
You may complete override your gallery shortcode using the filter `post_gallery`. The return is displayed in your page and no further processing of the shortcode is done. You may iterarate through the image attached to your post to build your own gallery. See the implementation of gallery shortcode here: < EDIT: There are some plugins that modify the default behaviour of the gallery shortcode. Search it from the "Add New Plugin" of the backend. Use the string "gallery shortcodes". Note: if you want you can use nextgen-gallery to manage your photos. It has numerous plugin to display with other gallery, like Smooth Gallery, Nivo Slider or jQuery cycle.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, gallery" }
Are there plugins that interfere with the admin part of Rss widget? I've been using the Rss widget in my site, and suddenly a few days ago, the admin part stopped responding. That is, I'd change the link to the Rss and it wouldn't get saved (and therefore would show the old Rss in the site). Or I would add another Rss widget, but after I refreshed the admin page, I'd see the widget, but without the links and the other options I added. Then I got to thinking that maybe one of the plugins could be causing the problem. Are there known plugins that would do that?
I found that I had to disable 2 plugins: WP-Polls and Search & Replace
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugins, widgets, rss" }
My WordPress site always displays a cached version of its homepage First of all, sorry if I'm making a mistake. I already asked this on the ServerFault forum, but got no answers at the moment and I thought it would be a good idea to ask the question here, considering that it is a WordPress specific question. I have a WordPress site that runs fine, but there's a strange behaviour: one a reader loads the page, **the site shows a "cached" version** of the site, with the same news and comment numbers that the reader viewed when he visited the site last time. So every user **has to reload the page** (Ctrl+F5, Cmd+R) in order to get the "real", and updated homepage. I don't know why this is happening. At the moment I'm not using any cache plugin, and my server is running **Nginx+MySQL+PHP-FPM** on a Ubuntu 10.04 LTS Linux VPS. Is there something I must change on the nginx config files, maybe?
Sounds like your expires headers are set to far in the future. ~~The following rules can be added to your .htaccess~~ Expires rules can be added to your Nginx server file to shorten the expires time down to 180 seconds. location ~* \/[^\/]+\/(feed|\.xml|.html|.HTML)\/? { expires 180; } I would also suggest installing the **Nginx Proxy Cache Integrator plugin** to control the Nginx static file proxy cache. Another plugin that is similar is **Nginx Proxy Cache Purge** that purges the proxy cache anytime you update your site. The problem your having is NOT being caused by WordPress.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "mysql, cache, nginx" }
query recent posts from several categories i'd like to list my 10 most recent posts but from certain categories only - anyone can tell me how to do this? thanks
simply add this above your loop $args = array( 'posts_per_page' => 10, 'category__in' => array( 2, 6 ), //change and add the category ids here 'orderby' => 'date', 'order' => 'ASC') query_posts($args); and you can read more about query_posts Parameters < ## Update By popular demand :) here is another example to doing the same but using tax_query $args = array( 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => array('category1','category2') ////change and add the category slugs here ) ) 'posts_per_page' => 10, 'orderby' => 'date', 'order' => 'ASC') query_posts($args);
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "query posts" }
definining own teaser text for post i'd like to have a small news box in my sidebar - so i need to display just a few lines of text, separated from the actual the_content() - how could i do that? it should be somekind of quicktag which will be hidden in the full post content. thanks
Use this widget: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, content" }
excerpt box not visible i'd like to use excerpts but for some reason the excerpt editor is not visible when editing posts. i'm using wordpress v3.1 - already searched up the options but couldn't find anything .. :( do i need a plugin for using excerpts? shouldn't it be included by default in wordpress? thanks
Do you have the excerpt field enabled in screen options? !Enable excerpt Screen options is in the top right-hand corner the screen, next to the help button (under the logout link).
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "excerpt" }
how to edit attachments? when attaching eg. files to a post, how can i edit/delete them afterwards? couldn't find anything in the post editor. thanks
Use the Media Uploader. 1. Press Upload Photo above the editor. 2. See the tab "Gallery( number-of-items-attacched )" 3. Manage / Rerrange order 4. To delete: show an item and press Delete (it's at below of the window)
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "posts, attachments" }
WordPress Multisite domain mapping with different IPs Hey there, I have 5 different sites with 5 different IP's on cyberwurx shared account. How can I install wordpress multisite and use the domain mapping plugin and also keep my sites on different IP's? Any ideeas? Ty!
WordPress won't care about the IPs, It's Apache's job to map IPs to your vhosts. You need to look at the Apache config: set up either 5 separate `VirtualHost` entries that all point to the same `DocumentRoot`, or tell Apache to listen on all available IPs, and use a wildcard match on a single `VirtualHost` section.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "multisite, customization, domain mapping, ip" }
If the_post_thumbnail(); is this - echo this text I'm using the_post_thumbnail(); (aka featured image) to show a news source logo. If I use that image, I'd like to output the name of the news source. For example: if the_post_thumbnail is "new-york-times.jpg" echo "New York Times" elseif the_post_thumbnail is "cbs-news.jpg" echo "CBS News" etc... Any help writing this code is greatly appreciated!
If You need title from media use something like this: <?php $thumb = get_post(get_post_thumbnail_id()); echo $thumb->post_title;
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "post thumbnails, text" }
Site does not work right, pages not showing up, even for root admin I have a problem. My database server isn't working right. On a wiki, it gives an error, and on my wordpress site, the pages don't show up. I am wondering if WordPress caches the DB data in any way, and if so, how do I clear it. I am hoping that will either totally break it or clear it. I am able to disable plugins and change settings, just the pages don't show up. **Edit:** The only thing I can't access is the pages. Everything else is working OK, I think. Also, this just cropped up in the last couple of days. Before that, it was fine. I just noticed it today. **Edit 2:** I mean pages as in posts and pages, not webpages.
Thanks all for your input. This may help someone else who has this problem. As for me, the problem has fixed itself (well, not exactly, but it is gone), so it must have been the DB. The wiki is still down, but it says that a table is marked as crashed now.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "database, troubleshooting" }
Custom post type / custom fields I'm working on a client site and need the following: * A custom post type called 'Agreements' * On the Agreements edit panel, show a list of "Offices" checkboxes. Users can select multiple Offices per Agreement. Here's the rub. I want the admins to be able to add/edit Offices, which would each have a title, abbreviation and URL. The admins can add/edit Offices in a totally separate place, but I want these new Offices to show up in the Agreements edit panel automatically. I've tried a number of approaches, but I'm having trouble pulling the Offices list into the Agreements custom edit panel. Magic Fields comes close with its "Related Types" option, and I almost got WPAlchemy working but ultimately failed. Any suggestions on better / easier ways to do this? Thanks so much for any and all tips and advice!
I'd recommend you **consider creatinga Custom Post Type of `'office'`** and use one of the following custom post relationship plugins to maintain relationships between Agreements and your Offices: * **ZigConnect** * **Custom Post Types Relationships** * **Post Type Linking** * **Posts 2 Posts** **_Note:** Also, here's a link to my own pinboard that I'll update in the future with any other **WordPress Post Relationship Plugins** as I find them._
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom post types, custom taxonomy, custom field" }
Form to Add Posts to Custom Post Type (Again) I pretty much got my answer in my last question, but not quite. I was supposed to add one last code to my source and it would have worked but the person helping hasn't replied now and I don't know what to do :S Form to Add Posts to Custom Post Type So can anybody tell me where to put `wp_redirect(get_permalink($pid)); exit;` in my code to have it redirect to the post after the post is added to the database?
You need to put the form processing part of the code at the top of the page before anything else and wp_redirect(get_permalink($pid)); exit; Right after $pid = wp_insert_post($new_post);
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development" }
Why is wp_get_attachment_image_src not working with my custom size (add_image_size) I have added an image size with add_image_size('gallery-thumb', 48, 48); Why when I do array_slice(wp_get_attachment_image_src($firstimg->ID, 'gallery-thumb')) I get the link to the full sized image? **UPDATE** Somehow it appears that even when I do wp_get_attachment_image_src($photo->ID, array(48,48)) I get the thumbnail image (150, 150)
Does the 48x48 thumbnail file exist? If not, you can use a plugin like Regenerate Thumbnails.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 5, "tags": "images, media library" }
Add a file type I am trying to upload java files to my WordPress blog but it does not let me upload any files with `.java` extension. I get this error: > ".java” has failed to upload due to an error > > File type does not meet security guidelines. Try another. How do I add `.java` extension so that it allows me to upload java source code? I am using WordPress version 3.0.4.
Use filter 'upload_mimes'. <?php add_filter('upload_mimes','add_java_files'); function add_java_files($mimes) { // Add file extension 'extension' with mime type 'mime/type' $mimes['java'] = 'text/x-java-source'; return $mimes; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "uploads" }
How do I test whether [gallery] is empty? How do I test whether there are any images attached to a post? I'm using the gallery shortcode, but I want to put it in a conditional so the surrounding styling isn't displayed if the gallery is empty.
You can check if an attachment for the given post exists with the get_posts function. This will create a new sql query - so there could be a performance issue. // Util.class.php class Util { public static function has_attachments() { $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID ); $attachments = get_posts($args); if(!empty($attachments)) { return TRUE; } else { return FALSE; } } } // In template require_once 'Util.class.php'; if (Util::has_attachments()) { // Display gallery }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "gallery, conditional content" }
Pluggable function and activation check? Plugin is defining pluggable `wp_mail()` function. My idea was to check if function is defined already and throw warning if other plugin beat me to it. However this warning causes issues on activation. As far as I understand during normal operation plugin is loaded **before** `pluggable.php` but for the purpose of activation check it is loaded **after** pluggables. What would be the robust/proper/suggested way to implement such check for pluggable function? There is no obvious (for me) way to distinguish activation and handle it separately.
Don't do the check on activation? Seriously, the best way I can think of is not to check for this on activation, but only in the normal plugin load process. And instead of throwing a warning (I assume you mean a PHP E_WARNING), perhaps putting an admin error box up would make more sense.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 6, "tags": "plugins, activation, wp mail" }
post-page: reference to parent page? i'm having a problem with wordpress and the post-page: my web has several pages like: news, projects, links each page is displaying posts of the corresponding category. my question: when clicking on a post's detail, it will execute always the same script (post-detail.php). now i want to implement a "back"-link which jumps page to the referring page. how can this be done? is it possible having several post-pages? thanks
You can do that: //add reff to query vars to hold the referring page ID add_filter('query_vars', 'my_query_vars'); function my_query_vars($vars) { // add movies_view to the valid list of variables $new_vars = array('reff'); $vars = $new_vars + $vars; return $vars; } then add `?reff=<?php echo $post->ID; ?>` to your "post's detail" link and on your "post-detail.php" you can create a back link using that query var <a href="<?php echo get_permalink(get_query_var('reff')); ?>">Go Back</a> and as for having several post-pages take a look at: How to quickly switch custom post type singular template
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "posts, pages" }
Custom Post Type and Labels I was wondering if there is a way to edit the default field labels on a custom post, for example instead of the author field saying "author" have it say "keynote speaker" I found one solution listed below, but this obviously edits it across the entire backend. add_filter( 'gettext', 'change_author_to_keynote' ); add_filter( 'ngettext', 'change_author_to_keynote' ); function change_author_to_keynote( $translated ) { $translated = str_replace( 'Author', 'Keynote Speaker', $translated ); $translated = str_replace( 'author', 'keynote speaker', $translated ); return $translated; } Thanks in advance, Pete
you can use: add_filter('gettext','custom_author_lable'); function custom_author_lable( $input ) { global $post_type; if( is_admin() && 'your_post_type' == $post_type ) if ('Author' == $input || 'author' == $input) return 'Keynote Speaker'; return $input; } just replace your_post_type.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom post types, author" }
Environment Specific Options Token Is it possible to add a token to any wp-option that could be replaced on get where the token being defined in a plugin’s option or the configure file? E.g. => or or To be more specific I am managing a Wordpress instance inside a development life cycle where I often copy production data down to staging and development servers. Often the options tables are unmanageable and have changed since the last dump. However, after analyzing what the most frequent changes are between servers I noticed it is the environmental specific tokens like dev and staging. I am a little concerned with running a string replace on every option get, but I am making use of page, data, and object caching.
See the filter reference on the codex. In particular, note that you can use the form `option_$foo` to filter just a specific option key. So if you wanted a filter specific to the `siteurl` option, you could do: add_filter( 'option_siteurl', 'my_url_filter' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "plugins, options" }
Custom Post Type Archives with 0 Posts Redirects as 404 I'm working with the new custom post type archives in 3.1 and I noticed that when my post type has 0 posts, the archive for the type results in a 404. Looking at the order of hooks being processed, it's redirecting to the 404 template before even processing my archive-{post_type}.php template and reaching the conditional for available posts. Reading various articles and questions here had clued me in on flushing the permalink state after creating my types. This shouldn't be an issue, however, as the archive page works if posts for the type exist. I even went as far as setting my has_archive value to the post type slug rather than just true to no avail. Is there a way to force the archive template to be loaded and not generate a 404 regardless of post count while keeping the query in place?
An FYI for those coming back to this question, this was fixed in 3.2: <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "custom post types, archives, custom post type archives" }
Custom Author Loop Essentially what I'd like to do is have the same effect as the wp_list_authors tag, but instead of just listing the name or their post count, I want to be able to do a loop with the IDs. Ultimately I'd like have to a page with every author, with their name, description, avatar and link. I can figure out the specifics, I just need a way to do something like: foreach $author as $author->ID Thanks in advance, Pete
Looks like you'll want to use get_users and you might want to take a look at the source code behind wp_list_authors to info on how to use it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "author, list authors" }
Shortcode content filter? I'm looking for something, but don't exactly know what. I have a shortcode, let's call it [shortcode]. Users will input HTML tags inside, mostly images, but also links, images in links, etc., for example: [shortcode] <img src=" /> <a href=" src=" /></a> (...) [/shortcode] The point is I want to format URLs, differently, I want every img src to start with files/myimagescript? So the code above should output: <!--- shortcode code before input --> <img src="files/myimagescript? /> <a href=" src="files/myimagescript? /></a> (...) <!-- shortcode code after input --> So basically I need to simply change src of images. And it should work for any number of images, from 1 to unlimited. I'm thinking about foreach PHP loop, but I'm not sure how to grab each img src line from shortcode and process it before displaying?
you can use regex to find your the src and use that to append your "files/myimagescript?" to it: function append_myimagescript($attr, $content){ $pattern = '/src="([^"]*)"/i'; $replacement = 'files/myimagescript?${1}'; return preg_replace($pattern, $replacement, $content); }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "php, functions, shortcode" }
if (has_custom_menu())? I've taken this line from header.php of TwentyTen where its loading the custom menus... <?php /* Our navigation menu. If one isn't filled out, wp_nav_menu falls back to wp_page_menu. The menu assiged to the primary position is the one used. If none is assigned, the menu with the lowest ID is used. */ ?> <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?> I understand their fallback plan, but for mine, if no custom menu has been assigned to my custom menu selector, I don't want to return anything. What's the function to determine if my custom menu has an assigned menu?
From looking at the Codex, you should be able to just pass the fallback_cb parameter as false to have wp_nav_menu return nothing. So something like: <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'fallback_cb' => FALSE ) ); ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, menus" }
How to add posts to custom menus? I'm just beginning to work the "Custom Menu" functionality that was introduced in 3.0 into my theme. I like everything about this new capability and API, with one exception: Why no posts? I can create menus containing pages, categories, even tags, but where is the posts selector? I know I could use the "Custom Links" tool as a workaround, by pasting in the URL to a given post, but I'd rather not expect my users to do that without creating a ton of support issues. I'd rather just add a menu box called "Posts" that has the same functionality as "Pages". Has anyone done this and if so can you share the code? Alternately, and I know I'm dreaming on this one, what about a single box with tabs for selecting between pages and posts?
OK, I found the answer to this one and its surprisingly simple but maddeningly frustrating at the same time. All you have to do is click "Screen Options" while viewing the "Custom Menu" manager and place a check beside "Posts" to show the elusive hidden "Posts" widget. Now you can add "Posts" to your custom menus. Who knew anyone would ever want to do that? Why this is not part of the default screen options, while "Tags" is, escapes me, but that's the default none the less. Also, just to get a few more bytes out of this rant.. Whoever decided that "Excerpt" should no longer be visible on the post editor screen should have to answer at least one of the 5 emails I get per day with on the topic of "What happened to the excerpt field, it was there, now its gone". Brilliant.
stackexchange-wordpress
{ "answer_score": 48, "question_score": 29, "tags": "theme development, menus" }
Checking if Database Table exists I read the wordpress codex and professional wordpress. It seems both use something like if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { to determine if the table exists. Is there any reason why `CREATE TABLE IF NOT EXISTS ( ... )` is not used? It will check and create the table in 1 query, won't it be better? Or am I missing something?
If you use "IF NOT EXISTS" then the dbdelta script will not upgrade your database with delta's appeared after the initial creation of the database. (assuming you want to re-use the same sql script) at least... that is what i think
stackexchange-wordpress
{ "answer_score": 12, "question_score": 20, "tags": "database, mysql" }
Get All Images in Media Gallery? Is there a way to fetch the URLs of **ALL** images in the media gallery? I think this would be an easy way for a website to have a Pictures page that just pulls all of the images from the media gallery, granted it would only be necessary in certain scenarios. I don't need instructions on how to create a Pictures page, just how to pull all of the image URLs. Thanks!
$query_images_args = array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'posts_per_page' => - 1, ); $query_images = new WP_Query( $query_images_args ); $images = array(); foreach ( $query_images->posts as $image ) { $images[] = wp_get_attachment_url( $image->ID ); } All the images url are now in `$images`;
stackexchange-wordpress
{ "answer_score": 70, "question_score": 34, "tags": "media library" }
Is it possible to create an "export to PDF" option? I have a custom post-type "model", and I want to be able to export certain values (eg Name, Height, Shoe Size, etc) and a set number of images from the gallery, from each Model to a PDF. Ultimately, what I want to be able to do is: 1. From the Admin backend, click an "options tab" or some such 2. select a number of Models, 3. enter an email (or multiple, comma separated emails) 4. Click a "send" button 5. and have the PDFs generated and emailed off without further intervention. Is this at all possible in WordPress? Or is this too complex? Surely you can do anything with PHP and WordPress ;)
To answer your questions: 1. Yes, it is possible. 2. Depends on what you consider to be "too complex". 3. No, you cannot do anything... For example, WordPress and PHP will not bring your deceased loved ones back.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "custom post types, php, pdf" }
Is there a plugin or something that allows you to use BuddyPress without having to create a BuddyPress-ready theme? It's an inconvenience to have to customize your theme just to use BuddyPress. It'd be much nicer if it simply used the wordpress page system for example, to inject content into standard WP pages. This way no theme editing is necessary, just activate BP and go. The idea would be that BuddyPress would just work in TwentyTen with off the shelf wordpress install + BuddyPress. Is there a solution?
There is actually a plugin for that (bptemplate pack). It works pretty well! <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "buddypress" }
Identify that a page is a grandchild page How do I identify that a page is a grandchild page?
use get_page twice like this handy little function function get_grandpapa($page_id){ $current_page = get_page( $page_id ); if ($current_page->post_parent > 0){ //has at least a parent $parent_page = get_page($current_page->post_parent); if ($parent_page->post_parent > 0){ return $parent_page->post_parent; }else{ return false; } } return false; } This function returns the grandparent page ID or false if there is no grandparent.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "pages" }
Wordpress 3.1 - Tag page not showing posts from custom post type On the site I am developing I have a few custom post types set up (Press Releases, Articles, Podcasts). I also have the Tag Cloud widget enabled in my sidebar. I have tagged a post with 'Testtest', and I've also tagged a Press Release with 'Testtest'. The problem I have is when I click the 'Testtest' tag on my tag cloud, it only shows the 'Post' that I tagged, and not the Press Release. Any idea why this would be, or a solution? Thanks!
you can add them using pre_get_posts filter: function myTagFilter($query) { $post_type = $_GET['type']; if (is_tag()){ if (!$post_type) { $post_type = 'any'; } $query->set('post_type', $post_type); } return $query; }; add_filter('pre_get_posts','myTagFilter');
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, tags" }
Using the on-board image editor for featured images: edits are not being used I've never really been comfortable with the on-board image editor in WordPress, and here's a good example of why: I'm just setting up a vanilla WP installation and am using the TwentyTen theme. I've uploaded an image, rotated it 90 degrees (using the Edit Image feature), saved it and have used it as my Featured Image. The image that appears in my header and featured image area is still the original, rotated version. When I go back to the Gallery for this page, by clicking on the Featured Image in the Edit Posts section, the image is rotated correctly. But back on the Edit Posts section, or on the actual site the image is not rotated. I've hit "Save all changes" a dozen times, I've switched sizes a few times, and I'm using "Apply changes to: All image sizes" in the Edit box. I'm running out of options. Can someone walk me through the correct process to upload, rotate, and set a featured image? thanks!
AFAIK, the featured image ignores all on-site edits. It just takes your base image, and applies crop/resize based on your add_image_size defs.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images, post thumbnails" }
Content/Excerpt length control for a specific loop? Is it possible to control the length of the content or excerpt for a specific query/loop? I have come across the following code, but this changes the length for all excerpts, I want it focused on a specific custom query. add_filter('excerpt_length', 'my_excerpt_length'); function my_excerpt_length($length) { return 20; }
Try this: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "loop, the content, excerpt" }
How can I determine if a post has an image attachment? As far as I know, there's not a simple function that will return true if a post has an attachment. With that in mind, what's the best way to determine if a post has an attachment (or even better, has an image attachment)? I'm automatically inserting a shortcode on posts, but would like that to only happen if there is actually an image attached to the post.
I think this should work: $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image') ); if ( $attachments ) { // do conditional stuff here }
stackexchange-wordpress
{ "answer_score": 16, "question_score": 5, "tags": "images, conditional content" }
Block registration by URL referrer? Is it possible to block user registration based on the referring URL? I have an open registration WP site (configured so users can post ads and events) and while I typically don't get a lot of spam registrations (there is a reCaptcha involved), I was listed on a site as an example of the capabilities of the theme I'm using, and it generates a lot of "test" type of traffic. I like the traffic, but I don't like people registering just to post false test posts just to see how the site works, so I'd ultimately like to simply block registration from that referring URL. Thanks!
You can use `"register_post"` hook that happens just before the user is saved to the database or you can use `"register_form"` hook and check the referring URL for a match and die();
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "urls, spam" }
query_posts for child pages I am having problems looking for info on the codex on how to query for child pages. It seems to be missing the reference for the available parameters
Yeah they've moved the parameters to WP_Query. You're looking for the post_parent parameter.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "query posts, pages" }
Stop Authors from submitting spam post I am designing a frontend for users, where they can submit an article/post from. But i am worrying if someone puts javascipt code, or SQL injection, or other malicious code. Is there a plugin or some sort of scripts which can help me to filter the post contents from security point of view. I'll appriate if someone can suggest me some code/script/plugin which can help to define rule over submmited contents like 1. No. of external hyperlinks 2. No. of Images 3. Length of content etc. Although i can do it manually. So the lower part of the question is less important.
If your really worried I would probably create custom write panels or custom meta boxes tied into custom post types. That way you can make the custom post types based on user role and control what shows up very easily. For instance you can make a custom post type called "tweens" with the user role of "contributor" so they can write posts but not submit them. Using custom meta box's with a custom post type will give you complete control over what kind of data is submitted. For instance if you want to limit the above post type "tweens" to 5 images you only supply 5 image meta boxes, or limit the amount of words per text box, or strip urls or js, or remove the wysiwyg, etc ( anything really). Some references: < <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, spam, front end, frontpage" }
Not Found when using activity stream as front page with BuddyPress I'm trying to create a Thematic child theme that uses BuddyPress. First, I tried using BuddyMatic -- which currently doesn't work with WP3. Next, I tried the BuddyPress compatibility pack -- which totally works! Except for one thing: when I select "Activity Feed" as an option for the front page, I get a Not Found error. Going to /activity/, /groups/, /members/, and all other BuddyPress pages, however, works fine. Any idea what the issue might be? Thanks!
I figured out how to make it work, but it's a bit hacky. Essentially, I coped the index.php from activity into the the main index.php of my Thematic child theme, adding the Thematic actions afterwards. Same error persists if I leave it on "Activity Stream" for the front page, but when I return it to the default "Most recent posts", my modified index.php in the root takes over. I'll post my code in a few days if nobody answers my question with how I can get it to work through that option -- I'm building this as a high-end in-house repeated use theme, rather not resort to what I did. (Redid as answer since no response.)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, customization, buddypress, loop, framework" }
Event Calendar on hosted wordpress? I see a number of posts on various plugins for doing an Event Calendar that work with Wordpress, but the free hosted version does not allow me to use these. Are there any solutions that would work for hosting a calendar of events for an organization that I volunteer for? Even embedding a Live/Google calendar would work, although I understand that iframes are also not allowed. Thanks!
It may be time to give up WordPress.com. There is little day to day difference in managing a self-hosted version, but there is a world of opportunities that will open with a few well selected plugins. You mentioned you're volunteering for an organization. If the issue is paying for hosting, Dreamhost and HostGator offer free lifetime hosting for US based 501(c)3 non-profits. Dreamhost's process is the easier of the two. (Disclosure, I'm an affilate for both...but look ma, no links). Between free hosting and plugins, your organization's events should get all the attention they need.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "calendar" }
On the post list, how do you show different text to the main content? Not sure if the title makes sense sorry, but at the moment on my blog there is a long list of posts (with the thumbnail custom field) - the text next to the thumbnail is just the first characters from within the post. How exactly do I change that to something else? Thanks!
See this. You should be able to control that text by altering your Post's excerpts. You may need to click "Screen Options" at the top right of your Dashboard to have the Excerpt box be displayed when you create or edit posts. HTH.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts" }
How long should it take for a plugin to fully load into the WordPress.org plugin repository? I updated my plugin, Export to Text, to 1.3 and committed it to the WordPress SVN repository yesterday. The 1.3 download button was available pretty quickly, but a day later the read me text is not rendering on the plugin page and the download update reminder is not working in the WP UI for users with earlier versions installed. How long does it typically take for plugins to be fully loaded by the WordPress.org website?
A readme update may take a week or more. Sometimes it helps to update just the readme file again. The **Last Updated** field is … dead. One of my plugins still shows the date 2010-12-24, but I had three updates in the mean time, the last one a week ago. The whole system feels like an old windows. :)
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin development, svn, plugin repository" }
Correct way to add a block element to sidebar layout First time experimenting with wordpress and looking for advice on the correct way to add a block of html to a sidebar. This doesn't seem like a custom widget to me as there is no functionality involved, other than displaying an image. I want to position it above a sidebar menu which exists there already - instead of just lobbing the html directly into the template file, should i be doing something else with it? Thanks for any help!
You should simply add the html block to the built in text widget. And as for positioning it above the menu just use the drag n' drop functionality of the sidebar widgets.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "widgets, sidebar, templates" }
Wordpress to end support for PHP 4? Recently getting into wordpress plugin development, I started to investigate how to make my code backward compatible to php 4+. I've focused only on php 5.1+ for the past 5 years, so this was an ordeal. Anyway, when looking at some plugins, one of them had this description: > IMPORTANT: This plugin is not compatible with PHP 4. If you try to install it on a host running PHP 4, you will get a parse error. WordPress is ending support for PHP 4 as of version 3.2 Is it true that wordpress is going to stop supporting php prior to php 5?
Yes, version 3.1 is the last version to support PHP 4. > For WordPress 3.2, due in the first half of 2011, we will be raising the minimum required PHP version to 5.2. Why 5.2? Because that’s what the vast majority of WordPress users are using, and it offers substantial improvements over earlier PHP 5 releases. It is also the minimum PHP version that the Drupal and Joomla projects will be supporting in their next versions, both due out this year. Based on that announcement page, I'd actually expect 3.2 to be released a little later this year (i.e. early Q3), since 3.1 ended up a few months later than that page projected (not a knock on the dev team, FYI - just conjecture on my part).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php" }
Change admin logout URL My site is using a short vanity URL. This is working across all of the custom theme pages. The only problem is when I logout in the admin it redirects to the long URL, which then 404s. My General Settings (which I can't change) are: WordPress address (URL): The long URL Site address (URL): The short URL Looks like the logout link is generated from wp-includes/general-template.php, but I hate to edit core, non-theme, WordPress files. Any ideas how to solve this logout 404 problem is greatly appreciated.
The quickest way to do this is through an Apache rewrite via mod_rewrite. You'll also have to tell WordPress where to points its login links using the login_url and logout_url filters. return apply_filters('login_url', $login_url, $redirect); return apply_filters('logout_url', $logout_url, $redirect);
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "admin, urls" }
Returning info from MYSQL table via custom taxonomy **Update:** I'm now trying to find a way to echo the metadata of a custom taxonomy's value. I'm trying to create some PHP to use in a plaintext widget that'll display information in my sidebar. Because some of the information will be identical across some of the parts of the site instead of storing the information in custom fields I'm trying to store it in a MYSQL table. What I'd like the code to do is to identify the post taxonomy, lookup the id field in my table, find the row with that shares the id with the taxonomy and then echo the values of other fields on that row. I have my taxonomy setup as well as my table but I can't find much of a precedent for this and therefore I'm struggling to know where to start. So far I'm trying to call the current post taxonomy's value but I can't get it to work outside the loop <?php $current_tax = get_query_var('game'); echo $current_tax; ?>
First of all, what you're calling $current_tax would more appropriately be named $current_term. The taxonomy is 'game'. Secondly, what you're trying to do is basically adding term metadata. There already are several plugins that provide the custom table and functions for that. I recommend Simple Term Meta.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom taxonomy, mysql" }
List top 5 authors with most posts How are you? I have a blog which have 20 authors. I want to write code to show the 5 author who have more posts. like this: Adam (10 Posts) Khal (8 Posts) Yous (5 Posts) Moha (3 Posts) Yousef (1 Post) but I don't know how can do it that
Are you using WordPress 3.1+? There's a nice `get_users()` function that'll do the trick! However, you will need a little magic to boot: add_action( 'pre_user_query', 'wpse_11832_pre_user_query' ); /** * Adds "post_count" to the SELECT clause. Without this, the "post_count" * property for users will be undefined. * * @param object $wp_user_query */ function wpse_11832_pre_user_query( $wp_user_query ) { if ( $wp_user_query->query_vars['orderby'] == 'post_count' ) $wp_user_query->query_fields .= ', post_count'; } And example usage: <?php foreach ( get_users( 'order=DESC&orderby=post_count&number=5' ) as $user ) : ?> <?php echo $user->display_name; ?> (<?php echo $user->post_count; ?> Posts) <?php endforeach; ?> **Important** : You _must_ order by `post_count`, otherwise it will be undefined.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 0, "tags": "customization, users, page template" }
restricted rss feed One of my wordpress blog is protected by the wordpress password plugin. however, I would like provide rss features. I found how to configure wordpress plugin to make rss work. But, by default, it seems that all the content of a post is sent by the feed. I would like to limit the information available by rss. Ideally, I would like to provide only the title of a post by rss. I have pictures and video (by vimeo) that have not to be available by rss ! Any help ? Thanks
I have found two solutions : 1) First one, very easy, just select _summary_ in the feed options of wordpress. Since this option is activated, neither pictures nor videos are displayed. 2)The second one is adding this piece of code in your theme's functions.php add_filter('excerpt_length',create_function('$a','return 0;')); ref : < With this solution, only the title of each post is available by rss ! Exactly what I want !
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "rss, password" }
Calling multiple scripts using wp_enqueue_script I'm trying to call multiple JQuery scripts using wp_enqueue_script. The call to JQuery works perfectly but the second call to cufon doesn't. I'm not a php or javascript expert - could anyone lend a hand, is there a best practice method for this? function my_init_method() { if (!is_admin()) { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', ' wp_enqueue_script( 'jquery' ); } } add_action('init', 'my_init_method'); function my_init_method2() { if (!is_admin()) { wp_deregister_script( 'cufon' ); wp_register_script( 'cufon', ' wp_enqueue_script( 'cufon' ); } } add_action('init', 'my_init_method2');
I'm not good at this, but it could be because Cufon is not included in Wordpress? So, you are deregistrating a script that is not included.. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "jquery, wp enqueue script" }
Different size video display for category page (smaller) & detail page (larger) I have a 'media' category page that pumps in videos / image galleries. I'm looking to have a smaller size video display (vimeo / youtube) on the category page, and the full size video on the single page. How do I change the size of the video embed on the fly for the both scenarios? Here's the loop for selecting anything in the "videos" category. <?php $videos = new WP_Query('category_name=video'); ?> <?php while ( $videos->have_posts() ) : $videos->the_post(); ?> <?php the_content(); ?> <?php endwhile; ?> Videos are entered into the post's main tinymce content editor. Am I being to vague?
The best solution here is to use the built-in filter for embed parameters: <?php function mytheme_embed_defaults( $defaults ) { return array( 'width' => 100, 'height' => 100 ); } add_filter( 'embed_defaults', 'mytheme_embed_defaults' ); ?> This code can be added to your theme's functions.php file and you can change the numbers to reflect the sizes that you desire. You can add conditionals as needed. Maybe something like: <?php function mytheme_embed_defaults( $defaults ) { if ( is_category() ) { $defaults = array( 'width' => 100, 'height' => 100 ); } return $defaults; } add_filter( 'embed_defaults', 'mytheme_embed_defaults' ); ?> Would work best for you.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "categories, functions, oembed, videos" }
Loading a remote WP website to Netbeans I have a Worpdress blog on a hosting company (it's remote and existing). I would like to load it to Netbeans. How do I do that? Thanks,
1. File > New Project 2. Categories select 'PHP' 3. Project select 'PHP Application from Remote Server' 4. click 'Next' and give the project a name and specify where local/downloaded files will be stored. 5. click next 6. Enter Project URL, and upload path on remote server (this probably be just / if WP is installed at root of the domain) 7. Here you'd need to specify how you will be connecting to remote server. Click 'Manage' button next to 'Remote Connection' 8. click 'Add' button to create a new remote connection and enter all the FTP/SFTP details and click OK 9. Click next until the end of the wizard
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "netbeans" }
Remove path from the create/edit a post view Been fiddling around, trying to remove the "path" info that's shown when you create/edit a post in wordpress. Been able to remove word count and the saving draft info, but not the path thingie This is what I'm talking about: < Also, the autosave-info that shows up on posts that's being edited. "Last edited by admin" etc. Can't seem to find that either. Any ideas?
Use the filter `tiny_mce_before_init` to customise the default configuration; function wpse_11867_tiny_mce( $config ) { $config['theme_advanced_path'] = false; return $config; } add_filter( 'tiny_mce_before_init', 'wpse_11867_tiny_mce' ); Check out all the options available on the Tiny MCE documentation.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "visual editor" }
Is disabling test_form in wp_handle_upload a security concern? I'm writing a plugin that modifies the default behavior when uploading a file for a post or to the media library. I'm setting $overrides in wp_handle_upload() with a custom $unique_filename_callback. Once I added that, it tripped the following check inside wp_handle_upload(), because $_POST['action'] wasn't set. (I'm not sure why it wasn't, but it wasn't). if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) ) return call_user_func($upload_error_handler, $file, __( 'Invalid form submission.' )); So, I set $overrides['test_form'] = false, and now it's working. I'm wondering if that could be a potential security issue, though. Would that allow someone to post a form from a remote source or something? It seems like it's normal to disable it when you're creating your own upload fields, but I'm using the built-in post upload form, so I want to make sure.
I wouldn't say security _concern_ \- since you're using this plugin within the admin (I presume after the user has been authenticated i.e. after `admin_init`), then already you've got protection against any Jon Doe posting a form to your script. What it _does_ provide, is an additional layer of authentication. All it really boils down to is sending a 'secret' along with the form, and then checking for it's existence (and that it matches) before continuing. For an attacker, they'd need to know this secret in order to breach, for example, using CSRF or XSS. This is the very nature of how WordPress nonces work. In fact you'd be a lot better off using these **instead of** test_form. They go one step better in that they're secrets that **expire** , so the window for an attacker is made even smaller. Check out Jaquith's article on Nonces.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugin development, security" }
making posts linked outside of Wordpress still use the same header and footer I set up my blog so that some of my posts get linked to a page outside of Wordpress. For these posts that get linked outside of Wordpress, I'd like to still include my header and footer so the page looks like it's still a part of my site. What would be the best way to do this? I tried adding `<?php include("/path/to/header.php"); ?>` and `<?php include("/path/to/footer.php"); ?>` but obviously it wouldn't work since my header and footer files contain Wordpress conditional tags.
You'll either need to load in _WordPress_ , which can be considered computationally expensive if your 'other' pages are also powered by another webapp (not to mention the conflicts it may bring). If they're just regular PHP files, you should be OK. To load WordPress, include the file `/path/to/wordpress/wp-load.php`, then you'll be able to use WordPress as you would normally, including things like `get_header()` and `get_footer()`. _However_ , whilst perhaps not the most 'compact' solution, my best advice would be to create header and footer files for these other pages that replicate the HTML of your theme without WordPress-specific PHP functions, and include them instead.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "headers" }
Need To Resize Images Exactly Without Losing Image Details I am working on a Wordpress site that heavily uses image uploading and whatnot, I have defined the image sizes in my functions.php and I have hard crop mode turned on which ensures that my images are always cropped to the exact size that I want. The problem with hard cropping is that peoples faces in images and other artefacts are cropped out and the images look ridiculous. Is there a way to have soft cropping mode turned on and have images always be an exact size? I find that when I use soft cropping mode, images vary in height and width. So an image I want to be 110x110 in soft crop mode can vary and sometimes be 110x96 or whatever and because that makes the layout look crappy and some photos look landscape, what is the best way to solve this issue?
It depends on the source image, aspect ratio is not magic, it must be maintained in order to lessen the proportional distortion. You best option is to upload images that will maintain the same aspect ratio. You can tweak your CSS to get a more consistent image size but be aware that doing so will create distortion the further it moves away from the proper aspect ratio.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, images" }
Highlighting the current page in a navigation menu which links are generated with a custom loop? This is a second navigation menu I'm using: <ul id="forums"> <?php $custom_posts = new WP_Query(); ?> <?php $custom_posts->query('post_type=bbp_forum'); ?> <?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?> <li><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></li> <?php endwhile; ?> </div><!-- #access --> Is a custom loop which list a custom post type called Forum. I would like to highlight the current Forum link, like this: !enter image description here Any suggestions?
So, if I understand correctly, when you're on a single post page, you want to have a navigation menu with all the posts of post_type bbp_forum. I had a similar case (without the post_type, but it's not a problem to add it), and I used code that I found that talked about posts of same category, on single post pages. The code goes as follows (with customization for post_type): <ul> <?php global $post; $cat_posts = get_posts('post_type=bbp_forum'); foreach($cat_posts as $post) : ?> <li <?php if($post->ID == get_the_ID()){ ?>class="cur_post" <?php } ?>> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); rel="bookmark"?>" ><?php the_title(); ?></a> </li> <?php endforeach; ?> </ul> I hope that's what you meant. P.S - I also see that you have an opening <ul> tag, but a closing <div> tag....
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "css, navigation" }
get_site_url is not returning anything? I'm using the twentyten theme with the bbpress plugin. I have the following in my header.php (twentyten): <div id="masthead"> <div id="branding" role="banner"> <h1><a href="<?php get_site_url(); ?>">TaiwanTalk</a></h1> </div><!-- #branding --> <div id="access" role="navigation"> <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?> </div><!-- #access --> </div><!-- #masthead --> `get_site_url` doesn't return anything. Any suggestions?
The functions that start with "get_" return the value to what's calling it. So you would do `<a href="<?php echo get_site_url(); ?>">` instead to print out the URL.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "urls, links" }
With get_posts(), how can I put a category as a variable I'm a noob at this so please bear with me. I have the following code to return post title as links within categoryID 6, which is working fine: <?php global $post; $cat_posts = get_posts('numberposts=10&category=6'); foreach($cat_posts as $post) : ?> <?php $postTitle = get_the_title(); if($title != $postTitle) :?> <li><a href="<?php the_permalink(); ?>">&rsaquo;&rsaquo; <?php the_title(); ?></a></li> <?php endif ;?> <?php endforeach; ?> However, the category ID is a variable, e.g. $catID, can I use this in the above code? Thanks in advance!
Have you tried the following code? $cat_posts = get_posts('numberposts=10&category='.$catID);
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "get posts" }
How to auto-upgrade my plugin? How do I have my plugin pop up with that `New version available. Upgrade Automatically` dialog to appear when my plugin has a new version? Specifically for plugins not hosted on the WP.org repository.
This library integrates auto-updates for privately hosted plugins. Looks great.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "plugin development" }
Move title "meta box" in post mode I've created a custom post type with my own custom meta boxes. Now I want to move the title box to the side or simply remove it and place the same content in a custom meta box. How do I go about to do this? Thanks
When you register your post type, use the `supports` argument to explicitly set which core meta boxes to use. register_post_type('my_type', array( 'supports' => array( 'editor' ) // if "title" isn't in this array, it won't appear on the edit post page // other arguments ));
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, metabox" }
Adding a post shortcode to a page template? hey guys, The "mingle forum plugin" provides the following shortcode [mingleforum]. When I paste this into a page the forum is shown. My forum is using a specific page-template called forum.php. Is it possible to already include this shortcode in the page-template itself, so I don't have to paste it in the wordpress backend anymore. So that when I use the forum.php page template the forum is always automatically embedded? Thank you for your tipps and info.
To use shortcode in a PHP file (outside the post editor) you have the handy little function do_shortcode(); so in your case you use: <?php do_shortcode('[mingleforum]'); ?> ## Update: following the first comment, I figured its publicly known for some reason, **if you are expecting output from the shortcode then echo it out**. <?php echo do_shortcode('[mingleforum]'); ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugins, php, page template" }
Is it possible to uninstall one plugin from within another plugin? I'd like to be able to automatically uninstall certain plugins if they're detected (specifically Akismet and Hello Dolly), either by writing another plugin to do so or via my theme's functions.php file. Is that possible?
Sure, just call the delete_plugins() function, found in `wp-admin/includes/plugin.php` \- you have to manually require() it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, uninstallation" }
How to get the parent's taxonomy? * I have 2 customs post type : "Artist" and "Concert", * the "Concert" custom post type is the child of the "Artist" custom post type, * the "Artist" custom post type has a "genre" taxonomy. What I'm trying to do (for instance): list all the concerts which belong to artists of the "pop" genre. Here is the query of my dream: `SELECT * FROM posts WHERE post_type = "concert" AND **post_parent_term** = "pop"` I think currently there is no such thing as **post_parent_term** , hope I'm wrong ... (I know i can add the "genre" taxonomy to the "Concert" custom post type and voilà! But I'm really curious to know if there is another way to achieve that). Thanks by advance.
> What I'm trying to do (for instance): list all the concerts which belong to artists of the "pop" genre. You can do it in two steps: // 1. Get all the pop artist IDs $artist_ids = get_posts( array( 'fields' => 'ids', 'post_type' => 'artist', 'genre' => 'pop' ) ); // 2. Get all the concerts associated to those artists $artist_ids = implode( ',', array_map( 'absint', $artist_ids ) ); $concerts = $wpdb->get_results( " SELECT * FROM $wpdb->posts WHERE post_type = 'concert' AND post_status = 'publish' AND post_parent IN ({$artist_ids}) ORDER BY post_date DESC " ); There's a post_parent argument in WP_Query, but it doesn't accept an array, hence the direct query.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom post types, custom taxonomy, query posts, taxonomy, wp query" }
Is there a need to do apply_filter('widget_title', $instance['title']) or any other 'widget_xxx' filters? I am reading the book Professional Wordpress, and have code like $title = apply_filters('widget_title', $instance['title']); $name = apply_filters('widget_name', $instance['name']); ... I wonder if there really are filters like `widget_xxx`? What do they do?
For example, it makes them editable using the Front-end Editor plugin. All the cool widgets are doing it: <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "plugin development, widgets" }
How can I develop a plugin that generates a page dynamically I want to develop a plugin that generates a page and embeds the page link in pages menu in the client part at the time of plugin activation. Please help me with this.
You can create the page using wp_insert_post() and make sure you send post type as 'page'. and if the user nav menu uses wp_list_pages the page will be added to the nav menu automatically and to run it on activation you can have you plugin check if it exists and save its id so it will only create it once. $my_page = get_option('my_plugin_page'); if (!$my_page){ // Create post/page object $my_new_page = array( 'post_title' => 'My page', 'post_content' => 'This is my page content.', 'post_status' => 'publish' ); // Insert the post into the database $my_page = wp_insert_post( $my_new_page ); update_option('my_plugin_page',$my_page); }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugin development" }
how can i add an array of post types to this query? `$pp = new WP_Query('orderby=comment_count&posts_per_page=4'); ?>`
$pp = new WP_Query(array( 'post_type' => array( 'post', 'custom_type' ), 'orderby' => 'comment_count', 'posts_per_page' => 4 ));
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types" }
extra post fields for url + youtube video / implementation i'm using wordpress v3.1 and i'm requiring 2 extra fields for external url + youtube-link. is it possible? in case it's not - i was considering using own tags for the post-content and filter it out. btw. what's the easiest way to implement youtube videos (via link) directly into the post? thx
< Is a post I wrote the other day about adding meta boxes. I use it to put links in to change the link some of my post titles use. I'm not sure if this is what you are looking for exactly, as I'm not quite sure what you mean by 'extra fields'
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "custom field" }
Wordpress Plugin Look & Feel Is there a list of the ID's and Classes I can give HTML elements in the admin panel in order to closely mimic the wordpress look and feel?
Onextrapixel's blog post How To Design And Style Your WordPress Plugin Admin Panel isn't an official reference, but it is a nicely detailed one.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "plugins, admin, css, design" }
Get_the_terms restrict output I have a custom post type Holiday associated with a taxonomy Country. On my single-holiday.php, I use the taxonomy to display in the title. For example Holiday in Spain (Spain being the tax) Rarely, but it can happen, a holiday can be in 2 taxonomy terms. Creating a problem for my title display as I use get_the_terms. Somebody has better solution for me. My code is as follow $taxonomy = 'country'; $terms=get_the_terms($post->ID,$taxonomy); if($terms) { foreach( $terms as $termcountry ) { ?> <h1>Holiday in <?php echo $termcountry->name;?></h1>}}
you can change you code a bit : $taxonomy = 'country'; $terms=get_the_terms($post->ID,$taxonomy); if($terms) { echo '<h1>Holiday '; $total_count = count($terms); $country_count = 1; foreach( $terms as $termcountry ) { if ($country_count = 1){ echo 'in '.$termcountry->name; }else{ if ($total_count = 2){ echo ' And '.$termcountry->name; }else{ echo ', '.$termcountry->name; } } $country_count = $country_count + 1 ; } echo '</h1>'; } This will output in case of one term: <h1>Holiday in Spain</h1> in case of two terms: <h1>Holiday in Spain And Japan</h1> and in case of more then two terms: <h1>Holiday in Spain, Japan, England</h1> hope this helps
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, posts, customization, terms" }
Internet Explorer "Security Information" on every page in https site My site is using a short vanity URL and https (for admin logins). This is working across all of the custom theme pages in every browser except Internet Explorer. Specifically in IE7, every page I visit in the site presents this warning message: > Security Information This page contains both secure and non-secure items. Do you want to display the nonsecure items? Do you think the site being https is causing this? Anything I can do to fix this?
Yes, your page(s) are loading images, CSS, or JS files that are called in the HTML via non secure mode (http versus https). Install the Firebug extension on your Firefox browser and look at your URLs that are loading in network tab. Screenshot: < Or you could use Pingdom tools to see what URLs are being loaded. Example: I think you'd have to edit your posts/pages, theme files to specifically call https:// for images, css, and js files.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "https" }
How do I echo the post type? `<?php $post_type = get_post_type( $post->ID ); if $post_type == 'project' : echo 'Work'; ?>` How can I make the above work? I want it so that if the post type is 'projects', then it echoes 'Work'. Also, I want to add another `if post type is 'movies' then it echoes 'Film'` on top of that.
Well, as far as I can tell you've got a syntax error there. Try this: <?php $post_type = get_post_type( $post->ID ); if ($post_type == 'project') echo 'Work'; ?> Also, make sure to check out what eileen.carpenter said in the comment to your question.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "custom post types" }
Featured image/thumbnail fallback placeholder image I'm currently using the_post_thumbnail(); to display featured images in my pages. Is it possible to set a fallback placeholder image in the event a featured image hasn't been set?
You can use `has_post_thumbnail()` as condition and change output accordingly. Example from Codex: if(has_post_thumbnail()) { the_post_thumbnail(); } else { echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />'; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "post thumbnails" }