INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Replacing a placeholder term with a session variable value in taxonomy filter I have in my themes some code which will set a session variable. For the sake of example, it's a geolocation routine which will set to either USA, UK or ROW, resulting in: $_SESSION['region'] = 'USA'; and I have a custom taxonomy of 'regionok' which any or all of the same terms are set. I wish to use the session variable value as the taxonomy term to filter on. The cleanest solution I can imagine would be to have a filter hook in my functions.php which would replace the placeholder term 'auto-region' with the session value before each query is executed. That way I can use widget plugins without having to hack them - I would just use the placeholder term in configuration. However, I don't know what the relevant hook would be. (Other use cases would be session variables for family filter, referrer, etc. The geolocation example is entirely incidental.)
If you want to apply this term filter to all queries on the site, then you'll want to use the 'parse_query' action. This action will accept the WP_Query instance as a parameter, which will allow you to add a term filter based on the $_SESSION variable.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "taxonomy, hooks, session" }
current_page_item and custom post type? I have a page on my site that lists all posts for my custom post type 'Literature'. However when I click on one of the posts, the highlighted active menu item changes to 'Blog'. How do I assign these posts to the menu item 'Literature'? Thanks
You should use wordpress's built in menu manager for this, along with a specific template file for listing the custom post types (for instance template-literature.php).
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, menus, navigation, wp list pages" }
Google map iframe into wordpress theme I have embedded a Google Map iframe in my theme and I'm trying to center a Google Map location in the middle of the map. All works fine except that my location is always shown to the upper left corner not the center This is my website: < The pop up is made using javascript to center it. Happy for all suggestions, tips or answers :)
I googled some more and found out that the problem was that the `<div>` element containing the iframe was `display:none;` in my css. My solution to this problem was to insert the iframe using jquery after i change the display type to block (also using jquery). Hope this helps someone else. Sorry for posting this in the wrong place...
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "google maps" }
Calling Posts from Specified Cat The following is not working to call posts from a specific category and only grab the number of posts selected. I'm using more than one loop on a page as I am using this to create a "featured content" section on my homepage. <?php ('cat=111&posts_per_page=1'); if (have_posts()) ?> <?php while (have_posts()) : the_post(); ?> <?php endwhile; ?>
You're not actually running any queries. Need to run **wp_query()** , **query_posts()** or **get_posts()**. All are covered in great detail within the codex. Though you already have your parameters listed up ;)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query posts, loop" }
Is it possible to associate different kinds of custom post types one to the other? I might be thinking too hard about this problem and i'm thinking the solution might be easier than we're i'm heading. Here's what i'm trying to accomplish: there a winery website built on wp and uses custom post types for "Wines" -> every wine has it's own description, picture, etc (cabarnet 2005, cabarnet 2006 etc...). Now, most wines have won medals - some of them even won up to 8 medals. i want to showcase all medal relevant to a specific wine in his specific page AND i want to have another page that showcases all medals, chronologically. I figured i might be able to accomplish this by creating a custom post type "medal" and to somehow associate the medal to the wine that won it. but can i associate the 'medal' object in a many to one relation to the 'wine' object? how can i do that? Any Ideas?
You can have a look at this plugin: Custom Post Types Relationships (CPTR). It lets you create relationships between posts, pages and custom posts types. There is also the Zig connect plugin that has a very nice feature of reciprocity (no need to edit the second post, it will automatically be related to the first one). Hope it helps.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "custom post types, theme development" }
Developing mobile version of WordPress site I would like to build a mobile version of my WordPress site. To avoid the problems and costs with developing for native platforms, I'd like to go for an HTML/CSS/jQuery approach that would be accessible from the Webkit browsers. The main site is already developed in WordPress, and content can be directly taken from the CMS. I'd like the mobile version to be available from a specific URL such as www.mysite.com/mobile or mobile.mysite.com How can I set this new URL to point to this version of the site? And how will this new URL change as I browse through the mobile site? And how can I load this URL by default when a user accesses the site from a mobile device? Am I right to think that I can then develop this as I would make a normal theme for WordPress, with no other worry about this being meant for mobile devices rather than desktop?
Have a look at the WordPress Mobile Pack plugin. Amongst many features, it allows you to map a (sub)domain to another theme.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "mobile" }
In a subdomain network, what .htaccess settings can I use to have WP ignore requests to one subdomain? I have a subdomain network installed at, say < I need to have my webmail running at < When I go to this domain it redirects to a page for creating a new site: < I know there are some entries WP uses in the .htaccess file, but how can I get WP to ignore requests to webmail.example.com? Thanks.
I found this article: < I had used it originally when setting up the wildcard subdomains on my Plesk server. At first I didn't need to worry about the webmail section, but now I do, and here's what I did: $ cd /etc/apache2/conf.d $ mv zzz_horde_vhost.conf zz001_horde_vhost.conf $ /etc/init.d/apache2 restart This way, the Horde config will be loaded before the wildcard subdomains.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "htaccess, multisite, subdomains" }
Change All Login/Signup Links in Plugin I would like to redirect all login and signup links to an external site. I would prefer to do this in a plugin, or somewhere that isn't affected by WordPress upgrades or theme changes. What is the best way? Thanks!
I solved this problem by putting the code below into a plugin. class My_Class { public static function go_to_login() { global $pagenow, $theme_my_login, $redirect_to; if ( 'wp-login.php' == $pagenow ) { $url = ( false === strpos( $redirect_to, 'wp-admin' ) ? $redirect_to : site_url() ); wp_redirect( ' . urlencode( $url ) ); exit; } } } add_action( 'login_head', 'My_Class::go_to_login' );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, login, authentication, signup" }
moving server can not login I design my site in win7 system, and today before a server rent, I moving my blog from win7 to my another computer witch is installed CentOS 5.5 for a last test, I have reference the article < moving my site from `d:/www/` to `/var/www/html`, and my site runs well, all the post, comment have no problem. But I can not login into my site. I have two test accounts, one is admin, another is normal user, both account can not login into. when I fill with the username and password, click login button, then page will refresh and do nothing still return to the login page with no error hint. I searched google with a ton of posts, I have tried to rename the plugin folder, clear the web browser's cookies... Sorry for I can not test a password forget and register, because I have't install any mail scripts in localhost. Waiting for a possible solution, regards.
I have solved this strange problem by myself. Share my experience to all. Find these 2 lines in `/etc/php.ini` upload_max_filesize 16M post_max_size 16M Add common before, so that change as: ;upload_max_filesize 16M ;post_max_size 16M And final, do not forget restart apache: `service httpd restart` via SSH. Then I could login into my site under linux as the win7 system.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "login, user access, server, linux, windows" }
Taxonomy template shows only 10 posts So I'm a little confused with this one. A blog I recently set up makes plenty of use of custom post types and custom taxonomies. In the reading settings the blog posts to show is at 100 but I can find no where to tell taxonomy pages to show 100 posts and they are stuck at 10. How do I change it without messing around with custom `get_posts();` or extensive `query_posts();` I have tried: A custom `query_posts();` loop
I fixed the issue by removing the taxnomy.php page and let it fall back to index.php
stackexchange-wordpress
{ "answer_score": -1, "question_score": 1, "tags": "custom taxonomy, taxonomy" }
Turn on again old expandable menu In the latest WP the admin interface is changed and you have a popup submenu. I really liked the old version better with expandable menu. Is it somehow possible to get that back again for all users?
Yep, believe so. Try this (enqueue in admin styles): **Show sub-menus at all times** #adminmenu .wp-submenu, .folded #adminmenu .wp-submenu { display: block !important; } **Hide Pop-up Navs** .wp-submenu.sub-open { display: none !important; } That should get you started with it, otherwise you can go to **wp-admin.dev.css** and edit the navigation there, starting at line c. 1519. Hope that helps..
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "admin menu" }
Hook to get image filename when it is uploaded I want to get the full local filename of an uploaded image so that I can copy it to a new directory and process it with my own image processing scripts. Which hooks/actions should I look into to achieve this? Thanks
The `handle_upload` hook is called after wp_handle_upload is run, and it sends in a named array consisting of 'file', 'url' & 'type'. You could possibly use code like this to utilise it, depending on what you need to achieve: function process_images($results) { if( $results['type'] === 'image/jpeg' ) { // or /png or /tif / /whatever $filename = $results[ 'file' ]; $url = $results[ 'url' ]; // manipulate the image } } add_action('wp_handle_upload', 'process_images'); Edit: If you need the attachment ID as well, it might be better hooking in at a higher level, such as add / edit attachment: add_action('add_attachment', 'process_images'); add_action('edit_attachment', 'process_images'); in which case the variable sent in is the attachment_id, from which you can derive the rest using something like: $metadata = wp_get_attachment_metadata( $results );
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "plugin development, images, hooks, uploads, actions" }
Is it possible to display a DIV to not logged in users and then change it for users who are logged in? Basically I'm putting together a magazine site that wants a strong focal point on the homepage for users who haven't signed up, if the user is logged in we need this content to show something else, is this possible? Basically I need a function to show X if the user is logged in and if not to show Y, the code will be placed in the header so whatever page the user has landed on it will encourage the viewer to register for an account.
Yes it's possible, just use the **is_user_logged_in()** function as descibed in the codex for this. It would go like this: <?php if ( is_user_logged_in() ) { echo "you are logged."; } else { echo "You are not logged"; } ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, functions, content" }
Why do themes have `while( have_posts() )` in templates like single.php? Example: < Isn't single.php's purpose to show single posts?
The idea is to ensure that all the content is displayed properly. Some functions are not available outside of The Loop, as it's called, so depending on what you are doing, it may be advantageous to start the loop, even if you're relatively certain it will only be used for one post object.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "loop" }
Post type cloud like tag cloud? Anyone know if it's possible to create something similar to the wordpress built in tag cloud (wp_tag_cloud) but instead of displaying tags, display custom post types? Thanks
How about the `wp_generate_tag_cloud()` function? You'll need to feed it `$tags`, which is an array of objects with the link and term_id, set something like this. $tags[]->link = $link; $tags[]->id = $tag->term_id; The term_id will only be used in the CSS...so don't sweat that too much.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, posts, tags" }
Twenty Eleven Theme Adjusts for iPhones. How to stop this feature? I would like to prevent Twenty Eleven from changing to mobile version when seen on an iPhone. Any way of doing this?
You can remove everything following the line /* =Responsive Structure ----------------------------------------------- */ up until in the style.css for Twenty Eleven /* =Print ----------------------------------------------- */ and it will get rid of all the media queries which are based on the size of the page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme twenty eleven, mobile, responsive" }
How to prevent plugins from sniffing/stealing other plugins' options? Many plugins require configuration with sensitive data such as API keys, passwords, etc. When implementing these plugins, this sensitive data is stored using functions such as `update_option()` and `get_option()`. It would be trivial to write a trojan plugin that provides a useful function but also performs a variety of `get_option()` calls on known-sensitive options. Even if this isn't possible, a manual SQL query can reveal this sensitive data. Is there any way to avoid this inherently insecure model?
Actually, there's not too much you can do. If an intruder has direct access to your site - where they can run `get_option()` or perform direct SQL queries - then you've already run into a problem. The safest bet here is to exercise your best judgement when installing new plugins. In other words, the best plan of action is **_prevention_**. Don't install plugins you don't recognize or written by developers you don't trust. While you _could_ use encryption to protect the data, remember that WordPress itself still needs access. So if WP can read the data, then anyone who can run `get_option()` can also read the data.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, plugin development, security, options" }
Get attachments by user Is there a way to get attachments by user? I need a way to display all the images uploaded by a specific user. (I probably need the attachment IDs so that I can use `wp_get_attachment_url` to display them.)
Use a custom query for this. $user_id = 1; $the_query = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'author' => $user_id) ); if ( $the_query->have_posts() ) while ( $the_query->have_posts() ) : $the_query->the_post(); the_title(); endwhile; This will show all the attachment titles for user with user id 1. You can use `get_the_ID()` in the loop to get the attachment ID.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "theme development, attachments, media library, uploads" }
How do I hide posts in a category from all listings but still allow the posts to be viewed? Let's say I have a category named "Hidden". I'd like to prevent all posts in "Hidden" from appearing within The Loop on the main blog listing page. Also, I'd like to prevent those posts from appearing anywhere else (category listing pages, archives, etc.) However, I'd still like the posts to be accessible via their permalink. Is this possible? Thanks! :)
Answering my own question here: Is it really as easy as including this within a pre_get_posts filter? $query->set('category__not_in', $term_id);
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, permalinks, loop" }
Reset positions of metaboxes in admin I am writing a theme and in it I have a function which creates two metaboxes. The forth parameter of the "add_meta_box()" function I used can be set to ( high, core, default or low). I want the boxes to appear in a particular order ( ie order within one of these 4 groups - eg with both metaboxes being set to 'priority' I would like to be able to determine which was displayed first and which second). That is the back story, but my question derives from the fact that while experimenting with this I must have moved one of the boxes to another column; and that action seemingly overrides the priority in the programming altogether ( I know this because when I rename the metaboxes I have programmatic control again) . I have tried everything to get it back to default but to no avail. Can anyone help ?
In you PhpMyAdmin query for: (if you have a different database prefix, change that in the query, also change the user_id to yours) SELECT * FROM `wp_usermeta` WHERE `user_id` =1 AND `meta_key` LIKE 'meta-box%' Than delete those values and you will get the original order back. If you only want to change the menu order back for a page than only delete "meta-box-order_page".
stackexchange-wordpress
{ "answer_score": 25, "question_score": 8, "tags": "theme development, metabox, dashboard, reset" }
order by numeric value for meta value I have read countless posts on ordering data by numeric value ( as opposed to string - it i have a numeric meta value and it gets ordered like this 1 11 12 2 233 etc as opposed to the way i want it I am using WP_Query have tried using meta_query => 'NUMERIC' but i'm not sure if that's what it's actually supposed to do eg $args = array( 'meta_query' => array( array( 'type' => 'NUMERIC' ) ), 'orderby' => 'meta_value', 'meta_key' => '_date', 'post_type' => 'events', 'posts_per_page' => 5, 'order' => 'ASC' );
you need to use 'orderby' => 'meta_value_num', also if you are ordering dates, the best advice is to put them in an easy to order way such as 2012-12-31
stackexchange-wordpress
{ "answer_score": 34, "question_score": 23, "tags": "wp query, query, post meta" }
How to prepend text to the_content, but after img/shortcode I was trying to add some text to the beginning of every post (the text comes from `post_meta`, but for this example let's assume it's static text). Here's what I tried: add_filter('the_content', function($content) { return 'Text from meta - ' . $content; }); However, if the post starts with a - usually floated - image (sometimes even wrapped in a caption shortcode), the added text will come before the image. I would like for the text to be prepended to the first paragraph in the post. Is there any way to accomplish this without parsing the full HTML?
I finally settled on using a regex, with a limit of 1 so it only happens on the first paragraph: add_filter('the_content', function($content) { $content = preg_replace('/<p[^>]*>/', '$1Text from meta - ', $content, 1); return $content; });
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "filters, the content" }
How to order by multiple date meta_values? I am trying to find some way when using `WP_Query` of ordering by multiple meta_values. I know I can order by multiple values and I know how to order by meta_values but I cant seem to figure out how to do multiple meta_values. Is it possible ?
you can also store it like yyyy-mm-dd and and use $date_array = explode( '-', $date_string ); to make it into an easy to manage array. or even better change it into a unix timestamp with $unix_time = strtotime( $date_string ); php loves to work with unix time stamps, it's the native format. and when you're ready to store the value again in the meta field use this to get the proper format again $date_string = date( 'Y-m-d', $unix_time );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme development, wp query, meta value" }
Add meta tags with a plugin? I've tried a number of plugins including Add Meta Tags and Meta SEO Pack which add a meta tag description to the home page. But my home page is static so the description is added to my blog page. I know I could add them manually but are there any plugins do this? Thanks
For anyone using Thematic, the thematic_create_description() filter worked nicely.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, post meta, homepage" }
After upgrading WordPress, can't access admin interface After performing a WordPress upgrade to 3.3.1, I can no longer access the administration interface. The website works fine, but when I click on Dashboard, I receive the following error: **Fatal error** : Call to undefined function _wp_admin_html_begin() in **/home/a7938356/public_html/wp-admin/admin-header.php** on line **40** ... help! What can I do? I don't have a lot of content, so I could reinstall WordPress, but I'd like to know what went wrong and prevent it in the future. Website: < Current version: 3.3.1 Not sure what version I upgraded from. Site hosting: <
It most likely was a bad upgrade. You should manually download the latest WP version and overwrite all directories except wp-content. Your wp-config.php file won't be overwritten. This should fix the issue.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "admin, updates" }
Managing event dates vs published dates in admin custom post type I have a custom post type which uses dates and i have my custom columns set up in the admin. I need to be able to do order by that column by default - i have tried this code which I found on the net but after playing with it for an hour i still couldn't make it work and it only seemed to want to sort by title; can anyone help me. <
I had to do this on a program management system. this should do the trick. add_filter( 'pre_get_posts', 'my_sort_posts_listing' ); function my_sort_posts_listing( $wp_query ) { if ( is_admin() && $wp_query->get( 'post_type' ) == 'my_post_type' ) { $wp_query->set( 'meta_key', '_my_date_meta' ); $wp_query->set( 'orderby', 'meta_value' ); $wp_query->set( 'order', 'DESC' ); } return $wp_query; } assuming your dates are stored like YYY-MM-DD
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, theme development" }
Combine two foreach Arrays into one table row right now I have two foreach arrays - one outputs the artist, the other a track title I would like to combine both so there is a row for each artist and corresponding track for example: Row 1 - Artist 1 Track 1 Row 2 - Artist 2 Track 2 <?php // Get duplicate fields $duplicate_field = get_post_custom_values('Artist', $post->ID); foreach ( $duplicate_field as $key => $value ) { echo $value . '<br />'; } ?> <?php // Get duplicate fields $duplicate_field = get_post_custom_values('Track', $post->ID); foreach ( $duplicate_field as $key => $value ) { echo $value . '<br />'; } ?>
if the artist names and track names are in matching order and the same in number then: <?php $artists = get_post_custom_values('Artist', $post->ID); $tracks = get_post_custom_values('Track', $post->ID); $i=0; foreach ( $artists as $key => $value ) { $class = ( $i % 2 ) ? 'alternative' : ''; // modulus operator echo '<li class="' . $class . '">'; echo $value . ' - '; echo tracks[ $i ] . '</li>'; $i++; } ?> otherwise if there is some other way they are matched up you need to figure that out in the loop.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "array, php" }
What's wrong with this wpdb query? I want to select some tags with the same term_group, I tested it in phpadmin, the query get the correct result, but once add $wpdb flavor, it returns an empty array. Any advice? $primary_tag_id = // a function to return term_group, result is 3, comfirmed $terms = $wpdb->get_col( $wpdb->prepare( "SELECT name FROM $wpdb->wp_terms WHERE term_group = %d ORDER BY name ASC", $primary_tag_id ));
Try this, it worked for me: global $wpdb; $terms = $wpdb->get_col( $wpdb->prepare( "SELECT name FROM {$wpdb->terms} WHERE term_group = %d ORDER BY name ASC", primary_tag_id )); What you are after is `$wpdb->terms` not `$wpdb->wp_terms`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query, wpdb" }
how to display the wordpress login and register forms on a page? I have a wordpress site. Which has the built-in login form with the url < and register page < As these pages have no sidebar and headers, therefore I want to display these forms on a page which I have created from the backend. Is it possible and how will I do this?
There are a couple of ways to do this. The most simple is probably to install a plugin, such as Theme My Login. The more complicated but flexible way to do it is to use `wp_login_form()` to output the form, presumably to a shortcode or something, and then you can style it yourself.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 5, "tags": "login, pages" }
Yoast's WordPress SEO plugin is not showing the correct snippet I am facing a problem. I am not getting the snippet which YOAST plugin showed me. The snippet in Google search is different from what YOAST is showing. Check out the screenshots ( Let me know what is the solution of it?
It is suppose to work this way. Joost's plugin only gives you a great tool for you to optimize your snippet. If you haven't done any optimizations whatsoever, like creating an awesome brief description of what your content is all about, Google will probably try to figure out what's the best bit of content by their own. Just a minor edit, Google just released a video exactly replying your question:
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugin wp seo yoast" }
Twenty Eleven unregister all default sidebars? I need to unregister all the default sidebars in the Twenty Eleven theme so I can add custom left and right sidebars via the functions.php file in a child theme. This function below is for Twenty Ten; but I don't know where to find the correct strings for the widget areas for Twenty Eleven, which are called Main, Showcase and Footer Areas one, Two and Three. function remove_some_widgets(){ // Unregister some of the TwentyTen sidebars unregister_sidebar( 'first-footer-widget-area' ); unregister_sidebar( 'second-footer-widget-area' ); unregister_sidebar( 'third-footer-widget-area' ); unregister_sidebar( 'fourth-footer-widget-area' ); } add_action( 'widgets_init', 'remove_some_widgets', 11 );
Found the answer elsewhere: //Remove all Twenty Eleven Sidebars add_action( 'after_setup_theme','remove_twentyeleven_all_widgets', 100 ); function remove_twentyeleven_all_widgets() { remove_filter( 'widgets_init', 'twentyeleven_widgets_init' ); }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "theme twenty eleven" }
Can this site be built using wordpress? I want to know if this site can be built with wordpress, I'm a programmer and I don't know anything about wordpress, how I'm just to get some good advices from you guys: The main aim of the site is to allow users to view several places of interest in a country Administrator: -create a place of interest \- add,delete,edit details such as place name, address, location with google map,rating(users can vote a place),latitude, longitude -add reviews for place on interest Users: -allow users to register -contribute to site by adding a place of interest with all its details(will then be approved by the administator) -add reviews to a place of interest -up vote or downvote a place of interest
## Short Answer Yes. Theoretically any site can be built on top of Wordpress. ## Long Answer You are going to need a lot of modifications to the standard Wordpress theme. But not to fret I have assembled a list of some of the things that you would need to do to get your feet wet. 1. Add _Custom Post Type_ for Places (Guide | Plugin) 2. Add _Custom Meta Boxes_ for address, latitude, longitude, etc. (Guide w/PHP Class) 3. Assign _Roles_ to users that will allow them to post. I suggest the Contributor role. If you need more control over permissions you can use the Members plugin 4. Add a WP-PostRatings plugin 5. Allow comments on posts to be used as reviews _Note: I see that you have tagged wordpress.com. I am unsure of what limitations they place on themes and plugins._
stackexchange-wordpress
{ "answer_score": 7, "question_score": 1, "tags": "development strategy" }
How to get comments by post ID? I have this custom post query to list all the posts within a specific category. For example I have this: $args = array('cat' => 'home','post_type' => 'post')); $post_obj = new WP_Query($args); while($post_obj->have_posts() ) : $post_obj->the_post(); // do stuff here endwhile; So for this page I would like to show the list of posts but also the accompanying comments. I am only showing maximum 2 comments for each post. Is there a built in function to do this?
You can use `get_comments`. Function Reference/get comments $args = array('cat' => 'home','post_type' => 'post')); $post_obj = new WP_Query($args); while($post_obj->have_posts() ) : $post_obj->the_post(); //display comments $comments = get_comments(array( 'post_id' => $post->ID, 'number' => '2' )); foreach($comments as $comment) { //format comments } endwhile;
stackexchange-wordpress
{ "answer_score": 10, "question_score": 9, "tags": "query, comments" }
What are the standard admin CSS id/class tags? Is there a list of WordPress CSS id/classes that I can use to build plugin option screens that look and feel more like a normal WordPress option page? I have found some through serendipity but it would have been nice to have a list. An example is this class: button-primary That makes a button look like this: !buttom-primary
We're working on updating < to have more of this information and reflect the style updates from 3.2. Other than that, I've seen a plugin (that I currently cannot locate) that shows a demo page of sorts that displays the various CSS selectors and what they look like, but I believe it was outdated. Other than that, your best option for now may be to just fire up Firebug/Web Inspector and take a look at wp-admin/css/wp-admin.dev.css.
stackexchange-wordpress
{ "answer_score": 18, "question_score": 55, "tags": "admin, wp admin, css" }
Disable image resizing on specific upload fields I am using the Options Framework Theme from devinsays, but am having a "small" problem with the Image Upload functionality. Basically, I need to disable resizing on a specific upload-field, but keep it on all others. I do realize that this functionality is not specifically dependent on this framework, but I haven't been able to find any resource on how to achieve this on a case by case basis for specific Theme Options, so I'm hoping someone here could help. Any input would be appreciated!
WordPress will always create the additional images for "thumbnail", "medium" and "large" sizes. The options panel doesn't add an additional size- it just resizes the one you've selected using CSS. If you want to override that CSS you can hook in an additional stylesheet that will override the id on that option.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme options, images, uploads" }
Using categories on navigation bar instead of pages Check this url (www.linuxstall.com). The top navigation bar has one page (about us). I want the categories there, not pages. How can I do that?
If you are using the nav menus you can just add specific categories from your administration panel in Apperence->menus. If you don't see the categories box open "screen options" and check them to display. If you want dinamicly add them you will need to write a plugin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "css, design" }
Advanced Permalinks plugin breaks RSS The plugin Advanced Permalinks breaks the RSS feed since Wordpress version 3.1. The developer has stopped working on the plugin, and I haven't seen any solution for it. Since my site is dependent on the plugin I can't just disable it either. Does anyone know of a way to either generate a feed differently, or of a similar plugin which could replace it?
Fixed this now, answering for anyone googling. In a recent version of Wordpress the Permalink functionality has had quite an overhaul, making Advanced Permalinks unnecessary, at least in my use case. More info here.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins" }
Wordpress ignoring specified template for front page. Why? I'm using the Roots theme which with custom css. I'm using the page "Home" as the front page the page "Blog" as the blog page (in WP reading settings) I'm trying to set the front page "Home" to use the template "full-width", but instead Wordpress ignores this and uses the "front page" template. This only happens on the front page, I can set any other page to use the "full width" template. Any ideas as to why this is happening and how I can resolve this? I can post some more information if this is helpful. Just let me know what. Thanks.
This is by design - check out `wp-includes/template-loader.php` to see why. Delete `front-page.php` and it will fallback to the page template.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "themes, templates, page template" }
handling login/logout redirects I have a couple issues with the way Wordpress handles redirects on login and logout. Standard behaviour is: login: /wp-login.php (with no redirect_to url) -> /wp-admin.php logout: /wp-admin.php -> /wp-login.php What want is: login: /wp-login.php (with no redirect_to url) -> homepage logout: /wp-admin.php -> homepage Would prefer a coded solution please. It helps me to learn and understand how Wordpress works. Thank you
This really does belong in a plugin, but you _can_ just as easily drop it in your theme's `functions.php` function default_login_redirect( $redirect, $request_redirect ) { if ( $request_redirect === '' ) $redirect = home_url(); return $redirect; } add_filter( 'login_redirect', 'default_login_redirect', 10, 2 );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "redirect, login, logout" }
Why does my site flash white every time it changes page? Any ideas? I've never had this problem before. Here is the site.
It looks like your site is doing a lot of processing when displaying a page. have you tried adding a caching mechanism? you can give plugin a try: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "server load, performance, cache" }
Can't Access Sessions or Variables through pages So I'm trying to use a session to move a variable through pages. For some reason I literally cannot access anything from index.php to archive. I declare my session at the very top of my header.php like: <?php if(!isset($_SESSION)) { $_SESSION['catID'] = 3; } ?> Then I move to the archive.php which pulls in the header via `<?php get_header() ?>` and my session is suddenly gone. I try to echo it out and get nothing. Same thing happens with normal variables - like it's out of scope. Anybody else have a similar problem or a solution?
In WordPress you need to start the session with `if ( !session_id() ) { session_start(); }` in order to use session variables. You can enter this code into wp-config See <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "archives, variables, headers, session" }
Get Stylesheet To Showup in WP Admin Panel Editor So I have a css file that is called `blue.css` and a universal one called `style.css` I have a few css colors inside a `/css` folder. How do I get all those css files to show up in my Admin panel editor?
Use the `add_editor_style()` function in your functions.php: add_editor_style( 'css/blue.css' ); You can call that function multiple times to load additonal stylesheets in to the admin editor.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "wp admin, css, editor, links" }
How can I redirect mobile users to diff url, but also allow them to come back to full site this is pretty straight forward: How do I redirect mobile users to /mobile, but still allow them to click a "Full site" button and see the full site without being redirected again back to the mobile site? I have played with a bunch of the plugins that say they do this, but none seem to handle the second step. They redirect to the /mobile . but if a user wants to go to the full site, it tries then redirects back to mobile. I am running WP3.0.1
function mobile_redirect() { if (isset($_COOKIE["redirected"]) && $_COOKIE["redirected"]) return; global $is_iphone; if( isset($is_iphone) && $is_iphone ) { wp_redirect( '/mobile/' ); setcookie("redirected", true); exit; } } add_action('init', 'mobile_redirect'); This code redirects every mobile visitor to /mobile/ and then sets a cookie that the user is redirected. If the cookie is set, then the redirect doesn't take place. So if the user again goes to your site it won't redirect to the mobile url. You can also set the cookie if there is a variable in the url, like /?v=desktop, then if that url is visited it sets the cookie and doesn't redirect anymore. * * * UPDATE Use of builtin $is_iphone variable; Thx to Kaiser. Btw: strange name for a variable that's used for every mobile device. $is_mobile would be a better name.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "mobile" }
How to order images in a post in Wordpress 3.3? In wordpress 3.2 when uploading images to a post, I would get a Gallery that is linked to the post. That is, I could see in the media uploader of the post a tab that contains only the images of this post, and there would be a place to mark the order of the images I wanted for the post. In wordpress 3.3 I can only see the media library of all the images I have ever uploaded, and I cannot order them in any way. Is there a way to order the images related to a post? Have I somehow managed to upload the images incorrectly so that they are not attached to a post? Any help would be appreciated.
As far as I know, media management didn't change from WP 3.2 to 3.3 (except for replacing the uploader itself with PLuploader). It has _always_ been possible to upload images directly to the media manager (by uploading via Dashboard -> Media Library ), in which case such uploaded images would not be attached to any particular post. To test that things are working properly, go to the edit post screen for a post that you know already has attached images, and verify that the media manager still displays the menu order field for the image gallery. Then, create a new post, upload some images, and again verify that the media manager still displays the menu order field.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "images, media library, uploads, wordpress version" }
Built in audio player? I was certain that WordPress had built in a basic audio player. Am I mistaken. I cant find any evidence of one anywhere, just plugins ?
WordPress does **not** have a built-in audio player. You will need to use one of the myriad audio-player Plugins available.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugins, theme development, audio" }
Create unique robots.txt for every site on multisite-installation Does anyone know how I can have a unique robots.txt file for every domain served by my wp-multisite-installation? I did a search on plugins but couldn't find anything suitable.
Straight from the source, (line 1845 `wp-includes/functions.php`, 3.3.1): function do_robots() { header( 'Content-Type: text/plain; charset=utf-8' ); do_action( 'do_robotstxt' ); $output = "User-agent: *\n"; $public = get_option( 'blog_public' ); if ( '0' == $public ) { $output .= "Disallow: /\n"; } else { $site_url = parse_url( site_url() ); $path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : ''; $output .= "Disallow: $path/wp-admin/\n"; $output .= "Disallow: $path/wp-includes/\n"; } echo apply_filters('robots_txt', $output, $public); } So to customise it: function my_custom_robots( $robots ) { if ( my_condition() ) $robots .= "\nDisallow: /something/else/"; return $robots; } add_filter( 'robots_txt', 'my_custom_robots' );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "multisite, robots.txt" }
What is the "proper" way to generate a javascript variable depending on a custom field value? On my site I have some posts with a custom field "Name". Now, in case the post has "Name" set, I want to generate this code: <script type='text/javascript'> var FG_DONATE_BUTTON_PARAMS = { attribution: 'honor', attribution_name: Name} </script> where Name after attribution_name refers to the custom field value. For test purpose, I've used this code in the header $nameAttribute= get_post_meta($post->ID, 'Name', true); printf('<script type=\'text/javascript\'> var FG_DONATE_BUTTON_PARAMS = { attribution: \'honor\', attribution_name: \'' . $nameAttribute .'\' } </script>'); But I have two problems. One, the value of the $nameAttribute doesn't get passed through, and secondly, it's ugly :) I think I can manage the value problem, but I'm unsure what would be the "proper" way to output this.
You may wish to look at this question. In that question, the admin-ajax url is passed through, but it can be any variable (or array of variables), like for instance `$nameAttribute`. For instance, you would call wp_localize_script('my_js_file_handle','my_js_object',array('attribute'=>$nameAttribute))` then in your js file, the variable would be accessible from my_js_object.attribute. (You must enqueue the javascript file though!)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "javascript, headers" }
Programatically add a page in Wordpress I am trying to add a page to WordPress programatically. I am using this code: function add_media_page(){ if(!(is_page('My New Post'))){ // Create post object $my_post = array( 'post_title' => 'My new Post', 'post_content' => 'This is my post.', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => ['page'] ); // Insert the post into the database wp_insert_post( $my_post ); } } add_action( 'init', 'add_media_page' ); However when i use the last line in the array 'post_type' => ['page'] it causes the admin to crash and show a blank page. Does anyone know what's happening here
'post_type' => ['page'] is wrong; it should be 'post_type' => 'page'
stackexchange-wordpress
{ "answer_score": -1, "question_score": -1, "tags": "theme development, wp insert post" }
Remove Admin sidebar link I have a taxonomy link in my admin sidebar i'd like removed from view. Only in the sidebar though, i will still be using the function in the post view, so if that creates problems a simple simple CSS trick will do. Just need it gone from the sidebar as it's unnecessary clutter. The current link looks like:
function remove_featured_tax_menu() { remove_submenu_page( 'edit.php?post_type=movies', 'edit-tags.php?taxonomy=featured&amp;post_type=movies' ); } add_action( 'admin_menu', 'remove_featured_tax_menu' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "admin, admin menu, links" }
How do I use just one category' posts on my home page? I have mainly protected categories, but I have one open category, how can I set it up so I load only the open catgeory posts to show on my home page
This should about do it for you, add args as needed $args = array( //basic post data 'posts_per_page' => 10, 'post_type' => 'post', 'post_status' => 'publish', //category 'category_name' => 'your-cat-slug' ); $posts = new WP_Query( $args ); Docs: `WP_Query`
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories" }
Trying to use Advanced Custom Fields with custom image sizes I have a product section on my wp-site. I am trying to display the attached thumbnail image in specific sizes that are automatically cropped to the right size. I have used **Advanced Custom Fields** to create a field called product_thumbnail I have used **Additional Image Sizes** to create a new image size called products I have used the following code on another word press site and it worked fine, but on my current site it returns empty. <?php $image = wp_get_attachment_image_src(get_field('product_thumbnail'), 'products'); ?> <a href="<?php the_permalink(); ?>"><img src="<?php echo $image[0]; ?>" /></a> I have ran a batch to make sure my images are created if not already. This is boggling my mind. Any help appreciated.
why **OH WHY** does everybody insist on making custom fields for everything . is there a special reason that you would want the use of custom fields ? If so, please explain exactly what you want to achieve . If not - a much better approach (and more fool-proof for non-computer-savvy-clients) would be to use `the_post_thumbnail();` \- like you stated in your question already, with Additional image sizes in the theme . I do not want to duplicate my answers - so you just as well read here : Display thumbnail from custom field Basically you will use <a href="<?php the_permalink(); ?>"><img src="the_post_thumbnail('your_size_name');" /></a>
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "plugins, custom field, thumbnails" }
Two "the_excerpt" questions In case there's more than one function the exact one is: php the_excerpt(); I want to decrease the character length to X amount and I want to remove the [...] and replace it with an image that users can click to take them to the article. How do I accomplish this (preferably without plugins)?
You need to hook into two WordPress filters. function custom_excerpt_length( $length ) { return 20; } add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); < function custom_excerpt_more( $more ) { return '[.....]'; } add_filter( 'excerpt_more', 'custom_excerpt_more' ); <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "images, excerpt" }
the_post_thumbnail not resizing I'm using the following code: <?php if (the_post_thumbnail()) : ?> <div class="thumbnail"> <?php the_post_thumbnail('thumbnail'); ?> </div> <?php endif; ?> But the thumbnail is appearing full size. Same applies if I use `(array(200,150))`. My "Media" settings are set correctly (thumbnails at 288 max width, 500 max height); I've checked the `uploads` directory to see if the images have been resized and they have. Any ideas?
Updated the answer to match my latest comment: Changing `<?php if (the_post_thumbnail()): ?>` to `<?php if (has_post_thumbnail()): ?>` will probably solve things. Also, some must have developer plugins when working with featured images: * Regenerate Thumbnails * AJAX Thumbnail Rebuild
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "post thumbnails" }
Failed: Filesystem preventing downloads. ( ftpext) I just move my server to Mac server before I use to be with GOdaddy was no problem updating framework of my theme now I'm getting this error `Failed: Filesystem preventing downloads. ( ftpext)` not sure why but I've put this code in wp-config.php already putenv('TMPDIR=' . ini_get('upload_tmp_dir')); define('FS_METHOD', 'ftpext'); define('FTP_BASE', 'wpdirectory'); define('FTP_USER', 'myuser'); define('FTP_PASS', 'mypassword'); define('FTP_HOST', 'myftphost'); define('FTP_SSL', false);
Just add this line in your `wp-config.php`: define( 'FS_METHOD', 'direct' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "errors, ftp" }
Append Second Link to Read More I'm looking for a way to filter the "Read More" link so I can append a second link and text. I know how to filter the text but not the entire output, eg: * * * Standard post excerpt before the more quicktag.... Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ut auctor ligula. Vestibulum ac lectus quis nisl tempor fermentum. Maecenas urna erat, convallis eu. Read More | Add a Comment * * * Thank you for any links / advice!
You need to hook into `excerpt_more` filter, for more information see Codex page, as examples of use Twenty Ten's and Twenty Eleven's function files.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "excerpt, read more" }
Add images to my theme with html I've uploaded an image to my directory (themes/themename/images/file.png). I want this image to be displayed even if the directory preceding themes is changed (in case someone installs wordpress in a directory other than the home directory). What is the call I need to find the image? Simply using img src="/images/file.png" does not work.
<img src = "<?php bloginfo('stylesheet_directory');?>/images/file.png" /> <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images" }
get post custom value I have a portfolio custom post type with a text field for a site link, I need to echo that link in the template page. What i have so far is this: <?php $site= get_post_custom_values('projLink'); if($site[0] != ""){ ?> <span><p><a href="<?php var_dump($site); ?>">Visit the Site</a></p></span> <?php }else{ ?> <p><em>Live Link Unavailable</em></p> <?php } ?> The problem is that it is not working, I have this on the link: Thanks.
I think you can better use get_post_meta(); Your code will look like this: <?php $site = get_post_meta(get_the_ID(), 'projLink', true); ?> <?php if(isset($site) && $site != "") : ?> <span><p><a href="<?php echo $site; ?>">Visit the Site</a></p></span> <?php else : ?> <p><em>Live Link Unavailable</em></p> <?php endif; ?> You use var_dump only for testing purposes (
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, customization" }
Pagination on 2nd loop OK, I am creating a business listing site that is using a custom taxonomy for the listing "type". I need to display two loops on the taxonomy archive page, one for "sponsored" listings and one for regular ones. taxonomy archive: < pagination function: < Both parts are doing exactly what I want, with one hitch: there are approx 50 non-sponsored listings in a specific category, but the 2nd query is maxing out at 5 "pages" (i.e. 25 listings if I set posts_per_page to 5, 35 if I set posts_per_page to 7) I'm stumped. Any ideas? **UPDATE** FWIW, I've been testing the code layout here: < and it's working a bit better, in that I get the total number of "pages" it should have. But it still gives me a 404 after page 5.
The issue is that before your custom queries load, WordPress runs the main taxonomy query (all results in that tax term, 10 per page). On page 6, the main query is trying to load posts 51-60, and since they don't exist the page 404's before you have a chance to load your custom query. Customize the main query using the pre_get_posts hook so that the second loop you're doing is the main query. Add this to functions.php: < Then for your second loop, just do: `if( have_posts() ): while( have_posts() ): the_post();` More information: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "pagination, loop" }
Single page site (Wordpress) including posts I'm creating a single page site and obviously want to include the blog posts. I'm currently looping through the pages and using the_content() and the_title() to display them. However, the_content doesn't include the blog posts on the blog page. I tried another loop in this one, but it didn't work. Any ideas to point me in the right direction? Thanks
To include posts and pages in the loop, use the 'post_type' argument: <?php $wp_query = new WP_Query(); $args = array( 'post_type' => array('post','page') ); $wp_query->query($args); while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <?php the_content(); ?> <?php endwhile; ?> <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "loop" }
Engadget Like most commented plugins i am looking for a most commented plugin like that of in engadget website and propakistani. I would be very thankful if someone could help me out with it. Thanks !enter image description here
You could use a plugin like < to get a widget based on popular posts (I've never personally used that one) or write your own. Everything else is just HTML markup and CSS.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, comments" }
action wp_set_comment_status never gets fired when i change the comment status I want to run some code on comment status change so using the action `wp_set_comment_status` but it seem to never fired when comment status gets changed. I am using wordpress 3.3.1. **Here is a simple code which doesn't work for me:** add_action('wp_set_comment_status ', 'update_business_rating_avg'); function update_business_rating_avg($comment_ID, $status){ update_option( 'business', 'checked' ); } There was a same bug on the wp version `2.8.2` and it was fixed later on. Not sure if i am doing something wrong or not. < The codex says about the action: **wp_set_comment_status:** Runs when the status of a comment changes. Action function arguments: comment ID, status string indicating the new status ("delete", "approve", "spam", "hold").
Your code is showing an empty space in the hook name add_action('wp_set_comment_status ', 'update_business_rating_avg'); ^ try removing it add_action('wp_set_comment_status', 'update_business_rating_avg');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "actions, comments" }
simplified explanation on child themes? I'm trying to create child theme for theme i'm using on my site... I read lot's of articles about this, but can't find simple tutorial or simple explanation how to do it... As i understand so far, if i copy (for example) loop.php file to child theme, and change if(is_home()) { do something } from original loop file to if(is_home()) { do something else and do another more thing } my function will be executed and original function will be ignored? Is this right? Thanks in advance
You are correct. The child theme would over-ride the parent theme's loop.php if you made changes. As for a simple tutorial I did a simple Google search, after a quick overview this one seems pretty simple: < Just in case you haven't been there, here is the WordPress Codex Page.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "themes, child theme" }
Need to add class="lightbox" for every single post image I got a theme that has lightbox built in, but only for galleries and featured images, not single images. It just needs to have class="lightbox" added to the images source. I'd like a simple function that will include this automatically. Not sure why the author left this out.
One way you can accomplish it is this way: _functions.php_ add_action( 'wp_enqueue_scripts', 'your_lightbox_callback' ); function your_lightbox_callback(){ if( is_single() /* or whatever here */ ) { wp_register_script( 'your-lightbox', get_bloginfo( 'template_url' ) . '/lightbox-class.js' ); wp_enqueue_script( 'your-lightbox' ); } } _lightbox-class.js_ var $j = jQuery.noConflict(); $j( document ).ready( function() { $j( '#whereveryourpostsare img' ).addClass( 'lightbox' ); } ); Let me add that this hasn't been tested, just typed here on the fly. If you try it do tell me if you have any issues, thanks!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "functions" }
Limit number of posts in wp loop I am using this code to get posts of specific taxonomy. It displays 10 posts by default. How can I set my own limit? <?php $count = 1; $the_query = new WP_Query( array( 'brand' => 'sony-vaio' ) ); while ($the_query->have_posts()) : $the_query->the_post(); ?>
To display 5 posts, say, use `posts_per_page`. See the Codex. $the_query = new WP_Query( array( 'brand' => 'sony-vaio','posts_per_page'=>5 ) );
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "custom taxonomy, limit" }
How to remove the tripadvisor logo from the wordpress theme? Tripadvisor offers a free wordpress theme at here If you go on this page, you'll see the free wordpress theme, and on the navigation bar, there is the trip advisor logo on the right, How can I remove this logo because i have many menu items?? By the way can i remove it not specified nothing as rules and regulation??
If you open header.php and remove line 96: `<a class="ta-bug" title=" TripAdvisor " href=" src="<?php echo get_stylesheet_directory_uri(); ?>/images/TA_bug.gif"></a>`, it will be gone. I cannot speak to the legality of this with certainty, but by my understanding of GPL2.0, you should be set.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "themes, menus, templates" }
How to Include File from Plugins into Template? I need to include a file from plugin Folder in my template file. How can I do that? Is there any other way to do that rather than: include('../../..'); Thanks
`plugins_url( 'file_location/relative_to.plugin', 'plugin/file/location' );`, or something along those lines at least, should do it for you. Alternatively, you could work from the top down and say something like `include( '/wp-content/plugins/you-plugin-name/file.php' )` to get it, whichever is easier.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, themes" }
how to handle forms in multiple pages? I have a simple contact form that I set up to display on multiple pages using a shortcode and a widget but since I need to form to post back on the same were it's displayed I'm not sure how to accomplish this. I was thinking about writing a function and plug it to the `wp_head` hook but I'm not sure if it's correct, is there a better way to do this? Thanks in advance.
Kind of - I would suggest using `init`. This would probably be the best way of doing it since you can process the form as described below. `wp_head` would work though. Also, you should make sure you are making necessary checks with 'nonces'. I suggest the `init` hook as you can employ something similar to 'post-redirect-get' (see here). This can help against resubmission of data when users click refresh. The usual way of doing this is to submit the url of the page along with the form, submit to a processing page, which when it's finished then redirects the user back to the original page (or a confirmation page). Of course you don't need a separate 'processing page'. An action hooked onto `init` can check a form is submitted, check the nonces, process the form and then redirect back to the page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "forms" }
Use [shortcode="value"] instead of [shortcode att="value"]? With shortcodes that have only one attribute, it would be much easier from a content-editing perspective to use, for example, `[icon="myicon"]` instead of `[icon whichicon="myicon"]`. Is this possible in Wordpress? Is it problematic?
I thought this was a rather good question, so I tinkered with it a little. It seems as though the catch to using the direct method (`[icon='myicon']`) vs using an attribute is that with the direct method, you cannot use spaces as it will split to separate attributes, even if you use quotation marks, and the quotation marks and equals sign are considered part of the value. For example: a `print_r( $atts )` on `[dev_dump returns `Array ( [0] => )`, whereas a `print_r( $atts )` on `[dev_dump='my icon']` returns `Array ( [0] => ='my [1] => icon' )`. That said, however, `[dev_dump foo='bar' does give you `Array ( [foo] => bar [0] => )`, so as long as there is only ONE unlabeled value, you should be pretty safe to use that method, as you can just use $atts[0]. Be careful with setting up defaults, as I can see that becoming tricky and buggy relatively quickly. Thanks for asking a great question, really made me think!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "shortcode" }
Hook/Filter before and after comments I'm writing a plugin that needs to display a custom link immediately near the comments. I have the option in the plugin admin to display before or after. I'm familiar with the comments_array, but that doesn't allow me to just add a string of html just before the comments or just after the comments but before the comment form. the_content -- ?? custom link before ?? -- comments_array -- ?? custom link after ?? -- comment_form
`do_action( 'comment_form_before' );` is called on line 1553 of /wp-includes/comment-template.php, right before the output of the comment form, that should handle that one for you. I'll update this if I can find the hook before the comments. # edit It seems like you might be able to modify Walker_Comment (found in the same file as above) to output the first link with __construct or something, but I can't give you precise implementation at the moment (for lack of time).
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "comments" }
How can I display the parts of custom posts? I have a custom post type called Testimonial that includes custom fields "name", "title" and "bank". I would like to display each of these items on a page. Here's what I have so far: <?php while ( $loop->have_posts() ) : $loop->the_post(); the_title(); echo '<div class="entry-content">'; the_content(); echo '</div>'; endwhile; ?> This gives me something close to what I want but I don't know how to get at the actual fields individually. How do I do that?
<?php while ( $loop->have_posts() ) : $loop->the_post(); the_title(); echo '<div class="entry-content">'; the_content(); echo '</div>'; echo '<div class="custom-field">'; echo get_post_meta( get_the_ID(), 'name', true ); echo get_post_meta( get_the_ID(), 'title', true ); echo get_post_meta( get_the_ID(), 'bank', true ); echo '</div>'; endwhile; ?> This is how you would display the custom fields below the content. I didn't test it but it should work. Hope this helps. Also read Milo's answer and read the Codex so you understand how it works. Also it looks like you are using a custom query object (`$loop`), so read this article as well: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types" }
Categorie parents and childs displayed I'm trying to create a menu directly hard-coded, basically I need to display the parent category and below its child categories, however I have to do this several times meaning something like this: Category 1 * category child of 1.1 * category child of 1.2 * category child of 1.3 Category 2 * category child of 2.1 * category child of 2.2 and so on.... I've tried whit different kinds functions like call the category and is subcategory to call its ancestor, however I haven't been able to get the result I'm looking for. Any suggestion??? Thanks in Advanced.
Have you tried wp_list_categories( array('depth'=>2,'title_li'=>null)); This outputs the categories as a list, with their children as a nested list. The categories are linked to their respective page.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "categories" }
Changing the RSS feed titles not working I'm trying to change my RSS feed titles to display the post type beforehand but it's not working. Code below. Any ideas? Thanks function changeRSStitles($content) { global $post; if (get_post_type($post) == 'literature') { $content = 'Literature: '.$content; } else if (get_post_type($post) == 'recipe') { $content = 'Recipe: '.$content; } else if (get_post_type($post) == 'restaurant') { $content = 'Restaurant: '.$content; } else if (get_post_type($post) == 'post') { $content = 'Sugar Street Blog: '.$content; }else { $content = $content; } return $content; } add_filter('the_title_rss', 'changeRSStitles');
Got it working! Just had to resync the feedburner feed
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "custom post types, rss, feed" }
How to handle PHP parse errors? I tried to execute the following code and I got a parsing error message (line:3). Here is the code on Pastebin < I tried echoing but didn't seem to solve the problem. Maybe I missed something. What am I doing wrong? Please help.
You have to close the PHP context if you use raw HTML output. Instead of … <?php global $EM_Event; <div class="content_left"> <?php gteventstore_before_loop(); ?> … close PHP before the div: <?php global $EM_Event; ?> <div class="content_left"> <?php gteventstore_before_loop(); ?> Use an IDE with a PHP parser to see such syntax errors early. You code looks in Eclipse PDT like this: !enter image description here If you tip the red icon you get an explanation: !enter image description here Read more about Eclipse and WordPress.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "php, errors, parse" }
In woocommerce who is responsible for sending the receipt email? I'm writing a Paypal Pro woo commerce extension to allow it to accept credit card directly on my websites. When I test things, everything works well. The only thing that I don't get is an email notification. So I would like to know does my gatway class need to send the receipt email or the internals of the WooCommerece should take care of that for successful order?
WooCommerce sends the emails - triggered by the payment_complete method of the order class. By the way, WC has an official paypal pro extension: < written by myself.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugin development, plugins" }
conditional statement for active permalinks I'm looking for a way to create an if...else statement hinging on whether pretty permalinks are active or not. So I need something which returns true when permalinks are changed from the default. if (pretty_permalinks_are_on) { do this; } else { do that; } Sort of thing. Just have no idea about the 'pretty_permalinks_are_on' part. If anyone would extend the hand of compassion and throw some crumbs to a php noob, I'd be a grateful learner :)
`get_option( 'permalink_structure' )` is your friend. If you're using the default it will be set as an empty string: if( get_option( 'permalink_structure' ) !== '' ) { // custom permalink enabled code } else { // no permalink }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "permalinks" }
is_archive for custom tax archive page? Having trouble getting the achieve page of a custom taxonomy to know its that page. It just shows the detail from the default is_archive blog page... This is what i've tried.. <?php } elseif ( is_archive() && is_tax() == 'article-area') { get_template_part( 'includes/inc-article' ) ?> When all its doing is showing the details from this... <?php } elseif ( is_archive() ) { get_template_part( 'includes/inc-blog' ) ?> Any ideas, as i'm stumped? :( Thanks for looking.. :)
shouldn't it be is_tax('article-area')
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "conditional tags" }
I want to know about the plugins that help in while I write code on my Page? I want to know about the plugins that help me to write the coded blocks. I have tried out two or three but I am not able to know how to get along and put it to use. Please suggest me some good plugins and also how to use it if I need to represent some codes. Yeah I have many different languages that I code in... so the highlighting and other stuffs does matter. Please help.
From personal experience, I've found **SyntaxHighlighter Evolved** to be the best: You put your code inside a shortcode and specify the language: [sourcecode language='php'] //Displays the php code [/sourcecode] [sourcecode language='html'] <!-- Displays the html code--> [/sourcecode]
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, plugin recommendation" }
How can I disable the multisite feature of WordPress 3.0? I want to use the Google XML Sitemaps plugin and it says: "The plugin will not be active until you disable the multisite mode". I don't need a multisite mode.
< <
stackexchange-wordpress
{ "answer_score": -1, "question_score": 1, "tags": "plugins, multisite" }
Looking for a filter to modify the months Hi making a simple plugin that replaces the wrong russian month with the right ones. But I can't find any filters that works. I have tried these filters without success: > add_filter('get_the_modified_date', 'russian-month'); > add_filter('the_modified_date', 'russian-month'); > add_filter('date_rewrite_rules', 'russian-month');
You can use `add_filter('the_time', 'your_function');` or `add_filter('the_date', 'your_function');` depending on which function you use in your theme.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, filters, date" }
Display email address field next to author in wp_dropdown_users the post_author_meta_box uses wp_dropdown_users showing the user name of authors. How do I display the email address in brackets next the author's name? Can one filter the wp_dropdown users do to this?
the only filter hook called in `wp_dropdown_users()` function is `wp_dropdown_users` which pass a string of the dropdown in an html form so you can manipulate this dropdown at that hook with some major REGEX. A better solution would be to use get_users() and create the dropdown your self, something like this: $selected = 1; //just for example, you can get that by get_post_meta() $siteusers = get_users(); // you can pass filters and option $re = ''; if (count($siteusers) > 0){ $re = '<select name="users_with_email">'; foreach ($siteusers as $user) { $re .= '<option value="' . $user->ID . '">'.$user->user_nicename . ' ('.$user->user_email .')</option>'; } $re .= '</select>'; $re = str_replace('value="' . $selected . '"','value="' . $selected . '" selected="selected"', $re ); } echo $re;
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "list authors" }
Remove dashboard, use Pages tab as default Is there a way to have "Pages" set as the default tab when the user logs in to the admin area? I am using a heavily customised set up, where none of the dashboard widgets are useful so they are hidden anyway.
The best way is to re-direct user logins to your page and also remove the dashboard from the menu, this can be done with 2 filters. Redirect logins to your page edit screen example based on user roles, this example uses "author": function dashboard_redirect($url) { global $current_user; // is there a user ? if(is_array($current_user->roles)) { // check, whether user has the author role: if(in_array('author', $current_user->roles)) { $url = admin_url('edit.php?post_type=page'); } return $url; } } add_filter('login_redirect', 'dashboard_redirect'); Remove the "dashboard from the admin menu" add_action( 'admin_menu', 'Wps_remove_tools', 99 ); function Wps_remove_tools(){ remove_menu_page( 'index.php' ); //dashboard } ps. You can also order the admin menu items using the same filter.
stackexchange-wordpress
{ "answer_score": 14, "question_score": 8, "tags": "wp admin, dashboard" }
Custom Post Type Category List & Post Count I'm looking for Cutom Post Type Category List & Post Count. Here is my code.. <?php $taxonomy = 'project-tags'; $tax_terms = get_terms($taxonomy); ?> <?php foreach ($tax_terms as $tax_term) { echo '<li>' . '<a class="tag" href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '><span class="tag_name">' . $tax_term->name.'</span><span class="tag_count">'. $show_count. '</span></a></li>'; }?> This code works perfect for getting categories under my custom post type. But How do I get number of post count per category ?
`$tax_term->count` should contain the number of posts in the category. You may need to add the `$args` parameter if you want to include subcategory counts. Docs: `get_terms()`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, custom taxonomy, count" }
Serious social interaction I have an old blog... 25 posts on wp 2.6. good content, valuable information, right to the point. I am about to update the blog and the posts. Make the posts more up-to-date (there are some 3 years old, and still new!) and repost it to media sites and create a buzz around this really good information. So the question is... What, if you build a new site TODAY (wp 3.3) and have good content to post... over the years... what will be your strategy/plugin/toolbox to get the info OUT THERE... I have tried wordbooker (to publish on facebook) which is always broken... and really bad to use... I have heard of dlvr.it, which seems promising. Twitter feed auto publish and anything and everything. I would like to know the basic plugin toolset to get the info into the social media and rate good on : < I would like to know your experience, your success, your fails... and the good news is, I will apply it RIGHT NOW
I will migrate the blog to wp 3.1, and add "add this". the others solutions is no reliable !
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "plugins, facebook, twitter" }
Plugin recommendation - posting to Social Networking sites I know there are a lot of Social Networking plugins around, so I thought I'd ask for some recommendations. When writing a new post in the admin area (standard post type), I'd like the option to post it (the excerpt and a link, for instance) to my Facebook and Twitter accounts. I'm not referring to buttons on the front-end for my users to share on their profiles. Does such a plugin exist?
take a look at this tutorial < a or if you feel like using an external serviceyou can use < which is not a plugin but will do the job more then fine.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "plugin recommendation" }
How do display simple page for printing product info? I'm using WP 3.1.2 and latest e-commerce plugin. Now I'm stuck at creating simple page for printing product info. It has to be only product information with not WordPress header and footer. The pop up window appears nicely but now I need to check against something in header and footer files to when not to display them. I can't check by post id cause then I need to edit it every time new product is added. And I can't add GET parameter to URL cause then WP e-commerce plugin doesn't show product, instead it displays products page. How can I possibly do this?
You can handle this much more simply with CSS and a print stylesheet. Just add `display:none` within that stylesheet for all elements you don't want visible in the print version.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "javascript, conditional content, plugin wp e commerce" }
Customizing the dashboard page or post overview What would be the best way to add some basic HTML to the page overview (edit.php)? Basically I want to add some text, like a meta box, to explain some things about the page system to my multisite users. Found the answer thanks to the solution provided by OleVik. Here's a few more resources on the topic: How to show an urgent message in the WordPress admin area Plugin API/Action Reference/admin notices
I use a version of the following, to add text to the top of the Page ( **edit.php?post_type=page** ): // Show message when viewing pages function page_AdminMessage() { showMessage("You are now viewing the Pages", false); } if ($_GET['post_type'] == 'page') { add_action('admin_notices', 'page_AdminMessage'); } Which just needs to be added into **functions.php**.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "dashboard" }
Custom Taxonomy Tree view I have been trying google for this, but not so easy to search for. I have a custom hierarchical taxonomy, something along the lines of: Chainsaws - Electric - Petrol - Other Grasscutters - Electric - Petrol - Other What I need to do is create an index page, retaining the hierarchical structure. The closest I have come to doing it is with: $products = get_terms('product-type'); foreach ($products as $product) { $out .= $product->name; } But this just shows the ones in use, and loses it hierarchy :( Any insights are very welcome. Thanks in advance Andy
<?php $args = array( 'taxonomy' => 'product-type', 'hierarchical' => true, 'title_li' => '', 'hide_empty' => false ); ?> <ul> <?php wp_list_categories( $args ); ?> </ul> You can use the wp_list_categories function also for taxonomies. <
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "theme development, custom taxonomy, hierarchical" }
Exclude categories and subcategories in QueryLoop I want a QueryLoop that exclude some categories and its subcategories, I have this: $args = array( 'category__not_in' => array( 2, 6 ), ); this exclude the categories, 2 and 6 , but no its subcategories, what can I do? ====== Update ======= This is what I did, but now I'm searching for a better solution: $excludes = array(2,6); $ex_childs = array(); foreach($excludes as $exclude){ $a = get_categories('child_of='.$exclude); foreach($a as $key => $value){ $ex_childs[] = $value->cat_ID; } } $all_excludes = array_merge($excludes, $ex_childs); $args = array( 'category__not_in' => $all_excludes );
How about something like this where you filter the posts once the WP_Query gets them?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp query, query posts" }
Load Next WordPress Posts With AJAX? I found an amazing plugin that loads the next posts with Ajax. < However it doesn't work with custom post types. The code looks fairly simple. Any idea how to edit the code to use custom post types? Thanks
In principal, you could use this with _any_ archive page. All it's doing is fetching the next page of results and displaying the data. The reason it won't work with CPTs is because of the way the PHP script is queued - with an `!is_singular()` filter. The core of the plugin is in the JavaScript. Namely, this section: $('.pbd-alp-placeholder-' + pageNum).load(nextLink + ' .post', function() { You are loading into a placeholder element the HTML contents of the "next posts" page. jQuery will fetch the page, select just the part that has a class of "post" (the `+ ' .post'` part). You aren't doing any custom queries or lookups, just using a link WordPress generates for you by default (`next_posts()` creates a link to the next page of results). So to make this work with CPTs you'll need to do two things: 1. Make sure the script is triggered for your custom post type archive page. 2. Make sure your CPT supports archives and pagination
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, posts, ajax, wp load.php" }
how to add previous and next link for the posts? i would like to know how to link the next and previous post of the current post with in that category..i tried lotta plugins put nothing worked out and I am a noob in WP so kindly help me
Here's a good place to start: * < * < As you will see, keeping the links to posts of the same category is as simple as setting an argument in the function. I would give an example but there are really good examples on the pages linked above.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "next post link, previous" }
Tabs and Category Widget I need some help with tabs in Wordpress. I tried several tab plugins for Wordpress, but none did what I wont. I tried Quick tabs, Hybrid tabs and SidebarTabs. I want sidebar to be like this: < In fact these are basic tabs, with possibility to put content in it. Another question is about displaying news from some category in widget on sidebar. I want to display it with thumbnail and title with link to that news. I want it to be like on this picture : < So can you recommend some plugin for that.
Tabber Tabs Widget I'd been looking around as well, and this one seems to fit the goal. And no coding, all done with plugin/widget.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "widgets, tabs" }
how to show the most viewed, random and recent posts in the home? I would like to make my home page in such a way it shows the most viewed, random and recent posts by thre differents part by limitin the number of posts......give me at least some hints or idea to try it. Thank you in advance
I've implemented this before with custom queries and widgets. You have to be tracking all of these stats, of course, but if you are, it's a rather simple matter to build a widget that displays it and drop it in. If you're not using widgets, you can do the same, it will just take a bit more coding on your part, but use the same concept. Without specifics, I don't think I can go much deeper on implementation for most viewed, but I can give you the other two. To get random posts, you can just do a `get_posts()` query with your `orderby` set to `rand` and everything else set as normal, voilà , random posts. Same deal for most recent posts, `get_posts()`, set your `order_by` to `post_date` and your order to `DESC`...which is actually the default behavior for `get_posts()`. Docs: `get_posts()`
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "homepage, recent posts" }
storing database in version control I am using a version control system to manage my wordpress code (git). What is the betst way to store the database information into version control? I want to go to my staging machine, run `git pull` to get the latest code from my development machine, then maybe click one button or something like that to update the DB to match what I have on my development computer. I also want a way to, on my stage machine, "merge" the my development DB with the production DB before pushing all of that to production. so: 1. how to update a DB after a `git pull` 2. how to "merge" DB information.
This is more a git question than a WordPress one IMHO, but what you need to do is write a bash script and associate with a git hook that does what you want.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "database, git, version control" }
How do I set the default "feature image" size? I know I can set up post, pages, and custom post types to use featured images in wordpress by enabling theme support: add_theme_support( 'post-thumbnails'); Or enabling theme support for a specific set of post types: add_theme_support( 'post-thumbnails', array('post','page')); I also know that I can add an "image size" like this: add_image_size( 'media_library', 333, 230, true ); But how do you control which image size of the "feature image" actually displays on the edit screen of Wordpress? For example in TwentyEleven I have uploaded a square photo and it shows up as a rectangle in the featured image box on the edit screen: Picture 1.png How do you pick which image size shows up there?
I believe that is what the `set_post_thumbnail_size` function is for. > Set the default Post Thumbnail dimensions. To register additional image sizes for Post Thumbnails use: add_image_size(). See <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "post thumbnails, images" }
In a loop of custom post type, display first custom taxonomy term I would like to display just the first term from a custom post type custom taxonomy. Inside my loop I've been displaying all the terms using: <?php echo get_the_term_list( $post->ID, 'traits', 'Physical Traits:', ''); ?> but I would like to only display the first term. Thanks!
A little bit more involved but: <?php function get_single_term($post_id, $taxonomy) { $terms = wp_get_object_terms($post_id, $taxonomy); if(!is_wp_error($terms)) { return '<a href="'.get_term_link($terms[0]->slug, $taxonomy).'">'.$terms[0]->name.'</a>'; } } //example echo get_single_term(5, 'category');
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "custom taxonomy" }
Modify output of custom loop using WP_query I have a custom loop from a custom post type and I want to NOT display posts with the category 'slider'. I'm using this to set up the query: $args = array( 'post_type' => 'hotwives', 'posts_per_page' => -1); $loop = new WP_Query( $args ); while ($loop->have_posts() ) : $loop->the_post(); I was going to use this in the $args variable: 'category' => 'slider' But not sure how to make that NOT display the posts from category 'slider'. And, incidentally, when I use that in the $args variable it still shows every post, not just the 'slider' posts. So, seems I'm not on the right track regardless. Thanks!
$args = array( 'posts_per_page' => -1, 'post_type' => 'hotwives', 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => 'slider', 'operator' => 'NOT IN' ) ) ); Use that as the args for your `WP_Query` and you should get posts that aren't in the category taxonomy. It also has the advantage of being expansible to more than one exclude, etc. If you're using a custom taxonomy, change `'taxonomy'`'s value to the name of that taxonomy. Docs: `WP_Query`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query" }
Using categories on navigation bar instead of pages Check this URL www.linuxstall.com. The top navigation bar has one page (about us). I want the categories there, not pages. How can I do that?
Assuming you're dealing with a recent version of Wordpress it should be pretty straightforward. * In your Wordpress admin panel, select Appearance->Menus. * Create a new menu. In the current wordpress there's a little plus sign at the top, enter a new menu name, and then click create menu. * On the bottom left there should be a little widget titled Categories that has your categories. Drag categories from there to your new menu. * Save the menu. * In the upper left there's a Theme Locations widget that allows you to select a menu.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "navigation" }
Loop through child images of a parent for a Nivo Slider I want to use a Nivo slider to cycle through the children of a parent page one by one, how can I do that? I have the following piece of code that grabs **ALL** the children of a parent page and displays them: <?php $pages = get_pages(array('child_of' => $post->ID)); foreach($pages as $post) { setup_postdata($post); $fields = get_fields(); ?> <?php echo $fields->title; ?> <?php } wp_reset_query(); ?> Is there a way to show 1 child image and upon clicking the next arrow on the Nivo it shows the next child image?
To get attached (i.e. child) images of a post, try using `get_children()`. e.g.: <?php $child_image_args = array( 'post_mime_type' => 'image', 'post_parent' => $postID, 'post_type' => 'attachment' ); $child_images = get_children( $child_image_args ); ?> Which returns an associative array of child images. Then, just loop through them, e.g. using `wp_get_attachment_image()`, to output. e.g.: <div id="nivoslider"> <?php foreach ( $child_images as $child_image ) { wp_get_attachment_image( $child_image->ID ); } ?> </div> Nivo Slider integration is mostly out of scope for WPSE, but if you want to advance manually, change the `manualAdvance` setting to `manual` in your `#nivoslider` jQuery instantiation.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "images, loop, php" }
Photography Based Design - Multiple Images Per Post I'm thinking of using WordPress for my new website. It's a photography based website and the client will be uploading groups of photographs primarily. They'll want to give it a title and upload up to 20 photographs. Is this possible through WordPress? To get rid of content in the form of text and instead, opt to upload a series of Photographs? I'm capable in WordPress, but I've not modified it much beyond vanilla previously, has anyone been able to achieve something similar?
There are many themes that focus on photography. Here are some examples: * Gallery Theme !Gallery Theme * Fotofolio !Fotofolio ... and many others - just search for photo or photography or portfolio themes. Good luck!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "images, customization" }
Export SQL query based on post type I'm looking to export only wp_posts where post_type = post. Is that possible?
In your WordPress Dashboard, if you go to `Tools > Export`, you can select your custom post type and export only posts in that post type. It gives you the option between All Content, Posts, Pages, and your custom post types following those three options. As for SQL, well are you looking to export the data from something like phpMyAdmin? You could use this: SELECT * FROM `wp_posts` WHERE `post_type` = "post type name here" Hope this helps. Also, as kaiser pointed out in a comment, you may need to deactivate all plugins and switch to the default theme.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "sql, export" }