INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
Wordpress overriding actual subdirectories
I have a site driven by Wordpress and a few custom directories that I've got at the top level. Some of these top-level directories work and the content inside of them are being read as expected.
However, I've just created a new folder directory with an index.html inside and when I try to visit it, Wordpress is overriding it and displaying a 404 error (since that directory structure doesn't exist in the Wordpress database).
I've disabled the W3 cache and I've checked the .htaccess file in the event that I put in a redirect in the past, but nothing that would indicate a redirect back to Wordpress.
|
WordPress tries to be transparent for physical files and folders. So either something gets broken at server configuration level or at WP rewrites level.
The first things to check in such cases would be disabling pretty permalinks and if there might be come paths generated by WP that conflict with that specific folder name.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "redirect"
}
|
Is there an easy way to get a list of Category IDs?
I'm working with a couple of plugins that ask for a list of category IDs to include/exclude.
When I go to the categories section and select "Edit" I don't see an ID field listed on the page, though I see all the other details. Since I will be relaying this information onto other users, how can I find the category ID for them?
|
there are some plugins that reveal the ID's on the admin side like WP Show IDs
and by code like this:
//as dropdown
$categories= get_categories(array('hide_empty' => 0,'taxonomy' => 'category'));
echo '<select>';
foreach ($categories as $category) {
$option = '<option value="'.$category->category_id.'">';
$option .= $category->cat_name;
$option .= '</option>';
echo $option;
}
echo '</select>';
//or just print the categories names by ids like this
$categories= get_categories(array('hide_empty' => 0,'taxonomy' => 'category'));
foreach ($categories as $category) {
echo $category->category_id;
echo $category->cat_name;
}
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "categories"
}
|
Limit User Iinterface for Admin?
Is there a plugin or a way where I can restrict or limit the buttons on the admin interface for a certain user?
For example:
* for the user who has a role of a writer, he/she can only post content,
the other buttons are deactivated.
* for the designer he/she can only change the "Appearance Tab",
all the others are deactivated.
Is there a solution for that?
|
Check out Adminimize, its done by Frank Bueltge a well known plugin author from germany. Link
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 0,
"tags": "menus, customization, plugin recommendation, wp admin"
}
|
Custom permalink structure for custom post type
I´m using the following code to create a new post type:
/* Create custom post type: "Tilbud" */
register_post_type('tilbud', array(
'label' => __('Tilbud'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => '???'),
'query_var' => false,
'taxonomies' => array('post_tag','category'),
'supports' => array('title'),
'register_meta_box_cb' => 'add_tilbud_metaboxes',
));
I would like the premalink of these custom posts to contain the custom post type name followed by the post category:
.../custom-post-type-name/post-category/post-title/
I´m aware that I use the rewrite argument to add a slug, but I don´t know what to write in order to insert the post type name and category name dynamically.
Any ideas?
Thanks!
|
My plugin here: < does exactly what you need. All you need to do with that code is remove the query_var argument and change the rewrite slug to 'tilbud' (or whatever you'd like to have in the permastruct).
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 2,
"tags": "custom post types, permalinks"
}
|
How can I create an "excerpt" with text that won't be displayed in the post itself?
I'm currently creating a new theme for my blog and I intend to make it in a magazine style manner.
So, to clarify the question in the title: what I want to do is to create a text assigned to the post, but not displayed in the post itself. Lets say that the user Tom writes a review of the movie Black Swan - what I want to be able to do is summarize that review in a sentence or two - and use that text as an "excerpt" on the front page.
Any ideas? It's probably a lot harder than I think it is.
|
It's not. I believe when you go to make a post, there's a box just below it that says "Excerpt" Whatever you put in that box will only show up as the excerpt.
I tested it out and it works. You can view it on the website i'm currently developing here: <
The first post. Note how the excerpt is different from the post itself!
Also, if you want to run it in a loop instead of making a post I think there's a way to do that, too. check here: <
Good luck and hope this helped.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "themes, excerpt"
}
|
How to correctly include jquery-ui effects on wordpress
I've been trying to include the jquery ui effects (more specifically the shake effect) on my wordpress theme. So far, I've only been able to include the jQuery script, but I really have no clue where to place the ui scripts and how to enqueue them.
This is the code I have. It obviously doesnt work:
<?php wp_enqueue_script("jquery"); ?>
<?php wp_enqueue_script("jquery-ui-core"); ?>
<?php wp_head(); ?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" />
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function() {
$j("#manita-imagen").mouseover(function(){
//$j(this).animate({ opacity: "hide" })
// alert('asd');
$j(this).effect("shake", { times:3 }, 300);
});
});
</script>
Thanks for your help!
|
While WordPress does include the jQuery UI libraries, it does not include the UI/Effects library. That library is separate and standalone. You'll need to include a copy of the effects.core.js file and enqueue it separately.
Note that you should name it jquery-effects-core when en-queuing it, for naming consistency.
You can include it like this:
wp_enqueue_script("jquery-effects-core",' array('jquery'), '1.8.8');
**Edit** : This answer was written before WordPress 3.3, which now includes the various effects libraries as part of core. You can simply enqueue the pieces of the effects library that you need to use now.
The list of slugs for these files can be found in wp-includes/script-loader.php, but the core's slug is jquery-effects-core.
wp_enqueue_script("jquery-effects-core");
|
stackexchange-wordpress
|
{
"answer_score": 39,
"question_score": 27,
"tags": "jquery, wp enqueue script"
}
|
Get FaceBook Friend Count
Is there a simple PHP or Javascript method of getting the total number of FaceBook friends? Twitter makes it super easy to do that, and I need to do the same for one of my WordPress installs.
|
To get your friends as a JSON object from Facebook, you can use their Graph API. Easiest way is to visit this page: <
Scroll down until you find the Friends link in the "Connections" table. That link will give you a JSON object containing all your friends. Note that the URL on that page is unique to you and contains your access token. Don't share the link.
You can use this sort of code in WP to get and use that information:
$body = wp_remote_retrieve_body(wp_remote_get('YOUR_FB_URL', array('sslverify'=>false)));
$dec = json_decode($body);
echo count($dec->data);
You'll want to use transients or something similar to cache the data so that you don't ask FB for it all the time.
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 3,
"tags": "facebook"
}
|
Looking for a related post plugin which slides-in like the one at inc.com does
Does anybody know a Wordpress "related post" plugin with behavior like the one at inc.com. For a demo, visit any article at inc.com (ex: < scroll down to the end of the article and you will notice a box sliding in from the bottom right corner of the page.
Although this is just like any other related post plugin, I feel its behavior increases site retention.
Any pointers will be helpful.
Thanks in advance
|
The plugin I think you're looking for is <
> "Just like the NYTimes button, upPrev allows WordPress site admins to provide the same functionality for their readers. When a reader scrolls to the bottom of a single post, a button animates in the page’s bottom right corner, allowing the reader to select the next available post in the single post’s category (the category is also clickable to access an archive page). If no next post exists, no button is displayed."
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": -1,
"tags": "plugins, plugin recommendation, post thumbnails"
}
|
Uploading files in admin panel?
I want to allow my users to upload files in admin panel, but I'm not sure where should I upload these files and how the script should look like?
<p>Please provide link to a file or click "Upload" to upload it from your PC:</p>
<form>
Link: <input type="text" name ="logo_url">
Upload: <input type="file" name="logo_file">
<input type="Submit" value="Upload">
How should back-end look for that script? I mean the type="file" part :)
Oh and of course I have fully working theme option page (so the first input works like a charm).
|
See this very similar question. The answer can be adjusted to work with all types of files, not just images.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 5,
"tags": "admin, uploads, theme options"
}
|
How to query details of images in gallery that is attached to a post
I have several images attached to each post. I need to generate a gallery, but because it's heavily customized I don't want to use a gallery plugin, nor the gallery short code. It's also situated in a DIV that is totally separated from the post content/title etc. so it has to be stand-alone code in PHP, hard-coded.
Basically if there's a method to retrieve the list of attachments in a URL format.. and then pull in the proper sizes (filename_80X80.jpg or something along those lines - I know the filenames are manipulated after the thumbnail size).
I already have the thumbnail sizes covered using
add_image_size( 'ourwork_full', 589, 315, true );
add_image_size( 'ourwork_thumb', 80, 80, true );
in the funtions.php file of the template.
How can I achieve this? Do I need to use custom WP query? Or is there a function/template tag that I am missing?
|
Query for image attachments would be something like this (taken from Get The Image plugin/extension) with `get_children()`:
$attachments = get_children( array(
'post_parent' => $args['post_id'],
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ID'
) );
Then you can loop through array and retrieve URLs with `wp_get_attachment_image_src()` which will get you URL and dimensions.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "customization, theme development, themes, attachments, template tags"
}
|
Permalink of a page that has already been deleted
I had a page.. and I by mistake added another one, so the permalink got appended by "-2" at the end. I had to delete one of the pages, so I happened to delete the one without the -2 attached. Now I'm trying to change the slug of the page so that it becomes "pagetitle/" rather than "pagetitle-2" but everytime I edit the permalink it reverts back to "pagetitle-2" any ideas?
|
Turns out I had not deleted the page from trash, so the URL has was still taken up! Once trash was emptied it worked.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "permalinks, pages"
}
|
Batch Emails with wp_mail()
I've searched all over Google with no luck. Can someone point me in the right direction for learning how to send out batch emails with the `wp_mail()` function?
|
While according to `wp_mail()` docs you can pass array of emails addressees it would be bad email tone since it will expose addresses between them.
There is no explicit bcc (blind copy) argument from quick look at source it does seems to be processed if passed in headers.
Note that many hosting providers are very nervous about mass outgoing emails and can react... poorly. :) It's better to check in advance how many and how often emails you are allowed to send.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 2,
"tags": "email, mailing list"
}
|
Display different number of posts from one category on the different pages
according with Pagination with custom loop. I use the custom loop for display flash game. For make a pagination on the page with posts from one category (mydomain/category/categoryName) I used:
add_action( 'pre_get_posts', 'wpse5477_pre_get_posts' );
function wpse5477_pre_get_posts( &$wp_query )
{
if ( $wp_query->is_category() ) {
$wp_query->set( 'post_type', 'game' );
$wp_query->set( 'posts_per_page', 9 );
}
}
I have the section on the main page of my site, where displayed three game from each category. But according with code above I can't display only 3 games, even if I determine in array('post_per_page', 3) or smth like this, because this number have been already determine in $wp-query. how could I kill two birds with one stone? Thanks.
|
You can check for the existence of a variable, so you don't overwrite it:
add_action( 'pre_get_posts', 'wpse7262_pre_get_posts' );
function wpse7262_pre_get_posts( &$wp_query )
{
if ( $wp_query->is_category() ) {
if ( ! array_key_exists( 'post_type', $wp_query->query_vars ) ) {
$wp_query->set( 'post_type', 'game' );
}
if ( ! array_key_exists( 'posts_per_page', $wp_query->query_vars ) ) {
$wp_query->set( 'posts_per_page', 9 );
}
}
}
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "wp query, pagination, loop, actions"
}
|
Get wordpress taxonomy slug name(s) to use as div class
I'm trying to mark up my posts using their custom taxonomy slug as the div class so that they can be filtered...
So far what I have displays the taxonomy name but what I need is the slug so I have a nice-space-free-name, I have the below so far outputting the name:
<div class="box-item cocktails-box
<?php $terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'cocktail_type', '', ' ', '' ) );
echo $terms_as_text; ?>">
Any help would be much appreciated - I'm getting a bald patch from scratching my head on this..
|
@Ambitious Amoeba's answer works. But have you looked into the `post_class` function? It'd do what you want, and save you a lot of trouble. Just use this as your div opener:
<div <?php post_class('box-item cocktails-box'); ?>>
where you pass the classes you want applied to all posts as a list or array, and let WordPress handle the rest (it'll add classes for all taxonomies that the post is in, and you can filter it to add additional class depending on the view, if you want).
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "customization, custom taxonomy, taxonomy, slug"
}
|
How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
I'm building a plugin and I want to add bits of javascript in the admin head but only for certain admin pages. I don't mean pages as in a WordPress page that you create yourself but rather existing admin section pages like 'Your Profile', 'Users', etc. Is there a wp function specifically for this task? I've been looking and I can only find the boolean function `is_admin` and action hooks but not a boolean function that just checks.
|
The way to do this is to use the 'admin_enqueue_scripts' hook to en-queue the files you need. This hook will get passed a $hook_suffix that relates to the current page that is loaded:
function my_admin_enqueue($hook_suffix) {
if($hook_suffix == 'appearance_page_theme-options') {
wp_enqueue_script('my-theme-settings', get_template_directory_uri() . '/js/theme-settings.js', array('jquery'));
wp_enqueue_style('my-theme-settings', get_template_directory_uri() . '/styles/theme-settings.css');
?>
<script type="text/javascript">
//<![CDATA[
var template_directory = '<?php echo get_template_directory_uri() ?>';
//]]>
</script>
<?php
}
}
add_action('admin_enqueue_scripts', 'my_admin_enqueue');
|
stackexchange-wordpress
|
{
"answer_score": 31,
"question_score": 51,
"tags": "plugin development, javascript, api, functions"
}
|
Modifying the markup in the Tag Cloud widget?
I need to modify the markup of the tag cloud widget.
Can someone tell me how to go about doing this without modifying any of the files outside of the theme directory so my changes don't get overwritten when updating WordPress?
|
What sort of custom markup do you need? Can you elaborate a little more?
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "themes, widgets, html"
}
|
How do I add a filter to wp_list_categories() to make links nofollow?
How can I add a rel="nofollow" attribute to my category widget listings?
I'm currently filtering the call to wp_list_categories with this code in my functions.php...
function my_wp_list_categories($cat_args){
$cat_args['title_li'] = '';
$cat_args['exclude_tree'] = 1;\
$cat_args['exclude'] = 1;
$cat_args['use_desc_for_title'] = 0;
return $cat_args;
}
add_filter('widget_categories_args', 'my_wp_list_categories', 10, 2);
Update: When I try this...
add_filter('wp_list_categories','wp_rel_nofollow');
My links come out with escape slashes...
<li class=\"cat-item cat-item-5\">
<a href=\" title=\"View all...Chinese Tea\" rel=\"nofollow\">Chinese Tea</a>
</li>
|
try:
add_filter('wp_list_categories','esc_wp_rel_nofollow');
function esc_wp_rel_nofollow($output){
return stripslashes(wp_rel_nofollow($output));
}
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "plugin development"
}
|
Alter query on edit.php
What's the best way to alter the query being run on the Posts Edit screen (edit.php)?
The current method I'm using is by passing an argument to the global $wp_query like so:
$wp_query->query( array ('category__in' => array(14,9,2) ) );
However, this doesn't really work as expected once the user pages back and forth, filters, or searches.
|
Few days ago I wrote a quick solution using pre_get_posts filter to hide some pages in admin area.
Maybe you could use it as a good starting point for whatever you'd like to achieve.
if ( is_admin() ) add_filter('pre_get_posts', 'mau_filter_admin_pages');
function mau_filter_admin_pages($query) {
$query->set('post__not_in', array(1,2,3) );
// Do not display posts with IDs 1, 2 and 3 in the admin area.
return $query;
}
But be careful: `pre_get_posts` **affects almost all post queries on your site.** You will have to use some conditions to make it work only where desired. `if (is_admin())` was enough for me, but like I said it was quick solution and I haven't tested it properly yet.
Im sure some local wp ninja will correct this if it's too dirty .)
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 4,
"tags": "php, posts, query posts, query, sql"
}
|
How to edit the Wordpress e-mail that gives the user their password?
Can't find the answer in the codex or on here. Just need to know what file to look in to find the e-mail template. The default e-mail that gets sent upon new user registration has a link which points to wp-admin, and I need it to point to frontend.
|
Have you looked at this question?
How do I customise the new user welcome email
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 0,
"tags": "email"
}
|
How to filter content on Save/Publish to add rel="nofollow" to all external links?
I'm looking for a plugin or example of code that can intercept the save/publish event and verify that all external links within the post content have rel="nofollow" attributes.
Is it possible to use add_filter or add_action on the post save/publish event?
|
I would try "wp_insert_post_data" filter.
add_filter('wp_insert_post_data', 'new_content' );
function new_content($content) {
preg_match_all('~<a.*>~isU',$content["post_content"],$matches);
for ( $i = 0; $i <= sizeof($matches[0]); $i++){
if ( !preg_match( '~nofollow~is',$matches[0][$i]) ){
$result = trim($matches[0][$i],">");
$result .= ' rel="nofollow">';
$content['post_content'] = str_replace($matches[0][$i], $result, $content['post_content']);
}
}
return $content;
}
Obviously needs work, just a PoC.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "plugin development"
}
|
Is it necessary to bump a plug-in's version if you're just updating the "Tested up to" attribute?
I've got a number of plug-in's hosted on the wordpress.org svn server ... with the immenent release of 3.1, I would like to update the "Tested up to" meta data.
There will be no functional changes to the code, just the meta data.
Is it necessary to change the revision number for such a trivial change?
|
I would only increase the version number if users needed to download the plugin again. The "Tested up to" variable is not used when the plugin is installed, only when people want to install it or want to upgrade. In that case, the information comes from the server anyway, so you don't need to force a new download of your plugin.
Of course, if your `readme.txt` in the `trunk` directory has `Stable tag` indicator, you should update the `readme.txt` in the correct `tags` subdirectory, otherwise it will get ignored. There is no problem updating a file in the `tags` directory and not creating a new version, for Subversion it's a normal directory just like all others, it's only a convention to use it for tagged historical releases.
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 12,
"tags": "plugin development, svn, wordpress version"
}
|
How to default/force the user's display_name to their nickname?
I'm creating a simple directory from the user accounts and want to simplify it as much as possible for the users. I changed the label on nickname to Lastname, Firstname so that the users can be alphabetized by the nickname field, but I want the display_name to default, or even force, to the nickname field. I haven't seen a plugin, so I'm looking for something I can add to the functions to do this. Any ideas?
|
You can force this with a hook that activates when the profile is updated. The next step would be to hide the `display_name` select box, you can do that with some Javascript.
add_action( 'user_profile_update_errors', 'wpse7352_set_user_display_name_to_nickname', 10, 3 );
function wpse7352_set_user_display_name_to_nickname( &$errors, $update, &$user )
{
if ( ! empty( $user->nickname ) ) {
$user->display_name = $user->nickname;
}
}
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 0,
"tags": "users"
}
|
What PNG Fix script do you recommend for IE6?
I saw this post on SO but the selected solution got a couple of really unflattering comments...
I need to add a png fix script to my theme to handle issues with PNG support on IE6 predominantly. I have customers who say that IE6 is upwards of 1/3rd of their traffic if you can believe that. I know that Google is completely abandoning IE6 in Google apps, including Gmail this year, which will hopefully put the nail in the coffin, but until then...
What's the best PNG fix for use with WP?
Ideally, I want something that works but is very concise in code footprint.
|
Drawbacks using javascript to fix the PNG issue:
* higher chances theat the IE-6 visitor doesn't have javascript turned on, than on a modern browser
* ~1-2 sec. flicker until page finishes loading and javascript completes processing (on IE-6 js is slow)
* fixing repeating transparent background images is very buggy in these type of scripts, in most cases you'll get a CSS mess...
So I don't recommend any PNG "fix" script. Instead create 8 bit PNG images with alpha transparency:
<
You'll need to follow that tutorial because Photoshop can't save in this type of format. Then simply use them for IE 6 in a dedicated stylesheet.
The only drawback here is the lower quality of 8 bit (256 color) PNG images converted from a image with a high number of colors (which should really be rare on a website because of their size). But that shouldn't be a problem because IE 6 users are used to sh* quality anyway :)
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "theme development"
}
|
Create custom fields as image uploads
How can I define a custom field that works as an image upload? Should be fairly basic but I can't seem to find the solution.
Let's say you create the post type 'book' and want to create 3 fields: cover, back, index... I don't know...
I've done similar stuff in the past with flutter/magic fields but they don't seem to be updated or support native WP3 custom post types.
Alternatives anyone? Thanks in advance
|
Try the Multiple Post Thumbnails plugin, < It will allow you to set a post type to have more than one post thumbnail, so you can set a front, back, index separately using the built-in handling.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "wp admin, custom field, customization, uploads, images"
}
|
Static directories in a WordPress multisite network
I’m planning ahead for a class website, where students will have the choice to either build their pages from scratch, or to use a WordPress multisite install as a CMS.
I would like their work to sport URLs such as :
http:// myschool.edu/2011/project1 WP blog
http:// myschool.edu/2011/project2 serves files directly uploaded by the students
http:// myschool.edu/2011/project3 WP blog
And to have it work for future years too (2012, etc.).
My gut feeling is that this would be possible to achieve with some Redirect rules in the Apache configuration. Even if I have to manually write them.
Can someone with more experience with the WP Network feature and ModRewrite confirm this is possible? Or suggest an altogether better alternative? Thanks!
|
If a folder physically exists on the server, that will override the blog address in multisite. No fancy rewrites needed.
Your only issue is making sure that they have access to that folder and that folder only, if they choose the static one. ;)
Also: You cannot nest URLs in multisite. You'd need a new install in each year folder to get what you want.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "multisite, mod rewrite"
}
|
Designing a custom archive.php inspired by the Autofocus theme
I've been trying to use the front page from the Autofocus theme in a different theme by copy pasting the code from index.php in the Autofocus theme to my new archive.php file. I have also copied the related functions from functions.php from Autofocus, I also tried to get some of the css over to the new theme.
I have tried this for a long time and with multiple tweaks but I can't get it to work. I get both images and text, but not in the same style as in the Autofocus theme, and definitely not with the cropping autofocus has on its front screen.
Am I missing something here? Shouldn't it work if I copy the whole fuctions.php in to the new one and copy all the css?
|
I think if you just copy-paste the functions and styles, you're still missing a lot of code in the actual templates (those PHP files). Like others said, you might be missing classes... you might also be missing entire DIVs and other stuff, too, though.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "theme development, images, archives"
}
|
How to add a "last" class to the last post in loop.php?
I need to add a "last" class to the last post that appears in loop.php.
Can someone tell me how to accomplish this?
|
assuming you're using `post_class()`:
add_filter('post_class', function($classes){
global $wp_query;
if(($wp_query->current_post + 1) == $wp_query->post_count)
$classes[] = 'last';
return $classes;
});
|
stackexchange-wordpress
|
{
"answer_score": 12,
"question_score": 6,
"tags": "css, posts, loop"
}
|
How to retrieve "sticky" post outside the "loop"?
I need to display the "sticky" post in a section that is outside the "loop".
Can someone tell me how to do this?
|
I am using this query;
<?php
$sticky = get_option( 'sticky_posts' ); // Get all sticky posts
rsort( $sticky ); // Sort the stickies, latest first
$sticky = array_slice( $sticky, 0, 1 ); // Number of stickies to show
query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) ); // The query
if (have_posts() ) { while ( have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<?php endwhile;?>
<?php } else { echo ""; }?>
Hope it works for you too.. :)
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "loop, sticky post"
}
|
How Do I Link My Whole Featured Article Image?
I'm using the Front Slider plugin to display featured articles on my site. I've done some editing to the plugin to make it look the way I want. Somewhere along the way, I must have missed changing a value, because the top half to the image for the article being displayed links to the article while the bottom half does not.
Assuming it's as simple as I think, all I need to know is what code I need to find and replace.
Thanks in advance.
|
It's because the div#imglink is set to height: 150px; in your css. Change it to the same height as the images in the slider.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "links, images"
}
|
How to include PHP files in plugins the correct way
My problem is when on the main plugin file I include a PHP file something like this:
include(WP_PLUGIN_URL . '/wordpress-group-buying/ipn/paypal-ipn.php');
// or
include_once(WP_PLUGIN_URL . '/wordpress-group-buying/ipn/paypal-ipn.php');
// or
require(WP_PLUGIN_URL . '/wordpress-group-buying/ipn/paypal-ipn.php');
// or
require_once(WP_PLUGIN_URL . '/wordpress-group-buying/ipn/paypal-ipn.php');
and on that file I have a call to a WordPress function like:
add_action('hook', 'callback');
and I get:
> Fatal Error: Call to undefined function add_action()
Now before you say "use `if(**function_exists**('add_action')){`" if I use that then it just doesn't work.
## The questions:
* What would be the correct way to do that?
* What are the difference between `include`, `include_once`, `require` and when do I use witch?
|
First , thank you to everyone who answered,
My problem was calling the included files with full url that way they don't go through WordPress. and that happened because as i stated on the question i was calling them from the main plugin file. so the fix ended up using:
include_once('/ipn/paypal-ipn.php');
i read about at the WordPress support. and again thanks for answering!
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 80,
"tags": "plugin development, functions"
}
|
Database structure cheatsheet
I am trying to create a custom search page for a site I developed, but I lack the information needed to create the custom sql queries.
Are there any useful resources you guys might know of?
|
See Database Description in Codex.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "database"
}
|
Display latest comments on page with pagination
Im trying to display latest comments from all the post on a page named comments, now im able to use `<?php wp_list_comments('per_page=25', get_comments()) ?>` and it gets all the comments but when I try to use `<?php get_paginate_comments_links() ?>` nothing shows even the next and previous buttons dont show, what am i doing wrong?
This is my current code, any help is appreciated
<?php wp_list_comments('per_page=5', get_comments()) ?>
<div class="navigation">
<?php get_paginate_comments_links(array() ?>
<?php previous_comments_link() ?>
<?php next_comments_link() ?>
</div>
|
I cannot find that function in source and also not sure about your code nesting there.
There is `paginate_comments_links()` function. Usage is around this:
if ( get_option( 'page_comments' ) )
paginate_comments_links();
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "pages, comments"
}
|
Exclude from the query posts with meta_key and meta_value
I use this function to exclude from the query posts that are 30 days old,
function filter_where($where = '') {
//posts in the last 30 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}
// Register the filtering function
add_filter('posts_where', 'filter_where');
// Perform the query, the filter will be applied automatically
query_posts($query_string);
is it possible to do something like this to exclude posts that have a meta_key=votes and meta_value=0 ?
|
I think you'll need to add a posts_join filter, to join the posts and postmeta tables.
This link should be helpful: < in particular this piece of example code:
add_filter('posts_join', 'geotag_search_join' );
add_filter('posts_where', 'geotag_search_where' );
function geotag_search_join( $join )
{
global $geotag_table, $wpdb;
if( is_search() ) {
$join .= " LEFT JOIN $geotag_table ON " .
$wpdb->posts . ".ID = " . $geotag_table .
".geotag_post_id ";
}
return $join;
}
function geotag_search_where( $where )
{
if( is_search() ) {
$where = preg_replace(
"/\(\s*post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(post_title LIKE $1) OR (geotag_city LIKE $1) OR (geotag_state LIKE $1) OR (geotag_country LIKE $1)", $where );
}
return $where;
}
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "functions, query posts, post meta"
}
|
Change order of Custom Taxonomy List
By default WordPress orders custom taxonomies (as tags in this case) by alphabetical order not by the order they were entered in the tag box.
Is anyone aware of a way to show the custom taxonomies in the order they were entered in the post edit screen?
The url in question is: <
The GGW (Goes Good With) artists are currently in alphabetical order and they want it changed so that they are ordered the same way they were entered.
So if the enter it Artist1, Artist3, Artist2 that's how it should show up on the frontend of the site.
|
This isn't possible "out of the box"...
The default 'orderby' options are (ascending or descending)
* ID name
* Default
* slug
* count
* term_group
These are all detailed in the codex.
\--
That said there are some clever ladies & gents here. If anyone can solve it, one of these guys can i'm sure!
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 18,
"tags": "custom taxonomy, terms"
}
|
Comment entry screen shows even though "Allow Comments" is unchecked
On my single.php and index.php I'm including the comment entry routine with this code...
<?php if(get_option('allow_comments_posts')){comments_template();} ?>
However, when the specific post being viewed in single.php has "Allow Comments" unchecked, I don't want the comment template to appear.
I was under the impression that the comments_template() routine automatically managed this, but apparently I need to wrap it or pass a paramater?
|
As far as I remember main purpose of `comments_template()` is to load template and specific logic should be handled inside that template.
Snippet from Twenty Ten `comments.php`:
if ( ! comments_open() ) :
?>
<p class="nocomments"><?php _e( 'Comments are closed.', 'twentyten' ); ?></p>
<?php endif; // end ! comments_open() ?>
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "theme development, comments"
}
|
Removing the "Popular Terms" area from the Taxonomy Edit Screen in the Admin Area
Personally I really dislike how wordpress shows all the "popular terms" in different sizes on the taxonomy add/edit screen in the admin area.
Does anyone know of a way to either remove this entire area completely by adding code to your functions.php file
and/or
how to just change this specific area so that none of the popular terms show up with different font sizes/styles?
Thank you
|
Oh, I love it when you give me an easy one. Starts to make up for all those harder ones... _(well, partly. ;-)_
So what you want is to replace this:

With this:

How? Use the `'wp_tag_cloud'` hook which you can put into your theme's `functions.php` file or in a `.php` file of a plugin you might be writing. For this one I tested the global variable `$pagenow` to make sure it was on the term edit page. In the hook just strip out the `style` attribute from each of the `<a>` elements:
add_action('wp_tag_cloud','modify_taxonomy_tag_cloud',10,2);
function modify_taxonomy_tag_cloud($html,$args) {
global $pagenow;
if ('edit-tags.php'==$pagenow) // Only for the tag edit page
$html = preg_replace("#style='[^']+'#Us",'',$html);
return $html;
}
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 1,
"tags": "custom taxonomy, admin, customization, taxonomy"
}
|
Add Google Map By Address
Is there a plugin that allowed me to add google map embed code by only supplying address?
|
5secGoogleMaps by WebFactory is a very promising one.
You enter a map like this:
[gmap]your address[/gmap]
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "plugin recommendation, map"
}
|
How do I delete all comments from a specific old blog post?
I'm cleaning up an old, controversial blog entry and I need to remove all the comments from the post.
Surprisingly, I can't find a way to do this within the existing WordPress (3.0.4) UI.
I can certainly go through and click "trash" on all 200+ comments, but that seems.. excessive. Is there another way to do this that I am missing?
|
Alternative for people reading this with a fear for SQL............... (or finding this via Google after Januari 2011):
Wait for this action until 3.1 comes out, then go to a post, check all comments and bulk "move to trash" :) (it should come out any day now) (<
(or download 3.1 RC3 from <
### Example:
<
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 8,
"tags": "comments"
}
|
Problem with widgets
I am using the theme 3Grey. It is widget enabled. There are few widgets that are hard coded in the theme. These widgets donot appear in the sidebar in the widgets page. If i try adding new widgets the old ones get deleted. Is this ths normal case. Or is there any problem here.
|
Most themes will have a default set of widgets that appear when you don't add any widgets yourself (using the widget page in admin).
You can normally just drag the widgets that were "hard-coded" into the correct sidebar, and all should be ok.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "widgets"
}
|
Is there a hook for when you switch themes?
I created a plugin but I just came across a bug that I don't really know how to solve.
When you activate my plugin, it creates a file in the active theme directory and when you deactivate it, it deletes that file.
The problem is, if you activate the plugin, and then switch the theme, the files won't exist in the new theme's directory. Is there a line of code I can add in my plugins functions file to deactivate the plugin before the theme is switched, and then activate it after the new theme has been activated?
Thanks, this is a great community so I know I'll get a great answer. :)
|
There is a 'switch_theme' action that runs right after the theme is switched.
function my_on_switch_theme($new_theme) {
$current_themes = wp_get_themes(); /* Fixed deprecated function */
$new_theme_info = $current_themes[$new_theme];
/*
$new_theme_info should now be an associative array with the following:
$new_theme_info['Title'];
$new_theme_info['Version'];
$new_theme_info['Parent Theme'];
$new_theme_info['Template Dir'];
$new_theme_info['Stylesheet Dir'];
$new_theme_info['Template'];
$new_theme_info['Stylesheet'];
$new_theme_info['Screenshot'];
$new_theme_info['Description'];
$new_theme_info['Author'];
$new_theme_info['Tags'];
$new_theme_info['Theme Root'];
$new_theme_info['Theme Root URI'];
...so do what you need from this.
*/
}
add_action('switch_theme', 'my_on_switch_theme');
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 5,
"tags": "plugin development"
}
|
filter "inactive" categories from wp_list_categories?
I'd like to add a checkbox to the category editor screen to allow the category to be "deactivated" (perhaps while the site owner works on the category content and posts). Once I've done this, what are my options for excluding the category's that are set to "inactive"?
One way I'm thinking I can do this is to just run a filter on wp_list_categories and in the exlude= list, I'd just insert a utility function that returns all cat_ids where inactive is checked true.
Are there other ways to do this?
|
If you are talking 5 or 10 categories then just save them as a comma-separated string of IDs in using `update_option()` and use it as you suggested with your `wp_list_categories()` `'exclude'` argument. And this answer should show you how to add a field to the category screen:
* Adding Custom Field to Taxonomy Input :Panel
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "theme development, categories"
}
|
Post thats in Two Categories, only want to display name for one
In my Wordpress site I've created, I'm having issues hiding or not displaying one of the category titles I set up. I'll try to explain better.
**Wordpress Admin Side**
I have a post that is in two categories, a "`Work`" & "`Front_Page`"
**Main Page / index.php**
On my main index page, I have 3 features below the header image. One of those features is a "Featured Project". This is how I'm starting the loop...
**Single Project Page**
Now on this page, the visual layout is
Category Name
Which is called `<h2 class="single_category"><?=$cat[0]->name;?></h2>`
Project Title
Large Header Image
Project Desription
**THE PROBLEM!!!**
For whichever post I put in "`Front_Page`", it displays that in the Category Name. I want it to default to the main category.
Is there a way to basically say "if post is in "`front_page`" category, don't display "`front_page`" category as name?
|
Here is a bad way that works.
<h2 class="single_category"><?
if ($cat[0]->name != "Front_Page") {
echo $cat[0]->name;
} else {
echo $cat[1]->name;
}
?></h2>
Here is a bad way that works and takes up less space.
<?php echo ($cat[0]->name != "Front_Page") ? $cat[0]->name : $cat[1]->name; ?>
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "customization, theme development, categories, php, loop"
}
|
Can you install / activate the multisite when the install is in a subfolder?
I have _primarydomain.com_ and an _addondomain.com_
_addondomain.com_ points to _primarydomain.com/addondomain_
I have installed 2 seperate installs of wordpress on _primarydomain.com_ and _primarydomain.com/addondomain_
Can I activate multisite on _primarydomain.com/addondomain_ as _addondomain.com_?
My reason for this is these are two separate sites with two separate functions, so I wanted to use separate databases. Is this possible?
|
Yes, it is possible, as long as you use addondomain.com to access the Multisite.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "multisite, domain"
}
|
Convert User ID's to User Names in a single.php file
I have a post_meta "thevoters" that store users ids like: 1,2,20 ...etc, How i can turn this id's to User Names to list them in a single page?
This will echo the numbers as text,
echo get_post_meta(get_the_ID(), "thevoters", true);
any help?
thanks a lot!
|
$thevoters_ids = get_post_meta( get_the_ID(), "thevoters", true ); // get a comma separated list of ids
$thevoters_ids = explode( ',', $thevoters_ids ); // turn the list into an array
foreach ( $thevoters_ids as $thevoter_id ) { // loop through the ids
$thevoter = get_user_by( 'id', $thevoter_id ); // get the user object by id
echo $thevoter->display_name; // display the user name
}
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "functions, post meta"
}
|
How to override parent functions in child themes?
I've been reading around and trying to figure out how to do this, but for some reason I can't seem to override parent functions in my child theme.
I'm using TwentyTen as a parent - can anyone tell me why this function in my child theme isn't overriding the parent function please?
// Override read more link
function osu_twentyten_continue_reading_link() {
return ' <a href="'. get_permalink() . '">' . __( 'Read on <span class="meta-nav">→</span>', 'twentyten-child' ) . '</a>';
}
function osu_twentyten_auto_excerpt_more( $more ) {
return ' …' . osu_twentyten_continue_reading_link();
}
remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
add_filter( 'excerpt_more', 'osu_twentyten_auto_excerpt_more' );
I thought you had to remove the filter/action etc. before re-adding it right?
Thanks,
osu
|
You should run the code after theme setup.
function osu_twentyten_continue_reading_link() {
return ' <a href="'. get_permalink() . '">' . __( 'Read on <span class="meta-nav">→</span>', 'twentyten-child' ) . '</a>';
}
function osu_twentyten_auto_excerpt_more( $more ) {
return ' …' . osu_twentyten_continue_reading_link();
}
function my_child_theme_setup() {
remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
add_filter( 'excerpt_more', 'osu_twentyten_auto_excerpt_more' );
}
add_action( 'after_setup_theme', 'my_child_theme_setup' );
|
stackexchange-wordpress
|
{
"answer_score": 33,
"question_score": 31,
"tags": "functions, pluggable, child theme, parent theme"
}
|
Uploading and inserting an image using a custom option panel like in the Twenty Ten theme?
Twenty Ten gives the option to change the background image of the header.
Where is the code involved in this feature? (uploading the picture and adding the picture).
I would like to mimic this feature to archive the following:
Upload a custom logo and upload various images (maybe 10) into a slider.
So `front-page.php` would look like this:
Custom Logo:
<div id=logo>
<!-- add custom logo here -->
</div>
Custom images for slider:
<div id=nivo-slider>
<!--- add the uploaded images for the slider here -->
<div>
**EDIT: I realised that the theme uses this: add_custom_image_header(). Does Wordpress have a similar function to add other type of custom images (like logo, feature image, etc...) ?**
(The simpler way I found was this, but I think it has a bug. In order for the image to appear, I have to upload it twice).
|
The only currently available Theme Features of this kind are for header and background.
Sliders are very popular feature so best bet to get such functionality is look through available plugins.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "options, theme twenty ten"
}
|
Pagination on archive.php page
I have an archive.php page with the following code:
<?php // Start your custom WP_query
$my_query = new WP_query();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' ?> 1, 'paged' => $paged, 'category_name' => 'Casino Slots');
// Assign predefined $args to your query
$my_query->query($args);
// Run your normal loop
if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
?>
Test
<?php endwhile;
else :
// do stuff for no results
endif;
wp_pagenavi();
// RESET THE QUERY
wp_reset_query();
?>
and it displays the posts fine, but the pagination never shows?
|
I think your issue is that wp_pagenavi() is doing pagination based off of the global $wp_query instance instead instance you created. You should either switch to using query_posts() to replace the global query instead, or use WordPress' built in paginate_links to output the paging.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 3,
"tags": "query posts, archives, pagination"
}
|
Different banner on home page
How can I have one larger banner on the home page, but a smaller banner on all other pages. My home page is actually a page (as opposed to a post). But I'm thinking the banner is too big (and the newness/cuteness of it is warn off to see it over and over on every page). <
P.S. - Someone with enough points, please add "banner" as a tag!
|
if you like a simple solution, you can use Wordpress Frontpage Banner plugin, it shows a banner or article only on frontpage <
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "homepage"
}
|
Organizing by super-categories (or nested categories)?
Suppose I want to blog about three somewhat unrelated main topics: Money, Languages, and Information-Technology on the same blog. How should I organize things for the best user experience? How does would such a structure affect the default menu structure at the top
So far I found this: Category-manager and researching further. Apparently Category-Manager is a plug-in, I'm installing it now.
|
Hi **@NealWalters:**
This is obviously more of an opinion question rather than a technical one but here's my opinion.
My advice: use no more than 10 categories. Those <=10 categories when viewed together should define the essence of your blog. Don't use subcategories. Then use lots of tags to define the topics you are talking about for each post. So if for example you are writing a blog post in your _"Money"_ category, you might tag it with _"401k"_ or _"stocks"_ and so on.
Viewed another way: _
> Force yourself to be very disciplined with categories and allow yourself to be very liberal with tags. _
If you do it this way then your questions about your menu becomes easy; use a tag cloud on your main page for each category but filter the tag cloud to be specific to the category.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "menus, customization"
}
|
Fixing custom rewrite rule
I am following the WP Example. I know my rewrite rule is being added into wordpress, so I just need to fix the actual rule. So here is my current code:
add_filter('rewrite_rules_array','mcs_TextbookRewriteRules');
add_filter('query_vars','mcs_insertTextbookQueryVars');
// Adding a new rule
function mcs_TextbookRewriteRules($rules) {
$newrules = array();
$newrules['textbook/(cantonese|mandarin)/([C|M]K?[0-9]+)/([0-9]+)$'] = 'index.php?pagename=textbook/$matches[1]/?cls=$matches[2]&ch=$matches[3]';
//$newrules['textbook/(cantonese|mandarin)/([C|M]K?[0-9]+)/([0-9]+)$'] = 'textbook/$matches[1]/index.php?cls=$matches[2]&ch=$matches[3]';
return $newrules + $rules;
}
// Adding the id var so that WP recognizes it
function mcs_insertTextbookQueryVars($vars) {
array_push($vars, 'cls');
array_push($vars, 'ch');
return $vars;
}
I want to map ` to `
|
I see a second `?` in your query variables (before the `cls` query variable), probably from experimenting with the commented-out form, I think you want to use `&` there.
Your `query_vars` hook currently adds the `id` variable, but you use `cls` and `ch` in your rewrite rule, so this will not have an effect.
If you are changing the rewrite rules I recommend my rewrite analyzer plugin (soon in the repository, but get the current version via Dropbox), it helps you debug these things.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "url rewriting"
}
|
Converting a hierarchy of off-site web-links to Word-Press
I'm looking at converting several PHP-Fusion sites to WordPress. I'm wondering how to convert a page like this: < Is there a plug-in for links that will create a similar type page. Each link can have an abstract and the URL, and with PHP-Fusion it even tracks which links get clicked, but I can do without the counts or use Google-Analytics for that.
|
I've found Link Library to be pretty flexible.
<
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "links, hierarchical"
}
|
How do I change the order (ASC and DESC) in the following retrieval method using WP_Query?
The following code retrieves only custom post types with the custom taxonomy "Slider."
I would like to change their order to ASC.
The code:
<?php // Retrive custom post type with a custom taxonomy assigned to it
$posts = new WP_Query('post_type=page_content&page_sections=Slider (Front Page)') ?>
<?php while ( $posts->have_posts() ) : $posts->the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
Not sure if I should use an array (not sure how anyways).
Any suggestions?
|
just change this line in your code:
$posts = new WP_Query('post_type=page_content&page_sections=Slider (Front Page)') ?>
to this:
$posts = new WP_Query('post_type=page_content&page_sections=Slider (Front Page)&order=ASC') ?>
Basically it adds the order parameter witch can take two values (ASC,DESC).
hope this helps.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "wp query"
}
|
If category is in parent category?
I have function that check what is main top category of post. So i have category tree like this
Foo
-bar
--foobar
cat2
and if post is in foobar, my function post_is_in_descendant_category shows me "foo" and i can style that post with style-foo.css. What i want now is to make this same possible for styling category page "foobar". Wordpress functions in_category works only for posts.
So, my code `if ( in_category( 'foo' ) || post_is_in_descendant_category( get_term_by( 'name', 'foo', 'category' )) || is_category('56') )` doesn't work for subcategories.
|
If i understand right your "post_is_in_descendant_category" function checks if a post is descendant of a category and you want to check if a category is descentand. If so the add this function to your functions.php
function is_desc_cat($cats, $_post = null) {
foreach ((array)$cats as $cat) {
if (in_category($cat, $_post)) {
return true;
} else {
if (!is_int($cat)) $cat = get_cat_ID($cat);
$descendants = get_term_children($cat, 'category');
if ($descendants && in_category($descendants, $_post)) return true;
}
}
return false;
}
and use it like this:
if (is_desc_cat("foo")) {
// use foo.css
} else {
// use default.css
}
Hope this helps.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 1,
"tags": "categories, functions"
}
|
How to change user`s avatar?
Is there a way o changing user's avatar without plugins? Why there's no "Avatar Upload" section in Users > Your Profile?
I can't use a plugin. Am I blind or being forced to use Gravatar? ;/
|
Avatars are meant to be controlled by the user, not by you. So yes, in a way, you're being forced to use the Gravatar service. But remember, it gives the user the ability to use the same avatar anywhere, and you can always restrict the display of a gravatar based on content ratings (G, PG, PG-13, R).
Gravatar is a hosted service, which is why there's no "Upload Avatar" section in the profile.
You say you "can't use a plugin," but really that's the only way you can add features. If you want to use something _other_ than Gravatar, you'll need to load a plug-in to support it. There are a few plug-ins that support local avatars:
* Add Local Avatar
* Simple Local Avatars
Otherwise, I recommend you educate your users on what Gravatars are and how to use them.
|
stackexchange-wordpress
|
{
"answer_score": 9,
"question_score": 5,
"tags": "users, avatar"
}
|
What is the best workaround for supporting all existing DATEs?
I want to make a weblog that has with every date 1 or more weblog posts, e.g.:
**Januari 24 Year 41 : Roman Emperor Caligula was murdered by Cassius Chaerea and the disgruntled Praetorian Guards. Caligula's uncle Claudius was proclaimed emperor in his place.**
or
**Januari 1 Year 153 BC : Roman consuls begin their year in office.**
or
**Februari 1 Year 2038 : Humans survived**
What would be the best way to do this in WordPress if I want to support URL hacking?
p.s. custom fields + custom posts + custom taxonomy was the first thing I thought of but maybe there are better alternatives relying on the current date system.
related: <
|
Unix time is defined as the amount of seconds since the "Unix epoch," which is 00:00:00 UTC on 1 January 1970.
It works both forwards and backwards -- so technically you shouldn't have trouble representing dates all the way back to Jan. 1, year 1, but the numbers would be negative and extremely large.
EDIT: PHP appears not to be able to handle those dates easily, at least according to one basic test. Both `echo $time = strtotime("January 1, 1");` and `echo $time = strtotime("January 1, 0001");` result in `978325200`.
I think the best option is, as you muse, categories. Whether or not you want to deal with custom categories might be a matter of preference, but I suspect normal categories with the names you lay out would work just fine.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 3,
"tags": "date time"
}
|
Adding admin menus to wordpress
I am trying to add a menu box to `Pages > Pages` or `Pages > Add New`, basically whenever they access a page, be it to edit an existing page or add a new one, I would like to add a menu box under the `Page Attributes` box on the right, or anywhere on those pages that I can add a input form into to work in conjunction with the plugin I am trying to build.
I am very very new to wordpress plugin development, so please forgive my ignorance on the subject, any learning materials or good resources on the subject would also be greatly appreciated!
Thanx in advance!
|
add_action('add_meta_boxes', 'add_testbox');
function add_testbox() {
add_meta_box( 'testmetabox', 'Test Meta Box', 'testmetabox_content', 'post', 'side', 'low');
}
function testmetabox_content() {
echo "hi";
}
You can drag and drop the box into the spot you want it to display.
Make sure you always wrap the `add_meta_box()` function in another function, then hook that in like I showed. If you call `add_meta_box()` outside the function, you'll get a fatal error.
This example is for WordPress 3.0 and above. As the WordPress Codex shows, the 'add_meta_boxes' hook I used was added in WP 3.0. If you're using an older version of WordPress, (which you shouldn't be), use 'admin_init' instead of 'add_meta_boxes'.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "plugin development, metabox"
}
|
Is there a plugin to show the code tag button on the visual editor?
I write a programming blog, so sometimes I just have to write a word to represent a `command` or `function` which I like writing between the code tags. (See, what I just did there).
So, just like StackExchange has the "code" button, is there a plugin to add this button to the visual editor? I know I got it on the HTML editor, but I rarely use it.
I was thinking of writing a plugin for this, but just in case I'm asking first in case anyone knows of a plugin doing this already.
|
There seem to be a few people scratching this itch over at the TinyMCE sourceforge tracker.
This looks promising.. "CodeExtras adds `<var> and <code>` markup buttons - ID: 2904557"
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 4,
"tags": "plugins, visual editor"
}
|
Use custom header as WordPress header
My site is running on site say : www.xyz.com
My blog is at say : <
I have one header implemented in my main site, I want to use that header file as a worpress header. Is there any way I can do this?
|
You should reproduce your site's header on the header.php file on your theme. If you want any more help you could show us some code. But basically that's it, WordPress gets the header for the page from the header.php on your theme. Check out say Twenty Ten's header as an example (wp-content/themes/twentyten/header.php), and try to adapt your site's header to this format.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "customization, headers"
}
|
What's the section of code (or loop) which retrieves the Page title and description?
What's the code of the loop which retrieves the Page title and description?
I checked the code inside page.php of the Starkers theme (I guess is the same as the TwentyTen theme):
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php if ( is_front_page() ) { ?>
<h2><?php the_title(); ?></h2>
<?php } else { ?>
<h1><?php the_title(); ?></h1>
<?php } ?>
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?>
<?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>
<?php comments_template( '', true ); ?>
I looks identical to the loop which retrieves the main (blog) posts.
What's the difference?
Which is the part which retrieves the title and content of the current Page?
|
As usual - `the_title()` and `the_content()`. Posts page and _a PAGE page_ are different in amount and type of content, but mechanics of main Loop and template tags are essentially same.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "pages"
}
|
Top ten tags ala Delicious
How would I create a list that only shows the ten most used tags for my site? Kind of how Delicious organizes tags. Any ideas?
|
Easy with `get_tags()`. Basic idea would be something like this:
$args = array(
'orderby' => 'count',
'order' => 'DESC',
'number' => 10,
);
$tags = get_tags( $args );
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "tags"
}
|
On the category page, get the category object
Right, hopefully a nice and simple one... I'm on a category page with the id of 4, I want to get the category object back so I can interogate a few values.
I've had a good old look in the WP codex with little success, remember I don't want to get the categories from a post, I want the category object from the current category.
Many thanks, Ben :-)
|
To get the category object use `get_category` (codex). It's easy if you know the name, slug or ID, but if you don't you could use `is_category` to check on which category you are and pass the ID to `get_category`.
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 7,
"tags": "categories, template tags"
}
|
What SQL Query to do a simple find and replace
Whenever I create a new website I first create a staging site on a subdomain like "stage.domain-name.com".
After everything works correctly I export the database, open it in notepad++ and do a find/replace for "subdomain.domain-name.com" and replace it with "domain-name.com"... finally I import it into a new database for the live site.
My question is... what SQL query would I need to run if I just wanted to do this simple find/replace on the entire database using phpmyadmin?
-CH
|
The table where your URL is saved is wp_options. You should do an update on the columns that use the URL for your site:
UPDATE TABLE wp_options SET option_value = "new domain" WHERE option_name = "siteurl"
UPDATE TABLE wp_options SET option_value = "new domain" WHERE option_name = "home"
I might be missing some value, but whenever you do this find/replace process again, you can notice the values and tables that should be updated and add them to this script.
WordPress Codex has a nice guide on how to change a site URL, maybe that's even handier for you: Changing the Site URL
|
stackexchange-wordpress
|
{
"answer_score": 15,
"question_score": 29,
"tags": "mysql, query, sql, customization"
}
|
Howto control custum taxonomy order?
I have a site with custom taxonomy. I want to give the client the ability to control the taxonomy order. How can I do that ?
|
You can use the Advanced Taxonomy Terms Order it's a great plugin for terms order
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "custom taxonomy"
}
|
How to create a shortcode to let the user add the ID of a YouTube video?
I use the following to add in a post a YouTube thumbnail and display the video in a fancybox:
<div><a class="fancybox" href="#video2">
<img src=" alt="Welcome To High Output" width="220px" height="120px" /></a></div>
<div id="video2" style="display: none;">
<iframe title="YouTube video player" class="youtube-player" type="text/html" width="480" height="390" src=" frameborder="0"
allowFullScreen></iframe></div>
Basically the shortcode must have one fields to enter the ID of the video in the thumbnail, the link to the video, the link of the first div, and the id of the second div.
` and `
`<a class="fancybox" href="#(HERE)">` and `<div id="(HERE)" style="display: none;">`
So the shortcode should look like:
[youtube VIDEO ID:(Enter ID)]
Does anybody know how to do this?
|
add_shortcode('youtube', 'youtube_shortcode');
function youtube_shortcode($atts){
if(!isset($atts[0])) return;
$id = strip_tags($atts[0]);
ob_start();
?>
<div><a class="fancybox" href="#video_<?php echo $id; ?>">
<img src=" echo $id; ?>/0.jpg" alt="Welcome To High Output" width="220px" height="120px" /></a></div>
<div id="video_<?php echo $id; ?>" style="display: none;">
<iframe title="YouTube video player" class="youtube-player" type="text/html" width="480" height="390" src=" echo $id; ?>" frameborder="0"
allowFullScreen></iframe></div>
<?php
return ob_get_clean();
}
use it like: `[youtube "dm36W5NTPag"]`
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "shortcode"
}
|
sort events based on event date custom field
I'm trying to list events (custom posttype 'kurs') by event date, which are stored as custom fields ('dato').
My loop so far looks like this:
<ul>
<?php $loop = new WP_Query( array( 'post_type' => 'kurs' ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li><?php the_title( '<a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a>' ); ?></li>
<?php endwhile; ?>
</ul>
What I need is a list of post(event)-titles from today forward in the future...
|
You need to use the `meta_key` to sort your events in your array. Like so:
<?php $loop = new WP_Query( array( 'post_type' => 'kurs', 'meta_key' => 'dato', 'order_by' => 'meta_value', 'order' => 'ASC' ) ); ?>
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "custom post types, sort, events"
}
|
What are the permalinks options for "Category" base and removing it?
Under "Settings > Permalinks", we can set up the default category base name to use for our category landing pages. For example, site.com/ **categories** /my-first-category/.
Is there **a setting I can add to my functions.php** to allow the option to remove the category base and direct link to the category? For example, the above link becomes: site.com/my-first-category/
I realize that this opens up the possibility of having conflicting post names and category names (assuming I have a post slug that's the same as a category slug for example), but in this case, my post permalinks end in .html and my category permalinks will not, so there should never be a conflict (I expect).
|
there is an answer to on how to do that in the WordPress way here
but a faster way is using the .htaccess file by adding this line
RewriteRule ^category/(.+)$ [R=301,L]
just make sure you change < to what ever is needed.
Hope this helps.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "theme development, permalinks"
}
|
How can I stop WP media uploader from creating duplicates of my uploaded images?
I have a setting in my theme that seeks to prevent the WP media manager upload utility from creating multiple copies of each image I upload. Apparently the latest versions of WP have changed the required settings to defeat this?
Here's the current settings I have in my theme's functions.php...
if(get_option('thumbnail_size_h')!==0){update_option('thumbnail_size_h', 0);}
if(get_option('thumbnail_size_w')!==0){update_option('thumbnail_size_w', 0);}
if(get_option('medium_size_h')!==0){update_option('medium_size_h', 0);}
if(get_option('medium_size_w')!==0){update_option('medium_size_w', 0);}
Even with these settings, I'm still getting a duplicate image every time I upload. For example, if my image filename is foo.jpg and it is 800x600 pixels, WP creates two images foo.jpg and foo-800x600.jpg
How can I force WP to not create the duplicate?
|
I believe the following should stop thumbnails from being created. If you're wanting to remove some then and unset the $size[{size}]. Following sizes are there "thumbnail","medium","large","post-thumbnail".
add_filter('intermediate_image_sizes_advanced','stop_thumbs');
function stop_thumbs($sizes){
return array();
}
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "theme development, uploads, media library"
}
|
Turn Off Automatic Trash Deletion?
I have a client who wants to use the trash feature, but keep items in there indefinitely (I have no idea why, but they insist on it).
From reading this codex article on the trash status, I see that you can set the `EMPTY_TRASH_DAYS` constant to zero. But it says that this will disable trash functionality altogether. I don't want to do this. I just want to disable the _auto-trash emptying_.
Is there any way to do this? Or am I stuck with just entering some huge number for the `EMPTY_TRASH_DAYS` value?
|
My guess is - yes, you are stuck with exactly that.
Checks for `EMPTY_TRASH_DAYS` seem to be hardcoded as condition for switching interface between trash and delete in several places.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 7,
"tags": "wp config, post status, constants, trash"
}
|
category__not_in -- anyway to use category name instead of id?
I would like to exclude categories from the loop using the "name" instead of the "id", since the ID can change when using new databases. The name however will always be the same.
Is this possible?
|
You can use List Category Posts (Disclaimer: I'm the author of List Category Posts) or you can code this yourself:
$category_id = get_cat_ID($category_name);
This way you can get the id and exclude it from the loop with the minus sign. Example:
get_posts(cat=-1);
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "loop"
}
|
the_content is always surrounded by paragraphs (how to disable or remove them)?
`the_content` is always surrounded by paragraphs, it doesn't matter if I'm in HTML view and there's nothing there. Does WordPress have a function to remove them? IS there any way?
|
Removing the filter that adds the P is the best option.
remove_filter('the_content','wpautop');
remove_filter('the_content','shortcode_autounp'); // You may want to do this aswell
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 1,
"tags": "the content"
}
|
Current navigation highlight for a menu that may be modified by the user?
I'm using the following to list my pages:
<ul id="nav">
<?php wp_list_pages('title_li='); ?>
</ul>
is there a way of highlight the link of the page of the current in the navigation. It shouldn't be fixed. The user should be able to call the page whatever he or she wants, and create as much pages as he or she wants (the highlight feature should still work).
Any suggestions or tutorials?
|
wp_list_pages has support for CSS styles. The current page is marked with the class .current_page_item. You can style it as you want.
Check < for reference.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "navigation"
}
|
How to determine if a category is empty?
Is there an existing function or call in which you can pass a category id to determine if the category has child posts?
|
The get_term() function accepts a term id and a taxonomy slug. It returns an object that contains a "count" for that term.
$obj_term = get_term(123, 'your-taxonomy-slug');
echo $term->count;
I'm not aware of any utility function that _just_ counts posts in a particular category.
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 3,
"tags": "theme development"
}
|
Could the WP script/style loader be used to concatenate and gzip scripts and styles in the front-end?
WP has a nice javascript loader included in wp-admin: <
and a CSS loader: <
I was wondering if it's possible to use them in the front-end too, not just admin, because they can concatenate all enqueued scripts, and serve them as a single gzipped file
|
_late answer_
From a brief look:
You'd have to use
* `include( admin_url().'load-scripts.php' );`
* and `include( admin_url().'script-loader.php' );`
Then jump into `$GLOBALS['wp_scripts']`:
Use…
$wp_scripts->default_dirs( array_merge(
$wp_scripts->default_dirs
,array( '/themes/your_theme/js/' )
);
…to extend it.
And then use
$wp_scripts->add( $handle, $path_from_content_dir, false/array( $deps ), $ver )
to add a script.
_Notes:_
1. Uncompressed scripts get searched by `.dev.js` (when `SCRIPT_DEBUG` is `TRUE`).
2. Same seems to be possible for `$wp_styles`.
3. EDIT: _WP 3.5_ will change this behavior and use `.js` for "dev" versions and ".min.js" when (`SCRIPT_DEBUG` is `TRUE`);
(But I guess this will only work if you use a plugin or mu-plugin.)
It´s not tested and I´m not shure if this will work.
|
stackexchange-wordpress
|
{
"answer_score": 12,
"question_score": 28,
"tags": "css, javascript, performance, wp enqueue script"
}
|
How to display comment form error messages in the same page
I want to display comment form validation errors (as well as captcha error) on the comment form itself and not on a different page. How can I do that?
|
This question have answered again, here
Also you can do the same with JQuery and Validation plugin
You not to do anything other than install comment form JS validation plugin. Click here and download.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 5,
"tags": "comments, comment form"
}
|
What's the best user registration library to integrate WordPress?
I'm looking for a library that can handle user registration (name, address, e-mail etc.) into my existing WordPress website. What options exist today, or will I have to pull my own?
|
This is tutorial on extending user information I have stored in bookmarks: Adding and using custom user profile fields. Take a look and see if it fits your needs.
PS I am not following developments in user functionality closely so there might have been changes/improvements since tutorial was published.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "php, user registration, library"
}
|
Changing the category permalink structure
Hopefully another simple one, I have some nested categories, like this:
- category-a
- category-b
-category-c
The permalink for category-c is as follows:
What I'd really like is for the permalink to not include any parent categories, instead it would become this:
Is there a way this can be achieved? I have some categories that do nothing but group sub-categories together, thus I don't really want them displaying to my users.
Many thanks!
|
The following code changes all links to category archives so they don't include the parent category:
add_filter( 'category_link', 'wpse7807_category_link', 10, 2 );
function wpse7807_category_link( $catlink, $category_id )
{
global $wp_rewrite;
$catlink = $wp_rewrite->get_category_permastruct();
if ( empty( $catlink ) ) {
$catlink = home_url('?cat=' . $category_id);
} else {
$category = &get_category( $category_id );
$category_nicename = $category->slug;
$catlink = str_replace( '%category%', $category_nicename, $catlink );
$catlink = home_url( user_trailingslashit( $catlink, 'category' ) );
}
return $catlink;
}
Add the code to the `functions.php` of your theme.
|
stackexchange-wordpress
|
{
"answer_score": 8,
"question_score": 0,
"tags": "categories, permalinks, url rewriting"
}
|
Title_save_pre - Simple problem that u know for sure
I have two custom post type. Then I need to use **title_save_pre** to post title prior to saving it in the database. I need to use this filter just for one custom post type.
This is my function:
<?php
function muda_titulo() {
global $post;
$type = get_post_type($post->ID);
if ($type== 'event') {
$title = $post->post_excerpt;
$day= get_the_time('l, d F, Y');
return $title.' - '.$day;
} else if ($type == 'post') {
// do nothing
}
}
add_filter ('title_save_pre','muda_titulo');
?>
On custom post type 'event' it works fine, but on custom post type 'post' the title changed to a white space.
Thank u
|
Try the code below. Filter's take a value and returns it afterwards.
<?php
function muda_titulo($title) {
global $post;
$type = get_post_type($post->ID);
if ($type== 'event') {
$title = $post->post_excerpt;
$day= get_the_time('l, d F, Y');
return $title.' - '.$day;
} else if ($type == 'post') {
return $title;
}
}
add_filter ('title_save_pre','muda_titulo');
?>
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "custom post types, filters"
}
|
How come pending comments are appearing in admin?
How come pending comments are appearing in our admin dashboard? We haven't enabled comments in any way and aren't really interested in that feature. How did someone manage to "add" a comment.
Some of them do appear to be genuine mentions of our blog post in Twitter, while others are rubbish.
What would happen if we approved them?
|
Your dashboard got alerted by trackbacks and pingbacks. Check the links for more info. As @eileen.carpenter mentioned on the comments, you should uncheck `Allow link notifications from other blogs (pingbacks and trackbacks.)` in your dashboard for them to be disabled.
If you approve them, they'll appear as comments in your posts/pages. Depending on the theme, they may actually appear as comments or trackbacks/pingbacks. Most modern themes display them differently. On code level, they're just comments with a different comment_type. So theme developers use this to display comments and trackbacks/pingback as different things.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "comments"
}
|
WPML - how to get the permalinks to display also the default language
Currently WPML adds /fr/ to permalinks to identify a url as French. The default language of the site is English, however WPML does not add /en/ by default for the default lannguage (English) permalinks. Is there a way to have the default language also show up in the permalinks?
|
EDIT: This feature has been added to the latest version of the plugin.
<
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "permalinks, url rewriting, multi language"
}
|
How to check user role without using current_user_can()
I am filtering the map_meta_cap() function, which is called from $user->has_cap (which is called from current_user_can()). I only want my filter to execute if the current user is an administrator, so I need a conditional in my filter that checks their role.
I can't use current_user_can(), because that invokes my filter, causing an infinite loop.
Is there a reliable way to check whether someone is an administrator without using current_user_can() ?
|
You could check the `$current_user` variable to determine the role.
I believe it should be realiable after init(maybe even on init) for a logged in user, a guest visitor obviously won't have any data associated with him or her yet(so it'll be empty/unset).
You can also call up `get_currentuserinfo()` to populate the `$current_user` var, but i've personally never found a need when calling `$current_user` after init(but i'm sure there may be cases when you need to call it, so it's linked below for reference).
<
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 4,
"tags": "users, user roles, capabilities"
}
|
WP upgrade can't create directory even though perms are 777
I'm trying to upgrade to WP 3 but I'm getting a weird error when I try to do so:
Downloading update from
Unpacking the update.
Could not create directory: /my/path/web/wp-content/upgrade/wordpress-3.tmp
Installation Failed
The reason it's weird is because the `upgrade` directory has 777 permissions. I ran `chmod -R 777 upgrade/` and when I do an `ls`, I see that `upgrade` is world-writable. I'm sure I'm dealing with the right directory because if I delete `upgrade`, I get a different error.
Any idea why this happening?
|
The fix turned out to be to change `vsftp`'s permissions in the `vsftp` config file.
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 8,
"tags": "upgrade"
}
|
Multiple auto-generated image slideshows/sliders on each (custom) post?
I'm working on a site for a client, which will have a custom post type (homes). I'd like the client to be able to add new posts, which would ideally include multiple pictures, in different 'categories', for each home (i.e. initial construction, finish work, completed home). Each different category would then get its own slider on that 'post'.
I've considered using something like the Premium Slider plugin, which offers multiple sliders, and includes a metabox on each post, but it would definitely need to be modified to fit my requirements.
Any ideas on the best way to go about doing this?
|
Basics of my approach to sliders:
1. Query arguments for selection of posts.
2. Get The Image (plus custom code and caching when needed) to mine for images.
3. Separate function for markup generation so it could be easily swapped.
4. Just add JavaScript slider you like. When you like/need another more just swap markup and script.
Of course this approach is better for pre-configured slider or parameters are generated by code and it doesn't need to have manual controls.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "plugin recommendation, images, automation"
}
|
Translate wordpress date from Italian to English
I'm developing a wordpress based site in English but I've installed the Italian version of it...
In my blog page, I get dates, exactly months, in Italian instead of English...
How can I translate this? Are there other things I must manually translate?
For example, where should I translate errors?
Thanks!
|
I do this with the One Backend Language plugin. This way, the `WPLANG` language is only used in the frontend, and another used in the admin area.
There are more plugins that do this, some allow you to choose a language per user. The downside is that you can still be logged in when you visit the frontend, and thus get the language of the admin area there too.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "php, themes, language"
}
|
What is the best page ordering plugin that works well with WPML?
The title says it all.
What is the best page ordering plugin that works well with WPML? It seems that may are reporting issues with different plugins such as my page order and WPML page order.
WordPress 3.1 RC3 WPML 2.0.4
|
So far the best plugin that I have tested to order pages by language is CMS Tree Page View. It allows you to select the language in which to order pages. Ordering is done in a drag and drop tree view. <
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 5,
"tags": "plugins, pages, multi language, hierarchical"
}
|
Adding page links to content that automatically convert to pretty permalinks?
Is it possible to insert links in Wordpress's wysiwyg editor that will convert to pretty permalinks when enabled?
i.e. the links would be this without pretty permalinks:
/?p=13
But with permalinks on, it would become this:
/mypagename/
I'm thinking I'd have to use a shortcode to do that right? Something that would use the ID and wp_list_pages() for pages at least... just thinking about a way to get links in content to work when permalinks are on and off.
Thanks
osu
|
Here is example of simple shortcode that will take ID as argument and echo permalink for it:
function link_from_id($atts) {
if( isset($atts['id']) )
return get_permalink( (int)$atts['id'] );
}
add_shortcode('link', 'link_from_id');
Usage:
[link id=1]
PS by the way non-pretty permalinks will keep working just fine if you enable pretty mode later and, if I remember right, will be redirected to canonical pretty version.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "permalinks"
}
|
how to pull wordpress post comments to a external page
Hello I would like to know if there is a way to pull the contents of comments on a post to a separate page from wordpress. currently this is what i have, i'd like to replace with a function to pull the comments instead of pulling the link to the comments.
<?php
// Include Wordpress
define('WP_USE_THEMES', false);
require('./blog/wp-load.php');
?>
<div>
<p style="font-size:18px;color:white;font-wieght:700;">Recently Asked Questions</p>
<?php query_posts('showposts=3'); ?>
<?php while (have_posts()): the_post(); ?>
<div id="faq">
<a href="<?php the_permalink() ?>"><?php the_title() ?></a><br />
<?php the_time('F jS, Y') ?>
<?php the_excerpt(); ?>
<?php comments_popup_link(); ?>
To see the answer to the question click <a href="<?php the_permalink() ?>">here</a>.<br /><br />
</div>
<?php endwhile; ?>
</div>
Any help is appreciated, thank you.
|
add to your loop and replace it with the the_permalink() function something like this:
<?php
// Include Wordpress
define('WP_USE_THEMES', false);
require('./blog/wp-load.php');
?>
<div>
<p style="font-size:18px;color:white;font-wieght:700;">Recently Asked Questions</p>
<?php query_posts('showposts=3'); ?>
<?php while (have_posts()): the_post(); ?>
<div id="faq">
<a href="<?php the_permalink() ?>"><?php the_title() ?></a><br />
<?php the_time('F jS, Y') ?>
<?php the_excerpt(); ?>
<?php comments_popup_link(); ?>
<?php comments_template( '', true ); ?>
<br />
</div>
<?php endwhile; ?>
</div>
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "theme development, themes, comments"
}
|
Length of Category Names
Based on this post, I'm hoping to create good categories now, that I won't have to change much later.
1. Can you change a category name later, without having to go back and re-categorize all articles?
2. Using the category "Information Technology" as a challenging example, would you call it: a. IT b. I.T. c. InfoTech d. InformationTechnology e. Information Technology (in other words, is shorter better? any downside of long category names? any problem with a space in the category?)
|
1.: Yes (Slugs differ then, but no need for you to re-categorize each post)
2.: As you wrote: "Information Technology". As a rule of thumb, Category Names should be between 2 and 26 characters, the actual length depends on your site and your needs as there is no hard nor soft limit to category length and there is no "ideal" or "perfect" category length. This needs to be decided individual based on preference and site content, context and the the current time. See as well your previous question.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "categories"
}
|
How to get back to same page of post-list - after updating a post
I'm going back and reworking categories and tags on some older posts. So I'm going back in time, to say for example page 4 of my posts. I know there are search filters, which might help, but let's follow through with this scenario.
I'm on page 4, and update the first post on that page. Now, is there a fast way to get back to page 4 to update the second post on that page? If I've changed a lot of tags or categories, I don't want to hit the browser back key five to ten times. Any shortcut I don't see in this case?
|
Open post to edit in new browser tab/window so that page X remains in original tab/window?
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "navigation"
}
|
It's okay if I do not write add_action()
I downloaded various themes on net and I found on `functions.php` they write something like this
Example to remove inline comment style.
function demo_remove_recent_comments_style() {
add_filter( 'show_recent_comments_widget_style', '__return_false' );
}
add_action( 'widgets_init', 'demo_remove_recent_comments_style' );
Question
Why we not write only this without a `function()`
add_filter( 'show_recent_comments_widget_style', '__return_false' );
Let me know
|
It is not always _required_ technically but it is _good practice_ to follow for multiple reasons:
1. Code is more organized by keeping hook-related stuff together
2. The more precise conditions when it runs - the better for performance
3. It is easier to unhook function, that performs multiple _add_ _, then unhook each _add_ _ individually.
4. The order of adding functions matters when not specifying priority.
5. The child theme (if used) is processed before parent theme and it can lead to confusing stuff with hooks if _add_ _ and _remove_ _ are performed inline.
Of course in some specific examples (yours does fit) it does seem overly verbose to write out all of that just to manipulate single item on single hook.
Myself I use couple of my own (and somewhat messy functions) - `add_filter_return()` and `add_action_with_arguments()` to lower amount of wrapping when working with hooks.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "themes, functions, hooks"
}
|
Shopping Cart Integration -- Experiences with Popular eCommerce Solutions
Researching various shopping cart solutions for a WordPress based eCommerce website. Based on research, it seems that two plugins stand out:
* shopplugin.net
* phpurchase.com
Can anyone share their experiences with these or offer some good alternatives?
The list of requirements is too long to include here, but the store will be shipping goods (not digital products) and the ability to have a robust marketing/promotional campaign integrated into the shopping experience is important, as is financial reporting. Product recommendations, coupons, sale prices/discounts, email marketing and a customer database would all be nice features to have.
I don't like WP-ecommerce or most of the other free options and the budget for software is as much as $1,000 (alternatively looking at shopify.com, a non-WP product). Thanks in advance!
|
WooCommerce all the way: <
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "plugin recommendation, e commerce"
}
|
I can't modify the 'Continue reading...' link of the_excerpt
I just placed this in my `functions.php` (I'm using Wordpress 3.0.4):
function new_excerpt_more($more) {
global $post;
return '<a href="'. get_permalink($post->ID) . '">Read the Rest...</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
But my post is still displaying `… Continue reading`
Any suggestions?
|
Hi **@janoChen:**
Your theme _(or a plugin)_ is overriding your filter. Try increasing the priority like this:
add_filter('excerpt_more', 'new_excerpt_more',11);
Or like this:
add_filter('excerpt_more', 'new_excerpt_more',20);
And if that doesn't work try:
add_filter('excerpt_more', 'new_excerpt_more',100);
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "excerpt"
}
|
$user_id vs. is_user_logged_in()
I found a code scrap on the internet which uses
if($user_id) {
instead of
if ( is_user_logged_in() ) {
to check if the user is logged in. I would assume that the first would be slightly faster because it's not running a function, but can anyone verify that this would always work?
|
Well it wouldn't always work unless you global $user_id. is_user_logged_in will however work without that extra line of code. The speed improvement is most likely so small it's less than the speed improvement between single and double quotes and not even worth thinking about.
Also $user_id variable may disappear in a new version and would promptly break your code, were as is_user_logged_in will be about for ages even if they decide to deprecate it.
|
stackexchange-wordpress
|
{
"answer_score": 7,
"question_score": 1,
"tags": "admin, functions, users"
}
|
Redirecting to home-page when saving any edited code
Whenever I edit any theme code in my Dashboard -> Appearance -> Editor and try to save it, the file is not saved and it automatically redirects me to the homepage.
I don't know why is this happening. I cleared the cache through the W3-Total Cache plugin.
A few hours before I did the same process, it was working perfectly.
But now, I can't tell what the problem is.
I also tried the same process in a different browser: the result is the same.
I'm using the latest version of WordPress (Version 3.0.4).
|
I experienced an issue similar to this several months ago. I was using a plugin to kill query strings from the URL for SEO purposes. Long story short the plugin was killing search pages and admin pages as well.
As Chris_O mentioned the redirection plugin I encountered a similar redirection issue when track modify posts is enabled.
The plugin is smart enough to realize when you edit a post or page and will set up a redirect if the post or page's permalink has changed. However, when creating a new page this feature will create a redirect back to the root because the page has never existed before. More found here ( and < ).
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "redirect, homepage"
}
|
add_filter multiple times with different addon functions?
I'm adding this filter when the condition is true. Can I add another function on the same filter when the 2nd condition is true or will the last one cancel out the previous one?
if(get_option('my_nofollow_flag'){
add_filter('wp_insert_post_data', 'save_add_nofollow' );
}
if(get_option('my_second_option'){
add_filter('wp_insert_post_data', 'another_function' );
}
|
Hi **@Scott B:**
Absolutely. That's part of the design of the system, you can add as many as you need _(other plugins do.)_
The only issue is if you might need to address which one runs first and that's when you may have to set the _priority._ In the below example the third one would run first and the second one would run last:
add_filter('wp_insert_post_data','norm_priority_func'); // 10=default priority
add_filter('wp_insert_post_data','run_last_funcn', 11 );
add_filter('wp_insert_post_data','run_first_func', 9 );
Of course when you have needs to set priorities you can find it may cause conflict with other plugins that set a priority higher or lower. Typical places where this happens is when you want a hook to run either before or after all others. Are 0 and 100 sufficient priorities? Not if another plugin used -1 and 101; see the quandry? Anyway, that's usually not an issue but when it is, it is.
|
stackexchange-wordpress
|
{
"answer_score": 14,
"question_score": 3,
"tags": "filters"
}
|
change front end menu depending on user login
How can i change my front end menu depending on if the user is logged in or not?
For Example:
View 1: user is not logged in
menu is : home , about us, testimonials
View 2: user is logged in
menu is : dashboard, my profile, support
Thanks in advance.
|
Define two menus and serve them based on if they are logged in or not which you can do in your theme's `functions.php` file:
if (is_user_logged_in()){
wp_nav_menu( array(
'menu' => 'Logged In Menu',
'container_class' => 'logged-in-menu',
'theme_location' => 'logged-in'
));
} else {
wp_nav_menu( array(
'menu' => 'Visitor Menu',
'container_class' => 'visitor-menu',
'theme_location' => 'visitor'
));
};
You'll also need to register their theme locations which you can do in your theme's `functions.php` file as well:
register_nav_menus( array(
'logged-in' => __( 'Logged-in Menu Area', 'yourtheme' ),
'visitor' => __( 'Visitor Menu Area', 'yourtheme' ),
));
And you'll have to assign those menus to their menu locations in the admin, like so:
!WordPress Admin Menu Locations
|
stackexchange-wordpress
|
{
"answer_score": 8,
"question_score": 2,
"tags": "menus"
}
|
Copy widget settings from one blog to another
I am trying to hook 'wpmu_new_blog' in a plugin so I can copy the widget settings from one blog to the new blog that is being created.
Does anyone know if there are WordPress functions to accomplish this, or should I just use straight SQL?
Thanks, Dave
|
I don't think there is anything specifically for this. You might want to look at the plugin code to find calls to `get_option()` and see what keys they are using, then browse the DB table `wp_options` with phpMyAdmin (or whatever) and grab the associated values.
Without specific support from the plugin this can be iffy since there may be other context-dependent info in there that you don't want on the new site.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 3,
"tags": "widgets, plugins"
}
|
Fatal error: Class 'ZipArchive' not found
What would cause this error:
Fatal error: Class 'ZipArchive' not found in /home/test/dummyurl.com/wp-content/themes/mytheme/upload-zip.php on line 14
PHP Version is 5.3.1
Does WP have a built in function I should use instead? Like perhaps the "unzip_file" function line 525 of ./wp-admin/includes/file.php"?
function openZip($file_to_open) {
global $target;
$zip = new ZipArchive(); //This is line 14
$x = $zip->open($file_to_open);
if($x === true) {
$zip->extractTo($target);
$zip->close();
unlink($file_to_open);
} else {
die("There was a problem. Please try again!");
}
}
|
It means your PHP installation doesn't have the Zip library. You can install it by recompiling PHP with the `--enable-zip` option, or install the PECL package.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "theme development"
}
|
Add new post redirection
I don't know whats wrong going on with my website, this is the second redirection problem going on, Whenever I add a new post, After adding title, When I try to add the content, My own websites home-page appears next to the content box, in a red bordered box, and a page tries to load, this page keeps on loading, nothing comes, the url of loading page is "< !enter image description here
|
As t31os said, first thing you should do is disable all plugins, see if wp-admin/post-new.php works fine then, and re-enable them one by one, see which one is causing trouble.
I would start with the plugin to change the admin theme, since this is the closest one to the admin dashboard.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "redirect, homepage"
}
|
How to run JS, PHP and etc. inside WP post?
I would like to try little web apps with WordPress.
Just to accept some values for few fields and present the output using AJAX.
What are all the necessary modifications on WordPress?
So, far I've tried some plugins like exec-php. But, I am in need of a better advice/suggestion.
|
Natively WordPress posts are subset of HTML (even more like semi-HTML - paragraph tags can be implied and added on output, but not stored). As result it really really doesn't like to store or process active code in post's content. This applies both to internal logic in PHP and front-end logic of post editor (it actively tries to strip some things like iframes, when switching to visual editor, etc).
Basically you have two options:
1. Loosen restrictions on what can be input and sotred in post content - like Exec-PHP you mention in question.
2. Store active code elsewhere (in custom fields for example) and use shortcode in post content to call it.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "php, plugins, ajax"
}
|
Get the post attached to a image attachment
Assuming I know the image attachment ID, how can I get the post permalink to which is attached (if any) ?
|
Roughly this:
$parent = get_post_field( 'post_parent', $id);
$link = get_permalink($parent);
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 1,
"tags": "customization, attachments"
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.