INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Adding post_class into functions.php query Obvious newbie question I'm sure. Working on a friend's site and trying to figure out how to add post_class to a query. Just adding works fine and adds the div, but I don't know how to get it to run the `"id="post-<?php the_ID(); ?>" <?php post_class(); ?>"` part of it instead of echoing it. $sidebar .= sprintf('<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>><p><span class="CityCountry">%s</span>' . chr(13), I'm sure it's a formatting thing of some sort that I don't know yet... still so much to learn...
* `post_class()` will echo the class in the format `class="postclassA postclassB"` * `get_post_class()` will return an array of all registred classes To use `get_post_class()` inside `sprintf()`, you have to return the array as a string. For this purpose you can use the `join()` function. ## Example $classes = join(' ', get_post_class()) $sidebar = sprintf('<div id="post-%s" class="%s">%s</div>', get_the_ID(), $classes, get_the_content());
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "post class" }
Disable revisions for a specific post type only? Any way to disable post revision on specific post types only?
Remove the `revisions` property inside the `supports` parameter of `register_post_type()`. **Example** $args = array( // ... 'supports' => array('title','editor','thumbnail','comments','revisions') ); register_post_type('book',$args); Change to: $args = array( // ... 'supports' => array('title','editor','thumbnail','comments') ); register_post_type('book',$args);
stackexchange-wordpress
{ "answer_score": 7, "question_score": 2, "tags": "custom post types, revisions" }
Apply function on all action hooks? Is there an easy way to apply a function on all action hooks? > I want to apply `esc_attr()` to every action hook (in a way that would work from functions.php or a plugin). I figure I would need to filter `do_action` and `do_action_ref_array` except that those functions don't use `apply_filters`. Is there any way to do this?
Just to answer the **title** > Apply function on all action hooks? isn't that hard, when you know where to look: add_action( 'all', 'callback_function' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": -2, "tags": "plugin development, filters, hooks, actions" }
Redirect blog page to latest post? How can I make it so when the blog link in the nav bar is clicked it redirects to the most recent post? I know how to display just the latest post on the blog page, but I want it to actually redirect to the post page itself as I'm displaying a full screen background image called in via a custom metabox on each post page. Is there perhaps a PHP query and redirect function I can apply to the blog page template, or is there a better way? UPDATE: the following redirect script works great but I just need a way to get the URL of the latest post: $URL = " wp_redirect( $URL, 301 ); exit;
You can use the get_posts() function: <?php /* Template Name: Redirect */ $args = array( 'posts_per_page' => '1', 'post_type' => 'post' ); $post = get_posts($args); if($post){ $url = get_permalink($post[0]->ID); wp_redirect( $url, 301 ); exit; }
stackexchange-wordpress
{ "answer_score": 10, "question_score": 4, "tags": "redirect, post meta" }
Allow users to upload multiple images to their profile I've asked this before but to no avail. I need the ability for any user (From Contributor up) of my website to upload a minimum of 5 and a maximum of 10 images to their profile and have they displayed immediately I'm sure there's a way to customize the User Photo plugin - < but it's beyond my skillset. Any ideas?
You can use Cimy User Extra Fields which will allow you to add as many fields as you'd like and currently supports: * text * textarea * textarea-rich * password * checkbox * radio * drop-down * picture * picture-url * registration-date * avatar * **file**
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images, uploads, profiles" }
Best way to include jQuery and fire with script at bottom of container I'm going to be using a jQuery slider on my homepage only (not a WP plugin, but a third party). What I'd like to do is include jQuery, the plugin's jQuery script using a .js file, then include the script needed to fire the plugin right before the closing body tag. I'm a bit confused about how that works. I know WordPress comes with jQuery built in, so does that mean I don't need to include it again? Looking for best practices on this. I understand there are conflict issues that need to be prevented, etc. Thanks
You typically should use the jQuery version that's built in. There are instances where you might want to use wp_dequeue_script('jquery') and then add a different version of jQuery. Here's the best way to add a script dependent on jQuery: function theme_register_scripts(){ wp_enqueue_script('jquery'); wp_enqueue_script('myscript-name', get_bloginfo('stylesheet_directory') . '/js/myscript.js', array('jquery')); } add_action('wp_print_scripts', 'theme_register_scripts'); The third argument of wp_enqueue_script is the script dependency which we identify as jQuery. This guarantees that jQuery will be printed before your custom script is printed.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "jquery, wp enqueue script" }
Get menu object from theme_location I'd like to get a menu object from its theme location argument. My goal is to output separately the menu name and its items name, url and description. Example of what I'm looking for : $menu = get_menu('nav-menu'); //get menu from its theme location echo $menu->name; //displays the menu name foreach($menu->items as $item){ echo '<a href="'.$item->link'">'.$item->name.'</a>'; //displays a link to the item destination echo $item->description; //displays the item description }
This method looks like what you're looking for, using get_nav_menu_locations() and get_term(): $theme_locations = get_nav_menu_locations(); $menu_obj = get_term( $theme_locations[$theme_location], 'nav_menu' ); $menu_name = $menu_obj->name; (See the link for the whole thing wrapped up in a custom function; the above code just highlights the relevant WP functions for getting what you're after.)
stackexchange-wordpress
{ "answer_score": 16, "question_score": 10, "tags": "functions, menus, oop" }
Zigconnect Plugin: Allowing editors to remove connections I'm using the ZigConnect plugin to set relationships between different types of posts. It appears that editors do not have the ability to remove connections, although this works fine for admins. How can I enable editors to remove connections? Also, I have the User Role Editor plugin installed, but I’m not sure which capability would allow an editor to remove a connection. I'm using WordPress 3.1.4 Multisite and Zigconnect plugin version 0.8.6
You could give the user the capability `manage_options`, however this will allow them to edit all options within wordpress. The best bet will be to change all the capabilites checks from `manage_options` to `level_7` or some other editor capability(like `edit_others_posts` ) within the plugin. (Found 12 matches, 7 on `zigconnect\zigconnect.php` and 5 on `zigconnect\zigconnect-admincallbacks.php` )
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "plugins, user roles" }
Is it mandatory to have a link to the theme designer? I just wanted to know if it's ok to modify/remove links pointing to the designer of the theme. In my case I have "theme by" and the site's logotype, would it be ok to remove the logotype and write the site's name? Or remove it altoghether? Does it have to do with the particular designer of the theme? Thanks
It depends on the license under which the Theme is released. Assuming the Theme was released under GPL: no; you are free to change the Theme in any way you want. If you redistribute the Theme, modified or unmodified, you are required to maintain the original copyright/license information _in the Theme file headers_ , but are still not required to have a public-facing attribution or link. If the Theme was released under CC-By: no; you are free to change the Theme in any way you want. As with GPL, you are required to maintain the original copyright/license information _in the Theme file headers_ , including a link to the Theme's license information, but are still not required to have public-facing attribution or an arbitrary public-facing link. If the Theme was released under any other license, you'll need to consult the terms of the applicable license.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "themes" }
Googles jQuery: Are There Avantages to Using It? Are there any good reasons to pull Google's jQuery from their servers as opposed to using the one included with Wordpress? I'm confused as to why I might want to use Google's library. Doesn't Wordpress, with its frequent updates, keep the latest version? Or am I missing something? Thanks.
The big advantages are the Google CDN and the client side caching of the library. Your visitor will probably have a version of the jquery library in the browsers cache already, so he doesn't have to re-download the script from the local version used by WordPress. One big disadvantage by including the library from the cloud: You have to trust Google.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "jquery" }
Image resizing - TimThumb vs convert on upload? I'm using jQuery Supersized to display a full screen background slideshow on my blog, and I'm using mobile detection to serve a smaller version of the images to mobile devices so it will load faster. Which option do you think would be better? 1. Use TimThumb to dynamically resize the image size and jpeg quality 2. On upload of the image, create another version for mobile devices e.g. myimage_mobile.jpg Also, how do these conversion options compare in quality to resizing in photoshop? Thanks
WordPress and TimThumb both use GD to resize images, so quality is going to be similar. GD's resize quality is not as good as Photoshop, you'll notice this especially in fine details. Both WP and TimThumb can be modified to use ImageMagick, WP via a plugin, TimThumb I think requires you edit the code directly, which is not ideal. ImageMagick will give better results, but you obviously have to be able to install it on your server. TimThumb creates images on-the-fly, but caches them so subsequent requests will pull the image from cache. As for my opinion, I would stick with native WordPress functions to keep things simple, especially in light of the recent TimThumb exploit that compromised a lot of WordPress sites.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "uploads, timthumb, images" }
search this custom post type I am trying to be able to search a particular custom post type on my blog. The custom post type is named: **website_bookmarks** I have modified my search form with a hidden field <input type="hidden" name="post_type" value="website_bookmarks" /> So on my search page in the URI I will see... www.mydomain.com/?s=mysearchterm&post_type=website_bookmarks The problem is it ONLY shows search results for my regular blog post and no results from my custom post type. It should not be showing any results for my blog post and ONLY results for my custom post type **website_bookmarks** Can someone help me? I can not figure out why it will not work and it will work on other people blogs simply by changing the search form to what I did above.
Could you check one thing for me: < When you register `website_bookmarks` is: **exclude_from_search** ( _boolean_ ) (importance) Whether to exclude posts with this post type from search results. Set to **false**?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, search" }
Would Amazon AWS Services be a good alternative to my current hosting provider? My WP sites keep crashing my server because I have huge amounts of load in a short amount of time. The server has to be rebooted every few minutes. We have tried everything but nothing seems to work...would Amazon AWS Services be a good alternative? If so, which AWS services would work best?
AWS is good, but a bit hard to understand if you've never set up a server. You should take a look at < for their cloud server package. It's about $25 USD/month for a decent server. They also have a control panel for load balancing setup. I've hosted a bunch of WP sites on my cloud servers there with no issues. Support is fantastic.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "server, server load, amazon, web services" }
WordPress Retrieve Post by Title The following code works brilliantly for retrieving certain pages, but I can't get it to retrieve POSTS by name. I'd like exactly the same code, but to retrieve posts rather than pages. Any help appreciated. <?php function get_my_content($page) { $my_id = $page; $post_id = get_post($my_id, ARRAY_A); $content = $post_id['post_content']; return $content; } ?> <div id='test'> <?php $page = get_page_by_title('testpage'); echo get_my_content($page); ?> </div>
As per docs you only need to specify different post type to make it work: $page = get_page_by_title('testpage', OBJECT, 'post');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts" }
Manipulate list of themes in wp-admin I'm running a multisite network with 100+ themes installed and activated. Is there a way to manipulate the list of available themes in wp-admin so that certain themes appear in the list first? (a kind of "Featured" or "recommended") After the first 9 or so alphabetical as default would be fine. Obviously Googling the words "wordpress" and "themes" has been pretty fruitless in this case.
Came up with a silly but effective measure to get certain themes at the front of the list. Because themes are listed alphabetically, it was possible to manipulate the output by changing the theme name, specifically by adding a symbol to the front of the theme name it will appear at the start of the list. I settled for a non-breaking-space `&nbsp;` as it didn't effect the name visually. You could also try invisible ascii characters. HTML is stripped so don't bother trying that. /* Theme Name: &nbsp;Ribbon Description: A customisable theme
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "multisite, themes, wp admin" }
How/where is the global variable $wp_registered_widgets filled? I have a problem of widgets not showing up, trying to investigate why $wp_registered_widgets is empty. Can somebody tell me where it gets filled from the database? How can I find out why the default widgets are not set.
As you can see here, `$wp_registered_widgets` is defined in wp-includes/widgets.php (as expected). You should be able to debug it by doing something like this: function yoast_print_active_widgets() { global $wp_registered_widgets; echo '<pre>'.print_r( $wp_registered_widgets, 1 ).'</pre>'; } add_action('init','yoast_print_active_widgets'); Then you could loop through the different stages, from `init`, to `send_headers` to `wp_head` and see where stuff goes wrong...
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "widgets, globals" }
Is it possible to link to the same page from wordpress page menu? I have a big one page wordpress site and a menu created from wordpress admin pages panel. I added everywhere in my main page such links like `<A NAME="gohere">` and similar. Now I need to add href's to the page menu name's like `<a href="#gohere">` Actually I do not know is it possible to do this from the wordpress admin page's menu or maybe anybody know where these pages are stored so that I could add the links manually in the file's. Thanks! Tried plugin "Page Links to" and added something like `<A NAME="gohere">` as a link in where, but unfortunately plugin do not understand this, Regards,
well you've to change code in loop for example currently now loop is like <?php if(have_post) : while(yourquery): the_post : <div>the_title</div><div>the_content</div> endwhile; endif; Then Just Add this line also <?php if(have_post) : while(yourquery): the_post <a name="$i"><div>the_title</div><div>the_content</div></a> endwhile; endif;
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "menus" }
Taxonomy Meta Box in User Profile? Is it possible to have users populate a taxonomy meta box(es), using the post_tag or any custom taxonomies I create? The idea is to include users in a network into the taxonomy schema, which would bring the community together in a better way. I guess a more specific way to ask this is how would I add taxonomy meta boxes to the user interface. Obviously anything's possible if I'm willing to go far enough. Is this something that can be done using existing WP API's etc? Thanks.
Best way to link taxonomies and users is to link the user account to a custom post type then link the taxonomy to the custom post type. **Example:** !User - Post - Taxonomy You can use the action user_register to automatically create a new post for every new user and then start linking everything. I have used this method on < and it works like a charm.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom taxonomy, taxonomy, users" }
Have users created automatically when a network site is created Trying to figure out how to have users created automatically when a network site is created. So currently when a new user registers, their account is created and their network site is created. That gives that new site one user already (the site's admin). But when that's created I'd like to also have 3 more users automatically created to each new network site on creation.
You can do that hooking into `wpmu_new_blog` and then creating the user if it does not exists, and adding that user to the blog being created. To do so, you will use a code like this ( only for 1 user) , as a network enabled plugin or on the main theme functions.php add_filter('wpmu_new_blog','wpse_29543_new_blog'); function wpse_29543_new_blog($blogid){ $user_name="user"; $user_password="password"; $user_email="[email protected]"; $role="editor"; $user_id = username_exists( $user_name ); if ( !$user_id ) { $user_id = wp_create_user( $user_name, $user_password, $user_email ); } add_user_to_blog( $blogid, $user_id, $role ); }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "users, multisite, automation, wp create user" }
How to set posts per page using WP_Query() I'm trying to set the number of posts_per_page dynamically using my own variable. This code works fine: query_posts( $query_string . "&posts_per_page=" . $myvar ) // then display the loop using get_template_part( 'loop' ); That works fine, but I would like to know how to do it using $wp_query instead of query_posts. However, this does not work: $wp_query->set('posts_per_page', $myvar) // then display the loop using get_template_part( 'loop' ); That has no effect on the number of posts displayed. Am I using the set method incorrectly, or is there something I'm missing?
`query_posts` will do the query again (destroy current wp_query and create a new one and then doing the query with the parameters you pass to it) To get the same behaviour after setting the new parameter with `set_var` you need to query the database again using something like this $wp_query->set('posts_per_page', 1); $wp_query->query($wp_query->query_vars);
stackexchange-wordpress
{ "answer_score": 14, "question_score": 4, "tags": "query posts, wp query" }
How would I compare and remove hacks to core? I have been put in charge of a site that have a lot (and i mean it) of core hacks, some are pretty easy, some are really hard to spot (like removing a do_action on `the_content`. So, my question is , how i would and remove the hacks the previous maintaners did, while adding the new features requested. Should i go and fix as soon as i spot them, or actively search for any hack in the core? (Side-Effect of the core hacks,can not update wordpress or it will completely break and a lot of features will be "removed" effectively putting the site down)
Pull down the copy of Wordpress from your client's server to your local. Download a clean zip of the version of Wordpress your client has installed. < From there, you will need to use a file comparison tool (i.e. Diff on Linux). You can also use GIT to find the difference in folders by creating a GIT repo of the hacked Wordpress, then overwrite the files with the new WP and GIT will track them and show you the differences. Github for Mac can make easy work for you.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 4, "tags": "multisite, core, hacks" }
Show only preview of posts on the homepage? Is it possible to only have a couple lines shown per post (or even 0 lines) on the homepage? Instead of dumping the whole article on the page?
Look somewhere after the "Loop" starts (it starts with `<?php while( have_posts() ): the_post(); ?>`) in your `index.php` file. Find `<?php the_content(); ?>` and change it to `<?php the_excerpt(); ?>`. If you don't want any content, just remove `the_content()` all together. If you're using a theme from wordpress.org, it would best to do this in a child theme, so you can keep the original theme up to date.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "plugins, homepage, previews" }
Getting selected (highlighted) html from the Visual Editor on Edit Post page? So I understand that the visual editor uses something called TinyMCE. How do I retrieve the html that the user selects from the visual editor? I am basically trying to create a button that gets the selected html and replaces it.
The visual editor (TinyMCE) has its own API and since its a JavaScript Based editor you can get the selection using JavaScript very easily tinyMCE.activeEditor.selection.getContent();
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugins, tinymce, visual editor, syntax highlighting" }
Theme name passed into some of the functions? I use a theme called **vigilance** I am starting to build my own themes and I notice in this them a lot of functions will have the theme name vigilance passed into the functions like this one below... <?php _e( 'This post is password protected. Enter the password to view comments.', 'vigilance' ); ?> Notice the theme name is passed as the second parameter, I am trying to figure out why? I have not found anything supporting this in the docs yet?
It's the text domain, for use in internationalization.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "theme development" }
Scrolling Ads? Live scrolling widget, not random on refresh I have a current job where my client has requested to have their "sponsors" rotate in the sidebar widget. Right now I have a random ad widget which rotates them randomly... I was wanting to know if there is a plugin or a way to make a number of image ads slide, or rotate live when you are on the page not via refresh and random. Thanks in advance!
_**UPDATE_** I ended up using the promo slider plugin which you can get here it worked great. I customized the css slightly and its easy to use and easy to set to custom sizes. Its generally made for a full size slider, I just shrunk it down to 250x375 for my ad space. You can see it live in the bottom right of this site here.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, widgets, ads" }
How to rewrite WordPress uploads folder to another folder using htaccess I found that the following code online could be used to spoof the WordPress uploads folder, rewriting URLs to a different folder on the server: # BEGIN Spoof wp-content/uploads directory RedirectMatch 301 ^/uploads/(.*)$ https?://yoursite.com/wp-content/uploads/$1 # END Spoof wp-content/uploads directory It is my understanding that under Media settings page the 'Full Path to files' needs to point to desired spoof folder. I have tried using the above code but WordPress throws a error 404. My uploads are set to be organized by year and month. The file was that uploaded and tested indeed exists on the server. Here is an example of the structure setup: Real folder path -> < Spoofed folder path -> < My question: Is there anything wrong with the rewrite code that could lead to the error 404 issue?
yes, this: https?://yoursite.com doesn't do anything you want, just make it ` Next to that, make sure your server actually supports RedirectMatch.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "uploads, htaccess, mod rewrite" }
Wordpress pages not working out correctly with HTML Hey all i am having some problems with finding out where wordpress saves my pages. I have a default theme selected and have added a few pages. However, the links to them seem to show up all the same (page.com/about, page.com/contact, etc etc). They all have the same content no matter what page i view (even though each page i set up has been published (saved) with different HTML in the box). Where can i go to find out where its saving my HTML for each of these pages? I don't see a about.php, contact.php, etc in the theme directory so where is it getting that information (and better yet, where is it storing my HTML i add and publish for each of those pages?) Thanks for your time! David
Wordpress store your pages in mysql database MySQL -> YOUR-DATABASE-NAME -> wp_posts / Your-Prefix_posts -> post_type for pages wp_type=page & for posts wp_type=post when you use wordpress visual editor it generates its own html but when you use HTML editors you can use your own HTML & works fine.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "pages" }
Editing the nav menu? I want to add | (vertical lines) between the page links in the nav menu. What's the easiest way to do this?
The `wp_nav_menu` function supports multiple styling parameters, < For instance you can add a `$menu_id` and then style the CSS for each `<li>` along the lines of `border-right:1px solid;` . Another option is to just add a "|" for the `$link_after` parameter, but you should probably use the ascii HTML entity value for it which is `&#124;`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "menus, navigation" }
How to edit products page of wp ecommerce plugin? The one problem that is always finds me again is that I cant find particular pages. Lets say I created a product from the admin panel. I have a link to the page, but now I need to edit the look of that page. Where I can find this page physicaly?
WordPress uses a template system- content is stored in a database and gets inserted into a template when a page is served, so pages and products don't exist as separate, physical things. To edit the templates Wp E-Commerce uses, go to Settings > Store and click on the presentation tab. There will be an advanced Theme Settings box which will allow you to select which templates you want to move into your active theme directory. Once you've moved them you can then edit those templates without losing changes in a plugin update. Note that, much like WordPress posts and pages, your single product pages all share the same template, so you'll need some additional code in your template to determine what the current product is if you want to style specific products differently than others.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin wp e commerce" }
Taxonomies: display hierarchical parent list I've been using WP for years, but this is my first time with taxonomies, so I need a little bit of help. Like in the question How to show a hierarchical terms list? I have a taxonomy called `places`, which contains a hierarchical list of places (first level for countries, second level for cities, etc...). A post can have an associated place: for example, we could take Berlin (child of Germany, child of Europe). Now, the output I want is something like this: Where: Berlin, Germany, Europe. I've tried some solutions, but none works. I'm pretty sure that there must be a simple and clean solution...
`wp_get_object_terms` will give you the term assigned to the post, you could then use `get_ancestors` to get an array of the parent's IDs, then `get_term_by` ID to get the names and slugs.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "custom taxonomy, hierarchical" }
How to Fetch Rss Feeds From Other Websites I've 3-4 Blogs 2 on same topics I want if i post on 1st blog then 2nd blog can fetch feeds automatically and save that in database as a post or Can anyone tell me how smashing network work when someone post in his blog smashing fetch feeds and excerpt and show it in smashing network and when user click on that post he/she redirect to original blog post.
If you are looking for something free I use FeedWordPress on one of my site which works well. There is also a commercial plugin AutoBlogged. These are the two I know of, I'm sure others exist.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "rss, feed" }
get_post_meta not working on category.php I'm referencing an attached image in my `header.php` page which is displayed as a full screen background on my posts: global $wp_query; $page_id = $wp_query->get_queried_object_id(); $background_image = get_post_meta( $page_id, 'mb_background_image', true ); $src = wp_get_attachment_image_src( $background_image, 'full' ); This works fine on single posts, but doesn't work when displaying just one post per page in `category.php`. How can I fix this?
The `$page_id variable` wasn't defined in `category.php` so I changed as seen below: $background_image = get_post_meta( $post->ID, 'mb_background_image', true );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "categories, images, attachments, post meta" }
Generating images from an array of categories I'm using the following code to display images based on the category id: <?php if (is_category( 'web-design' )){ ?> <img src="<?php bloginfo('template_directory'); ?>/images/slider_webdesign.png" title="خدمات تصميم وتطوير المواقع" height="200px" width="960px" /> <?php }else if (is_category( 'printing' )){ ?> <img src="<?php bloginfo('template_directory'); ?>/images/slider_printing.png" title="تصميم مطبوعات" height="200px" width="960px" /> <?php }else if (is_category( 'online-marketing' )){ ?> I would like to make an array of only one condition to display an image with the category slug, is that possible?
`is_category()` takes an array as arguments if you want to check for more than one category. But you can make it even easier with a check for existing files: if ( is_category() ) { $slug = get_queried_object()->slug; $theme_path = "/images/slider_$slug.png"; $file = get_template_directory() . $theme_path; if ( file_exists( $file ) ) { echo '<img src="' . get_template_directory_uri() . $theme_path . '" alt="" height="200px" width="960px" />'; } }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "conditional content" }
In a loop, do not display content that does not have a thumbnail In a multisite installation, I have a loop set up on my main blog that displays all posts from sub blogs, along with a thumbnail image. The image is important and without one will break the grid. Is there a way to reject posts that do not have a featured image? Thanks.
Try to use the has_post_thumbnail function. From the codex: <?php //This must be in one loop if(has_post_thumbnail()) { the_post_thumbnail(); } else { echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />'; } ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "multisite, post thumbnails, loop" }
Display Post Format as a String I hope this isn't a stupid question, but I can't find an answer. I just want to display (in the loop) what post format a post is in. I'm trying to avoid using a bunch of if / else if conditions. I'm not trying to restyle the post based on format, just display "Gallery" or "Quote" or whatever the current post format is, given they are enabled for my current theme.
Try: <?php echo get_post_format_string( get_post_format() ); ?> **EDIT** Note, if you want a fail-safe output, try this: <?php if ( get_post_format() ) { echo get_post_format_string( get_post_format() ); } else { ehco 'Standard'; } ?> Or, if you want to store it in a variable: <?php $post_format_string = ( get_post_format() ? get_post_format_string( get_post_format() ) : 'Standard' ); // echo the result echo $post_format_string; ?> Codex ref: get_post_format(), get_post_format_string()
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "post formats" }
Query specific Pages I wonder if someone would know how to query specific pages (not by id), lets say I create a custom field called "product", and I would like to query all pages with that custom field. Any Help? Kind Regards :)! UPDATE: So far I've found this solution thank u so much! so far I've found this solution global $wp_query; $args = array_merge( $wp_query->query, array( 'post_type' => 'page' , 'meta_key' => 'product' ) ); query_posts( $args ); ?> and works really cool!
As you can see on < you can query by meta_key , so to query by `product` custom field, you will do something like this . $args=array( 'meta_key' => 'product' ); $pages = get_pages( $args );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "pages, query" }
Archiving custom post content? Last year, I built a movie festival website using "movie" as a custom post type. Now that the festival is over and we're getting ready for next year, how would I archive that content so that I can start adding movies for the coming festival? Thanks!
You could add a category for that custom type with the year number . So old movies will been archived into a category of 2010 , and newer one into a category of 2011. Also it will allow an easy way for your users to view and figure what year is a movie from.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, archives" }
Add quicktag buttons to the HTML editor I am trying to figure out how to modify the HTML editor in wordpress; on the image below you can see a screenshot of the editor and the buttons on the top. Is it possible to add new buttons? I would like to add a button that will insert "" tags and some custom short-code tags as well. I know it's not impossible, but does anyone know how to do it? !enter image description here
Download and install HTML Editor Reloaded Plugin and go to setting pages and you can add your own new buttons. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 5, "tags": "editor, html editor" }
Where is the reset password key stored/generated? Where is the reset password key stored in the wordpress DB? Is this the same as the user_activation_key? WP version 3.2.1
From line 213 of wp-login.php: $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login)); So yes, the key is the `user_activation_key`. Don't know what you need to know that for but if you look in that file you'll see there are several ways to hook into it.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "password" }
Wordpress automatically adding "&nbsp;"? I'm not sure if is wordpress itself or Tiny MCE that's doing it. But when switching between HTML and Visual editor it's adding `&nbsp;`, and adding an extra one each time I switch back and forth. I don't even have a line break in the code, it seems to somehow be deciding where it wants to place them based on the tags in my html code. What's causing this and how do I fix it? I've already tried this in the template functions file: //disable auto p remove_filter ('the_content', 'wpautop'); remove_filter ('comment_text', 'wpautop'); // Remove auto formatting remove_filter('the_content', 'wptexturize'); remove_filter('comment_text', 'wptexturize'); remove_filter('the_title', 'wptexturize');
All I use is `remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' );` and that stops Wordpress from creating any extra markup. Are you copying and pasting your code from an external editor?
stackexchange-wordpress
{ "answer_score": 2, "question_score": 13, "tags": "tinymce" }
Alternative loop syntax error I'm trying to minimize my code and have put together this little snippet, it doesn't seem to work however. What am I missing? query_posts( 'year=2011' ); if ( have_posts() ); while ( have_posts() ); echo 'test'; endwhile; wp_reset_query(); endif;
Because you're using semicolons when you should be using colons after the `if` and the `while` :) query_posts( 'year=2011' ); if ( have_posts() ): while ( have_posts() ): the_post(); the_title(); endwhile; wp_reset_query(); endif; That works just fine.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "php, loop" }
Remove ShareDaddy meta box from Pages only I'm trying to take away the option to have sharing options on 'pages' (but leave on posts). So I have a function to make sure the sharing option is always no on pages function page_disable_share($post_id) { if ( 'page' != get_post_type() ) return; update_post_meta($post_id, "sharing_disabled", 1); } add_action('save_post', 'page_disable_share'); But I'd rather not have the meta box there at all, it might confuse the user if they tick it and it always unticks itself. function page_remove_share() { remove_meta_box( 'sharing_meta' , 'page' , 'normal' ); } add_action('admin_menu' , 'page_remove_share'); Bu that's not working. Maybe JetPack is getting hooked in after 'admin_menu'? I tried other hooks (< but none work. Any ideas?
Use the `add_meta_boxes` action with a very low priority, so: function page_remove_share() { remove_meta_box( 'sharing_meta' , 'page' , 'advanced' ); } add_action( 'add_meta_boxes', 'page_remove_share', 99 ); I think that should work.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "metabox, plugin jetpack" }
Using WP functions such as the_title() in an included php file I'm including a php file in single.php, in the loop. Is it possible to use WP variables such as the_title(), the_date(), etc in the included php file?
Get the title into a variable, and use the variable in the included PHP instead: $title = get_the_title(); include "yourfile.php"; yourfile.php: <?php echo $title; ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, include" }
First Custom Post Custom Fields Empty After New Custom Post I am working on a theme which contains a custom post type with custom fields. Everything is working perfectly except the when a new custom post is added, the custom fields for the first custom post and first one only are wiped. function save_details(){ global $post; update_post_meta($post->ID, "testimonyname", $_POST["testimonyname"]); } add_action('save_post', 'save_details'); This is what i am using to save the custom field data
the problem was worse than I thought. Here is the solution: Add New Post (Custom Post Type) Deletes 1 Post's Custom Meta Data
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, custom field, customization" }
Flushing rewrite rules I'm using this function to add a custom end point to the WordPress urls add_rewrite_endpoint('print', EP_ALL); When the plug-in gets deactivated, I run this function flush_rewrite_rules(); This flush the rewrite rules, and disable the 'print' end point. Fine. But I'm thinking of other plug-ins. What if other plug-ins have registered some rewrite rules. Will they be flushed too? If so, how can I preserve them as this will run their rewrite rules. And the same being for my plug-in. Do you have to re-register the rules everytime WordPress is called?
What `flush_rewrite_rules();` does is call `$wp_rewrite->flush_rules();` (Also called when updating permalinks). All plugins rewrite rules are regenerated then, so you dont need to worry about other plugins rules being "missing". Also is not a good idea to call this function (`flush_rewrite_rule`) on hooks that run each time wordpress is loaded, and is enough to call `add_rewrite_endpoint` or `add_rewrite_rule` on activation or deactivation hooks.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "url rewriting, urls" }
Categories show 404 error on multisite installation I have a wp multisite installation with multiple blogs that are totally separated websites. I use a plugin for domain mapping. Right now I am configuring everything and I wanted to remove the /blog slug from the main blog, I did it by editing the settings as "network admin". I used /%POSTNAME%/ and / for category and tags base. The posts opens fine opening www.url.com/postname, but www.url.com/categoryname show 404, I tested changing the category base to anything (like /c) and www.url.com/c/categoryname works. But I don't want to have a category base I want the category post lists to open on www.url.com/categoryname. How can this be done?
You can't have / as category and tags base, at least not without using a plugin like this one: < Doing it for both tags _and_ categories seems almost impossible to me though.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, multisite, permalinks" }
How to link to the image editor's Edit Image function? How do I link to the image editor's _Edit Image_ function from the front end? I know that I can open the lightbox with a simple link, such as `<a href="wp-admin/media-upload.php?post_id=719&amp;type=image" id="content-add_image" class="thickbox add_image" title="Add an Image">Upload photos</a>` However unlike opening the image edit lightbox, _Edit Image_ is an input... example: `<input type="button" id="imgedit-open-btn-766" onclick="imageEdit.open( 766, &quot;83bc6c7af5&quot; )" class="button" value="Edit Image">` Any thoughts or direction would be appreciated. The screenshot below is from v3.3 nightly. ![]( EDIT: The direct url to the editor in the backend is `wp-admin/media.php?attachment_id=772&action=edit`. My goal is to get this edit form to popout in the lightbox without the other wp-admin stuff.
You may add the following scripts: wp_enqueue_script( 'wp-ajax-response' ); wp_enqueue_script('image-edit'); wp_enqueue_style('imgareaselect'); Maybe this already helps? I think the html in the front-end should be similar to the html in `/wp-admin/media.php?attachment_id=...&action=edit`
stackexchange-wordpress
{ "answer_score": 0, "question_score": 3, "tags": "uploads, images" }
Wordpress query_posts and orderby page order I have a page that lists all sub pages of the current page. Each page has been assigned an order number in the wordpress editor but they aren't ordering for some reason. I'm set up like this: Products -page1 -page2 -page3 -page4 -page5 my query_posts looks like this: query_posts('post_type=page&order=ASC&orderby='.$post->menu_order.'&post_parent='.$post->ID); But the output comes out like: 1,3,2,5,4 How do I simply order pages with the built in page order field? I thought this was default...
I was going to suggest using `&orderby=menu_order`, but you already pointed it out in your comment. :) p.s. you can answer your own question, I think. Since you found the answer to your question, just post your own answer. I _think_ it's kosher to accept your own answer?
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "query posts, order" }
Ignoring a category in WP_Query still shows the links in next_post_link()? So I have a WP_Query like so: $homepage = new WP_Query( 'posts_per_page=1&cat=-5' ); and in my while loop, I have a call to `next_post_link()` and `previous_post_link()`, which are both showing posts from the excluded category. Here is what my code looks like next: <?php while ( $homepage->have_posts() ) : $homepage->the_post(); ?> <?php next_post_link('&laquo; %link'); ?> <?php previous_post_link('%link &raquo;'); ?> <?php endwhile; ?> According to the wordpress docs on next_posts_link & previous_posts_link, these functions are based on the current query: > Prints a link to the next set of posts within the current query. So does anybody have an idea of why `next_post_link()` and `previous_post_link()` would show posts that should be excluded while the rest of the loop works as expected?
You'll have to exclude the category in your `next_post_link` and `previous_post_link` calls too, as it's using the posts data, not your specific queries data, so, this should fix it: while ( $homepage->have_posts() ) : $homepage->the_post(); next_post_link( '&laquo; %link', '%title', false, '5' ); previous_post_link( '%link &raquo;', '%title', false, '5' ); endwhile; Where 5 is the excluded category. If you need to exclude more categories, just comma separate them.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "categories, wp query" }
Elegant way to include only published posts with get_objects_in_term()? The obvious way is to iterate through the resulting array of IDs, get_post for each and test against `post_status == 'publish'`. But I wonder whether this could cause memory issues since `get_post` will attempt by default to cache each result? Short of a custom SQL join, are there any surprise args one can pass to `get_objects_in_term()` or is there some other tax function I'm not leveraging that I should be?
You can add `'post_status' => 'publish'` in your query to retrieve only objects with status publish , this will work for `get_posts`, `query_posts` or `$wp_query` and to include also custom taxonomies you can use `tax_query` in your args list
stackexchange-wordpress
{ "answer_score": 11, "question_score": 6, "tags": "posts, taxonomy, publish, get post" }
Query for specific taxonomy that executes a particular loop depending on volume of posts? Is it possible to create a special wp query that looks to see how many posts exist in a specific taxonomy, or taxonomy term, and executes a particular loop depending on the volume of posts? My idea behind this is - **Id like to be able to show particular CPT content in a different styled format depending on how many of those posts exist**. For example: _Lets say the **taxonomy "product categories"** only contains about **2 posts** listed with **child terms** that exist in that taxonomy **rather then something like 20**... Well what Id like to do is list those products in a larger style via CSS instead of having to default on the more consolidated styling for when their are a larger volume of products._ Can this be done, and if so how?
Just check the total number of posts found: if($your_query->found_posts > 20) ... and decide how do you want your mark-up to be. If want to see how many products are associated with a certain product_category term, use get_term() and check out the 'count' property
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, custom taxonomy, wp query, terms, loop" }
WPMU function get_blog_details, last_updated/registered and formatting time and date string Within my multisite installation I can get the registered and last updated time strings for a sub blog through get_blog_details and the blog ID: echo get_blog_details($blog_ID)->registered Ok, how do I format the resulting time string: 2011-09-28 00:20:34 Thanks
$time = get_blog_details($blog_ID)->registered; $unix_time = strtotime($time); $my_time_format = date('Y-m-d H:i:s', $time); // eg. 2011-09-28 00:20:34 $diff_format = human_time_diff($time); // eg. 2 days See date() and replace `Y-m-d H:i:s` with the format you want
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "multisite, blog id" }
Should I go for Multisite or separate WP Installation? I'm developing an article site where an user can register and post the articles and the URL would be like ** The site will also be having a blog under ** And the blog section will only be accessed by site owners and not by any registered users. I want the blog URL to be like < and not to be like < So should I go for a separate WP Installation or enable Multisite for this URL structure ? Any other better options/ideas are always welcome. **I don't want to do an installation on a subdomain like blog.domain.com** Thanks in advance.
Generally choosing separate WP installations means that your websites won't have anything in common. Choosing Multisite installation enables you some sort of centralization. Your blogs usually are separate (eg. different domains / themes), but they may share something. According to your description you might want consider a single installation. It is possible to create the described URL structure using Wordpress Custom Post Types and Custom Taxonomies. For the registered users functionality, you could adapt the Contributor user role to your needs, so users, who are Contributors are limited only to posting articles to your website.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "multisite, customization, installation" }
Creating fields in the database I am newbie to wordpress plugin and this is my first plugin which I am doing now. I want that when the plugin will be activate it will make some predefined fields in the database and also the same fields in the form page. So how to do that. Any help will be highly appriciable.
Read the WordPress codex, specifically < and if you are looking to create tables read < Make sure you remove them if the plugin is uninstalled.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, plugin development, database, forms" }
Application form plugin with payment gateway I'm working on a site for a small business academy. We're trying to create an application for potential students to fill out to apply for the school. The form needs to be able to have multiple long-form questions, (paginated would be nice for each), and before the application is submitted, the students would have to pay an application fee. Does anyone know of any application form plugins that support these features: paginated questionnaire and payment gateway for application fee? TIA
Yeah, go with Gravity Forms, it has several options for payment, supports paginated forms and there are even more third party extensions to add payment gateways. Check out my review for some more tips about it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin recommendation" }
Most Effective Method? Exclude Category and Number of Posts Per Page I want to create a loop that excludes a category and only displays a certain number of posts per page. I have tried both have_posts and query_posts to do this, but I'm a bit stuck on the most effective method. What would you use to do this?
Just use a custom query like this: $exclude_cats = '2,52,3'; $posts_per_page = '4'; $loop = new WP_Query("category__not_in=$exclude_cats&posts_per_page=$posts_per_page"); if($loop->have_posts()): while($loop->have_posts()): $loop->the_post(); //Do stuff here the_content(), the_title() etc... endwhile; else: //Do something here endif;
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query posts, loop" }
How to add pagination with page numbers rather than next/previous links? Does WordPress have any built-in pagination functions to show the page numbers instead of previous and next page links? If not, how can I add that? Thanks
It depends on _which_ pagination you're talking about: * Archive Index pagination * Single-Post pagination * Comments pagination In all three cases, the answer is **yes** , but the implementation is different. **Archive Index Pagination** WordPress provides a function, `paginate_links()`, for post-archive pagination links. It's use isn't exactly straightforward, but fortunately, implementation is mostly cut-and-paste from the Codex example. Here's how I use it in Oenology. **Single-Post Pagination** WordPress provides a function, `wp_link_pages()`, for intra-post pagination links. It's use is straight-forward, as a normal template tag. **Comments Pagination** WordPress provides a function, `paginate_comments_links()`, for comments pagination links. This template tag is actually a wrapper for `paginate_links()`, but its use is straight-forward.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin recommendation, pagination" }
How to Run a jQuery Script after a Javascript Script has Finished in WordPress I've got javascript (a) and jQuery script (b). I need (b) to run after (a) has finished running. I need them to run sequentially. How do I do that? In wp_enqueue_script, I've made (b) dependent on (a), but it appears that (b) runs before (a) has finished processing. I'm trying to use the_maps_bounds, a variable I've put in the global scope. It gets set in (a) and used in (b). The problem is that (b) is trying to use the variable before it has been set. Any suggestions? Thank you.
To accomplish this, wrap wp_enqueue_script in a function and run it through the action hook wp_enqueue_scripts while using the 'priority' parameter available in add_action to set the load order. function these_go_first() { wp_enqueue_script('first_script', '[path to file]/first.js', array('jquery'), '1.0' ); } function these_go_first() { wp_enqueue_script('after_script', '[path to file]/after.js', array('jquery', 'first_script'), '1.0' ); } add_action('wp_enqueue_scripts', 'these_go_first', 1); add_action('wp_enqueue_scripts', 'these_go_after', 2); wp_enqueue_script can also define script dependencies as well. This is why I added 'first_script' which I had already defined in the function just before, to the dependencies array in the second function.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "jquery, javascript, wp enqueue script" }
How does Wordpress remember which editor is being used? Hey so I am trying to determine how Wordpress remembers which editor is being used for a particular post (HTML or Visual Editor (tinyMCE)). When you write a post, and then come back, it goes to the last used editor. I am assuming its a cookie of some sort (because I couldn't find any info in the database), but does anyone know where the code for this is?
**wp-settings cookie screenshot** its stored in the cookie wp-settings-USERID, replace USERID with the id of the logged in user. the two values are editor=tinymce or editor=html
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "tinymce, post editor, cookies" }
Remove Title, Editor and Meta Box Support Based on Post Formats Been looking around and can't find this. Is it possible to remove, let's say, the title area on post format: "quote"? Or the editor on post format: "image"? I noticed this page in the Codex: < Seems you could pull it off if you created a custom post type for images, for example, then removed support for that type, but that defeats the purpose of formats and also would break new themes, which I don't want to do.
You're talking about the format setting which was introduced in WP 3.1 for the `posts` post type? No, I don't think this is possible. To remove the title-, editor- or any other metabox, you have to remove the `support` for this feature from the current `post type`. (e.g. remove the feature from the `supports` parameter inside `register_post_type()` or during execution with `remove_post_type_support()`). This will affect the hole post type `posts`. You cannot limit this behavior by the post formats property. This isn't a post type, it's just a post meta for the post type `posts`. What you could do is to hide the boxes based on the post formats value with jQuery. But this only works if the user has enabled JavaScript. It's also more a hack than a solution.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "metabox, editor, title, post formats" }
How to associate an image with a term taxononmy and publish it on frontpage? I couldn't find the solution anywhere else, so I believe is a valid question for this website. I think my problem is divided in two parts. I created a custom taxonomy called "Type" and within it, I have terms (tags) like "cool", "sad", "amazing"..and so on. 1) I want to associate an icon for each one of my terms. 2) I want to display those icons (within link to the term archive) in my front page, like a feature image for each post. No idea how to do that. Help please.
My Media Categories plugin lets you categorize images, and in the latest update I've added to ability to pass a 'category' parameter to the standard gallery shortcode. So perhaps you could use the gallery shortcode to present your images on your front page. My next release will include the ability to filter the taxonomy that is being used so that its not tied to the category taxonomy specifically.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "images, taxonomy, terms" }
How to restrict plugin's sub-menu pages to admin/subscribers? I am working on a plugin with 6 submenu pages. I want 5 of them to be accessible by Administrators only and 1 of them to be accessible by Subscribers only. Both user roles will have different features available on their respective pages. Is it possible to do that? If yes, how? If no, what are the alternatives? Thanks for your time!
Is this right: First 5 pages - Administrators ONLY, NO subscribers Sixth page - Subscriber ONLY, NO Administrator ? If this is correct than you only have to add the capability type as 'administrator' when creating the first 5, and 'subscriber' for creating the sixth. That should work. Or add a new capability for admin, use it while adding the first 5, and a new capability for subscriber, use it while adding the sixth.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "plugin development, user roles, sub menu" }
Stop wordpress from hardcoding img width and height attributes I'm wondering if there's a simple way top stop WordPress automatically hardcoding featured image height and width attributes, other than using regex... As I'm using a flexible grid for my project (who isn't!) this is causing some funky image issues.
You can get featured image URL and add it to your content manually, eg: <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' ); if ($image) : ?> <img src="<?php echo $image[0]; ?>" alt="" /> <?php endif; ?>
stackexchange-wordpress
{ "answer_score": 8, "question_score": 17, "tags": "images, post thumbnails" }
Is there any way I can put google ads on wordpress.com? I know they do not allow plugins on wordpress.com and hence no ads. I know I can put adds on own wordpress site hosted on my own domain. But I really like wordpress.com and the ease you can create blogs there. Is there any decent way that I can put my ads on google? Weren't they allowed the ads before? Or would anyone encourage me to go with my own site instead of wordpress.com ?
No, you cannot, unless you have 25,000 pageviews/month, as stated here! < Go with hosted or self-hosted solution of Wordpress instead.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "wordpress.com hosting, ads, adsense" }
Why does the TwentyTen Theme sidebar <ul> have a class called 'xoxo'? Why is the CSS class called 'xoxo'? What does it mean?
I was curious about this myself one day. Here's a link explaining it. Excerpt from Wikipedia link above: > XOXO (eXtensible Open XHTML Outlines) is an XML microformat for outlines built on top of XHTML. Developed by several authors as an attempt to reuse XHTML building blocks instead of inventing unnecessary new XML elements/attributes, XOXO is based on existing conventions for publishing outlines, lists, and blogrolls on the Web.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "sidebar, theme twenty ten" }
Is there a conditional tag to determine whether the post is _any_ custom post type? We know you can do `if ( is_singular( 'my-cpt' ) )` to test for a _specific_ custom post type, but what about doing one thing if the post is a built-in post type, and another if it is not? Is it enough to just test against `if ( is_singular() && ! is_singular( 'post' ) )`? Or are there some implications or subtleties that are escaping me at the moment?
I don't know of a conditional tag, but here's how you would list the built-in types: echo implode(',', get_post_types( array('_builtin' => true ) ) ); Output: post,page,attachment,revision,nav_menu_item Maybe better: // 1 result if it exists and is builtin, 0 otherwise get_post_types( array('_builtin' => true, 'name' => $post_type ) );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, conditional tags" }
Page template query with WP_Query I would like to query only pages with a certain page template with `WP_Query` or a function that would return the post object, but I can't find any information about that on the official codex.
UPDATE: This is now a decade old answer, meant for a very old version of WordPress. I can see the comments informing me that this might not work for newer WP versions, please do refer to the other answers below if mine is not working for your version of WP. For WP 2.*, this will work. Try this... Assuming the template name is 'my_template.php', $query = new WP_Query( array( 'post_type' => 'page', 'meta_key' => '_wp_page_template', 'meta_value' => 'my_template.php' ) ); //Down goes the loop... You can also use get_posts, or modify query posts to get the job done. Both these functions use the same parameters as WP_Query.
stackexchange-wordpress
{ "answer_score": 27, "question_score": 20, "tags": "wp query, pages, templates" }
Template Tag "template_directory" pulling wrong path I'm working on a theme index.php and it seems that when I use the "template_directory" it is not actually pulling the url path of the file, but instead is just pulling the main domain name. So instead of its pulling the domain url and showing this I don't understand why it's doing this, since the index.php file is actually in the right directory. (which is inside the theme folder). There is the index.php file that is in the wordpress directory... but I don't understand why it would conflict with the themes index.php file.
To get the exact path of image which is placed in < in your theme. All you have to use below code: 1. To show image > > <img src="<?php bloginfo('template_url'); ?>/images/pic.jpg" /> >
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme development" }
How do I get category and page ID's? I want to insert the category or page ID of the current page into my HTML so that I can use CSS to style each page based on what it is. For example, if had a category called "News" and it's ID was 5, my source code would end up having in it. Then I could use CSS to style #category-id-5 to suit my needs. How would I accomplish this?
`get_queried_object()` has a property with that ID. But you don't really need it, because the `<body>` tag should have a class with the current category / page ID...
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "categories, pages" }
Can I upload media to a specific folder? By default, media uploaded through the Wordpress dashboard goes into a folder determined by the current date. For example: /wp-content/uploads/2011/09/. Once the media is uploaded I'm not seeing any options in Wordpress to change the location of my file to something else. Can I tell Wordpress to place my media in a separate folder? **Not all my media.** Just ones that I specifically select.
1. Go to `Dashboard -> Settings -> Media` 2. Enter the desired location in _Store uploads in this folder_ 3. **Uncheck** _Organize my uploads into month- and year-based folders_ This will specify the _global_ upload location. To specify a per-file upload location, you'll need to use a Plugin, such as WP Easy Uploader (not an endorsement, _per se_ ; it was just the first one I found).
stackexchange-wordpress
{ "answer_score": 18, "question_score": 22, "tags": "uploads" }
Filter Loop by Custom Field Value I'm trying to filter a loop by a custom field value. I've tried all of the suggestions on the site, but it just won't filter. This loop is being used for a custom template of an rss feed. It pulls together the custom post type and only the posts that are "published", but I can't get it to filter by custom field value. ` global $wp_query; $args = array_merge( $wp_query->query, array( 'post_type' => 'custom_type', 'post_status' => 'publish', 'meta_key' => 'my_custom_field', 'meta_value' => 'custom field value', ) ); query_posts( $args ); ?> while( have_posts()) : the_post(); ?>` Any suggestions?
How about this: $my_query = new WP_Query(array( 'post_type'=> 'custom_type', 'post_status' => 'publish', 'meta_key' => 'my_custom_field', 'meta_value' => 'custom field value' )); if($my_query->have_posts()): while($my_query->have_posts()):$my_query->the_post(); //All the post stuff here. endwhile; endif; wp_reset_postdata(); Check this out.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "query posts, loop, meta query" }
Gallery Thumbnail Layout Template Is there a way to create a template to display a gallery thumb layout? Or am I stuck with selecting a thumbnail size and rows in the upload image/gallery area and media settings area?
One of the better approaches is to unregister WP's default gallery shortcode function, and add your own customized replacement. WP engineer has a great post about it here. This also will let you fix that funky inline CSS that the default gallery adds to the page.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "attachments, gallery" }
Placing <div> tags on wordpress visual editor using shortcodes Hello I need to have the following code on a specific page: <div class="searchbar" > <div class="searchbar-inner" > search <input type="text" id="search" /> <span class="result-count" ></span> </div> </div> Is it possible that I use a shortcode to place it on the visual editor while editing the page?
Assuming you don't have the shortcode written down... function search_shortcode() { $struct = '<div class="searchbar" ><div class="searchbar-inner" >search <input type="text" id="search" /><span class="result-count" ></span></div></div>'; return $struct; } add_shortcode('search_box', 'search_shortcode'); Make sure your editor is in the 'HTML' mode, and paste the shortcode as 'search_box'. Using a shortcode will allow you to reuse this form anywhere you want.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "shortcode, tinymce, visual editor" }
Tagcloud: different color for different text size I'm using `<?php wp_tag_cloud( $args ); ?>` to create a tag in my sidebar. With the "args" you can style it quite a bit, even the different text size, but it doesn't seem to be possible to apply different colors. What I did is a plain CSS solution which looks somewhat like this: #tagcloud ul .tag-link-8 { color:#666; } #tagcloud ul .tag-link-7 { color:#7EA7C9; } #tagcloud ul .tag-link-9 { color:#6A9EA5; } It works okay, but this is a hassle. I have to apply the colors manually and once I have 50 tags or so this will be kind of ridiculous. I was wondering if there is a way to connect e.g. the text-size to a specific color (like some tagcloud plugins seem to do anyways) (size:8 = red etc.)? Anybody any ideas? Thanks a lot in advance!
Use a filter for the tag cloud to change the inline size declarations to CSS classes and declare the colors in your style sheet: .tag-cloud-size-8 { color: #009; font-size: .8em; } .tag-cloud-size-10 { color: #900; font-size: 1em; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "tags" }
How to display comments and comment form on custom post type? Is it possible in wordpress to display comments and comment form on custom post type, and how to do that? Thanks in advance.
**1)** add "comments" to the supports array when registering the post type. !Register Post Type **2)** add the comments_template() function inside the loop of the single.php template and you are good to go. !Add Comment Template To Post
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "posts, forms, comments, customization" }
wp_handle_upload() does not list uploaded file in the media library? Is it supposed to? My code: if ($_POST && $_FILES) { $tmp_name = $_FILES['file']['tmp_name']; $item = $_FILES['file']; $uploads = wp_upload_dir(); if (is_writable($uploads['path'])) { if (!empty($tmp_name)) { if ($tmp_name) { $overrides = array('test_form' => false); $file = wp_handle_upload($item, $overrides); } } } }
To list uploaded file in the media library use wp_insert_attachment
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "uploads" }
Conditional Tags and Echo HTML / divs or CSS and Display: none? If I wanted to show a slider on the home page only, is it better or does it make a difference if I: * use a PHP if/then statement and echo a division and markup, or * use CSS along with a body class and display none the division? or * a combination of both What's the best practice?
target homepage only with if statement. if ( is_front_page() or is_home() ) } if your home page has page/2 page/3 then use the following to display the slider on only page 1 of the homepage. if ( is_front_page() or is_home() && ! is_paged() ) { }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "conditional tags" }
Download all Wordpress.com available themes, somewhere? I am looking for a website, or a way to find and download all Wordpress.com available themes for my WPMU website. I have searched for some on < but they don't seem to be there. So do you know any repo or list with those themes listed and links to download them?
You can from now on download all free themes on wordpress.com. On theme's page look for "Download [name] for your self-hosted WordPress site" link in sidebar, under "Stats & Info". Konstantin Obenland announced that in a tweet today.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "themes, wordpress.com hosting, list" }
Localization: Textdomain of Child teme I am creating a series of WP child themes which are dependent of a parent theme which I will be using as a framework. I need to have these themes (both parent and children) localized. from < I understood I need to add the following to my theme: add_action('after_setup_theme', 'my_theme_setup'); function my_theme_setup(){ load_theme_textdomain('mytextdomain', get_template_directory() . '/lang'); } this goes in the functions.php, I suppose however, what about children themes? functions.php of a children theme overrides functions.php of a parent theme should textdomain ("mytextdomain") of the child theme be the same as parent theme or be different (and also call load_theme_textdomain function with a different function name (see above code "my_theme_Setup()")? what is the correct way of localizing both a parent and child theme? thank you for clarifying this :)
Child themes should use `load_child_theme_textdomain()`. You can find it in `/wp-includes/l10n.php`. Use a new slug and a separate po file.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "child theme, parent theme, localization, translation" }
How do i change the footer? I downloaded a free theme and I changed everything except the footer I can't change it. I opened the file **footer.php** and there was only written as shown: </div><!-- /content-wrapper --> <div id="footer"><?php wp_footer(); ?> <ul id="footer-nav"> <?php wp_list_pages('title_li=&depth=1' ); ?> </div> </div> </body> </html> I can not find a way to change the `wp_footer ();`. Did there is an external file that I need to change?
The `wp_footer()` function is a WordPress hook. It allows plugins to place additional content at the bottom of the page - this is very useful if you're installing tracking scripts like Google Analytics. But that function is _not_ what is adding copyright information or other junk usually bundled with free themes. Instead, look in the theme's `functions.php` file. There's likely a function somewhere in there that's outputting the content you see. You'll also see somewhere this line: add_action( 'wp_footer', 'some-function-name' ); That line will fire the `some-function-name()` function whenever WordPress calls `wp_footer()`. Just delete that line and you should clean your footer up.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "footer" }
How to display related posts from same category? Is it possible to display related posts from same category as the current post?
One possibility: $related = get_posts( array( 'category__in' => wp_get_post_categories( $post->ID ), 'numberposts' => 5, 'post__not_in' => array( $post->ID ) ) ); if( $related ) { foreach( $related as $post ) { setup_postdata($post); /*whatever you want to output*/ } wp_reset_postdata(); } Reference: * `get_posts` * `wp_reset_postdata` * `wp_get_post_categories` Answer re-written based on `WP_Query()`: $related = new WP_Query( array( 'category__in' => wp_get_post_categories( $post->ID ), 'posts_per_page' => 5, 'post__not_in' => array( $post->ID ) ) ); if( $related->have_posts() ) { while( $related->have_posts() ) { $related->the_post(); /*whatever you want to output*/ } wp_reset_postdata(); }
stackexchange-wordpress
{ "answer_score": 32, "question_score": 17, "tags": "posts, categories" }
Query pages by category Trying to query pages based on the category they are associated with. I am passing in the cat_ID, but it doesn't seem to be working. Always returns a single post with the title "Hello World" while there is an actual page with real title associated with this category. // The Query query_posts('cat='.$current); // The Loop while ( have_posts() ) : the_post(); the_title(); endwhile; // Reset Query wp_reset_query();
It's because the default query is only querying for post_type post, you have to explicitly add page to get it to also query for pages: $args = array( 'cat' => $current, 'post_type' => array( 'page', 'post' ) ); query_posts( $args );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, query posts" }
display tag slug as class per link in tag cloud I would like to filter `wp_generate_tag_cloud` so each of the tag links include the slug as a class. More specifically, I would like to output "tag-" + the tag slug. Currently what is assigned as the class is "tag-link-" + the tag ID. The the end, I would happy with either a replacement or just adding this additional class to the links.
one possible way: add a filter in functions.php of your theme: add_filter ( 'wp_tag_cloud', 'tag_cloud_slug_class' ); function tag_cloud_slug_class( $taglinks ) { $tags = explode('</a>', $taglinks); $regex = "#(.*tag-link[-])(.*)(' title.*)#e"; foreach( $tags as $tag ) { $tagn[] = preg_replace($regex, "('$1$2 tag-'.get_tag($2)->slug.'$3')", $tag ); } $taglinks = implode('</a>', $tagn); return $taglinks; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "tags, filters, cloud" }
Permalinks - Different structures for different categories? Currently I use /%category%/%postname%/ as my permalink structure. However, I would like to have a different structure for different categories. This is because I have a "News" blog that I would like to have organized by date like this - /2011/10/02/. But I have other categories where I do not want a date structure at all. Is this possible?
This is probably not possible or it would require some really scary and fragile hacks. Use a custom taxonomy for the news or a custom post type instead. Setting a different permalink structure for these is much easier. You should find enough examples on our site.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "categories, permalinks" }
Social network plugins for Wordpress I would like to make my blog fully integrated with social networks. This mean: * Login via facebook / twitter * Share to facebook / twitter * Include open graph data in the page * any other suggestions I've tried: * Twit Connect but if you enable showing of tweet button under posts, it is included under pages too. * ShareThis - it has option to show only under posts, but it stopped working after I've installed Simple OpenGraph. * Simple OpenGraph - I'm happy with this one. _So, I think a canonical answer for this would be helpfull for the community and I'll be happy to give bounty for such._
Not knowing any one-shop-for-all plugin type, but for Facebook, you can try the Simple Facebook Plugin by Otto. This plugin let you enable the single features that you require for your blog, including registering via FB, login via FB, post to your wall... OpenGraph... etc.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "plugins, plugin recommendation, customization" }
How do I get posts to appear at mydomain.com/blog? I'd like to use WP to manage my whole site, not just the blog. I don't want the blog to appear on the home page, but instead at mydomain.com/blog. What I've done so far under Settings/Reading is to change the "Front page displays" from the default of "Your latest posts" to the other option, "A static page". So that allows me to have a static page for my homepage, which is what I want. Now how do I go about getting the blog portion of my site (posts) to live at mydomain.com/blog ? Any assistance would be most appreciated. Thanks. Eddie
Check out the Codex, specifically step 2. What you need to do is create a new page, name it "Blog". Make sure the permalink is < Then, in Settings > Reading, select that page as your posts page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "url rewriting, urls, customization" }
Custom Post Types, Custom Taxonomies and Permalinks ? So let's say i register a custom taxonomy called: Clients With a few terms such as: `Microsoft, IBM, Apple` Under a CPT (custom post type) called `projects`: # Permalinks `/%year%/%monthnum%/%taxonomy%/%postname%/` this is the structure i am using; < \- Displays All posts under 'projects' < Displays a 404 < displays all posts under `projects` with the term `ibm` How can i get Wordpress to display an Index of all the posts under Clients? so for example if the user visited /projects/clients/ all the posts with Microsoft, Apple and IBM would be displayed. I know a method is to use a page and then query into the page, but in essence of SEO, and relevance, i can not name the page-slug something else. Thanks in advance.
You need to write a custom rule. I did similar stuff for a recent project. Create a template, and assign it to a page, with slug as 'clients' (or anything you like, but change the slug in the following rule as well). Try the following code, use **functions.php** : add_action('init', 'custom_rule'); function custom_rule() { global $wp, $wp_rewrite; $wp_rewrite->add_rule('^projects/clients/', 'index.php?pagename=clients', 'top'); } Then on that template, form a custom query with your desired params (clients taxonomy) and loop through it. > Note: After you put the above code in your functions.php file, go to Settings > Permalinks, and click on save. Hope this helps (I recommend you try it locally first)!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom post types, custom taxonomy, permalinks" }
Only show theme option if it option exists I have a slideshow in a custom theme I am developing and I am using the UpThemes Framework, what I want to know is, is there a way and image will only display if it has been defined? For example, at the moment the max. number of images in the slideshow is 6, but if only 5 are uploaded the "alt" attribute displays for the 6th For those unfamiliar with the framework, this is the PHP tag I am using <?php echo $up_options->slideshow6; ?> I have done this with custom fields in the past but I can't for the life of me figure out how I did it.
If you're wanting to output based on the option being _defined_ , then use `isset()`. e.g. this: <?php echo $up_options->slideshow6; ?> ...becomes this: <?php if ( isset( $up_options->slideshow6 ) ) { echo $up_options->slideshow6; } ?> **EDIT** > How would I get the following to appear only if "slideshow6" was defined `<a href="#"><img src="<?php echo $up_options->slideshow1; ?>" alt="#"/></a>` I would go with: <?php if ( isset( $up_options->slideshow6 ) ) { echo '<a href="#"><img src="' . $up_options->slideshow1 . '" alt="#"/></a>'; } ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "options" }
FB Comments box post to wall? I have a blog that I have a FB comment box. When I post the blog Its also sent a blurb about the blog to the fan page and then database the post id with the post. But is it possible that when a user posts a comment in the FB comment box I can also have that post as a comment to the actual post on the fan page?
I believe the new Social plugin takes care of that. Let me know if it works.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "facebook" }
Query all posts under one taxonomy? Why is my code not working? I'm trying to show all the posts associated with a Taxonomy (not a term) but it seems to not work. <?php $args = array( 'post_type' => 'projects', 'tax_query' => array( array( 'taxonomy' => 'clients', 'terms' => 'Unilever' ) ) ); $the_query = new WP_query(); $the_query->query($args); if($the_query->have_posts()):while($the_query->have_posts()):$the_query->the_post(); php the_title(); endwhile; endif; wp_reset_query(); ?>
You haven't specified the 'field' value e.g. `'field' => 'slug',` <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, query posts, taxonomy, tax query" }
Can "Recent Posts" widget be filtered by functions.php? I have my own "Recent Posts" menu, but its not currently implemented as a Widget. I'm just including it in sidebar.php. I had to "roll my own" so to speak in order to filter the menu of certain categories whose posts I don't want to appear in the menu. Would it be possible, via functions.php, to filter the default "Recent Posts: widget's menu items in order to exclude posts belonging to a specific category? If so, I'd really be grateful for an example.
Unfortunately there is no filter for `WP_Query` args in `WP_Widget_Recent_Posts` class, so it's impossible. I think there are plugins for recent post that have category filtering option - <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "theme development" }
Jquery not working (function($) { $(document).ready(function(){ /*$('body').css('position','relative'); $('body').animate({'left':'-9999px'},3000);*/ alert('hello'); }); }(jQuery)); Tried also $(document).ready(function(){ /*$('body').css('position','relative'); $('body').animate({'left':'-9999px'},3000);*/ alert('hello'); }); And firebug jumps: jQuery is not defined [Detener en este error] }(jQuery));
Are you sure the jQuery library is loaded on your page? The error you're getting implies it isn't. View the source and search for jQuery. Then try adding this some where in your functions.php (or plugin) file and see if your script works. <?php add_action( 'wp_enqueue_scripts', 'wpse30127_enqueue' ); function wpse30127_enqueue() { wp_enqueue_script( 'jquery' ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "jquery, javascript" }
How do I get rid of "category" from my URL structure? By default WP links to a category like this, mydomain.com/category/travel. Having the word "category" appear in the URL seems unnecessary. I'd prefer have the link read mydomain.com/travel. How can I remove "category" from the URL structure? I don't want to replace it with something else as I can do by entering a new Category Base under Settings/Permalinks. But instead eliminate the Category Base all together so that the category names follows the domain name as in mydomain.com/travel. Thanks in advance for any advice you can offer. Its most appreciated. Eddie
Many plugins take care of that. The one i prefer is Yoast Wordpress SEO plugin, as it does a lot of good things to your blog in terms of SEO.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "categories, url rewriting, urls, link category" }
Split post edit screen into sub-edit screens for users, is this good or bad, and is it possible? I am working on my user back end access in which users can control a few posts based on post type as well as submit posts in a few other areas (Guides and Encyclopedia entries). The single post types they have access to have a large amount of meta-data and taxonomies to choose from/enter data into. I was thinking of splitting the post edit screen into separate "sub-edit" screens to divide up the entry input. 1. Is this a good idea? 2. How should I go about setting it up? Set up Ideas: 2a. I can hide certain parts of the edit screen if I pass a $_GET in the url OR 2b. I can set up customized edit forms via add_submenu_page function. Which I used when first trying to set up user access from the front end - abandoned this idea as I could not get the WYSIWYG editor to function on the front end. Any suggestions or insights are greatly appreciated. Thanx!
I decided against the idea. Answered my question for clarity.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "user access, post editor, user interface" }
Adding a class (arrows) to main menu links that have children? I'm wondering if it is possible to add different classes to second/third/fourth/etc-level items that have children in Appearance > Menus tree? That's how I call the menu: <?php $menu_args = array( 'container' => '', 'menu_class' => '', 'menu_id' => 'my-menu', 'walker' => new Description_Walker); wp_nav_menu($menu_args ); ?> I know every link owns different ID like `<li id="menu-item-3230">`, but I want the solution to be dynamic so I won't have to edit code every time I change something. I guess the easiest way will be to attach additional class to these items but how? !enter image description here
There are two ways of doing this: * Javascript. You could use JQuery to select the `<li>` that have `<ul>` children of class 'sub-menu', inserting content, or appending a CSS class which you then style. For example: `$('.sub-menu').parent().addClass('myclass')` * PHP, a new walker function. Copy the code from wp-includes/nav-menu-template.php (until approx line 109) into your themes functions.php to create a new walker. Pass this walker as an argument to your menu call. In the modified Walker insert a `<span>` for an arrow on a sub-menu level item. function start_lvl(&$output, $depth) { $indent = str_repeat("\t", $depth); $output .= "\n$indent<span class=\"right-arrow\">&rarr;</span><ul class=\"sub-menu\">\n"; } This will add a small arrow that you can then style just before the sub-menu list item.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "menus, javascript, walker" }
Moving WP from /blog to root directory I'm moving a WordPress installation from /blog to the root directory on the server. There weren't more than ten blog posts in the blog, but I'm concerned about Google finding dead urls. Is there an easy way to handle redirects? A plugin, etc. Or a simple best practice? Thanks very much.
see if this plugin can work for you: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "directory" }
Downloading Wordpress: Nightly Build vs. Stable Download Whats the difference between a nightly build and the latest stable download, and what is the ideal use case for each? On the Nightly Build Page it says: > Development of WordPress moves fairly quickly and day-to-day things break as often as they are fixed. This high churn is part of our development process that aims to produce the most stable releases possible. Should this be interpreted to mean that the Nightly is a version with less bugs? I've been on support threads where an issue is brought up and it's suggested to download the nightly build (on WordPress forums and elsewhere) and I'm wondering if this is a best practice? Thanks very much.
Stable release of WP is the one meant for production. Any serious issues (such as security) are addressed via minor releases. Some of the fixes for not that serious issues can be received ahead of schedule with Hotfix plugin. Non-stable versions are usually run by WordPress developers for the sake of experimentation and early access to new features. That is not meant to be general practice.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "wordpress version" }
Syntax Highlighting Plugins and 3.2.1 I was looking for some decent syntax highlighting plugins to display php code on posts. But most of the plugins in the wordpress repository are not updated for years. I found wp-syntax causing issues with the theme. So is there any good plugin with less bugs and better syntax highlighting that works fine with wordpress 3.2.1 ?
I use SyntaxHighlighter Evolved on my site which is based on Alex Gorbatchev’s SyntaxHighlighter and used by WordPress.com blogs/sites to get something like this: !enter image description here And i just recently published a plugin named Simple Gist Embed > This Plugin allows to embed GitHub Gist to your posts/pages/custom using a simple shortcode and even simpler using a built-in Tinymce button. I know there are other plugins which do that already but this plugin also lets you create a GitHub Gist From within your WordPress admin. Other then the option to create Gists from your admin this plugin is faster then the others because of it’s built-in caching of Gists to the database.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugins" }
Inserting a Download Link in the Quick Edit Actions of the Media Library? What's the best way of doing this: On The 'Media Library' page, I would like a link next to 'View' (the 'View' that appears when you hover over a Media item) for 'Download'. The 'Download' hyperlink would link directly to the file, unlike the 'View' link which links to a template-based page with either the embedded image or a link to the non-image file. I have a lot of PDF's in my media library that I look up regularly, having to click on 'View' and then click on the hyper-linked file name just to get to the file is a little cumbersome.
Modified version of a piece of code found in this tutorial. add_filter('media_row_actions', 'wpse_30159_qe_download_link', 10, 2); function wpse_30159_qe_download_link($actions, $post) { /* Almost sure this is not necessary. Just in case... */ global $current_screen; if ( 'upload' != $current_screen->id ) return $actions; // if not PDF file, return default $actions if ( 'application/pdf' != $post->post_mime_type ) return $actions; // relative path/name of the file $the_file = str_replace(WP_CONTENT_URL, '.', $post->guid); // adding the Action to the Quick Edit row $actions['Download'] = '<a href="'.WP_CONTENT_URL.'/download.php?file='.$the_file.'">Download</a>'; return $actions; } The download script resides here: `/wp-content/download.php`. And here's a sample code of a _force download_ script.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "media library" }
How to make that google wont follow some of the wordpress pages? How to make that google wont follow these two pages: < Thanks! P.S. Im using worpdress with WP Ecommerce plugin.
You can do two things: 1. Create a sitemap.xml excluding the pages you just mentioned. 2. Create a robots.txt which disallows the Google robot from looking at certain files: To exclude all robots from parts of a server: > User-agent: * > Disallow: /product-page/checkout This is not WordPress specific. HTH
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "e commerce" }