INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
What is the best way to create a menu item that links to all posts with a certain tag?
I guess the title says it all. Short of creating a page with a custom template that links all the posts with a given tag (this is NOT a scalable solution, particularly if you want to let a customer do this), how would you add a menu item that takes you to a tag archive?
|
When setting up custom menu click `Screen Options` (top right, near `Help`) and check `Post Tags` there. You will get metabox that will allow to add links to tag archives as menu item.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "tags, menus"
}
|
How does WordPress handle permalinks?
WordPress auto corrects the permalinks(URLs) even if it is entered incorrectly. For e.g. WordPress will land you in `example.com/some-post` even if you enter `example.com/idontexist/some-post` or even `example.com/some`
It could be that, WordPress uses RegEx like or some matching algorithm that compares from right to left and if it finds a match, it will take you to the page even if there are `/.*/` left on the left. Just a guess! How does WordPress do this?
Edit: I also noticed that the .htaccess file checks for virtual file/directories using `!f` and `!d` and redirects the request to index.php on the blog folder.
|
The redirect_canonical function in /wp-includes/canonical.php is called on any given URL and will attempt to best-guess the URL the user wanted, and redirect them to there, when a URL does not exist. It has a whole huge amount of code to do this for all sorts of common errors.
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 11,
"tags": "permalinks, url rewriting, redirect"
}
|
How to store post meta in an array?
What is the best way to store post meta in an array (using a custom write box, know how to do that) so that all post meta is in a single custom field?
|
From codex:
> $meta_value (mixed) (required) The value of the custom field you will add. An array will be serialized into a string. Default: None
So `<?php add_post_meta(7, 'fruit', 'banana', 'apple', 'tornado', 'bob saget')`
To grab them you can also use <
besides just `get_post_meta`.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "post meta, array"
}
|
How do I add a custom taxonomy as an option for menus under "Appearance" > "Menus"
I've created a custom taxonomy and I want to add it as an option for custom menus (under Appearance > Menus). How do I get it to show up there (see the illustration, I want it to show up where the red square is).
!enter image description here
|
Your custom taxonomy should show up as an option for custom menus, if you have
'show_in_nav_menus' => true
as a parameter when you register your post type with `register_post_type()`. You can check all the available parameters in the codex entry <
|
stackexchange-wordpress
|
{
"answer_score": 13,
"question_score": 7,
"tags": "custom taxonomy"
}
|
Instead of 4 loops, how can I do it better?
I want to grab all posts from an author under category X. Right now, I am using 4 separate loops to do this for 4 different categories. Is there a better way to do this? `query_posts`
|
Have a look at the category parameters of WP_Query
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "query posts"
}
|
What's the best way to include PHP code in pages?
I'm currently creating a bunch of (empty) pages and performing conditionals such as `is_page('Blabla')` on it, which increases my page.php significantly. I'm already using `require_once` for different content, but is there a cleaner way of doing this?
|
Wordpress has a function for including template parts, which you can use for that purpose : get_template_part
You can also use `include(TEMPLATEPATH . '/includes/myfunction.php');`
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "php, pages, include"
}
|
oEmbed, thumbnails and wordpress
Wordpress has wp_oembed_get, which I use to get rich media content with embed.ly. I've previously used oEmbed api calls such as this. As you can see it provides thumbnail_url, which I like to use instead of embedding the video. How can I do this with wordpress?
Thanks!
|
Use the oembed_dataparse filter to modify the resulting HTML output by any given oembed call.
Example:
add_filter('oembed_dataparse','test',10,3);
function test($return, $data, $url) {
if ($data->provider_name == 'YouTube') {
return "<img src='{$data->thumbnail_url}'>";
}
else return $return;
}
Then putting this in a post:
[embed]
Will give you a picture of Rick Astley instead of a flash video of him. :)
Edit: Note that WordPress caches oEmbed results in postmeta. So after making your code, you'll have to go and Update a post for it to know to go re-get the oEmbed data and have code like this take effect. In case you want to do testing and such.
|
stackexchange-wordpress
|
{
"answer_score": 9,
"question_score": 5,
"tags": "post thumbnails, oembed"
}
|
display 20 lines only with the_content
I like to display only 20 lines of post with the read more link using
the_content( __( 'Continue reading <span class="meta-nav">→</span>' ) );
But it shows full content . How can i strip it .please help me !
|
You need to add a more quicktag to your content
See here: <
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "theme development, theme twenty ten"
}
|
Sort "get_pages" by menu order not ordering
I'm using this bit of code to generate a page full of items but they won't sort into the menu order, any ideas as to why?
<?php $pages = get_pages(array('child_of', 'menu_order')); ?>
|
It should look like this:
`<?php $pages = get_pages( array('sort_column' => 'menu_order') ); ?> `
|
stackexchange-wordpress
|
{
"answer_score": 11,
"question_score": 4,
"tags": "get posts, pages"
}
|
Create anchor from Wysiwyg editor
Is there any way to create internal anchors without using the HTML rendering option? I don't mind but I guess my customer will ;)
Thanks!
|
In the "tinyMCE Advanced" plugin has a special icon for that. The default WordPress installation don't offer the anchor icon/attribute editor.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "links, wysiwyg"
}
|
Can I set the post_type query_var as a link is clicked?
I have 2 custom post types that use some of the same taxonomies. I would like to be able to show all entries in the taxonomy ( no problem here) and then just each of the post types. But I would like to do it without creating a mess of custom pages using a template.
Can I set up a function to change the post_type query_var when the link is clicked? SO if I had a set of navigation links in my left sidebar, the set to 'designer' post type would set the post_type query_var to 'designer'. The same would need to happen for the 'boutique' post type navigation links.
I think I may need to use some javascript but am unsure. Is this possible? I'm not an expert by an means but I believe this MIGHT be possible,
Thanx in advance!
|
You can use `pre_get_posts` filter hook to set the post type passed by the user:
paste this code in your theme's functions.php file:
function user_set_type( $query ) {
//only on your taxonomy page
if ( $query->is_tax('YOUR_CUSTOM_TAXONOMY') ) {
//and only if the guesst has selected a type
if (isset($_GET['UTYPE']) && !empty($_GET['UTYPE'])){
$query->set( 'post_type', $_GET['UTYPE'] );
}
}
return $query;
}
add_filter( 'pre_get_posts', 'user_set_type' );
Change `YOUR_CUSTOM_TAXONOMY` to the name of your taxonomy, then on your taxonomy page or widgets all you need to do is create links with the post_type as parameters in them eg:
<a href="<?php echo get_permalink() . '?UTYPE=designer"; ?>">Designers</a> - <a href="<?php echo get_permalink() . '?UTYPE=boutique" ?>">Boutiques</a>
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "custom post types, custom taxonomy"
}
|
Saving data to database and exporting to excel
I'm creating a form in a blog for users to register their emails so I can send a newsletter later but I don't want to use any newsletter plugin for that.
I'd like to save the emails and than export them to something else like excel or a cvs file.
Is there any plugin or any other solution to do that?
|
You have some options:
* the cformsII plugin, with tracking enabled
* the Contact Form 7, plus the Contact Form 7 to Database Extension
other may be suitable as well!
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "database, forms, export"
}
|
Do you have to have command line access to use Subversion with Wordpress?
My group does not have command line access to the machine that is running our WordPress instance. However, we would still like to install/update using Subversion. Is this possible? Also, does Subversion need to be on the same machine?
|
You would need to have subversion installed on the same machine and command line access to the machine.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "svn, command line"
}
|
Link to Particular Page Within Template PHP Code
I want to simply create a link to a page that I know the title (or ID), but I want to make sure it works on any Wordpress install. What is the best way to do this?
|
You probably want to use get_permalink and get_the_title. Example:
<a href="<?php echo get_permalink( YOUR POST ID ); ?>"><?php echo get_the_title( YOUR POST ID ); ?></a>
Replace YOUR POST ID with the ID of the post you'd like to link to. Post ID's will change from install to install, however, so this might not work as expected.
<
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "pages, permalinks"
}
|
File Upload with Server in safe_mode
When I try to upload an image to a post, I get an error:
"The uploaded file could not be moved to /home/httpd/xxxx/xxxx/xxx/wp/wp-content/uploads."
My server is set up in safe_mode - is that the problem? What can I do about it?
|
It has nothing to do with safe_mode try this:
* login to your ftp
* make your wp-content folder 755
* inside wp-content create a new folder called "uploads", make it 777 (755 should also work)
* inside the control admin panel, go to settings>miscellaneous and on the first line enter "wp-content/uploads" as where your uploads will go to.
Save and go try !
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "php, uploads"
}
|
Is there a template tag/function for getting the URL (or slug or name or ID) of the blog page when using a "static" front page
Done some reasonable searching for this and don't think it's been asked before.
I've got a site which I'm developing a custom template/theme for. The site will use a page as the front page (rather than the list of posts), but I want to create a link in the template to the page of blog posts.
There are some functions for finding various URL's like site_url() and admin_url(), and, of course, there's bloginfo(), but I can see anything that will get me the name/slug/URL/ID of the page used as the blog page.
I'm sure I've seen this somewhere before but can't track it down now that I need it.
Any ideas?
Thanks RW
|
<?php $blog_link = get_page_link( get_option( 'page_for_posts' ) ); ?>
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "pages, blog"
}
|
Multisite - getting a 404 for additional site created using subdomain install
I created an additional site on my multisite subdomain installation. Now when I try to visit the new site or its wp-admin, I get a 404 error.
My wordpress instance is hosted on AWS
Checked the following
* AllowOverride is set to All in httpd.conf
* contents of .htaccess are the same as those in Network settings
* added the necessary statements to wp-config.php
* Tried restarting httpd as well
What else could I be doing wrong?
Thanks.
|
You need to set a wildcard serveralias in that site's virtualhost declaration. Right under where it says `ServerName example.com` you should add another line like this:
ServerAlias *.example.com
You might have already done that, but it was the only thing missing from the list of things you had checked.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "multisite, subdomains"
}
|
Wordpress Copyright Dillema (i.e. Powered by)
> **Possible Duplicate:**
> Removing the "Powered by WordPress" Link?
i have a bit odd question but here it goes: Due to page styling issues with the copyright logo, i deleted the whole div that says: "Powered by Wordpress (logo)". Now due to my SEO plugin, the source doesn't include the meta-generator tag. Now am i in violation of the Wordpress License, or im ok (although i do look irresponsible)?
|
There is no requirement to retain the "Powered by WordPress" note in the footer or the WordPress reference in the `<meta>` tags in your header. There is nothing in the WordPress license (GPL) that requires these remain intact.
To take things a bit further ... the "Powered by WordPress" tag in the footer is added by your _theme_ , not by WordPress itself. And the `<meta>` tag in the header is pluggable specifically to make it easy to remove.
|
stackexchange-wordpress
|
{
"answer_score": 11,
"question_score": 5,
"tags": "licensing"
}
|
WordPress built-in method to extract array of term IDs?
I'm querying a custom taxonomy for a post, hoping to get a list of all terms for that post and taxonomy. `get_the_terms($post_id, $taxonomy)` works, but gives this ungodly array of term objects that will require an extra layer of parsing before I can run the following code:
`if (in_array($list_of_term_ids, $my_term_id)){ do good stuff... }`
I'm looking to see whether anyone has come across a native WP function or method that extracts term ids into a flat list before rolling my own utility function, just so I can be using built-in best practices.
|
Well, I had seen it and was thrown off by the first argument, but it does exactly what is needed. From wp-includes/taxonomy.php:
`function wp_get_object_terms($object_ids, $taxonomies, $args = array())`
And to use it as I wished, giving me a flat list of matching IDs, push 'fields'=>'ids' into $args, like so:
`wp_get_object_terms($post_id, TAXONOMY_NAME, array('fields'=>'ids'));`
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "taxonomy, terms"
}
|
What are WordPress installation percentages by version?
I'm in the process of developing a plugin, and I'd like to figure out which versions of WordPress to support. But to get a good idea I'd need to know what percentages of old Wordpress versions make up the install base. Does such information exist?
Alternatively if such information doesn't exist, does anyone have a suggested version I should support my plugin back to?
|
There's a page in the Codex that shows exactly that:
* WordPress > About » Statistics
But really, it all depends on what features you're using. A safe bet for a new plugin would be to support WordPress 3.1.X and above (since that's the current stable release). You're setting yourself up for a lot of hurt if you try to do too much backwards compatibility work.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "plugins, wordpress version"
}
|
Creating an option for writing a post without an author attribution for a group blog on Wordpress
I'm developing a group blog on wordpress (first time working with it) and the client has requested that a 'None' option be added where an item can be posted without a "by" attribution. So basically there would be one article / excerpt template for attributed author's posts and another for the none option where the byline would just be the date posted without the "by [author name]." Is this possible with wordpress?
Thanks!
|
This is entirely possible. Though, I would recommend using the Post custom metadata (i.e. custom fields, or better yet, a custom metabox).
I would use a custom metabox, with two radio select options:
Byline:
(*) Author
( ) None
Then, in your template file, you can output the author byline only if the appropriate post_meta key has the appropriate value. If you want to get really fancy with it, you can even use the post_meta key/value to customize the Loop for your Author archive index output, so that Posts indicated not to display the byline don't output in the Author's archive index.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "custom post types, theme development, author"
}
|
Cannot Access Console
< I can log into the site. When I try to access the WP console I get the following error: PHP Fatal error: Call to undefined function is_site_admin() in D:\websites\bigpicturepartnering\wp-content\plugins\wordpress-related-posts\related-posts.php on line 81
How can I get into the console to disable the plugin?
|
Using the FTP client of your choice, go to `wp-content\plugins\`, and delete (or move) the `wordpress-related-posts` directory.
By the way: what version of WordPress are you using? And is this a local install or a live site?
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "plugins, php"
}
|
Upload image through URL?
I'm trying to create a custom form which takes an image (offsite) and attaches it to the post so I can use it as a thumbnail in the loop. I've been looking at media_handle_upload but that appears to only be working for content that's locally uploaded.
Ideas?
Thanks, Dennis
|
When you link to an external image, WordPress will reference the external URL. `media_handle_upload` is meant to handle uploaded images that are now living on your server. So unless you're telling the server to download the image from the external source and save it on your server, `media_handle_upload` won't apply.
It sounds like you're building your own custom importer. I recommend you take a deeper look at the process. A typical upload:
* User selects file from local system
* File uploads through form to $_POST variable
* WordPress takes file out of POSTed form, runs it through `media_handle_upload`, and stores it on the server
If you're referencing an offsite image and attaching it to the post, WordPress won't do steps 2 and 3. You'll need to add your own scripts to grab the remote image and store a copy locally.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "post thumbnails, uploads"
}
|
How To Detect Posted Comment in Theme Development?
A theme normally posts to wp-comments-post.php when someone leaves a comment. When successful, it does a redirect to the page again but tacks on "#comment-" into the URL. What I was wanting to do was leave a message, "Your comment awaits moderation, which takes about 24 hours." Sure, I can intercept location.href and see if it contains "#comment-" in it, and show the moderation message then. But there are other ways one can click on a page and "#comment-" gets shown, which makes this a visual quirk, not the way I intended it.
What's an easy way to make a WordPress theme detect that a comment was just posted and redirected back to the page?
|
The easiest and most straight-forward way is to put appropriate code in your `wp_list_comments()` callback, that outputs a message if a comment is awaiting moderation.
The usual code looks something like this:
<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Your comment is awaiting moderation.') ?>
Otherwise, if you're not using a callback, you can hook into an appropriate action hook, such as `pre_comment_content`, to inject the same content.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "theme development, comment form"
}
|
WPML & CFT: keeping custom field file to translation
i got a wp site with the WPML plugin and the CFT plugin. I set up custom fields for posts and what i'm trying to do is to keep the content of an `input type file` from the original post to its translation. That would save time as the pictures are the same between both posts and also save disk space on the ftp.
So far i couldnt get it working, not even to get basic `input type text` automatically pasted from the 1st post to its translation. I tried the different options in WPML > Translation management > Mutlilingual content setup > Custom fields translation without any result.
PS: am using WP 3.1.3, WPML 2.0.4.1 and CFT 1.9.2.
|
The latest version of WPML (version 2.3) has a new module for Media and this module takes care of the previous images issue. Now there is no longer the need to upload the same image twice.
Just like copying the content from the original language, it is now also possible to duplicate the images and/or the featured image: !enter image description here
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "custom field, plugin wpml"
}
|
wordpress on localhost lamp doesn't let me install plugins
i've installed a LAMP server on my ubunutu 11.04. i've installed wordpress and hooked it right with the MySQL db. i've changed the permissions of the www-data group to read and write files.
every thing is seems to work and i can manage the site through the admin panel, but i can't install plugins cause the system is asking me the FTP details, and i can't seem to go through it.
can any body help? please...
|
I usually do this when that happens (only locally, not for production) :
chown -R nobody:nobody /path/to/wordpress
|
stackexchange-wordpress
|
{
"answer_score": -1,
"question_score": 19,
"tags": "plugins, installation, ftp, localhost"
}
|
What happened to my Inactive Widgets?
I have purchased the DynamiX theme, and I'm trying to use it for the first time.
I was looking at the widgets, and I saw some neat customized (Dynamic maybe?) widgets in the Inactive Widgets section. I was going to drag one to my Sidebar, but accidentally dropped it, and now it is gone. Is there any way to retrieve those? I don't even know exactly what it was, I just know that it was part of my theme.
I'm pretty new to Wordpress, so please bear with me.
Thanks in advance!
|
Inactive widgets are just normal widgets from the "Available widgets" list, which have been put in the "Inactive" section in order to keep the data they contained.
What probably happened is that you dropped one of them over the "Available widgets" space and it dissapeared. But don't worry that doesn't mean that the widget is gone, widgets cannot "dissapear", in the worst case you just lost the data of the widget.
For example if you have a text widget in your colum, with the title "My cool widget" and the text "Hey check this out", and you decide to temporarly remove it from your website, but wish to keep the text data, you would drop it to the "Inactive" space. You can then drop it back whenever you wish to use it again with the same text. BUT, if you remove it completely, then there will always still be the "Text" widget available in the upper space "Available widgets".
Hope that helps.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "themes, widgets"
}
|
archive as a page, so that it can be added in the wp_menu_nav
` is a custom post type.
my question is how to display ` as a page and not an archive?
my goal really is just for it be added to `wp_nav_menu`.
I have created a page named `lyrics` but it won't direct me there. Instead it brings me to `archive.php`. With that, the `lyrics` in menu, don't have the `current-menu-item` class.
|
Look for this in the code where you registered the lyrics post type:
'has_archive' => true,
Set `'has_archive' => false`. That won't work right away, however. So you need to go in an "refresh" your permalinks. Just go to the permalinks options page, and hit the save button.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "custom post types, archives"
}
|
How to test custom rewrite rules /permalinks?
After much research, I think I can wrap my brain around WP's rewrite system. I would like to know, though, how to properly test rewrite rules to see if the right rule/tags is being used and the right query vars are being passed. Is there a way to create a temporary template that supersedes everything in a theme whose sole purpose is to spit out current query_vars?
|
Check out my favorite Rewrite Analyzer plugin written by @Jan Fabry. It allows you to analyze your rewrite rules and really helps in debugging those rules.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "permalinks, rewrite rules, rewrite tag"
}
|
WordPress Plugin Development from Scratch. How?
I would like to learn how to create a plugin from scratch, there are tons of tutorials out there on the internet, but they are either premium or not a reliable resource. would like to know which are the best resources available on the internet.
|
A very first advice from me will be: Don't follow the tutorials on the tutorial sites blindly they are full of bad coding practices.
Some of the resources that I follow:
* Mark on Wordpress
* Justin Tad Lock (You can also buy the copy of his e-book Professional Wordpress Plugin Development)
* Otto on Wordpress
* scribu's development blog
And here is the list of Specific tutorials that you should consider going through, some are old but are still valid.
* <
* <
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 5,
"tags": "plugins, plugin development"
}
|
Wordpress Post Deletion Issue
I have installed wordpress on one membership site and found that whenever editor writes post on wordpress and attempts to post it, deletes the half of post randomly. I don't know what could be the problem. I have already did my search within community forums here and here. These two threads explain the same problem that i'm having but none of the solutions are working for me. I also tried post revision plugins, sql query (for deletion of revisions), wp-config file modification and everything i could find on google. WP is just on spree of eating half the post no matter what.
Is there any solution for this ?
|
The issue is related with the server permissions. I asked my hosts support to fix this. I found that they somehow fixed the issue. Also i noticed that ciprian's answer helped some of my friends but i was unable to solve issue that way.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "posts, customization"
}
|
Which hook to use when adding ajax to viewer-facing side?
I have a shortcode that contains a form. I want to use jQuery/Ajax for POSTing. For this, I want to add javascript to the page where shortcode is added? Which hook should I use?
1. wp_enqueue_scripts
2. wp_print_scripts
3. wp_print_footer_scripts
|
You want to use `wp_enqueue_scripts`, but you'll probably first want to:
1. Loop through the Posts
2. Grep your shortcode
3. Enqueue the script, if shortcode is found
4. Rewind Posts
That way, you only enqueue the script where necessary.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "jquery, hooks, ajax, actions"
}
|
WP_DEBUG is not set, but I'm still getting warnings
If WP_DEBUG is not set, as I understand it, you should never ever see warnings. But on some sites on some servers, I'm still seeing a few. Not all the warnings that would be displayed if WP_DEBUG was set, but a select few.
I've tried changing the error level in php.ini, but that seems to have no effect on whether warnings appear or not, but they do appear in differing amounts on different servers (i.e. no warnings on development, one warning on staging, and a few more warnings on production).
|
WP_DEBUG has no impact on PHP error output. In addition to error_reporting setting, set display_errors=0 in your php.ini file. It's enabled by default for development. But you'll want it off on production servers.
|
stackexchange-wordpress
|
{
"answer_score": 11,
"question_score": 18,
"tags": "errors, warnings, wp debug, notices"
}
|
How to redirect a sucessful registration to a page template?
Each time I register I end up in the wp-login page (back-end):
!enter image description here
Is there any way of redirecting the users who register to a page template (front-end)?
|
You can use the filter `registration_redirect` to pass back your own URL, for example;
function wpse_19692_registration_redirect() {
return home_url( '/my-page' );
}
add_filter( 'registration_redirect', 'wpse_19692_registration_redirect' );
Drop it in your `functions.php` or a plugin :)
|
stackexchange-wordpress
|
{
"answer_score": 14,
"question_score": 5,
"tags": "redirect, user registration"
}
|
How to add a class to the comment submit button?
How do I add a class to the comment submit button? The simplified function `comment_form(array('id_submit'=>'buttonPro'));` obviously only changes the id and `class_submit` does not seem to exist.
I have read through both Otto's and Beau's writeups but to no avail.
|
If you check out the source of the function `comment_form()`, you'll see it doesn't even print a class on the input;
<input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
I'm guessing you need to add a class for styling? Why not modify your CSS to just;
input.submit, #buttonPro {
/* some awesome style */
}
Otherwise I guess the 'easiest' solution would be to simply copy the function to your `functions.php`, rename it, add in a class argument & print, and use that instead - which you can find here ;)
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 7,
"tags": "comments, comment form"
}
|
Custom Permalinks for Custom post Type Archives?
I know that WP 3.1 has added support for archives for custom post types but is there any way to customize the permalinks for them?
|
Take an example custom post type called `movie` the code below will create custom permalinks `awesomemovies/` regardless of the one created by using the has_archive and rewrite options of register_post_type.
add_filter( 'rewrite_rules_array', 'custom_permalink_for_my_cpt' );
function custom_permalink_for_my_cpt( $rules ) {
$custom_rules = array();
// for archive urls
$custom_rules['awesomemovies/?$'] = 'index.php?post_type=movie';
// for individual post urls e.g:
$custom_rules['awesomemovies/([^/]+)/?$'] = 'index.php?post_type=movie&pagename=$matches[1]';
return $custom_rules + $rules;
}
For more information see WP_Rewrite
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "custom post types, permalinks, archives"
}
|
Post Format Archive template name for theme folder?
What should I call the archive file for a post format? Ex archive-gallery.php? (doesn't work)
I would like to create a list of all the gallery formats with a preview and some custom taxonomies thrown in.
|
Well.... for querying, formats are a taxonomy parameter...so that should work.... <
Lemme loook...
And yep, here's how that works <
taxonomy-post_format-post-format-link.php
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 3,
"tags": "posts, archives, post formats"
}
|
Custom post type with custom taxonomy
My WP site has 2 custom post types, "Projects" and "People". There can be unlimited number of "People" per project and I'm thinking about a way to integrate the projects section with "People" section. My first impression was using custom taxonomies. But the problem is, is there a way to set a relationship between these 2? If custom taxonomy is the only way, is there a way to make it so when adding new people custom taxonomy get created as well?
|
As you haven't stated your requirements of People type and Project type. So I am assuming that you must have both as a post type. To create relations between them you can use @scribu's Post 2 Post relations plugin.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, custom taxonomy"
}
|
Prevent duplicate posts in wp_insert_post using custom fields
My source links are something linke this :
.
.
.
I cache content form links.I use wp_insert_post to post cached content from source site to wordpress:
$my_post = array(
'post_title' => "$title",
'post_content' => "$content",
'post_status' => 'draft',
'post_author' => 1,
'post_category' => array(1),
);
wp_insert_post( $my_post );
I want to put each link in custom fields and in the next cache , before post to WP , check new links with links in custom fields. If link is repeated , prevent insert content.
Sorry for my bad description.
|
To save the link in the post meta you can use `update_post_meta`
like this for example:
$url = "
$my_post = array(
'post_title' => "$title",
'post_content' => "$content",
'post_status' => 'draft',
'post_author' => 1,
'post_category' => array(1),
);
$post_id = wp_insert_post( $my_post );
update_post_meta($post_id,'source_link',$url);
and to prevent the insertion add a simple conditional check:
$args = array("meta_key" => "source_link", "meta_value" =>$url);
$posts = get_posts($args);
if (count($posts) < 0){
//add new post
}
* * *
if (count($posts) < 0){
//add new post
}
is not working, change it to
if (empty($posts)){
//add new post
}
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "posts, custom field, customization, wp insert post"
}
|
How can I update a wordpress plugin from a Git repository (github)
is there any way to easily update a plugin installed on multiple sites from a github repo. I know I can do it from the command line of each server using git pull. but is there a way to do it from the wordpress admin similar to how plugins are updated?
|
I wrote a PHP class that allows a plugin developer to incorporate updates from GitHub within their plugin. Here's a link for it -> <
|
stackexchange-wordpress
|
{
"answer_score": 11,
"question_score": 13,
"tags": "plugin development, git"
}
|
How Can I Set the Post Author of a Post I Just Created With PHP?
I'm using PHP to dynamically create a custom post, and I need the author to be someone other than the logged in user. I found this < but I'm wondering if there is a way to do it after the post is already inserted. I guess I could just do a db query...
|
If you know the ID of the author you can use wp_insert_post specifying the ID and the author ID to it.
$id = $post->ID; // change this to whathever
$user_id = '4'; // change this too
$the_post = array();
$the_post['ID'] = $id;
$the_post['post_author'] = $user_id;
wp_insert_post( $the_post );
The trick is to specify the ID to update the post. See `wp_insert_post()`.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "custom post types, posts, author, wp insert post, wp update post"
}
|
Remove "Posted on" and "Posted in" from the Twenty Ten Theme
I just upgraded to the latest Wordpress and activated this theme.
It displays the following
* * *
## Hello world!
Posted on May 27, 2010 by admin
Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
Posted in Uncategorized | 1 Comment | Edit
* * *
Is there an option to remove the Posted on and Posted in ?
|
I don't think there is an **option** to do that. You can edit the theme to remove those elements, but then you will have a problem when the theme gets updated (pretty frequently for _Twenty Ten_ right now.
But if you did want to do it, you have three ways to do it:
* You can edit PHP files for the presentation (e.g. loop.php) under Appearance/Editor and delete the whole section responsible for it
* You can edit functions.php that contains twentyten_posted_on and twentyten_posted_in functions to stub them out to return nothing
* You can edit CSS to make corresponding classes (entry-meta and entry-utility I believe) to be invisible. WordPress still has to do all work and it is still there in source code, but it could be the faster option. You could even use FireBug to test whether the display will look correct when you remove those.
There are better and more esoteric ways to do it (child themes), but I am not sure I could describe it in a text box.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 3,
"tags": "theme twenty ten"
}
|
Display all custom post types in archives.php
How would I do this? `archive.php` only has this:
wp_get_archives('type=monthly');
And `wp_get_archives()` does not have a parameter to display all post types.
Also I think `archive-[post_type].php` is not the one I am looking for since I want all post types to be displayed in one archive page.
Thanks!
W
|
If you set up the right parameters for your custom post type using
'has_archive' => true // Will use the post type slug, ie. example
// or
'has_archive' => 'my-example-archive' // Explicitly setting the archive slug
<
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 3,
"tags": "custom post types, archives, wp get archives"
}
|
Widget's container?
I have some custom-made widgets:
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo $output;
echo $after_widget;
Let's assume the $title is "Widget's Title" and the output is "Hello world".
I'm getting something like:
> Widget's Title
>
> Hello world
Now, I don't know where it comes, but there's container wrapping every one of my widgets, it looks like:
<li id="widgets-id" class="widget widget_name">
<h3>$title</h3>
<ul>
<li>$output</li>
</ul>
</li>
Any ideas how to change the first "li" into "section" or a "div"? :)
|
It's the default behavior of a dynamic sidebar to output li tags around widgets. You can override that though in the sidebar declaration.
You would do that by passing the sidebar registration the following additional arguments:
register_sidebar(
array(
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => "</div>"
)
);
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "plugins, plugin development, widgets, sidebar"
}
|
A function like is_page() but returns true if on any sub page of given page
In my header I use this code:
if(is_page("stores")) {
// Do something
}
I run some code if on the page `stores` but what I want to do is run that code if the page is `stores` or any page that is a sub page of stores. Not only that, but is recursive so if we are on a sub sub sub page of `stores` the code still runs.
|
When using pretty permalinks, I simply check against the request;
if ( preg_match( '#^stores(/.+)?$#', $wp->request ) ) {
// away we go!
}
No extra DB queries, little computation, and works right down the tree!
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 1,
"tags": "pages, conditional content, recursive"
}
|
Setting higher upload limit
How can I change the standard 7MB upload limit?
I have full shell and admin access to my Wordpress blog.
|
add this to your .htaccess file in the root of WordPress installation directory:
php_value upload_max_filesize 20M
php_value post_max_size 20M
and you can change 20 to whatever you want, unless your hosting server is limiting it it should work just fine.
## Update:
Create the php.ini File and add the Following:
memory_limit = 20M
upload_max_filesize = 192M
post_max_size = 20M
file_uploads = On
then Upload the File to your wp-admin Directory.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "uploads, media"
}
|
Alternate header image
Is there a convenient and configurable way to alternate between different header images?
The main features I'm looking for are:
* Random select from a set of images
* Specific header image in given date range (a la Google Doodle)
* Specific header image for specific posts or pages
|
You can try this
**Random from a set of images :**
<img src=" echo rand(1,10); ?>.jpg" alt="" />
This would load a random image from image_1.jpg, image_2.jpg ... to image_10.jpg
or
$images = array("cool_image.jpg", "nice_pic.jpg", "sunset.jpg");
$rand = array_rand($images);
<img src=" echo $images[$rand]; ?>" alt="" />
This would select a randow image from thoses specified in the $images array.
**Date range :**
<?php
if ((date('m') == 3) && (date('d') == 17)) { ?>
<img src=" alt="" />
<?php } ?>
This would show an image for St Patricks
**Specific posts or pages :**
See : Change image based on menu item id
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "themes, images, design"
}
|
post categories
I have posts which i would like to put in to 3 categories News, Events, and Press Releases, then i have three pages which are using the same template. I would like to display those posts on to relevant pages so News posts on News page etc. Could someone tell me what would be the best way to do that.
I guess its something easy but I'm fairly new to Wordpress.
Many thanks,
|
You could simply use the category pages WordPress generates using the `category.php` template, or `category-{slug}.php`. If you don't like the /category/categoryname/ url format WP uses, there are a few plugins that remove the category base- I use Yoast SEO plugin for this, which gives you lots of other great features on top.
Your other option is to create a special template for these pages with some additional code to load posts from your category. The WP Codex actually has exactly this code for you already, using a custom field on each page to designate which category you'd like it to load.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "posts, categories, pages"
}
|
Change name & menu_name for Profile in the default menu, w/o altering core files?
I want to change the name and menu_name of the profile menu in the default menu without altering the core files.
|
you could filter gettext to change it. Note that this will change every translatable instance of "Profile".
function change_admin_profile_to_account( $thename ){
$thename = str_replace( 'Profile', 'Account', $thename );
return $thename;
}
add_filter( 'gettext', 'change_admin_profile_to_account' );
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "menus, admin menu"
}
|
previewing my posts on static page?
I am new to WP.
**What i allready have -**
I am building a news blog with few posts categories. each category function as a different section (Economics, Sports etc.)
**What i want to achieve-**
What i am trying to achieve is to set a static page that will preview the last post from each category and will serve as the main page of the "news site".
1. how can i nest posts preview on a static page (I understand that static pages are posts right?).
2. is there a way to retrieve all the posts from a specific date?
3. is there a way to group them by category?
I know it is a "Big" question. I am only looking for directions and not tutorial.
Thanks a lot
Shani
|
You will need to set a Static Page as your front page, create and assign a PHP Template for that page, and stack multiple Queries in the template to search out your required categories and display them. Here is one, you might have many:
// get the last post (any date) from 'Featured' category
$featured = new WP_Query( 'category_name=Featured&posts_per_page=1' );
if ( $featured->have_posts() )
{
while ( $featured->have_posts() )
{
$featured->the_post(); // fill $post with data
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- output markup and display the post(s) -->
</div>
<?php
}
}
rewind_posts();
// start next query
That should give you an idea, at least, there is a fair bit to it. Good luck.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "posts, query posts"
}
|
how to put functions inside of widgets
I'm trying to put my own function in a widget but it doesn't run. I want to use it everywhere within the widget.
If I could see an example,that'd be great.
|
there are a few way to run a function in widgets:
**option 1 - ShortCodes**
You can create a custom shortcode and run that function by entering the shortcode into a simple text widget:
//this is to make sure WordPress renders the shortcodes in a text widget
add_filter('widget_text', 'do_shortcode');
add_shortcode('my_short_code','my_function');
function my_function(){
//do whatever you want
}
and then simply add `[my_short_code]` to any text widget to run your function.
**Option 2 Plugins**
You can use one of the many plugins out there that let you run php in a widget like:
* PHP Code Widget
* WP Sidebar Essential
* PHP-Widgetify
**Option 3 Custom Widgets**
The last way is to write your own widget using the very simple Widgets API
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "widgets"
}
|
Looking for the code in twentyten that allows users to select images for the header/banner
I am looking for the code that renders the below page. Where can I find it, it does not appear to be in functions.php?
.
To understand what they have done in TwentyTen, I would suggest that you read the following:
<
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "theme development, theme twenty ten"
}
|
Hide "Gallery Settings" and "Insert into Post" button from Attachment window
I'm using different method to form a gallery in Wordpress, so I would like to hide an option to insert images and galleries into post for anyone but Administrator.
Can someone show me an example how it's done?
|
If you actually wanted to remove it instead of just hiding it you could remove the 'admin-gallery' script that is used to insert the gallery settings form. And if you wanted it to be remove only for non-admins then something like this should work:
function disable_wp_gallery()
{
if( !current_user_can('manage_options') )
wp_deregister_script('admin-gallery');
}
add_action('admin_enqueue_scripts', 'disable_wp_gallery');
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 2,
"tags": "attachments, gallery"
}
|
Changing 'rewrite' argument after custom post type is registered
I'm am attempting to change the rewrite argument after it has been defined and passed as an argument for 'register_post_type' in a plugin. My issue is that I am utilizing a plugin that defines a custom post type. I can manually edit the rewrite argument in the plugin; however, doing so will mean that I have to do this every time the plugin updates. I was wondering if there is a way that I can change this with some code in another plugin or functions.php file.
I was thinking there might be a function that would allow me to alter these arguments or a way in which I could unregister and reregister the custom post type.
Any ideas?
|
I had a very similar question and found the answer. Take a look, it might be helpful for You aswell: Change custom post type to hierarchical after being registered
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "custom post types"
}
|
How to upload images using Settings API
I want to allow users to upload images for use in a rotating banner. I tried using the media library, but didn't get much help ... So I thought, I'd just implement the upload myself. But I encountered another problem... I am using the settings API they do the update options and stuff for me. How can I handle the upload then?
I thought of using the validate callback to upload images and then set $_POST variables manually so that Settings API can save those. But it sounds wrong. Any ideas?
|
You should only need a list of URL's selected from the Media Loader. There are others out there, but I have a Theme Options Panel for your admin that is Settings API compliant. It has an 'upload' option that uses the Media Loader to upload a file and fill a text field with the returned URL of that file. This is saved as an option with the Settings API. Perhaps you can get an idea from that. You could provide a pre-set amount of 'upload' options (5 URLS/images for example) or modify the code to handle it differently.
Theme Options Panel Framework
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 2,
"tags": "theme development, uploads, options"
}
|
Plugin - Social media share buttons
Is there a plugin with the social media share buttons where I have more control of where to place them?
At the moment, the only one's I can find only allow you to place the buttons at the top or bottom of pages/posts.
Ideally I'd like a snippet of code to just place wherever I wanted.
|
I finally came across one that wasn't over the top and there was also a manual function:
<
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "plugins"
}
|
Is there a need for nonce with Post Metabox?
I looking at the docs for `add_meta_box`. They used a nonce.
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
I am wondering, probably the save post form itself should already have a nonce so this is redundant?
|
Yes, the save action has a nonce already. But you don’t know it – so you cannot validate it. Besides that, you may want to fill a meta box from other places like a user profile or the dashboard, and then you need your own nonce anyway.
An example from my current work: There is a custom post type `domicile` with a booking schedule meta box. My client is the agent or broker (English is not my native language …) for the domicile and fills the schedule from the editor for the CPT. But the owners of the domiciles can fill the schedule too – from their dashboard. I just load all booking schedules they are assigned to and they edit them without ever seeing the complete data of the domicile. Without separate nonces this would be very awkward.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "theme development, metabox, post meta"
}
|
Metadata Query when storing data as array possible?
Suppose I store all my post meta data in an array like
$meta = array(
'img' => '',
'caption' => ''
);
update_post_meta($post->ID, 'theme_banner', $meta);
Can I query posts where the img is filled?
|
Short answer: NO!
I've asked a similar question before mysql order by serialized data? and the answer i got is:
> The only possible case when serialized data is acceptable is when you don't need to search , filter or order by through that data. In all other cases - store your data as a separated fields.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "theme development, wp query, post meta"
}
|
Alternative to email notification system?
Instead of having an email on every comment on a blog post I've wrote, I'm looking for a visual notification on wordpress itself, an "inbox" if you get what I mean.
Does that exist?
Thanks, Dennis
|
This should be visible by default on your WP admin dashboard under "recent comments". is there something else you're looking for it to do?
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "email, notifications"
}
|
How to get the value of particular get $meta value in wordpress
I am using this wordpress Script to add metaboxes under posts.. I followed as it was written.. but I am having trouble on how to get those values in singe.php Example an uploaded image Please guide me on this..
|
<?php if ( get_post_meta($post->ID, 'your_metabox_id', true) ) : ?>
<?php echo get_post_meta($post->ID, 'your_metabox_id', true) ?>
<?php endif; ?>
The trick is to use get_post_meta hook
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "custom field, metabox"
}
|
How to redirect http://mydomain/blog/blahblah/ to http://mydomain/blahblah/ in wordpress htaccess?
I would like the htaccess rewrite rule to compare to IIS rewrite rule I tried which doesn't seem to work:
<rule name="rewrite /blog/">
<match url="^blog/([_0-9a-zA-Z\-]+)/$" />
<action type="Rewrite" url="/{R:1}/" />
</rule>
|
This is not a WordPress question. Anyway …
RewriteRule ^blog/(.*) /$1 [L,R=301]
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "url rewriting, htaccess, apache"
}
|
Getting lots of errors with sitemap on google webmasters
I use the Google XML Sitemaps (Wordpress Plugin) and the latest wordpress version. Recently i have had a lot of 404 not found errors in webmasters. The urls show up without any categories and it links to the sitemap.xml file. It shows the url as < instead of <
Since the categories are missing these links return a 404 not found error. These faulty links are piling up and i am in a fix. Please help.
|
the XML sitemaps plugin should be pulling your URL structure that you've set in the permalinks setting. Are you using a plugin or other method to remove the /category-name/ from the URL?
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "categories, google xml sitemaps"
}
|
User roles - enable custom posts disable posts
Im just wondering if its possible to create user role that allows to write/edit custom post type for example: Consultants, but not allow to write normal posts (used for as news for example).
I know that if user wants to edit posts its a must to have edit_post enabled for him. Question is if i can create something like: edit_[custom_post_type] or something?
Thanks in avance if anyone can help me with this issue...
Kindest regards
|
I suspect that Justin Tadlock's Members Plugin would make this very easy for you.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 3,
"tags": "custom post types, users, user roles"
}
|
Display both standard posts in a specific category along with a custom post type in a single loop?
I'm building a content slider that needs to show posts from a custom post type called "Features," and also show standard blog posts that are assigned to a "Featured" category. I'd like to do this within a single loop. Can anyone help me put together the query that could handle this?
|
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( array(
'post_type' => array(
'post',
'features',
),
'category_name' => 'Featured',
'paged' => $paged )
);
// have some posts?
if (have_posts()) :
while (have_posts()) : the_post();
// the loop
endwhile;
endif;
?>
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "wp query, loop"
}
|
Find most recent authors
What I'm looking to do it get the 16 latest posts from 16 different authors. In other words there would be the 16 latest posts, but no one single author would have more that 1 post on the page.
The way I've thought about doing it, is looping through all the authors, removing the duplicates, then limited that to 16 and use that to generate the posts in a for each loop, but I'd imagine that would be heavy on the server.
Any suggestions?
|
Use a custom SQL query to grab the latest 16 post IDs with unique authors;
$post_IDs = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'product' AND post_status = 'publish' GROUP BY post_author ORDER BY post_date DESC LIMIT 16" );
Then start up a new query with the `post__in` argument;
$recent_posts = new WP_Query( array( 'post__in' => $post_IDs, 'post_type' => 'product' ) );
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "posts, loop, author"
}
|
Custom Theme Design: do I need to "enable" jquery/javascript libraries?
When I build a theme from scratch I have to "enable" sidebars and specific menus in the functions.php.
Similarly, do I need to "enable" access to the javascript and jquery libraries that come bundled with WordPress?
I ask because 2 How-to books I've been using (WordPress 2.8 Theme Design, and Beginning WP 3) both talk about needing to do this and provide code, but neither of them makes explicit whether you need to do this just to make things work in general, or whether you need to do this only if you want to include your own "standalone" javascript(s) as opposed to a script that is part of a plugin/widget.
I'm assuming the latter but want to confirm -
|
If you'll be using jQuery in your theme you need to "enqueue" it. If you do not need the JS , ie if you do not run custom jQuery plugins, you don't need to "enqueue" it
via wp_enqueue_script
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "jquery"
}
|
Forum plugin with private forum option
I'm in need of a forum plugin for Wordpress that has an option for a private forum that is only accessible (both for reading and posting) to registered users. Restricted posting appears to be _de rigueur_ , but restricted viewing appears to be harder to find.
Ideally, it'll integrate directly with Wordpress but if it needs to open in a separate window ( _a la_ BBPress) then that's fine.
I've been looking around at different Wordpress forum options (such as BBPress and Mingle), but I can't see whether any support this feature.
Does anyone know of a simple forum solution that offers this? Thanks.
|
Simple:Press
Can limit forums to no access, read only, limited, standard, full, moderator
It's decently simple, I've been using it a bit for my personal blog. I didn't have too hard of a time integrating it. Lots of features available, with pretty fine grained ability to turn things on and off
Also, as information, bbPress no longer requires stand-alone operation It is now developed as a plugin and is maturing rapidly. I've integrated it into one of my sites with no problems. However, I don't think it meets your needs. Just wanted to include the info in case you were interested.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "forum"
}
|
Have Plugin Handle Specific URLs
Does Wordpress have the ability to use the currently defined template to serve up content in the database?
For example, I have a database of a bunch of custom content-- the name of an item, the price, etc.
I want all requests for < to be redirected to the plugin (so that the plugin handles the content generation), where the * is an item number or some other parameter. Can I use the Wordpress template and display my custom content? I would be handling all of the HTML generation for inserting into the template...
The best example I can find is the WP Ecommerce plugin here: < Basically, the plugin is handling the checkout page (/checkout in most cases, /icons/checkout on IconDock). How can I do this?
|
There are two different things happening here. I'll start with your second example, as that's easier.
Most shopping carts, in your example WP-Ecommerce, create placeholder pages with a shortcode for things like the cart page and checkout page. All they're doing to handle that is creating a shortcode function and inserting it on a page, then outputting whatever they need to in the shortcode function. In this case the shortcode is static, and there isn't any other data being passed via the url. The actual product pages in WP-Ecommerce are just a WordPress custom post type with some extra meta data.
What you're talking about, creating your own url structure via a plugin to pass data, involves writing your own rewrite rules via the WP_Rewrite class and inserting your own query vars.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "plugins, php"
}
|
How can 2 blogs share the same users
I have a running normal WP blog (blog 1). I want to create a Q&A section for my users, so I setup another blog with WP-Answer theme (blog 2).
The problem is I don't want my users at blog 1 have to register at blog 2 to post questions. I want they automatically grant the same privileges at blog 2.
How can this be achieved? Do you have any advice for me?
Thank you very much.
|
I think you want to install your second site on the same database but with a different table prefix, e.g. `$table_prefix = "qa_";` in `wp-config.php`
You are then able to define a custom user and/or user_meta table by adding the following lines to `wp-config.php`
define('CUSTOM_USER_TABLE', [orig_table_prefix].'my_users');
define('CUSTOM_USER_META_TABLE', [orig_table_prefix].'my_usermeta');
Source: <
I have read somewhere before that you may have to sort out a couple of issues of admin users on the second site, can't find the link at the moment.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 7,
"tags": "users, migration"
}
|
Archive widget - limit number of months to 12
The default Archive widget display monthly archives in a dropdown.
I would like to limit the number of months to 12 (in dropdown).
What filter I should apply in my functions.php?
I tried this, but it gives me parsed error:
add_filter('WP_Widget_Archives','set_number_months');
function set_number_months($args) {
$args = array('number' => 12);
return $args;
}
I also tried with wp_get_archives but same parsed error
|
Use the `widget_archives_args` filter to add the archives limit.
function my_limit_archives( $args ) {
$args['limit'] = 12;
return $args;
}
add_filter( 'widget_archives_args', 'my_limit_archives' );
And to limit the number of months in Archives widget dropdown use the following drop down filter.
add_filter( 'widget_archives_dropdown_args', 'my_limit_archives' );
|
stackexchange-wordpress
|
{
"answer_score": 7,
"question_score": 3,
"tags": "archives"
}
|
How do I reset a self-hosted Wordpress URL?
i was using a wordpress install on an ubuntu server virtual machine. At first the adapter was host-only at an address of 192.168.55.55. The host had this on a vboxnet0 subnet.
i changed to bridged adapter to try port forwarding from the router, and now i cant access the page with the new address.
the new address is 192.168.1.5 and everything appears fine on routing tables of host.
i also cleared the dnsCache on the host.
but when i type in:
192.168.1.5/wordpress
in the browser, the activity bar shows it is trying to contact the old ip of 192.168.55.55, which was the vboxnet0 host-only adapter.
|
The easiest way to do this is by using copy&replace in the SQL file. Export the database. Use your favorite text editor and do a copy&replace and import it into a new database.
Then you go to wp-config.php and you change the WP_HOME and WP_SITEURL to the new host. Then you change the databasename. You also need to ensure that the same db user has access to the database.
Btw: There is a separate stackexchange for wordpress. Check out How do I move a Wordpress site to another server?
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 1,
"tags": "database, migration"
}
|
Slideshow control for use in Wordpress Thesis theme - non flash
I want to use a good elegant slideshow control in my website. The website is created in wordpress and I am using the Thesis theme.
I did find a Nivo slider but am stuck at the integration with Thesis (using the custom functions and custom css files).
Can someone suggest a good non-flash slideshow widget which I can easily integrate with the theme (and also how to integrate it)
Thanks.
|
Here is a list with some of the widgets: <
Then, here is the slideshow list from the official plugin directory: <
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 4,
"tags": "plugin recommendation, slideshow, theme thesis"
}
|
get values from contact form 7 wp plugin
I am using contact form 7 plugin in my blog.I am having donate option in the form with price option in radio button. user can select and submit.After submitting the form it should redirect to the paypal. with selected price .
i tried
> on_sent_ok: "location = '
in additional option in form management. But here value of price is static . I need to change that value what user selects.
Thanks in advance
|
First change the `on_sent_ok' to:
on_sent_ok: 'my_redirect();'
then create that `my_redirect()` function in the page that displays the form:
<script>
function my_redirect() {
var price = document.getElementById('PRICE_FIELD').value;
var url = '
window.location = url;
}
</script
and done! Just make sure that you correct the email in that url and replace `PRICE_FIELD` with the actual id of the price field.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "plugins, plugin contact form 7"
}
|
Create a page for a theme only
I am in the process of creating a wordpress mobile theme for one of my wpmu networks. I have created 2 + pages that show our other sites and a custom login form. Right now i have labeled them page-other-sites.php and page-login.php and created 2 pages in the backend. When you click on the link it loads the page-(slugs).php
Now instead of having to create a page every time is there a way to have my themes function.php file create a set of default pages.?
|
So instead of creating a theme for it i ended up using the `template_redirect` with an if statement to check the url for a certain thing.
function page_redirect() {
if ($_SERVER['REQUEST_URI'] == $home . '/other-sites') {
require(TEMPLATEPATH . '/includes/other-sites.php');
}
if ($_SERVER['REQUEST_URI'] == $home . 'login') {
require(TEMPLATEPATH . '/includes/login.php');
}
}
add_action('template_redirect', 'page_redirect');
Simply all this does is check to see if the requested URI is `wpsite.com/other-sites` or `wpsite.com/login` and if this is true then load this template instead. Since i am using some WordPress features though in these custom templates i have also made a check for the title since WordPress will return a page not found title.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "multisite, templates, mobile"
}
|
How to batch resize images and change image url?
I'm making a new theme for a blog that will be slightly narrower. Thus I need to resize every image and also change the image url in every post. Is there any kind of plugin handling this?
|
This plugin might help you : Regenerate Thumbnails
Just change the image dimensions in WP's Media Settings and run the plugin.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "plugin recommendation, images"
}
|
HTML table attributes ignored
I'm trying to add a table to a php page template.
The headers and cells contents show well, but the table attributes are being ignored.
This code:
<table border="1" cellspacing="10">
<tr>
<th>Name</th><span/>
<th>Address</th>
</tr>
<tr>
<td>name_1</td>
<td>name_2</td>
</tr>
</table>
produces the following result:
Name Address
name_1name_2
I get no border and no spacing (the headers are bolded, I just couldn't do it here).
Does it have something to do with wordpress?
How can it be solved?
|
Remove the border="1" attribute but leave the cellspacing. Then go into styles.css and either add your CSS selectors or modify the existing selectors. If your table is within the id="content" block, the styling is being affected by the existing selectors. The ones you will want to adjust are:
#content table {
border: 1px solid #e7e7e7;
margin: 0 -1px 24px 0;
text-align: left;
width: 100%;
}
#content tr th,
#content thead th {
color: #888;
font-size: 12px;
font-weight: bold;
line-height: 18px;
padding: 9px 24px;
}
#content tr td {
border-top: 1px solid #e7e7e7;
padding: 6px 24px;
}
#content tr.odd td {
background: #f2f7fc;
}
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "php, html"
}
|
Allow users to edit home page from WordPress (home.php problems)
I am wondering how do you create a home page with a custom design like banners different layout from other pages while allowing users to edit it.
I used to use `home.php` problem is user cannot edit it ... unless they know PHP.
An option will be to create shortcodes for each section of the home page eg. `[banner]`, `[services]` or even an empty tag `[latestBlogPosts]` etc. I dont think its correct.
Whats the way of accomplishing this? A quick "mockup" below of a typical home page
!enter image description here
Things like latest blog post and portfolio are dynamic from wordpress.
|
First, do _not_ use `home.php` for this purpose. It is a reserved template file name, and is used to display the **Blog Posts Index**.
Your best option is probably to create a `front-page.php` template file, and make the output Widget-based, so that users can modify the display via `Dashboard -> Appearance -> Widgets`.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "theme development, homepage"
}
|
show term description instead of list terms of custom taxonomy
For a custom post type (review) I have enabled a few custom taxonomies. One of them is author rating and for that I have added images to the description field of the terms in the taxonomy (1 star to 5 stars).
Now I am wondering how to show that description instead of the term itself on the `single-review.php`?
I am already using the function to allow XHTML in category descriptions as per Justin Tadlock's function described on his website
|
If i understand correctly what you are trying to achieve then you can use `get_the_terms` function to get the rating terms object and from that echo out the description.
replace:
<?php echo get_the_term_list( $post->ID, 'rating', __('Author Rating: ', 'appz'), ', ', '' ); // HERE I WANT THE DESCRIPTION (I.E. THE IMAGE THAT I USED AS THE DESCRIPTION INSTEAD OF THE TERM) ?>
with:
<?php
echo '<span class="rating-author">'.__('Author Rating: ', 'appz').'</span>';
$reating_terms = get_the_terms ($post->id, 'rating');
foreach ($reating_terms as $term){
echo $term->description;
}
?>
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "custom taxonomy, terms, description"
}
|
Multisite features
I was thinking about creating a network of user-created blogs. I've read somewhere about wordpress multisite feature, and i was wondering if this is what i'l looking for... What i need to do is create a website where users register and create their onw blog. Does wordpress multisite offer this feature out of the box ? If not, would manually implementing this feature into wp be doable, or should i start from 0 or another platform ? Thank you!
|
WordPress multisite sounds exactly like what you are looking for. It takes a little work to get multisite set up, but once that's done, the options for allowing anybody to register and create a new site are built right in. See < for setting up a multisite instance.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "multisite"
}
|
Hide comments column in WordPress backend
Is there a way to hide the comments column in the backend? When you look at the pages, there's a comments column even though I've disabled them.
I made WordPress into a CMS and it may cause some confusion.
|
Try this:
add_filter("manage_edit-page_columns", "my_page_edit_columns");
function my_page_edit_columns($columns){
unset($columns['comments']);
return $columns;
}
If you need it for posts instead of pages, use `manage_edit-post_columns` instead. The same goes for any post type, really, as `manage_edit-{post_type}_columns`.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "comments, cms"
}
|
CMS - User confusion when creating new page and having to select template and save first to see correct fields
I've made WP into a cms and there's a few niggling things that cause confusion. The main one is that when you create a page, you have to first select a template then enter a title then save as draft for it to show the correct fields on the page (I'm using the advanced custom field plugin).
Is there any way to get around this? A couple of users have now said "why aren't I seeing the correct fields to fill in?", this is down to not selecting the template and saving first.
|
Why are custom fields conditional upon the Page template? Wouldn't an easier, more elegant, and more intuitive approach be to use _Custom Post Types_?
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "custom post types, custom field"
}
|
Unable to select image with custom field
I'm using the advanced custom field plugin to convert WP into a CMS (it's works brilliantly for this). There's just one issue - with an image field it's not quite a smooth process as images need to be selected twice, this causes user confusion.
Rather than me up all the images again - please see here for step by step process of the problem.
I'm not sure if this is a WP problem or a problem with the plugin.
|
This has now been solved.
It was a case of fixing the http error I was getting with the flash uploader. It then gives you the select button rather than the insert into post.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "custom field, images"
}
|
blank page after submitting a comment
I was testing a new website with Chrome (latest build), everything working fine (no new plugin installed during the test) when suddendly when I try to post a comment, after pressing the "reply" button it stops on a blank wp-comments-post.php without posting.
I am testing on localhost with MAMP. The funny thing is on the other browsers installed in the same machine (Safari, FF) it is working regularly.
I have tried to overwrite the file from a wordrpess install, clear the cache, reboot, reboot MAMP, but nothing. I also checked the file wp-comments-post.php in the root and it is not blank and Akismet is disabled.
any ideas?
|
Problem solved. It was an unclosed div. Lesson learned: first validate your code completely, then ask for help ;)
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "comments, comment form"
}
|
Automatically republish old posts
been seaching on google for a plugin for this and can't seem to find anything realiable. The only plugin I found is called "old post promoter". Any ideeas? Can this be done with googl old fashion coding, not a plugin?
Ty!
|
<
it takes your oldest post and reposts it in the front every 24 hours, but you can change the hours on the php file in the plugin folder
not sure if this is what u are looking for.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "posts, get posts, date"
}
|
How do I permanently disable Pingbacks?
How can I permanently disable pingbacks on my wordpress multi user installation?
I have disabled access to the wp-trackback.php file through permissions (chmod 000 trackback.php) thinking this would stop any pingbacks from being received.
I do not want to run any SQL queries on the posts table, as there is a separate posts table for each blog.
|
Put this in a network activated plugin.
add_filter('pings_open','__return_false');
No more incoming pings.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "spam, pingbacks"
}
|
Varying Search Result Pages
I have two different kinds of search results on my site and I'd like to change the look of the search result page entirely. I've played around with the search form a bit but I'm unsure how to force it to redirect to an alternate search.php Any help would be appreciated
<form role="search" method="get" id="searchsupport" action="/">
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" onfocus="if (this.value == 'Search')
{this.value = '';}" onblur="if (this.value == '')
{this.value = 'search';}" id="s" name="s" value="search" class="search-form round">
<input type="hidden" id="searchsubmit">
<input type='hidden' name='post_type' value='software, documents' />
</form>
|
you can add an hidden filed to your search form and include a different template based on that:
<form role="search" method="get" id="searchsupport" action="/">
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" onfocus="if (this.value == 'Search')
{this.value = '';}" onblur="if (this.value == '')
{this.value = 'search';}" id="s" name="s" value="search" class="search-form round">
<input type="hidden" id="searchsubmit">
<!-- this is the magic field --->
<input type="hidden" name="custom_search" value="1">
<input type='hidden' name='post_type' value='software, documents' />
</form>
then in your theme's search.php at the very top add:
if (isset($_GET['custom_search']) && $_GET['custom_search'] == 1){
include('custom_search.php'); // change it to whatever template file you would like to use
break;
}
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "themes, loop, search, forms"
}
|
Wordpress themes under GPL license
On a themes site they stipulate, in the terms and conditions, that their themes inherit the GNU general public license from WordPress. I believe that this means that they can be copied and modified.
However the themes are being sold. Shouldn't they be free? Could someone enlighten me.
|
The GPL absolutely _does **not** preclude selling_ code, for cost. In fact, the terms of the license _explicitly allow_ for selling of code.
The GPL merely allows the end user, whether he received the GPL-licensed code for free or for cost, to use the code however he likes, to redistribute the code, to modify the code, and to redistribute the modified code - provided that any such-distributed code be licensed under the same license.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "themes, copyright"
}
|
WP_Query by just the id?
In the codex for `WP_Query` I see you can query by `page_id=7` for pages or by `p=7` for posts. Is there a way to get a _post of any post type_ by ID? Like `id=7` that will get it no matter if it's a page, post or custom post type?
I can only get `WP_Query` with `p=7` to work if I add `&post_type=customposttype`. Is there a way to get it from the ID regardless of the post type?
|
`any` should retrieve any type:
$args = array(
'p' => 42, // ID of a page, post, or custom type
'post_type' => 'any'
);
$my_posts = new WP_Query($args);
Note the description of `any` in the documentation:
> 'any' - retrieves any type except revisions and types with 'exclude_from_search' set to true.
For more information, have a look at the documentation of WP_Query.
|
stackexchange-wordpress
|
{
"answer_score": 92,
"question_score": 59,
"tags": "wp query"
}
|
Why does this line of code make photo albums appear?
In a theme I built from scratch I'm using the WP Photo Album Plus plugin. Per some books I've been using as guides, I need to include this code in the header in order to make comments work in a blog:
<?php if ( is_singular() ) wp_enqueue_script ( 'comment-reply'); wp_head() ; ?>
I've been including this line in the header of all my custom themes, whether the site includes a blog or not (my sites are all business sites, some with blogs included but none are primarily or only blogs). This site didn't have a blog so I removed that line of code. Doing that caused the photo albums to stop appearing on the pages. The shortcodes appeared as text instead. The albums were still in the admin and the plugin was still there, and everything else still worked.
Can anyone explain the connection?
Thanks!
|
This line has wrong syntax:
<?php if ( is_singular() ) wp_enqueue_script ( 'comment-reply'); wp_head() ; ?>
The call to `wp_head()` should not be on the same line as the conditional for the comment-reply script.
Change it to this:
<?php
// Conditional to determine if comment-reply form script should be included
if ( is_singular() ) wp_enqueue_script ( 'comment-reply');
// Fire the `wp_head` hook, which should happen always, on every pageload
wp_head();
?>
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 3,
"tags": "wp enqueue script"
}
|
How can I minimize the content of my RSS feed to fit more items in Feedburner's 512k limit?
Feedburner won't read your feed if it's over 512k. Our podcast ( has been around for 3 years now, and returning all items puts us way over that limit. We've had new listeners request that we include them all, though, and I'm wondering if that's easily possible.
I'm thinking I could hack around with feed-rss2.php and add some conditional logic that puts full details for the most recent 75 shows and truncated descriptions for all the older shows. Has someone already done this, or got some tips on how to set it up?
|
Dunno if you have images in your feed, but those could be sucking up a bit of space: Reducing image size in RSS only
Here are the basics for setting WP to use a custom feed template: <
Here are some tips in authoring the template itself: <
As for your looping, try something like this for your "full" 75 most recent posts (inside your RSS structure of course):
<?php
query_posts('showposts=75');
$ids = array();
while (have_posts()) : the_post();
$ids[] = get_the_ID();
the_title();
the_content();
endwhile;
?>
Once that’s done, get all the rest, with just truncated info:
<?php
query_posts(array('post__not_in' => $ids));
while (have_posts()) : the_post();
the_title();
the_excerpt();
endwhile;
?>
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "rss, feed, feedburner"
}
|
Is it proper to create a page just to generate a listing page (eg. for a custom post type)
I find myself creating pages just as a "placeholder" to a listing page.
eg. I create a page "Blog" and "Portfolio". Both has the editor emtpy. And I just use it so that I can use `page-blog.php` and `page-portfolio.php` for the respective listing pages. It doesnt seem proper? Is there a better way?
|
I guess another way would be including `'has_archive' => true,` into your register_post_type array and using archive-{posttype}.php to style your custom post type listings
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 3,
"tags": "custom post types, theme development, pages"
}
|
Why is save_post triggered even when I havent saved the post
I created a meta box I notice that `save_post` seems to be triggered when I land on the page, thus giving me errors like `Undefined index: xxx in /data/www/ae/wp-content/themes/xx/functions.php on line 121`
add_action('save_post', function($id) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!isset($_POST) || !is_array($_POST)) {
return;
}
update_post_meta($id, 'xxx', sprintf('%f', $_POST['xxx']));
...
});
|
See Why does save_post action fire when creating a new post?
You're getting the error as you need to check for the existence of `$_POST['xxx']`, rather than just checking if `$_POST` is set (it will _always_ be set & an empty array by default).
add_action('save_post', function($id) {
if ( ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) || !isset( $_POST['xxx'] ) )
return;
update_post_meta( $id, 'xxx', sprintf( '%f', $_POST['xxx'] ) );
// run further code
});
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "theme development, metabox"
}
|
How can I query for all values of a custom taxonomies?
Suppose I have a Custom Taxonomy "Fruits". I want to query for all the values available eg. Oranges, Apples, Mangos etc. How can I do that?
|
Use `get_terms($taxonomy, $args)`
$terms = get_terms('Fruits');
Codex page
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "custom taxonomy, query"
}
|
Registering Class methods as hook callbacks
I'm not sure if I have done this correctly.
As I understand it:
if I have a class foo and a static method bar I can register that as the callback by passing the array `array("foo","bar")` as the function name.
If I have an instance of a class in $foo and want to call the method bar I pass the array `array($foo,'bar')`.
If I need to register an action inside the class itself would it work with `array($this,'bar')`?
|
> If I need to register an action inside the class itself would it work with `array($this, 'bar')`?
Yes, it works. `$this` _Docs_ is referring to the concrete instance needed for the callback. That's exactly like the `$foo` example you give. It's just that `$this` is bit more special, but it represents basically the same and it works flawlessly with callbacks in PHP.
**Additional:**
> if I have a class foo and a static method bar I can register that as the callback by passing the array `array("foo","bar")` as the function name.
Yes you can do so, for the static function, you can write it as a string instead of the array as well: `foo::bar`, see Callbacks _Docs_. Might be handy.
|
stackexchange-wordpress
|
{
"answer_score": 12,
"question_score": 17,
"tags": "plugins, hooks, oop"
}
|
Downloadable Documents
I have Press Release Section on my page where i would like to be able to add documents pdf, ms doc's etc. Every time when i add new document to a post I would like download button to appear so user will be able to download that document. Could anyone point me at right direction or maybe there is a plugin existing which does that.
Many thanks,
|
No need to insert the download into the post as @kaiser says, you can automate:
$download = get_children( 'post_type=attachment&post_mime_type=application/pdf&post_parent='.$post->ID );
if ($download) {
foreach ( $download as $attachment_id => $attachment ) {
echo '<a href="'.wp_get_attachment_url($attachment_id).'" target="_blank" class="download">Download PDF</a>';
}
}
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 3,
"tags": "posts, media library, uploads"
}
|
Why does WP rename similar "term name"-slugs in separate taxonomies?
I have several custom taxonomies and within two of those ( Company Categories and Photographer Categories ) I have a term that is similar. The Company Category called Boudoir and the Photographer category called Boudoir Photographers.
When I created the Boudoir Photographer term in the Photographer Categories it renamed the Boudoir term in the Company Categories to Boudoir Photography.
Why did this happen? The number of posts for either taxonomy term doe snot change, only its name and the slug.
Thanx in advance!
|
They are all in your `{wpdb->prefix}_terms` table and therefore need to be unique. Else you could only get them via ID.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 2,
"tags": "custom taxonomy, slug, terms"
}
|
Changing Wordpress blog name and web address
I created a self-hosted WordPress blog (on Dreamhost) several years ago. I've never truly been happy with the name and URL/domain of the blog, and I've decided that I want to change it.
Here's what I'd like to do:
1. Register the new domain name. (Say www.newblog.com for example.)
2. Redirect traffic from the old domain name (www.oldblog.com) to the new one (www.newblog.com).
3. Begin using www.newblog.com as the new web address.
I'll be staying at the same web host through all this. I know there are lots of smaller steps I need to take in here, so I'd appreciate it if someone could help me fill in the blanks.
Thanks!
|
Every thing you need is covered in the codex **Moving WordPress** entry.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "url rewriting, domain, site url"
}
|
Wordpress Locale Switching on Accept-Language Header
Is there anyway to get wordpress to automatically switch locales based on the HTTP Accept-Language header?
Similar to how ASP.NET can do it with their globalization="auto" config setting. The reason for this is that I want my dates to be custom formatted based on where you are viewing the site from - not what the wordpress site settings use for everybody around the world.
This way somebody from the USA (en-US) will see 12/25/2011 but somebody from Australia (en-AU) will see 25/12/2011.
|
that's going to be a bit tricky since WordPress doesn't relate date and time format to language. so to get the current language from the browser you can use `$_SERVER['HTTP_ACCEPT_LANGUAGE']` and then based on that you can change the date format:
function update_date_format(){
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if (strpos($lang, 'au') > 0){
$date_format = 'd/m/Y'; // 25/12/2011
}else{
$date_format = 'm/d/Y'; // 12/25/2011
}
update_option('date_format',$date_format);
}
after you paste this function in your theme's functions.php add to your theme's header.php at the very top:
<?php update_date_format(); ?>
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "customization, date time, localization"
}
|
RTL Stylesheet Confusion with WordPress
All I understand about RTL is that some languages are written right-to-left.
In a WordPress theme, what role does the `rtl.css` stylesheet have? I was under the impression that the only difference was paragraph alignment, but the WordPress themes that I have seen have massive `rtl.css` files.
What other requirements are there of CSS to provide true RTL support?
|
This guy explains it fairly well for wordpress (video, no transcript): Yoav Farhi: Right to Left WordPress.
The Wordpress Manual (Codex) has as well some information regarding Right to Left Language Support.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "php, css"
}
|
Why does this check to see if user is authorized to edit a post fail for all but super admins?
I'm trying to determine if a piece of content can be edited by a user. I would like all roles contributor and above to be authorized by a single check. Here's my code:
if( empty( $post_id ) || !current_user_can('edit_post', $post_id) ) { return; }
Unfortunately, the only users that don't get the `return` are super admins. Any idea why?
|
And the correct capability name is `edit_posts`. So the correct way of using `current_user_can` will be like following:
if( empty( $post_id ) || !current_user_can( 'edit_posts' ) ) { return; }
**UPDATE:** I have removed the wrong statement, but as the asker mentioned he would like to allow all roles of contributors and above to be authorized for that particular check, I think just checking for `edit_posts` caps is enough. Sorry for the wrong statement.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 2,
"tags": "user roles, authorization"
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.