question
stringlengths 0
34.8k
| answer
stringlengths 0
28.3k
| title
stringlengths 7
150
| forum_tag
stringclasses 12
values |
---|---|---|---|
I am displaying WP comments on homepage in my index.php file, but the problem I have is that some comments are displayed under each post. The comment number is okay, but the comments are assigned wrong to the post. However when displaying the single page, everything is okay. I checked the IDs of the comments in the DB and it seems to be okay too. Any ideas what's going on? I am using the following code in my index.php to display the comments: <code> <?php global $withcomments; $withcomments = 1; comments_template(); ?> </code> Here is the whole index.php and if it helps here is the actual page. See for example the comment on the latest post from "Linda Walker", it is displayed under each post :-/ P.S. The posts were originally imported from MovableType, I hope it has nothing with that as I used the official import plugin.
|
Seems I fixed it myself, I had to call <code> <?php global $withcomments; $withcomments = 1; comments_template('/comments.php', true); ?> </code> as I am filtering comments by type: <code> <?php wp_list_comments('type=comment&callback=jennygg_comment'); ?> </code>
|
Comments on homepage (index.php) are duplicated under posts
|
wordpress
|
I have a little problem with my self hosted wordpress blog. the problem is it keeps truncating my feeds even when I have chosen not to in the settings page. one thing to bear in mind is that I use <code> <!--more--> </code> tag in almost all of my posts. I was wondering if it's because of that or something else?! any help would be awesome. thanks
|
Make sure you check the page source of your feed - some browsers will not show the full feed when looking at it raw (as the plain XML file) when using your browser to view http://yourdomain/feed If you look at the raw source the full text should be found in under the "content" tag - Firefox for example will only show the "title" "link" and "description" but hide the content. IE will show the full feed in the browser. Also make sure the full feed is set in the wordpress settings
|
Wordpress keeps truncating my feeds and I can't stop it
|
wordpress
|
I'm using a custom query with custom post-types to display a blog-archive for my brothers photography-website. I integrated this code to link to the larger version of the thumbnail. Sadly it doesn't work. Is it because its a custom query? <code> <?php /* Template Name: Archiv */ ?> <?php get_header(); ?> <section id="content"> <div id="archive"> <?php $args = array( 'post_type' => array('blog'), 'numberposts' => -1, 'post_status' => null, 'post_parent' => null, ); $posts = get_posts($args); ?> <?php if ($posts) { foreach ($posts as $post) { setup_postdata($post); $month = mysql2date('F Y', $post->post_date); if ($month != $check) { } $check = $month; ?> <div class="einzelbild einzelbild-<?php the_ID(); ?>"> <a href="<?php $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "medium" ); ?>"><?php the_post_thumbnail('medium'); ?></a> <a href="<?php $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "medium" ); ?>" class="linkbox-<?php the_ID(); ?> linkbox" style="display:none;"><span class="datum"><?php the_date('M jS'); ?></span><br /><h1 class="post-title"><?php the_title(); ?></h1> </a> </div> <script type="text/javascript"> $(document).ready(function() { var hide = false; $(".einzelbild-<?php the_ID(); ?>").hover(function(){ if (hide) clearTimeout(hide); $(".linkbox-<?php the_ID(); ?>").fadeIn(); }, function() { hide = setTimeout(function() {$(".linkbox-<?php the_ID(); ?>").fadeOut(500);}, 100); }); $(".linkbox-<?php the_ID(); ?>").hover(function(){ if (hide) clearTimeout(hide); }, function() { hide = setTimeout(function() {$(".linkbox-<?php the_ID(); ?>").fadeOut(500);}, 100); }); }); </script> <?php } } ?> </div> </section> <script> $(function(){ var $container = $('#archive'); $container.imagesLoaded( function(){ $container.masonry({ itemSelector : '.einzelbild', columnWidth: 10, isAnimated: true, animationOptions: { duration: 750, easing: 'linear', queue: false } }); }); });</script> <?php include 'sidebar-blog.php'; ?> <?php get_footer(); ?> </code>
|
In your code you are linking to an image using this code: <code> wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "medium" ); </code> So what you are doing is showing the medium sized image as well as linking to the medium image. What you need to do is link to the full sized image: <code> wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full" ); </code> Also <code> wp_get_attachment_image_src </code> returns the following: <code> array ( [0] => url [1] => width [2] => height ) </code> So this: <code> <a href="<?php $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "medium" ); ?>"><?php the_post_thumbnail('medium'); ?></a> </code> needs to become: <code> <?php $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full" ); ?> <a href="<?php echo $thumbnail_src[0]; ?>"><?php the_post_thumbnail('medium'); ?></a> </code>
|
Link to larger thumbnail in custom query (with custom post-types)
|
wordpress
|
I read the following and try to apply this scheme to my website running WordPress: http://code.google.com/intl/fr-CA/web/ajaxcrawling/index.html If you visit my website at http://www.visualise.ca/ you will see that it loads the posts within the home page and the url becomes http://visualise.ca/#!/anne-au-cherry when this post is loaded. A static version of the same content is available for the crawler at http://visualise.ca/anne-au-cherry but if a visitor using a browser visits it he will be redirected to http://visualise.ca/#!/anne-au-cherry (this is done with javascript). In order to provide the crawler with the needed <code> ?_escaped_fragment_= </code> I used a WordPress hack I've found on the net: http://www.wordpress-fr.net/support/sujet-54810-add-action-parse-request and now the GoogleBot can see the content of my AJAX powered pages. I thought it was all done. But when I paste a post link to Facebook (i.e.) it is unable to read the content of the page so I guessed that my website isn't really respecting the scheme described in the Google documentation since Facebook is supporting it (If you paste http://twitter.com/#!/gablabelle it will work). So since I'm using the jQuery.address plugin to get my hashbang (#!) I went to their website and downloaded their sample files to see what were the differences between their files and mine and realized that they were probably using a php function to create the needed HTML snapshots: https://github.com/bartaz/jquery-address/blob/master/samples/crawling/index.php because this is why, I guess, Facebook can't read mine. <code> <?php error_reporting(E_ALL ^ (E_NOTICE | E_WARNING)); $fragment = $_REQUEST['_escaped_fragment_']; $file = 'data/' . (isset($fragment) && $fragment != '' && $fragment != '/' ? preg_replace('/\//', '', $fragment) : 'home') . '.xml'; $re = '/(^<[^>]*>)|(\n|\r\n|\t|\s{2,4})*/'; $handle = fopen($file, 'r'); if ($handle != false) { $content = preg_replace($re, '', fread($handle, filesize($file))); fclose($handle); } else { $content = 'Page not found!'; header(php_sapi_name() == 'cgi' ? 'Status: 404' : 'HTTP/1.1 404'); } ?> </code> So my guess is that I could maybe use a similar php function to serv the HTML snapshots instead of using the WordPress hack but I would need to adapt it to WordPress. The problem is that I'm no programmer and I did my best so far. My post are in this format: http://visualise.ca/#!/anne-au-cherry and the static version is available at http://visualise.ca/anne-au-cherry (Where anne-au-cherry is the slug of the post and changes depending on the page we are viewing). So my question is could someone confirm that I'm on the right path and if possible also help creating that php function? Many thanks for your time and help!
|
What I did actually is to not use hashbangs like WraithKenny suggested. Using the jQuery address plugin with the $.address.state(value) method in order to set the base path of the website that is utilized in HTML5 state management and the $.address.value(value) method in order to set the current deep linking value I was able to do what I wished for. http://visualise.ca/ Posts (click on an image thumbnail) are loaded via AJAX and the URL changes at the same time, the posts exist on their own using, of course, the same permalink structure so it's fully crawlable. The only problem will be for older browsers that will, I think (needs to be verified), still see the hashbangs. Since I'm not a developper it took me much time to understand. :-/ But I'm quite happy with the results now ;-) jQuery address: http://www.asual.com/jquery/address/
|
Making my AJAX powered WordPress Crawlable
|
wordpress
|
I can easily add menu in the admin panel menus.just select the pages and cretae menu. i need to set pages URL with querystring. is that possible?. for example, http://mysite.com/about for this url i need to set http://mysite.com/about?abt=12 how can i set this querystring value using menu?. thanks Ravi
|
You can create a "custom link" for those pages where you need to add a querystring. Have you tried that? Best of luck!
|
How to pass the Querystring in pages?
|
wordpress
|
We would want a user to login and be presented with a form that they would potentially have to submit multiple times (disclosures of any industry relationships, one form per disclosure). The challenge is how do we capture and display what has been previously entered by a user when they log back in and give them a chance to delete or edit previous entries without investing in a ton of custom coding because we have a very tight deadline on this project. Has anyone seen WordPress do data collection and management in this manner on a per-user basis and if so, which plugins or other add ins were used?
|
The Formidable Pro plugin (paid) does what I was describing. It allows a logged-in user to submit a form multiple times and also will display a list of entries and a link to edit each one. Gravity and Wufoo don't match up.
|
Allow users to enter and edit data in one-to-many configuration
|
wordpress
|
This is less a technical question, and more a ’how would you do it’ question that I’m hoping the more experienced users may have some advice on… (I still think its a valid question for this forum) I’m creating a Flash application which allows users to upload an image, and then add a product to the shopping basket with that image on it (WPeC plugin is my shopping basket - I'm going to need to add a product to my shopping basket from within the flash application). My problem is this… many users will upload images, but not all will actually complete the order. When a user orders a product, I need to know which image on my server is their image! I thought about naming each image uploaded with the users Session Id, then when someone orders a customised product I would somehow find the session id and match them up. I ruled this out because a user might upload 3 or 4 images – each image would have the same Session Id so I wouldn’t be able to tell which image they wanted to use. Knowing what I’m trying to do, do you have any advice on how to go about this? Before I even start to work out the technical side of things I’d like to get a plan together of matching images to orders. PLEASE HELP IF YOU CAN! Thank you Dean
|
upload the file and add the item to the cart in one process, passing the filename as extra meta data with the cart item. if they remove the item from the cart, you can delete the file so you don't have abandoned files.
|
How to Match Orders to User Sessions in WPeC
|
wordpress
|
OK I head that WP can now host more sites using one installation. I host my blog on my own computer using MAMP and latest WP. But I can't find option to create another blog?
|
To achieve this simply, make sure your WordPress version is 3.0+. It is always recommended that you have the latest. First you need to activate the network: http://codex.wordpress.org/Create_A_Network Note that, as you are using a local installation, you won't have the choice to create your network in sub-directories as subdomains won't work. By reading and following the information in the link above, you'll get what I mean.
|
Can I run multiple blogs from my local machine
|
wordpress
|
I have a site that has two different bodies of content: more formal content (using various different custom post types) and a blog (using a blog post type). These two different bodies of content use the same taxonomies—but I would like to have two different versions of the taxonomy archives: one for the formal content, and one for blog content. For example, for a term science in the taxonomy subjects I'd like to have both mysite.com/subjects/science AND mysite.com/blog/subjects/science (or mysite.com/subjects/science/blog ) What's the best way to accomplish this in Wordpress? I don't want to use pages, because terms are being added all the time. I just want some way to be able to provide two archive templates for taxonomy terms.
|
My solution at the moment is to use a GET variable to request a different page template: Regular version of taxonomy page: mysite.com/subjects/science Blog version of taxonomy page: mysite.com/subjects/science?view=blog To handle the ?view=blog variable, I add this conditional to the top of taxonomy.php (or taxonomy-subjects.php and any other taxonomy-{slug} that I want to have an alternate version of): <code> /**************************************************** Tell Wordpress to fetch a different template if our URL ends in ?view=blog ****************************************************/ $view = $_GET["view"]; if ( $view == "blog" ) { get_template_part( 'blog-archive' ); exit(); } </code> Then, in the blog-archive.php template, I adjust the query_vars of $wp_query to output a loop with only blog posts. <code> // adjust $wp_query->query_vars to taste $newloop = array_merge( $wp_query->query_vars, array( 'post_type' => 'blog', 'posts_per_page' => 5 )); $the_query = new WP_Query ($newloop); while ( $the_query->have_posts() ) : $the_query->the_post(); //output your posts however you like endwhile; wp_reset_postdata(); </code> This works for me at the moment; the only unfortunate aspect is that the URLs show ?view=blog instead of nice /blog. I borrowed the main $_GET[] idea from the answer here: stackexchange-url ("How can I dynamically load another page template to provide an alternate layout of the posts?"). (I wonder if the latter can be done more intuitively with $the_query = $wp_query-> set('post_type', 'blog'); but this seemed to turn $the_query into a non-object and give an error.)
|
How to have two different versions of a tag/category/taxonomy archive page?
|
wordpress
|
I am considering to develop a new portfolio website in the form of a single page website. I do not know if this is a new concept, but I see it becoming popular for portfolio websites, it is also quite a handy form. Now I want to create the about, portfolio, contact on one page, and have a normal blog on another page. So actually there is one single page, and one blog page. To give you an example of the single page, here is a link to a tutorial that creates such a single page. But this is just a normal static page. http://tutorialzine.com/2010/02/html5-css3-website-template/ Now is the best way to go about this to just create a single page, and have all my content displayed there just formatted in one big pile of html. Or is there a more elegant solution to do this. Maybe with several custom post types on a single page, or is this not possible or not efficient. I am pretty new to wordpress, sorry for if this is a stupid Q
|
here's how I would set things up, not necessarily the correct / best / only way. create a home page, blog page, about page, contact page, etc.. as individual pages. create a custom post type for my portfolio items. use posts as the blog posts. set static front page to my home page, blog page as the posts page. create a front-page.php template, this will load whatever content I have in home by default. use get_page and wp_query to load all of my pages and portfolio items into the template. use a caching plugin to make it all nice and speedy
|
Creating the modern 'single page' html5 css3 layout in wordpress
|
wordpress
|
I need to apply a certain style to every second widget in my sidebar, and I'm reluctant to use :nth-child due to cross-browser compatibility issues. Is there a bit of PHP that will allow me to apply a class to every other widget?
|
Use the <code> dynamic_sidebar_params </code> filter. The following code adds classes to say whether the widget is odd or even, what index it is in the sidebar, and what sidebar it's in. Note : the <code> str_replace("class=\"", "class=\"$class ", $before_widget); </code> code below depends on your <code> before_widget </code> using double quotes -- it probably should be done with a regular expression to handle single quotes as well. I just haven't ever got around to it. <code> function my_filter_dynamic_sidebar_params($params){ static $sidebar_widget_count = array(); $sidebar_id = $params[0]["id"]; if (! isset($sidebar_widget_count[$sidebar_id])){ $sidebar_widget_count[$sidebar_id] = 0; } $before_widget = $params[0]['before_widget']; $class = $sidebar_widget_count[$sidebar_id] % 2 ? "widget-odd" : "widget-even"; $class .= " widget-index-" . $sidebar_widget_count[$sidebar_id]; $class .= " widget-in-$sidebar_id"; $before_widget = str_replace("class=\"", "class=\"$class ", $before_widget); $params[0]['before_widget'] = $before_widget; $sidebar_widget_count[$sidebar_id]++; return $params; } add_filter("dynamic_sidebar_params", "my_filter_dynamic_sidebar_params"); </code>
|
Style every second widget?
|
wordpress
|
Sometimes I forget to empty my debug.log file (or that it exists) and after trying to get around a bug, I find it having simply too much content to open it in ex. the basic Windows Text Editor. Part of my wp-config.php file: <code> error_reporting( E_ALL ); define( 'WP_DEBUG', true ); define( 'SAVEQUERIES', true ); define( 'WP_DEBUG_LOG', true ); // file: /core_root/wp-content/debug.log define( 'WP_DEBUG_DISPLAY', true ); </code> Question: Is there a way to do this via Wordpress, or do I have to do it with basic php functions?
|
Create a cron job for a function which checks the file size and runs <code> unlink( WP_CONTENT_DIR . '/debug.log' ) </code> if necessary.
|
How to empty debug.log when file size is above xyMB?
|
wordpress
|
Fatal error: Call to undefined function wp() in /home/content/33/7211533/html/someSite/wp-blog-header.php on line 14 can anyone figure whats the problem? I already update the wp-includes and wp-admin folder, my functions.php is fine but havent figure how to fix it any good suggestions? ----EDIT---- hi guys Im back, theres only 2 plugin installed its the http://wordpress.org/extend/plugins/wp-db-backup/ I cant really figure out on what happen on the website, but what I did to fix this weird problem ,...is I reinstall wordpress , (upload the new copy of wordpress on the site, and I make sure its latest one) - equivalent to a manual update . After that its started to work fine... so this problem is now fixed...
|
<code> wp() </code> is quite essential function. It resides in <code> functions.php </code> file (don't confuse with <code> functions.php </code> in theme, different thing) and I don't think you can load WP without passing <code> require </code> directive for that file at some point. So your install seems very broken - either <code> functions.php </code> file in core is damaged or something else is broken and makes it skip loading that file.
|
How to fix this this error Fatal error: Call to undefined function...?
|
wordpress
|
If I call the following function (on a page template, e.g. page-home.php) before the loop, nothing is returned. If I call it during or after the loop, the expected values are returned. Is there a way to access these meta fields before the loop runs? <code> function home_content() { global $post; $headline = get_post_meta($post->ID, 'top-headline', true); $body = get_post_meta($post->ID, 'top-body', true); $return = '<h4>' . $headline . '</h4>'; $return .= '<p>' . $body . '</p>'; echo $return; } </code>
|
You can get it by calling global $wp_query and assigning post-> ID to a variable. <code> <?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'top-headline', true); ?> </code>
|
Can I access a post meta field before the loop?
|
wordpress
|
i can make an easy template for displaying custom post types. but what i'd like to do is add some editable text to the top of my loop. for example: Hey wow, we really make cool products. I think it'd be nice if this text wasn't had coded into the template. any ideas? product 1 product 2 product 3 and so on. what is the easiest way to do that? is it possible to attach meta to a post "type"? i know you can sort of do something like that for categories/tags/tax, etc. but for a "type"? should i make it a theme option? would i be better served by making a post type and then displaying it through a taxonomy? i do want the resulting permalink to be mysite.com/products
|
I believe wp_options is the best solution for this. It's easily editable in an theme option page, but still you must hand code a new option each time you register a new Custom Post Type.You can use these get_option update_option Creating Options Page
|
Add meta data to the custom post type ARCHIVES page
|
wordpress
|
I currently have a blog set up on my domain (eg domain.com), but I would like to move it and all of its contents to a subdomain (eg sub.domain.com). Is there anything I need to watch out for or modify? Is there a tool which might do this more easily? I'm afraid of database issues (it will be using the database instance as it is now) or calls from within the blog itself not resolving.
|
Check out this word-press plugin: Backup and Move . Backup And Move plugin allow blog administrators to create a complete backup of their blog and easy option for restore it on a different server, domain, location, etc. This plugin can make all the transitions of moving a wordpress blog , creating a complete backup and restoring a previous backup very simple and smooth.
|
Moving my current wordpress blog to a subdomain
|
wordpress
|
I created a non-hierarchical custom post type and, by default, it's sorted by date published. I know I can reorder them by Title with <code> query_posts() </code> in the archive template: <code> global $query_string; query_posts( $query_string . '&orderby=title&order=ASC' ); </code> but it takes another SQL query on each archive page. Is there a way to register the sort order natively, eventually to get posts sorted by title even in the admin?
|
Try... <code> add_filter("posts_orderby", "my_orderby_filter", 10, 2); function my_orderby_filter($orderby, &$query){ global $wpdb; //figure out whether you want to change the order if (get_query_var("post_type") == "my_post_type") { return "$wpdb->posts.post_title ASC"; } return $orderby; } </code>
|
Custom Post Type sorted by Title
|
wordpress
|
I'm having trouble passing a table variable to $wpdb-> prepare(); Here is functioning code: <code> $table = $wpdb->get_blog_prefix( $blog_id ) . 'my_table'; $voters = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table WHERE user_id= %d AND post_id = %d;", $user_ID, $post->ID )); </code> This works great. However I think I should also be including my table in the prepare statement. But, it breaks when I change it to this: <code> $table = $wpdb->get_blog_prefix( $blog_id ) . 'my_table'; $voters = $wpdb->get_row($wpdb->prepare("SELECT * FROM %s WHERE user_id= %d AND post_id = %d;", $table, $user_ID, $post->ID )); </code> Any ideas on why it might be breaking?
|
The prepare() method escapes %s. The second piece of code you listed breaks because quotation marks are added to the table name, hence it doesn't match what's in the DB. The first piece of code works because it's a straight string replacement hence matching the name of the table in the database. What is the error message you are getting? HTH
|
Can't pass table to $wpdb-> prepare
|
wordpress
|
I'm trying to load the jQuery UI library into a WordPress plugin using this enqueue statement: <code> wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); </code> The jQuery library loads fine, but the ui-core is MIA. The only way I can get ui-core functions to fire is to load the library with a static include like this: <code> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/jquery-ui.min.js"></script> </code> What am I missing?
|
jquery is enqueued by default on admin side. So, it may not be loading due to your <code> wp_enqueue_script </code> statement. Are you using <code> wp_enqueue_script </code> inside some action hook? Because you have to. I use it like this: <code> add_action( 'admin_enqueue_scripts-options_page-{page}', 'myplugin_admin_scripts' ); function myplugin_admin_scripts() { wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); } </code>
|
How to include jquery-ui library in WordPress?
|
wordpress
|
I have migrate my web site from Joomla to WordPress. All are fine, I have create my Rewrites in htaccess to stop 404 from old URLs but I have problem with pagination. In Joomla web site, I had 6 posts per page, but now in WordPress I need to display 10 posts per page. That's fine too. The problem is that, in WordPress site now the very very last pages return 404 error because of the 10 posts per page I use now. i.e.: In Joomla to get the 60th article I had to go on page 10, but now page 10 does not exists anymore, because In WordPress the very very last page now is the page 6. In that case, I will try to access the 7th, 8th, 9th or 10th page I get a 404 HTTP Error. How can I fix that?
|
The only way to really know if it's going to be a 404 is to let WordPress try to load it and check results before WP sends headers. If you put this in your functions.php ( not on a live site! use a dev mirror. ), then visit a page that throws a 404, you can see the contents of the <code> $wp_query </code> object produced, <code> is_404 </code> will be true. By inspecting this you can determine what you want to do. <code> add_filter('template_redirect', 'wpse25745_inspect_query' ); function wpse25745_inspect_query() { global $wp_query; echo '<pre>'; print_r($wp_query); echo '</pre>'; die(); } </code> Following on that, you can redirect somewhere like this: <code> add_filter('template_redirect', 'wpse25745_inspect_query' ); function wpse25745_inspect_query() { global $wp_query; if( $wp_query->is_404 && $some_other_conditions_met == 'foo' ): wp_redirect( home_url(),301 ); exit; endif; } </code>
|
WordPress total posts per page changed and now 404 Http error comes out
|
wordpress
|
In most of the posts on my site, embedded images link to the actual image file. I'm also using Web-App mode via WPTouch. In web-app mode images linked to their larger versions shouldn't open; since Web-App mode has no back button, a user can follow a link to a image and become "stranded" there. I'm also using W3 Total Cache, which appends the param string "?9d7bd4" to all my images. This makes sure that if you change your browser cache policies all users immediately see that change. However, apparently the the appended image string allows for the images to be clicked on and stranded. Interferes with whatever is stripping the image links. All BraveNewCode can tell me is try "disabling Browser Cache in W3TC" which I obviously I'm not interested in doing. Suggestions?
|
Best way to avoid this is to go to "Browser Cache" and uncheck "Prevent caching of objects after settings change" under "Media and Other Files"
|
Web App mode leaves users stranded when following image links when using WPTouch with W3 Total Cache
|
wordpress
|
How can in wordpress, one sell the "create post" option To elaborate more. One has to pay an amount before he can make create a post on the wordpress site. MORE ELABORATION Suppose a person pays $20, he gets to write a post on wordpress. This is just like a paid listing website. If the person wants to create another post, he has to pay another 20 Bucks.
|
As per comments you can make use of user meta functions to store user-specific information and use capabilities (or some more simple check) to control if user can create a post.
|
Sell "create a post", paid account for post creation
|
wordpress
|
I recently updated my site to wordpress 3.2.1 automatically. Now I tried to manage my sidebar widgets, and noticed I can no longer drag and drop the widgets around. If I look into my browser-console, I notice that the page is unable to load jQuery. Weird: it appends my root-url to the jquery-url, like so: <code> <script type="text/javascript" src="http://meanderend.dixis.com//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js?ver=3.2.1"></script> </code> So it is normal that it is not found. How can I fix this. Is there something wrong in my configuration? Or is this a bug? Then it should be general, for everybody, no?
|
Your theme may be written badly and replace the correct jQuery. Switch to TwentyEleven to check for this. If this doesn’t help, turn off all plugins and re-enable them step by step.
|
cannot drag and drop widgets since wordpress 3.2.1
|
wordpress
|
I was surprised to discover that add_role() modifies the database and fails if the role already exists. There are two implications here, one first more serious than the other: 1) if you're in development and update your add_role code, you must first remove_role() 2) once you have it right, you should never have to run that code again. So typically I have been putting my add_role() inside a wp_loaded action hook. And since I'm in development, I've also added a remove_role() before my add_role so I can be sure that if I modify my list of caps, it will actually take effect. But clearly this is now being run every time a page of the blog is being accessed. Okay, I could put it in an admin-only action, or I could create a plugin page maybe under Users or Tools where this role can be created once. I guess I'm hoping there's a simpler, more elegant solution out there. I don't imagine there's a run_once kind of action is there? Or is the best practice just to add the role and then use add_cap() a bunch of times? And even then I imagine add_cap is accessing the db. Just thinking in terms of the best way to reduce unncessary db access. What are your best practices?
|
The user roles and capabilities are saved in the database so once you have you have used <code> add_role() </code> its saved and then next load WordPress will know that role just like the built in roles. Now if you look at the function <code> add_role() </code> more specifically at line 141 you will see that it only saves the role and capabilities in the database if the var <code> $use_db </code> is set to true (which he is by default) so you can simply change it before you call your <code> add_role() </code> function and the role won't be saved. try: <code> //globalize $wp_roles global $wp_roles; //set use_db to flase $wp_roles->use_db = false; //then add your role $wp_roles->add_role( $role, $display_name, $capabilities ); </code> Update: If its in a test/development environment then i see no downside, but if you are on a live environment then you save the time it take to create that on role every load. As for best practice run once, if in a plugin you should use <code> register_activation_hook </code> and for any thing else i use a simple custom made conditional function: <code> function run_once($key){ $test_case = get_option('run_once'); if (isset($test_case[$key]) && $test_case[$key]){ return false; }else{ $test_case[$key] = true; update_option('run_once',$test_case); return true; } } **usage:** if (run_once('add_user_role')){ //do you stuff and it will only run once } </code>
|
add_role() run only once?
|
wordpress
|
I have two custom post types. One of them, I would like the author role to be able to publish. The other one, I would like for them to "Submit for Review". Any suggestions?
|
When the post type is registered, http://codex.wordpress.org/Function_Reference/register_post_type one can specify custom 'capabilities'. eg I have an events post type, with event as a base for the capabilities, so automatically, there is a matching set like the page/post capabilties. Then one can use justin tadlock's members plugin to assign capabilities to roles. Assign 'create' but not 'publish' to the 'review' post type, but full rights to the other type. Simple.
|
Allow Author role to publish one post type and not another
|
wordpress
|
<code> <div class="example"> <h1>Menu</h1> <ul> <li>sub-menu</li> <li>sub-menu</li> <li>sub-menu</li> </ul> </div><!-- end of example --> <div class="example> <h1>Menu</h1> <ul> <li>sub-menu</li> <li>sub-menu</li> <li>sub-menu</li> </ul> </div><!-- end of example --> </code> I'm trying to make a menu with wp_nav_menu() and I want to achieve a clean code like this. I'm trying to do it with a custom walker but I don't have experience with this. I think I have to overwrite a class but ... Coud you help me with the code?? Thanks for all
|
In my basis theme I use a walker for a simplified output : <code> <?php # -*- coding: utf-8 -*- /** * Create a nav menu with very basic markup. * * @author Thomas Scholz http://toscho.de * @version 1.0 */ class T5_Nav_Menu_Walker_Simple extends Walker_Nav_Menu { /** * Start the element output. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. May be used for padding. * @param array $args Additional strings. * @return void */ public function start_el( &$output, $item, $depth, $args ) { $output .= '<li>'; $attributes = ''; ! empty ( $item->attr_title ) // Avoid redundant titles and $item->attr_title !== $item->title and $attributes .= ' title="' . esc_attr( $item->attr_title ) .'"'; ! empty ( $item->url ) and $attributes .= ' href="' . esc_attr( $item->url ) .'"'; $attributes = trim( $attributes ); $title = apply_filters( 'the_title', $item->title, $item->ID ); $item_output = "$args->before<a $attributes>$args->link_before$title</a>" . "$args->link_after$args->after"; // Since $output is called by reference we don't need to return anything. $output .= apply_filters( 'walker_nav_menu_start_el' , $item_output , $item , $depth , $args ); } /** * @see Walker::start_lvl() * * @param string $output Passed by reference. Used to append additional content. * @return void */ public function start_lvl( &$output ) { $output .= '<ul class="sub-menu">'; } /** * @see Walker::end_lvl() * * @param string $output Passed by reference. Used to append additional content. * @return void */ public function end_lvl( &$output ) { $output .= '</ul>'; } /** * @see Walker::end_el() * * @param string $output Passed by reference. Used to append additional content. * @return void */ function end_el( &$output ) { $output .= '</li>'; } } </code> See stackexchange-url ("this answer") for implementation details.
|
wp_nav_menu() customized
|
wordpress
|
Currently i'm working on a simple WordPress Plugin. I know within the Plugin i need to write my strings as <code> __() </code> or <code> _e() </code> and call <code> load_plugin_textdomain() </code> but i wonder how to localize the Plugin Description. Example: This is not the Plugin i'm working on. It's just an example to show what i mean.
|
Add two extra headers: <code> Text Domain: your-text-domain Domain Path: /languages </code> Then use the plugin Codestyling Localization to create your language files. Usually it'll find the description.
|
Localize Plugin Description
|
wordpress
|
in the codepad link you can find what I am using to edit profile from the front-end. http://codepad.org/QJjDEA7p The code is working (which I got from stackexchange-url ("How to edit a user profile on the front end?") and change some things for me to work correctly). I have installed Simple Local Avatar plugin to allow avatar uploading, but how can I modify the code to have it also from the front-end ? I found these below, which I tested, showed the upload button, did not showed the current avatar and didn't let me to change it. Thank you for your help on this. <code> do_action('show_user_profile'); do_action('edit_user_profile'); do_action('personal_options_update'); do_action('edit_user_profile_update'); </code> UPDATE There goes a 50 bounty for a working example. Unfortunately I can not get Bainternet's example to work that I tested with User Avatar plugin also, and I am really stuck with this issue can't finding the solution.
|
You only need to of these hooks <code> show_user_profile </code> to show the extra fields and <code> personal_options_update </code> to update, try: <code> <?php ob_start(); include_once("../../../wp-load.php"); get_header(); /* Get user info. */ global $current_user, $wp_roles; get_currentuserinfo(); /* Load the registration file. */ require_once( ABSPATH . WPINC . '/registration.php' ); /* If profile was saved, update profile. */ if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'update-user' ) { /* Update user password. */ if ( !empty($_POST['pass1'] ) && !empty( $_POST['pass2'] ) ) { if ( $_POST['pass1'] == $_POST['pass2'] ) wp_update_user( array( 'ID' => $current_user->id, 'user_pass' => esc_attr( $_POST['pass1'] ) ) ); else $error = __('The passwords you entered do not match. Your password was not updated.', 'profile'); } /* Update user information. */ if ( !empty( $_POST['url'] ) ) update_usermeta( $current_user->id, 'user_url', esc_url( $_POST['url'] ) ); if ( !empty( $_POST['email'] ) ) update_usermeta( $current_user->id, 'user_email', esc_attr( $_POST['email'] ) ); if ( !empty( $_POST['first-name'] ) ) update_usermeta( $current_user->id, 'first_name', esc_attr( $_POST['first-name'] ) ); if ( !empty( $_POST['last-name'] ) ) update_usermeta($current_user->id, 'last_name', esc_attr( $_POST['last-name'] ) ); if ( !empty( $_POST['yim'] ) ) update_usermeta($current_user->id, 'yim', esc_attr( $_POST['yim'] ) ); if ( !empty( $_POST['description'] ) ) update_usermeta( $current_user->id, 'description', esc_attr( $_POST['description'] ) ); //extra fields (simple local avatars ....) do_action('personal_options_update', $current_user->id); /* Redirect so the page will show updated info. */ if ( !$error ) { header("Location: ".$_SERVER['PHP_SELF']); exit; ob_flush(); } } ?> <div id="post-<?php the_ID(); ?>"> <div class="entry-content entry"> <?php the_content(); ?> <?php if ( !is_user_logged_in() ) : ?> <p class="warning"> <?php _e('You must be logged in to edit your profile.', 'profile'); ?> </p><!-- .warning --> <?php else : ?> <?php if ( $error ) echo '<p class="error">' . $error . '</p>'; ?> <form method="post" id="adduser" action="<?php the_permalink(); ?>"> <p class="form-username"> <label for="first-name"><?php _e('First Name', 'profile'); ?></label> <input class="text-input" name="first-name" type="text" id="first-name" value="<?php the_author_meta( 'user_firstname', $current_user->id ); ?>" /> </p><!-- .form-username --> <p class="form-username"> <label for="last-name"><?php _e('Last Name', 'profile'); ?></label> <input class="text-input" name="last-name" type="text" id="last-name" value="<?php the_author_meta( 'user_lastname', $current_user->id ); ?>" /> </p><!-- .form-username --> <p class="form-email"> <label for="email"><?php _e('E-mail *', 'profile'); ?></label> <input class="text-input" name="email" type="text" id="email" value="<?php the_author_meta( 'user_email', $current_user->id ); ?>" /> </p><!-- .form-email --> <p class="form-url"> <label for="url"><?php _e('Website', 'profile'); ?></label> <input class="text-input" name="url" type="text" id="url" value="<?php the_author_meta( 'user_url', $current_user->id ); ?>" /> </p><!-- .form-url --> <p class="form-yim"> <label for="yim">yahoo</label> <input class="text-input" name="yim" type="text" id="yim" value="<?php the_author_meta( 'yim', $current_user->id ); ?>" /> </p><!-- .form-yim --> <p class="form-password"> <label for="pass1"><?php _e('Password *', 'profile'); ?> </label> <input class="text-input" name="pass1" type="password" id="pass1" /> </p><!-- .form-password --> <p class="form-password"> <label for="pass2"><?php _e('Repeat Password *', 'profile'); ?></label> <input class="text-input" name="pass2" type="password" id="pass2" /> </p><!-- .form-password --> <p class="form-textarea"> <label for="description"><?php _e('Biographical Information', 'profile') ?></label> <textarea name="description" id="description" rows="3" cols="50"><?php the_author_meta( 'description', $current_user->id ); ?></textarea> </p><!-- .form-textarea --> <?php do_action('show_user_profile',$current_user->id); ?> <p class="form-submit"> <?php echo $referer; ?> <input name="updateuser" type="submit" id="updateuser" class="submit button" value="<?php _e('Update', 'profile'); ?>" /> <?php wp_nonce_field( 'update-user' ) ?> <input name="action" type="hidden" id="action" value="update-user" /> </p><!-- .form-submit --> </form><!-- #adduser --> <?php endif; ?> </div><!-- .entry-content --> </div><!-- .hentry .post --> <?php comments_template( '', true ); ?> </code>
|
Uploading avatar from the frontend
|
wordpress
|
It's not hard i think, but i run out of ideas... In template file I have code like this; <code> $current = $post->ID; $parent = $post->post_parent; $pages = get_pages('child_of='.$parent.'&parent='.$parent.'&sort_column=post_title&title_li&hierarchical=0'); $front_id = get_option('page_on_front'); </code> I cant figure out how will statement to determine if <code> $front_id </code> is in <code> $pages </code> array look like ! thx for Your time!
|
If you just need to remove, or ignore, it from <code> $pages </code> , use the <code> exclude </code> argument instead; <code> $pages = wp_list_pages( array( 'exclude' => get_option( 'page_on_front' ), 'child_of' => $parent, 'parent' => $parent, 'sort_column' => 'post_title', 'title_li' => '', 'hierarchical' => '0' ) ); </code> I've used <code> wp_list_pages </code> as I assume this is the function you've intended to use ( <code> get_pages </code> does not have a <code> title_li </code> argument). If that isn't what you were after, then just loop over the pages to determine if it's there; <code> foreach ( $pages as $page ) { if ( $front_is_here = ( $page->ID == $front_id ) ) break; } if ( $front_is_here ) { // front page is among pages } else { // front page is *not* among pages } </code>
|
determine if specific page is in list?
|
wordpress
|
I have a multisite install with 2 sites. I am working on site A, and I have a lot fo users on site B. I can individually move users from B to A, but there is a nontrivial number of users, and this could take days of repetitive work to do. How would I move assign all of the users at once to site A from site B?
|
Here is code I wrote to automatically move the users from site A to site B within a network en masse. May need running twice <code> <?php add_action( 'admin_init', 'user_move_init' ); add_action( 'admin_menu', 'user_move_add_page' ); /** * Init plugin options to white list our options */ function user_move_init(){ register_setting( 'user_move', 'user_move', 'user_move_validate' ); } /** * Load up the menu page */ function user_move_add_page() { add_users_page( __( 'User Import', 'user_move' ), __( 'User Import', 'user_move' ), 'edit_theme_options', 'theme_options', 'user_move_do_page' ); } /** * Create the options page */ function user_move_do_page() { if ( ! isset( $_REQUEST['settings-updated'] ) ) $_REQUEST['settings-updated'] = false; ?> <div class="wrap"> <h2><?php echo __( ' User Network Import', 'user_move' ) ; ?></h2> <?php if ( false !== $_REQUEST['settings-updated'] ) : ?> <p>Starting transfer</p><?php global $wpdb; switch_to_blog(2); $aUsersID = $wpdb->get_col( $wpdb->prepare("SELECT $wpdb->users.ID FROM $wpdb->users" )); /* Once we have the IDs we loop through them with a Foreach statement. */ foreach ( $aUsersID as $iUserID ) : /* We use get_userdata() function with each ID. */ $user = get_userdata( $iUserID ); $capabilities = $user->{$wpdb->prefix . 'capabilities'}; if(!empty($capabilities)){ if ( !isset( $wp_roles ) ){ $wp_roles = new WP_Roles(); } $r = ''; foreach ( $wp_roles->role_names as $role => $name ) : if ( array_key_exists( $role, $capabilities ) ){ $r = $role; break; } endforeach; } if(empty($r)){ $r = 'subscriber'; } /* Here we finally print the details wanted. Check the description of the database tables linked above to see all the fields you can retrieve. To echo a property simply call it with $user->name_of_the_column. In this example I print the first and last name. */ echo '<li>Transfering '.$user->user_login.' ('. ucwords( strtolower( $user->first_name . ' ' . $user->last_name ) ) . '), '.$r.'</li>'; add_user_to_blog(1,$iUserID,$r); /* The strtolower and ucwords part is to be sure the full names will all be capitalized. */ endforeach; restore_current_blog(); ?><p>Transfer complete</p> <?php endif; ?> <form method="post" action="options.php"> <?php settings_fields( 'user_move' ); ?> <p>Click to import Users from the blog site to the main site</p> <p class="submit"> <input type="submit" class="button-primary" value="<?php _e( 'Start Import', 'user_move' ); ?>" /> </p> </form> </div> <?php } /** * Sanitize and validate input. Accepts an array, return a sanitized array. */ function user_move_validate( $input ) { return $input; } </code>
|
Bulk Move Users from one site to another within a network ( Multisite )
|
wordpress
|
For example, inside the loop could i do something like this <code> if lastpost { } else { } </code>
|
http://wordpress.org/support/topic/last-post-in-the-loop
|
Is there an if statement that can determine if a post in the loop is the last post?
|
wordpress
|
I love stackexchange's tag subscription feature. Now i'm receiving email notifications only for the topics i'm interested in. I would like to have this feature in my wordpress site. Is there any good tag subscription plugin available?. If there is no plugin available why not WA experts create one and submit it in the stackexchange-url ("WPSE Plugin Repository")?
|
If you're willing to use an outside provider, you can add the tag feed to Feedburner. First get the tag feed: <code> http://www.example.com/?tag=tagname&amp;feed=rss2 </code> Then to to feedburner.com and create a feed, then enable "Email Subscriptions" (under the "Publicize" tab). I've done this, and it works well.
|
Tag subscription option in wordpress. How?
|
wordpress
|
I want to validate this deprecated function: <code> add_filter('user_has_cap', array(&$this, 'filter_user_has_cap'), 10, 3); </code> It needs to use roles or capatibilies, so I guess 10 is the admin level, so I could use "edit_pages": <code> add_filter('user_has_cap', array(&$this, 'filter_user_has_cap'), 'edit_pages', 3); </code> But what is argument "3"? Thank you Oliver
|
First of all, it's not the add_filter() call that you're supposed to be modifying, but the callback: 'filter_user_has_cap', i.e. go to where that method is defined and change the user level to 'edit_pages'. Fixing deprecated notices is easier with the Log Deprecated Notices plugin.
|
How to validate this deprecated function
|
wordpress
|
I'm looking to print out All of the Main Categories (So Exclude Sub-Categories) in a Loop, I need to get the ID's to do some advanced category listings. So I need to echo this out: <code> 3 CatName 4 CatName 5 CatName x CatName </code> Where the number is the category # and the CatName is the name of the category
|
http://codex.wordpress.org/Function_Reference/get_categories example: <code> <?php foreach(get_categories('parent=0&orderby=id') as $cat) { echo $cat->term_id.' '.$cat->name.'<br/>'; } ?> </code>
|
Printing out Main Category ID's in a Loop
|
wordpress
|
I have a client who wants their blog to display both Posts and Tweets in chronological order. These should be mixed into the same feed. I didn't find any plugins that accomplished this, although there may be one I missed which someone could recommend. I was thinking to pull the tweets and store them as a custom post type, and then just pull both post types when displaying, but Twitter's TOS does not allow the storing of the data. Only option I see is to pull the tweets on page load, and then write a custom function to merge the two chronologically, which seems like a bit of work. Also, as far a caching the tweets, how can I go about this, considering that Twitter does not allow for storage of this information? Does anyone have a recommendation on the best way to accomplish this? Also the most efficient? Thanks in advanced.
|
I've done this with Twitter Tools . Basically it hooks up the blog to a Twitter feed, and for each new tweet creates a blog post. You can put twitter posts in a separate category (or add tags), and use that to style twitter-posts differently from regular posts, hide the comments field, whatever. Hope this helps - good luck!
|
Mixing Tweets with Posts
|
wordpress
|
This is probably totally off the wall, but I want to create a new wordpress plugin, that will have its own subset of templates and pages. Whats the best way to do this? The plugin will be used on three pages of the wordpress site. It will use the same theme, though It will have three different page templates. Is it possible to group the templates together in a sub-folder inside the theme or plugin. The pages will be static ie dont need to be available to wp-admin. How it currently is..... option a -> templates in theme root, using wordpress page admin. Below is two ideas of how i'd like it to be.... option b -> sub folder in theme with static pages (No need to create/edit in wp-admin). option c -> self contained templates inside plugin folder using current theme, and custom filters/ actions with static pages (No need to create/edit in wp-admin). This plugin is essentially a section of the wordpress site grouped together that uses the wordpress objects and database. It will have its own loops and pages. <code> /wp-content/plugins/mycustomplugin/mycustomplugin.php /wp-content/plugins/mycustomplugin/templates/default.php /wp-content/plugins/mycustomplugin/templates/template2.php /wp-content/plugins/mycustomplugin/templates/mycustomplugin-loop.php </code> or <code> /wp-content/plugins/mycustomplugin/mycustomplugin.php /wp-content/themes/mytheme/mycustomplugin/mycustomplugin.php /wp-content/themes/mytheme/mycustomplugin/template2.php /wp-content/themes/mytheme/mycustomplugin/mycustomplugin-loop.php </code>
|
If this is a plugin you should really keep the files in your plugin folder. Alternatively you can use the theme folder under it's own name separate from the active theme. I have seen the latter done and it works fine but you don't want some unsuspecting users to activate it by mistake. You should never write to the active theme or any theme the user has installed.
|
Working with wordpress plugin and theme templates structures
|
wordpress
|
I'm in middle of re-building a website that's coded in a rather terrible custom CMS. Since the site is essentially a blog, I've been doing it in Wordpress. One thing I'd like to do is be able to add a few "related links" to each post. These links are not the same thing as "related posts". When a new article is posted, I'd like the post author to be able to attach a handful of links from other sites (e.g. an article on nytimes.com, something from other blogs, etc). Each related link item would consist of the original URL, the Title, the Author(s), Source, and a brief description. See image for an example: Since I don't have enough rep points (yet), here's an image link instead: http://i.stack.imgur.com/nlhbt.png My first thought was I could use Custom Fields - but this would quickly fall apart if there were multiple links. My current thought is to have each link as a separate Custom Post Type, but then I'm stumped on ways to link them to the post it should be shown with. If only WP had an auto-complete field that I could use for the article title. I'm using Magic Fields for certain categories, but it doesn't look like it would work here. Is there anything I could use for this? I'm not very familiar with the WP core/plugins development, but I'm great with PHP/MySQL, so I don't mind having to code something up. I couldn't find anything by searching so I'm asking here. Any ideas for plugins/implementations that would work?
|
Have you tried this plugin: http://eskapism.se/code-playground/simple-fields/ It's quite capable and should do what you want without getting your hands too dirty.
|
Related links - from other sites
|
wordpress
|
I need to add a class of "two-sidebars" to the regular bunch of WP classes that are generated by <code> <?php body_class(); ?>> </code> The reason I need to do this is I'm integrating WP into a Drupal install, and need to keep the "two-sidebars" class for style reasons for the Drupal part of the page. What's the best way? jQuery? Is it possible to hook into body_class?
|
You can add to the function simply by placing the desired class as the first parameter like so <code> body_class('class-name') </code> . If you'd like a little more flexibility you can hook into it using <code> add_filter('body_class','my_class_names') </code> . You can read more here .
|
How do I add a class to that is generated by >
|
wordpress
|
For additional security, the suggestion is made to move the wp-config.php up one level. Can this be done after the site has already been launched? Any potential issues in doing this? Are there an restrictions/suggestions on what the new folder should be called?
|
You can safely move it as far as I know.... but what do you mean folder? Up one level would already be a folder.... if your site is in html, or public_html or whatever, you place the wp-config file in whatever folder holds your html or public_html folder like if your path is /home/content/u/s/e/user/html/ And your WP is in html, the wp-config would go in user, the next folder up which is not web accessible. WP will automatically look for it there If you are on shared hosting, you probably can't do that anyway And if you have WP in a subdirectory, there would be no point in moving wp-config, as moving it up a level would still put it in a web accessible directory
|
Moving wp-config.php: Can this be done after site launch?
|
wordpress
|
I would need to simplify the "upload new image" interface for our Authors : basically, hide a few fields that will only confuse my wordpress "authors" (like the "Description" and "Alt" text inputs). Administrators and Editors need to see these, though. How can i implement that hiding/showing inputs according to the user's priviledges?
|
You will need to hook into <code> attachment_fields_to_edit </code> and unset them for a role. You can use <code> current_user_can('author') </code> http://codex.wordpress.org/Function_Reference/current_user_can Example to remove image alt field <code> function remove_caption($form_fields) { if (current_user_can('author')){ $form_fields['image_alt']['input'] = 'hidden'; return $form_fields; }} add_filter('attachment_fields_to_edit','remove_caption', 15, 2); </code> My initial post used <code> unset </code> but I tried it and it did not work, from the example in this post: stackexchange-url ("How can I remove fields in the attachment editor?") , not sure why, instead the example above works using <code> hidden </code> .
|
Customize the upload screen
|
wordpress
|
I have a custom post type of 'events' which has a meta key 'event_date' Im using the following to retrieve those posts and arrange them by 'event_date' <code> global $wpdb; $today = date('Y/m/d', strtotime("now")); $events = $wpdb->get_results("SELECT posts.id, posts.post_title, meta.meta_value FROM {$wpdb->prefix}postmeta as meta LEFT JOIN {$wpdb->prefix}posts as posts ON (meta.post_id = posts.id) WHERE (meta.meta_key = 'event_date' AND meta.meta_value >= '{$today}' AND posts.post_status='publish' and posts.post_date < NOW()) ORDER BY meta.meta_value "); </code> The above works fine however i would like to show 'events' from only certain categories (say category id '5'). How can i modify the query to achive this? Any help would be appreciated :)
|
First, you shouldn't use <code> NOW() </code> in select queries since <code> NOW() </code> returns the current date and time to the split second. In other words: This query will never land in the cache. And you can use the WP_Query with filter of <code> posts_where </code> eg: <code> function filter_event_where( $where = '' ) { $date = date('Y-m-d'); $where .= " AND posts.post_date < '".$date."'"; return $where; } add_filter( 'posts_where', 'filter_event_where' ); $today = date('Y/m/d', strtotime("now")); $query = new WP_Query( array( 'meta_key' => 'event_date', //used for order 'orderby' => 'meta_value', //used for order 'post_type' => 'event', 'meta_query' => array( array( 'key' => 'event_date', 'value' => $today, 'compare' => '>=' ) ) )); remove_filter( 'posts_where', 'filter_event_where' ); </code>
|
Wordpress $wpdb get posts from category and sort by custom meta
|
wordpress
|
I'm trying to build a wp plugin, which will basically add some text for every post, in the post itself, I'm afraid that the codex is too large for me to even know what to look for, so I'd appreciate if someone could point me in the right direction. Edit: As per request, the info should be added to the post's text on the database, at the end of the post, it's not static, it's a random embed from a tube site, based on a query I run on the tubesite.
|
Your best bet is to use the <code> the_content </code> filter hook and add your content to the post "on the fly" for ex: <code> add_filter('the_content','add_my_extra_content'); function add_my_extra_content($content){ $my_extra = "<h5>this is the extra content</h5>'; //add before post content // return $my_extra.$content; //add after post content return $content.$my_extra.; } </code>
|
Adding more text to a post, after it was published
|
wordpress
|
There is the situation. I have created the custom post type - products withfuncionality like pages - I have to create hierarchy. f.e: Chairs: Oak Chair Nice Chair The weird thing happens with wp_nav_menu(). When I open the first level page Chairs and display all the Chairs childrens in theme, the nav menu for the li item Products, gets the .current-menu-item class, but when I open the child page f.e. Oak Chair, the class disapears. Why is that and how to set .current-menu-item class also when child page is opened? This same problem happens again :( WP Version 3.2.1 the ancestor-class .current-products-ancestor is not setted up :(
|
Use this selector: <code> .current-products-ancestor </code> ... to change the styles on that menu.
|
.current-menu-item class on custom post type children pages - again?
|
wordpress
|
Sorry for this but I am sure this is a duplicate question, but I have been searching, but I cannot find a suitable answer for this question. I hope you still can help. I want to create a website with a few static pages, and a blog. Now on one of the static pages, the portfolio page, I want to have all of my work in boxes in a list. Just like you would have blog posts. Now I not want to create a post for each of the work I have done, because it will mingle with the blog I guess. Is there another option on WP to have snippets of content, just as posts, which could be loaded into a page. Or should I just create the whole portfolio page just as a big static page.
|
You have to create Custom Post Type, I've done it for the very first time using this tutorial . Basically, you have to add "a few" lines to functions.php and then add your portfolio items as posts in new custom post type (it will be available in your admin panel). I hope it helps :)
|
How can I get dynamic content on my static home page
|
wordpress
|
When viewing a list of all standard post or pages there are convient quick edit and bulk edit functions to edit author, template, status, dates, etc... Is there an easy to enable similar quick edit and bulk edit tools on Custom Post types? For example going to: ../wp-admin/edit.php?post_type=page select all checkboxes, select edit from drop down, click apply, you get options for Author, Parent, Template, Comments, Status, but none of those show up for ../wp-admin/edit.php?post_type=mycustomposttype
|
Make sure that show_ui and show_in_menu are set to true when the post type is enabled. then all the usual post/pages features will be available. See http://codex.wordpress.org/Function_Reference/register_post_type Also make sure that those features are explicitly declared as by the CPT as supported.
|
Is there a way to enable bulk edit and quick edit on custom post types?
|
wordpress
|
I will describe here steps I made to make my galleries for my first WP theme. I wanted to have a few links in my menu which will take user to page with thumbnails. Each thumbnail takes user to gallery with bunch of horizontally displayed images. First, in my functions.php file I've added new size for my icons: <code> add_image_size( 'wide-image-icon', 200, 150, true ); </code> Then, I've made my template file for gallery category (lets call it Gallery1) and category "Gallery1". In my <code> gallery1.php </code> template file I used query for posts with galleries: <code> query_posts(array('category_name'=>'Gallery1','posts_per_page'=>-1)) </code> Then, in posts loop I've displayed my gallery icons (which are featured images of posts): <code> the_post_thumbnail('wide-image-icon'); </code> So now, after creating new page with "Gallery1" template, I can add post, select "Gallery1" category for it, add pictures using standard "Insert gallery", choose one as featured image and I'm good to go. The problem is that's not universal way of doing this. What if I would like to make another gallery page (Gallery2). Then I need to make new template file, create new category, change category name in query inside template file, add new page with this template attached to it. How do you do it? I'd also like to ask about some admin side improvements for gallery. I've seen themes where there was a completely new tab inside admin area where you saw all galleries, you could easily change images order, add/remove galleries etc. Right now on my website I add my news ( I use the same system here ), galleries, blog posts and normal pages like "Bio" as posts only which is definitely not good. PS. Any articles, video tutorials, books or tips and tricks are welcome. @edit: How can I manage display of my galleries on admin side? I'd like to remove whole editor and leave just pictures if you know what I mean.
|
This is all sorts of wrong, you need to first decide if you want to use posts, pages or custom post types. You alluded at the end that you wanted a new tab like you have seen in some themes, this would be the right way to do it using Custom Post Types. You can learn how to create them here, http://codex.wordpress.org/Post_Types#Custom_Types http://codex.wordpress.org/Function_Reference/register_post_type After that you can create a template file for your post type that is specific to how you want it to look. For instance say you created a CPT called "Gallery", your theme file can be <code> single-gallery.php </code> . There you can use the loop anyway you want to display and style your photos, and every post made in this post type (Gallery) will use that theme file. To answer your second question, when you register a new custom post type there are parameters, one of them can enable or disable the editor. The one your looking for is <code> supports --> 'editor' </code> By default to manage the post's photos you click on Add Photo---> Gallery--> there you find the management options. If you want to customize a new photo management "console" you will have to make another question as it would be to complicated to go into details here, I have seen them but I'm not entirely sure what the best method is to accomplish this.
|
How to make universal gallery and improve admin side of managing galleries?
|
wordpress
|
I'm trying to create sidebar in my wordpress admin. This is because I'm trying to make my wordpress admin look like my front end. My front end theme has sidebar in the right side. So i would like to display the same sidebar in my admin area. I know its possible by editing wordpress core files. But if i update my wordpress core in the future then all my works will be wasted. So i'm trying to find some alternate ways. Is there any wordpress admin hook available out there to edit admin body, like editing admin header(admin_head) ? I respect and appreciate everyone's comments/answers. So please help me. Thanks to all
|
It's a bad idea to try to make the wp-admin area look like the front-end. It's an uphill battle. Try using my Front-end Editor plugin: it allows editing widgets directly from the front-end etc.
|
Is it possible to display my theme sidebar in wordpress admin?
|
wordpress
|
I created a new template page with code to allow front-end posting. Everything works great, with tags, post meta and image uploading (as featured image). I have seen many codes about front-end post editing, but even though I tried to figure it out I can not successfully make it to work. I took as example this stackexchange-url ("How can I edit a post from the frontend?") and placed it in single.php with no luck. I guess the right way to have it, is to have an EDIT link below the post and there will be appear a new php template that contains the edit form when it is clicked. Is this correct? Secondly, how can I update the featured image I added from the front-end ? Thank you for your help.
|
The Front-end Editor plugin allows you to change post thumbnails (featured images).
|
How to update post's featured image in front-end
|
wordpress
|
I'm new to Wordpress and am a little confused with which Wordpress user types can access plugin functionality? As administator I know I can activate (and deactivate) plugins. I can access their settings through the dashboard. However, this doesn't seem to be the case for the editor user. Which plugins settings (if any) are editable for an editor? The reason for me asking is because I want to manage my clients sites, but there may be some plugin settings that I will want my clients to use. I am assuming that the best way of working will be me as administrator and my clients as editors.
|
By default only super admins/administrators can edit plugin/theme settings. http://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table If you want to give access to plugin/theme settings (or other stuff) for an editor you can add a capability to a role. stackexchange-url ("How can I allow the Editor Role to change Theme Settings?")
|
Plugin access and Roles
|
wordpress
|
Probably it can by reverse engineering, but is there any easier way of doing this?
|
Quite simply put there is no easy way to make a plugin that's made for WordPress to work without WordPress. The amount of effort to convert a plugin is dependant on the complexity of the plugin and on how much it integrates with WordPress. Most plugins will make use of native WP functions, DB tables, hooks and filters. There is a lot there that you would have to consider. Either way you look at it any plugin to make it work standalone would require a lot of time coding, to be honest I just wouldn't bother. You would be better finding scripts that work standalone and do the functions you are after or build one from scratch for your needs.
|
How to Display Wordpress Plugins in Normal Website (Without Wordpress)?
|
wordpress
|
I am using the nivo slider in one of my website, the slider looks perfect in Firefox, but in IE 7, 8 its height is increased upto 1006px, the slider works, but the height has increased a lot, I have deactivated all the plugins, still its viewing the same, but in my localhost it works in IE also, but I cant differentiate the actual problem in it, here is the site http://www.marqueehireauckland.net.nz/ Can anyone help me in this? My nivo slider code is this <code> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-1.6.1.min.js"></script> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.nivo.slider.pack.js"></script> <script type="text/javascript"> jQuery(window).load(function() { jQuery('#slider').nivoSlider(); }); </script> <div style="margin-top:-75px;"> <div class="slider-wrapper theme-default"> <div class="ribbon"></div> <div id="slider" class="nivoSlider"> <img src="<?php bloginfo('template_directory'); ?>/images/header.jpg" alt="" width="1002"/> <img src="<?php bloginfo('template_directory'); ?>/images/header1.jpg" alt="" width="1002" /> <img src="<?php bloginfo('template_directory'); ?>/images/header2.jpg" alt="" width="1002"/> <img src="<?php bloginfo('template_directory'); ?>/images/header4.jpg" alt="" width="1002"/> <img src="<?php bloginfo('template_directory'); ?>/images/header5.jpg" alt="" width="1002"/> </div> </div> </div> </code> EDIT: I have fixed this. Thank you
|
After a long debugging, I found that the class <code> .nivoSlider </code> was not having a definite height, so I gave a height <code> height:288px !important; </code> and woila, it worked,
|
Jquery in IE, fully messed up
|
wordpress
|
I have a custom field. I would like to change the text of that custom field after x days. I want something like this: <code> if ( published post is more than 90 days old ) { echo "your post is more than 90 days old"; } else { echo "your post is less than 90 days old"; } </code> Can anyone help me to achieve this? Thanks.
|
You shouldn't need to use a meta field for this logic. In the loop <code> $post->post_date </code> holds when the post is published. From there you can determine if the date is 90 days old: <code> $datetime = strtotime($post->post_date); if( $datetime < ( time() - ( 60 * 60 * 24 * 90 ) ) ) { echo "> 90 days old" } else { echo "< 90 days old" } </code>
|
How to change a meta value (of a published post) after X days.?
|
wordpress
|
I want to create new sidebars, footers, etc. where I'll be able to move widgets. Can I try just try to edit the main CSS file to accomplish this or is it more complicated?
|
Linda, I actually answered a question very similar to this earlier today. See the following: stackexchange-url ("Display specific widgets in different area's around the page") It's not overly difficult, and opens up a lot of possibilities.
|
How do I customize the positioning of Wordpress widgets?
|
wordpress
|
I can get a category id or slug for my custom taxonomy just fine, but I then need to be able to get all the posts as an array for that taxonomy entry. My code is as follows: <code> $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1 ); $the_query = new WP_Query( $args ); while ( $the_query->have_posts() ) : $the_query->the_post(); endwhile; </code> When I add 'category_name'=> 'my_taxonomy_name' to the args array, it just causes the $the_query to be empty although I know that there is post in there. I have also tried changing it to 'cat'=> 22, but this also has the same fault. Can anyone help? Cheers John
|
Check out the Taxonomy Parameters . <code> <?php $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => 'taxonomy_name', 'field' => 'id', 'terms' => '22' ) ) ); $the_query = new WP_Query( $args ); while ( $the_query->have_posts() ) : $the_query->the_post(); //content endwhile; ?> </code>
|
get a list of posts from Custom Taxonomy
|
wordpress
|
I'm trying to, essentially, check whether a post exists and if it does (in published, draft or auto-draft states) return the post info. I'm finding <code> get_post() </code> doesn't seem to work with drafts, and <code> get_posts() </code> doesn't allow me to specify the specific post ID I'm looking for. Is there a function to get post info for any <code> publish_status </code> by post ID?
|
There is nothing in the codex that would suggest that <code> get_post() </code> would not work with drafts. if you experience otherwise, try <code> get_posts() </code> with the <code> include </code> or <code> post__in </code> parameter. Also see the supported type and status parameters here .
|
Is there a function to get post info for any publish_status by post ID?
|
wordpress
|
Is it possible to change the Wordpress logo and header in the Dashboard so I can customise it a little more to my business? Ideally it could be done in a way so that it wouldn't break every time I upgrade Wordpress to the latest version.
|
baritoneuk - There are several plugin which can handle the branding as well as code which removes the need for the plugin. For a plugin, I recommend White Label CMS , if you're feeling adventurous try this article from WP Beginner
|
Can I add/replace the Wordpress image in the Dashboard
|
wordpress
|
I have created some content using php, js and html which shows the bandwidth the site has used (using the cPanel API and the Google Graphs API) I want this to be shown on the dashboard in Wordpress (viewable to Admins and Editors only) How do I do this?
|
<code> <?php /* Plugin Name: Dashboard Google Page Rank Plugin URI: http://wordpress.org/extend/plugins/dashboard-google-pagerank/ Description: Shows your google pagerank in the wordpress dashboard Author: Weston Deboer Version: 1.1 Author URI: http://westondeboer.com */ function gpr_wp_dashboard_test() { include('yourfile.php'); } function gpr_wp_dashboard_setup() { wp_add_dashboard_widget( 'gpr_wp_dashboard_test', __( 'Google Page Rank' ),'gpr_wp_dashboard_test'); } add_action('wp_dashboard_setup', 'gpr_wp_dashboard_setup'); ?> </code> I have made a small modification to the above plugin. But all you should need to do is include your file which displays the data and it should show your widget in the admin dashboard.
|
How do I add content to the dashboard in Wordpress?
|
wordpress
|
I'm using the Jigoshop plugin (everything's going great so far!) and need to display the product SKU on a page, does anyone know how to do this? p.s I would ask on the Jigoshop forum but you have to pay for it.
|
In the loop-shop.php you can just add this: <code> SKU: <?php echo $_product->sku; ?> </code>
|
Display product SKU on page with Jigoshop
|
wordpress
|
I want to show products like an eCommerce store with product categories and detail pages, but I have no need for a shopping cart or checkout system. This is just to display the products for informational purposes. I have used custom post types on another project and that worked out fine, but I am wondering if anyone knows of a plugin that would make this fast and easy to customize. Also an import/export feature would be nice for adding lots of products.
|
if you have no need for regular blog posts, you can just use those. the post is probably not overly different from a custom post type for a product. though i just did a CPT for products and added some cool features. though since they were related to metaboxes and custom columns there's no reason you couldn't add them to posts, but in case you want to use your blog ever, i'd probably keep them as a separate CPT. the ecommerce plugins i've seen are usually related to setting up your shopping cart. where do you want to import from? you can always import/export your posts w/ the xml built-in import/exporter
|
How to approach displaying products with no shopping cart plugin or post type?
|
wordpress
|
Is there a way to return the comments link instead of echoing it? I've been searching the Codex for a little while now, without being able to find a function that just returns the link and doesn't echo it. Thanks.
|
Use get_comments_link() , it retrieve the link without echoing it. This is the function that is used by <code> comments_link() </code> . See also: http://codex.wordpress.org/Function_Reference/comments_link
|
Return comments_link() instead of echoing it
|
wordpress
|
I am trying to have some information specific to a taxonomy term appear above that taxonomy's archive list. Example: Taxonomy is 'Sports', with football, soccer, and baseball being terms within the 'Sports' taxonomy. I would like to have a small description of each sport display above that term's archive page. In researching this possibility, I have read the Category Templates page, found a plugin that appears to do what I want, but only with regard to Categories and not custom taxonomies. I would do it with Categories, but I have multiple taxonomies now and cannot use the simple categories solution any longer :( Am I being dense, or are custom taxonomy templates not possible?
|
Custom Taxonomy templates are entirely possible, the order of the template loading is, <code> taxonomy-{sometax}-{someterm}.php </code> - If the taxonomy were sometax, and taxonomy's slug were someterm <code> taxonomy-{sometax}.php </code> - If the taxonomy were sometax. <code> taxonomy.php </code> <code> archive.php </code> <code> index.php </code> This template hierarchy give you tons of control on how you want to alter the display of taxonomies as a whole, as a group or alone. http://codex.wordpress.org/Template_Hierarchy For example in your case you can create a template called <code> taxonomy-sports.php </code> and then customize it however you want using conditionals, template tags and functions.
|
Are Custom Taxonomy Templates Possible?
|
wordpress
|
I am looking for a solution, it can be pre-existing plugin or code I put into my functions.php file that will allow me to batch upload images to a post, and then have the ability to rearrange the positioning of them. I know Wordpress by default allows you to batch upload images, so I am presuming the solution will use that functionality. But to my knowledge it doesn't let you adjust the order of which they are attached to the post. The reason I need to be able to have the option of rearranging bulk-uploaded images, is because on the front-end, images are shown sort of like a mosaic where multiple images make up one larger image in the form of grid. The scenario : A user creates a new post. A user then clicks on a button which shows the media uploader and allows them to upload a whole bunch of images at once. The images are processed and then associated with the post. The user is then able to rearrange the order of the attached post images which will then be displayed in that particular order on the homepage in a WP post loop. Thank you in advance for your assistance.
|
The gallery tab allows you to order images by default. Click Add Image ---> Gallery You can then number the photos in the little boxes. They can then be sorted in ascending/descending/date/time/random
|
Bulk Image Upload And Rerrange Functionality
|
wordpress
|
I have a series of paypal buttons on a web page that I am trying to migrate from another site onto Wordpress. When I copy the html and paste it into the (HTML TAB) of the wordpress editor, I can see the buttons. But when I press save the code disappears...
|
Elements like these (Paypal buttons) should not be inserted as page content in the editor. Instead, put them in your Wordpress template files. I assume you are developing your own Wordpress theme but even if not, you can modify the existing one ("Twenty Eleven"). Depending on the placement of the button, you should do it in header.php, sidebar.php or footer.php in the directory of the theme.
|
Paypal buttons disappear in the text editor
|
wordpress
|
Just put up a new WP 3.2.1 install running twenty eleven, with one post "coming soon". I haven't yet begun developing the site. At my place of business, it is currently blocked by WebSense as "potentially damaging content", yet I was able to access the site yesterday. Does it appear as if my site is hacked or has spam links, or does the web filter just not like my newfound sense of freedom? :) The site is here , I can't currently check into it due to the whole web filter issue. It does look fine on my iPhone, but I can't view source. Theme : Twenty Eleven (no modifications) Plugins : Remove Double Space
|
Websense blocks based on URLs, not on site content. You can use their Site Lookup tool to have it fixed: http://www.websense.com/sitelookup/ You'll have to register with their site.
|
Site blocked by WebSense on fresh WP Install
|
wordpress
|
Sorry but I get lost on Wordpress's codex. I am trying to add a mail this page sharing link and want to include some info from the page. In pseudo code is this possible? <code> <a href="mailto:?subject=".CURRENT_BLOG_NAME." ".CURRENT_PAGE_TITLE."&amp;body="intro%20text%20".WP_PLUGIN_URL.$_SERVER['REQUEST_URI'].">Mail to a friend</a> </code> Where <code> CURRENT_BLOG_NAME </code> is ??? and <code> CURRENT_PAGE_TITLE </code> is ??? <code> WP_PLUGIN_URL.$_SERVER['REQUEST_URI'] </code> does get me the path to the current page.
|
<code> <?php $link = 'mailto:?subject='. get_bloginfo() .' '. the_title_attribute(array('echo'=>0)); $link .= '&amp;body=some text '. get_permalink(); ?> <a href="<?php echo $link ?>">mail to a friend</a> </code>
|
Get current page id, title, url, etc
|
wordpress
|
I want to add a custom link to linkedin near author name. It should be very easy if it would be only one author, but now it's not. So, I have to add something on all single.php and somewhere the real links. Can anybody help me with this? Thanks!
|
Have a look at this tutorial . It will teach you how to add a linkedin box to a user's profile and how to display that in a post.
|
Want to add a custom author link to a single.php
|
wordpress
|
I'm working on flickr Wp-widget. Here is code to fetch flickr pics. <code> class imperia_flickr extends WP_Widget { function imperia_flickr() { $widget_ops = array('description' => 'This Flickr widget populates photos from a Flickr ID.' ); parent::WP_Widget(false, __('imperia - Flickr', 'imperiathemes'),$widget_ops); } function widget($args, $instance) { extract( $args ); $id = $instance['id']; $number = $instance['number']; echo $before_widget; echo $before_title; ?> <div class="flickr-icon"></div> <?php _e('Photostream'); ?> <?php echo $after_title; ?> <script type="text/javascript"> $(document).ready(function() { $('#flickr').jflickrfeed({ limit: <?php echo $number; ?>, qstrings: { id: '<?php echo $id; ?>' }, itemTemplate: '<li><a href="{{image_b}}" rel="prettyPhoto[pp_gal]"><img class="flickr" src="{{image_s}}" alt="{{title}}" width="45" height="45"></a></li>' }, function(data) { $('#flickr a').prettyPhoto(); }); }); </script> <ul id="flickr"></ul> <div class="clear"></div> <?php echo $after_widget; } function update($new_instance, $old_instance) { return $new_instance; } function form($instance) { ****** $id = esc_attr($instance['id']); ****** $number = esc_attr($instance['number']); ?> <p> <label for="<?php echo $this->get_field_id('id'); ?>"><?php _e('Flickr ID (<a href="http://www.idgettr.com">idGettr</a>):','imperiathemes'); ?></label> <input type="text" name="<?php echo $this->get_field_name('id'); ?>" value="<?php echo $id; ?>" class="widefat" id="<?php echo $this->get_field_id('id'); ?>" /> </p> <p> <label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number:','imperiathemes'); ?></label> <select name="<?php echo $this->get_field_name('number'); ?>" class="widefat" id="<?php echo $this->get_field_id('number'); ?>"> <?php for ( $i = 1; $i <= 12; $i += 1) { ?> <option value="<?php echo $i; ?>" <?php if($number == $i){ echo "selected='selected'";} ?>><?php echo $i; ?></option> <?php } ?> </select> </p> <?php } } register_widget('imperia_flickr'); </code> This widget works fine but gives following error <code> -- Debug: Undefined index: id on line 54 of /wp-content/themes/imperia/includes/widgets/widget-imperia-flickr.php -- Debug: Undefined index: number on line 55 of /wp-content/themes/imperia/includes/widgets/widget-imperia-flickr.php </code> I have marked these lines with ** above. Where I'm going wrong ? What needs to be fixed ? Thanks
|
You should use isset <code> $id = isset( $instance['id'] ) ? esc_attr( $instance['id'] ) : ''; $number = isset( $instance['number'] ) ? esc_attr( $instance['number'] ) : ''; </code>
|
Help me out with this Undefined index ?
|
wordpress
|
I'm trying to achieve like this. See the image. Is there any good free or premium plugin available to add this feature? I know there are some plugins out there like janrain,gigya. But those plugins have limits in free version. Their fee also high. So i don't like their plugin. Any other good plugin available? Thanks
|
Try the JetPack Plugin from WordPress.com http://wordpress.org/extend/plugins/jetpack/
|
Is there any wordpress plugin available to auto share comments?
|
wordpress
|
I've installed the Jigoshop plugin to create an e-commerce site. It has several built in widgets that I want to use. Is it possible to pull out specific widgets and display them within a page template? Within Jigoshop it's specifically the cart, product search and layered nav. I don't just want to display them one under another. I want the cart in the top right of the page with the product search and nav on the left of the page so I need control of each one really.
|
You will want to create a new widget area or dynamic sidebar in your theme's code. Justin Tadlock has a great tutorial about how to do this, but the basics boil down to this. Add the widget area declaration in your theme's functions.php file: <code> <?php add_action('widgets_init', 'my_register_sidebars'); function my_register_sidebars() { /* Register the 'cartwidgets' sidebar. */ register_sidebar( array( 'id' => 'cartwidgets', 'name' => __( 'Cart Widgets' ), 'description' => __( 'A short description of the sidebar.' ), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) ); } ?> </code> Then in the appropriate files in your theme (page.php, single.php, index.php, etc.) include code similar to the following to actually show the new widget area: <code> <div id="sidebar-primary" class="sidebar"> <?php dynamic_sidebar( 'cartwidgets' ); ?> </div> </code> Those are the basics, but I would highly recommend you read Tadlock's post, as he's done a great job of explaining all of the parameters and pitfalls. Doing this, you'll be able to drag the cart's widgets into these new sidebars and they will show up, just as WordPress is designed.
|
Display specific widgets in different area's around the page
|
wordpress
|
I'm trying to implement a sliding control panel where logged in users can change background colors, fonts, etc. the point being that they should only be able to do it on their own author pages, nowhere else. So to put it simply: User logs in, goes to his author page and the slider appears from where he can customize the appearance of the said author page. I have the slider working, but how can I save the customizations for each author page, so every user can have customized author page? Usually these kind of control panel sliders are used for the whole site where admin can do the customizations for the whole site and they are saved to a cookie. This one works the same way currently, but should I save the selections to database for each user or what? All recommendations, suggestions and everything else is most welcome. Here's how the control panel works from functions.php: <code> add_action('header_top','control_panel');function control_panel(){ $admin_access = apply_filters( 'showcontrol_panel', current_user_can('switch_themes') ); if ( !$admin_access ) return; if ( get_option('show_control_panel') <> 'on' ) return; global $bg_texture_urls, $google_fonts; ?> <div id="et-control-panel"> <div id="control-panel-main"> <a id="et-control-close" href="#"></a> <div id="et-control-inner"> <h3 class="control_title">Example Colors</h3> <a href="#" class="et-control-colorpicker" id="et-control-background"></a> <div class="clear"></div> <?php $sample_colors = array( '6a8e94', '8da49c', 'b0b083', '859a7c', 'c6bea6', 'b08383', 'a4869d', 'f5f5f5', '4e4e4e', '556f6a', '6f5555', '6f6755' ); for ( $i=1; $i<=12; $i++ ) { ?> <a class="et-sample-setting" id="et-sample-color<?php echo $i; ?>" href="#" rel="<?php echo $sample_colors[$i-1]; ?>" title="#<?php echo $sample_colors[$i-1]; ?>"><span class="et-sample-overlay"></span></a> <?php } ?> <h3 class="control_title">Texture Overlays</h3> <div class="clear"></div> <?php $sample_textures = $bg_texture_urls; for ( $i=1; $i<=count($bg_texture_urls); $i++ ) { ?> <a title="<?php echo $sample_textures[$i-1]; ?>" class="et-sample-setting et-texture" id="et-sample-texture<?php echo $i; ?>" href="#" rel="bg<?php echo $i+1; ?>"><span class="et-sample-overlay"></span></a> <?php } ?> <?php $google_fonts = $google_fonts; $font_setting = 'Lobster'; $body_font_setting = 'Droid+Sans'; if ( isset( $_COOKIE['header_font'] ) ) $font_setting = $_COOKIE['header_font']; if ( isset( $_COOKIE['body_font'] ) ) $body_font_setting = $_COOKIE['body_font']; ?> <h3 class="control_title">Fonts</h3> <div class="clear"></div> <label for="control_header_font">Header <select name="control_header_font" id="control_header_font"> <?php foreach( $google_fonts as $google_font ) { ?> <?php $encoded_value = urlencode($google_font); ?> <option value="<?php echo $encoded_value; ?>" <?php selected( $font_setting, $encoded_value ); ?>><?php echo $google_font; ?></option> <?php } ?> </select> </label> <a href="#" class="et-control-colorpicker et-font-control" id="et-control-headerfont_bg"></a> <div class="clear"></div> <label for="control_body_font">Body <select name="control_body_font" id="control_body_font"> <?php foreach( $google_fonts as $google_font ) { ?> <?php $encoded_value = urlencode($google_font); ?> <option value="<?php echo $encoded_value; ?>" <?php selected( $body_font_setting, $encoded_value ); ?>><?php echo $google_font; ?></option> <?php } ?> </select> </label> <a href="#" class="et-control-colorpicker et-font-control" id="et-control-bodyfont_bg"></a> <div class="clear"></div> </div> <!-- end #et-control-inner --> </div> <!-- end #control-panel-main --> </div> <!-- end #et-control-panel --> <?php } add_action( 'template_redirect', 'load_scripts' ); function load_scripts(){ $slider_type = apply_filters( 'slider_type', get_option('slider_type') ); $template_dir = get_bloginfo('template_directory'); wp_enqueue_script('jquery_cycle', $template_dir . '/js/jquery.cycle.all.min.js', array('jquery'), '1.0', false); $admin_access = apply_filters( 'showcontrol_panel', current_user_can('switch_themes') ); if ( $admin_access && get_option('show_control_panel') == 'on' ) { wp_enqueue_script('colorpicker', $template_dir . '/js/colorpicker.js', array('jquery'), '1.0', true); wp_enqueue_script('eye', $template_dir . '/js/eye.js', array('jquery'), '1.0', true); wp_enqueue_script('cookie', $template_dir . '/js/jquery.cookie.js', array('jquery'), '1.0', true); wp_enqueue_script('control_panel', get_bloginfo('template_directory') . '/js/control_panel.js', array('jquery'), '1.0', true); } } add_action( 'wp_head', 'set_bg_properties' ); function et_bg_properties(){ global $bg_texture_urls; $bgcolor = ''; $bgcolor = ( isset( $_COOKIE['bgcolor'] ) && get_option('show_control_panel') == 'on' ) ? $_COOKIE['bgcolor'] : get_option('bgcolor'); $bgtexture_url = ''; $bgimage_url = ''; if ( get_option('bgimage') == '' ) { if ( isset( $_COOKIE['texture_url'] ) && get_option('show_control_panel') == 'on' ) $bgtexture_url = $_COOKIE['texture_url']; else { $bgtexture_url = get_option('bgtexture_url'); if ( $bgtexture_url == 'Default' ) $bgtexture_url = ''; else $bgtexture_url = get_bloginfo('template_directory') . '/images/body-bg' . ( array_search( $bgtexture_url, $bg_texture_urls )+2 ) . '.png'; } } else { $bgimage_url = get_option('bgimage'); } $style = ''; $style .= '<style type="text/css">';if ( $bgcolor <> '' ) $style .= 'body { background-color: #' . $bgcolor . '; }'; if ( $bgtexture_url <> '' ) $style .= 'body { background-image: url(' . $bgtexture_url . '); }'; if ( $bgimage_url <> '' ) $style .= 'body { background-image: url(' . $bgimage_url . '); background-position: top center; background-repeat: no-repeat; }'; $style .= '</style>'; if ( $bgcolor <> '' || $bgtexture_url <> '' || $bgimage_url <> '' ) echo $style; } add_action( 'wp_head', 'font_properties' ); function font_properties(){ $font_style = ''; $font_color = ''; $font_family = ''; $font_color_string = ''; if ( isset( $_COOKIE['header_font'] ) && get_option('show_control_panel') == 'on' ) $header_font = $_COOKIE['header_font']; else { $header_font = get_option('header_font'); if ( $header_font == 'Lobster' ) $header_font = ''; } if ( isset( $_COOKIE['header_font_color'] ) && get_option('show_control_panel') == 'on' ) $header_font_color = $_COOKIE['header_font_color']; else $header_font_color = get_option('header_font_color'); if ( $header_font <> '' || $header_font_color <> '' ) { $header_font_id = strtolower( str_replace( '+', '_', $header_font ) ); if ( $header_font <> '' ) { $font_style .= "<link id='" . $header_font_id . "' href='http://fonts.googleapis.com/css?family=" . $header_font . "' rel='stylesheet' type='text/css' />"; $font_family = "font-family: '" . str_replace( '+', ' ', $header_font ) . "', Arial, sans-serif !important; "; } if ( $header_font_color <> '' ) { $font_color_string = "color: #" . $header_font_color . " !important; "; } $font_style .= "<style type='text/css'>h1,h2,h3,h4,h5,h6 { ". $font_family . " }</style>"; $font_style .= "<style type='text/css'>h1,h2,h3,h4,h5,h6 { ". $font_color_string . " } #featured h2 a, #footer h4.widgettitle { color: #fff !important; } </style>"; echo $font_style; } $font_style = ''; $font_color = ''; $font_family = ''; $font_color_string = ''; if ( isset( $_COOKIE['body_font'] ) && get_option('show_control_panel') == 'on' ) $body_font = $_COOKIE['body_font']; else { $body_font = get_option('body_font'); if ( $body_font == 'Droid+Sans' ) $body_font = ''; } if ( isset( $_COOKIE['body_font_color'] ) && get_option('show_control_panel') == 'on' ) $body_font_color = $_COOKIE['body_font_color']; else $body_font_color = get_option('body_font_color'); if ( $body_font <> '' || $body_font_color <> '' ) { $body_font_id = strtolower( str_replace( '+', '_', $body_font ) ); if ( $body_font <> '' ) { $font_style .= "<link id='" . $body_font_id . "' href='http://fonts.googleapis.com/css?family=" . $body_font . "' rel='stylesheet' type='text/css' />"; $font_family = "font-family: '" . str_replace( '+', ' ', $body_font ) . "', Arial, sans-serif !important; "; } if ( $body_font_color <> '' ) { $font_color_string = "color: #" . $body_font_color . " !important; "; } $font_style .= "<style type='text/css'>body, .blurb h3.title, #footer h4.widgettitle, .widget h4.title { ". $font_family . " !important }</style>"; $font_style .= "<style type='text/css'>body { ". $font_color_string . " }</style>"; echo $font_style; }} ?> </code>
|
So if i understand correctly you want to let the authors style their profile and save the data in a way that every visitor will see their saved style, kind of like twitter lets you style your own author page. If so then using cookies won't help you here since cookies are user specific and not saved on your server or in the database do you won't be able to generate the style the author has picked anywhere but on that authors browser. What you should do is save all of the style data as an array in the usermeta table using <code> add_user_meta() </code> or <code> update_user_meta() </code> and then on your author page call that array of data using <code> get_user_meta </code> and generate the style the user has picked for his author page.
|
Authors to be able to customize their author pages?
|
wordpress
|
I been looking around for this, but couldn't find a way. The scenario is: I have a custom post type 'Company', and I'm creating Company type posts through my plugin's code. When I create a new Company post, I set the author as Admin. Now further down the code, I'm creating a custom role 'Representative' and assigning users to this role through my code again. What I want to do is, assign a Representative to a Company Post as an author. But I can't even see this user(Rep.) in the dropdown for switching authors. Is there any argument that I need to pass to wp_insert_user or register_post_type or add_role/add_cap for achieving this? Thanks in advance!
|
I'm reposting this with an example, I really don't get the code formatting of this editor, last time I was so irritated with it that I skipped the code! That dropdown is populated using a filter 'wp_dropdown_users' (user.php, line 976). This filter returns the dropdown (html select) as a string. You can intercept this string, and add your own options, which is the list of users with the custom role. Inspect the select with Firebug, the option value is the user id, and text is the login name for that user. <code> <?php add_filter('wp_dropdown_users', 'test'); function test($output) { global $post; //Doing it only for the custom post type if($post->post_type == 'my_custom_post') { $users = get_users(array('role'=>'my_custom_role')); //We're forming a new select with our values, you can add an option //with value 1, and text as 'admin' if you want the admin to be listed as well, //optionally you can use a simple string replace trick to insert your options, //if you don't want to override the defaults $output .= "<select id='post_author_override' name='post_author_override' class=''>"; foreach($users as $user) { $output .= "<option value='".$user->id."'>".$user->user_login."</option>"; } $output .= "</select>"; } return $output; } ?> </code> That's it! You'll have the dropdown listing your custom roles. Try changing the post author, it gets updated neatly. It's a hack, but it worked for me!
|
Assign a Custom Role to a Custom Post?
|
wordpress
|
I want my plugin to be installed on each blog and create database tables per blog. I have this code: <code> register_activation_hook( __FILE__, 'install1' ); function install1() { global $wpdb; if (function_exists('is_multisite') && is_multisite()) { // check if it is a network activation - if so, run the activation function for each blog id if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) { $old_blog = $wpdb->blogid; // Get all blog ids $blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs")); foreach ($blogids as $blog_id) { switch_to_blog($blog_id); _install2(); } switch_to_blog($old_blog); return; } } _install2(); } function _install2() { require_once WP_PLUGIN_DIR . '/pluginfolder/functions/database.php'; require_once WP_PLUGIN_DIR . '/pluginfolder/functions/general.php'; $db_error = false; $sql_file = WP_PLUGIN_DIR . '/pluginfolder/ossq.sql'; os_db_connect(DB_HOST, DB_USER, DB_PASSWORD); os_set_time_limit(0); os_db_install(DB_NAME, $sql_file); if ($db_error != false) { // echo 'instalation successfull'; } else { } </code> The code is inspired on this blog post [http://shibashake.com/wordpress-theme/write-a-plugin-for-wordpress-multi-site] The SQL File consist of: <code> DROP TABLE IF EXISTS address_book; CREATE TABLE address_book ( address_book_id int NOT NULL auto_increment, customers_id int NOT NULL, entry_gender char(1), entry_company varchar(255), entry_firstname varchar(255) NOT NULL, entry_lastname varchar(255) NOT NULL, entry_street_address varchar(255) NOT NULL, entry_suburb varchar(255), entry_postcode varchar(255) NOT NULL, entry_city varchar(255) NOT NULL, entry_state varchar(255), entry_country_id int DEFAULT '0' NOT NULL, entry_zone_id int DEFAULT '0' NOT NULL, PRIMARY KEY (address_book_id), KEY idx_address_book_customers_id (customers_id) ); </code> However, Its not working, the plugin does create tables just like on a regular wordpress but not on each blog on the multisite environment. Please help!
|
The Proper Network Activation meta-plugin was written precisely for cases like this.
|
Making my plugin multi-site compatible
|
wordpress
|
I have a post with a custom meta value which is populated via a jQuery datepicker and it gets stored in the following format: yyyy/mm/dd - is there a way I can group all posts from the same day together easily? I'm not using Wordpress's publish date, as I need to have future posts published. I know using the function 'the_date()' will by default in Wordpress only show the date once per x amount of posts, giving the appearance they're grouped. Is there anything that does something similar with a custom meta date value?
|
The only built in way ( using a function) is to use <code> WP Query </code> and the custom field parameters, specifically <code> meta_query </code> and <code> compare </code> . http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters An example to get you started: <code> $query = new WP_Query( array( 'meta_key' => 'your_date', 'meta_compare' => '=' ) ); </code> Alternatively, the custom field functions in Wordpress do not have many parameters, they are basically for adding and retrieving data, which you can then use with native PHP, for instance you can return the custom field as an array using something like: <code> $meta_date_array = get_post_meta($post_id, $key, false); ksort($meta_date_array); </code> and use PHP's <code> ksort </code> to sort the order.
|
Group Posts By Custom Meta Value: Date
|
wordpress
|
I've enabled the custom header image panel for my theme.. That all works fine, but it has a predetermined height. How can i make it dynamic? The width can be permanent. I used this code. http://www.wpbeginner.com/wp-themes/how-to-enable-custom-header-images-panel-in-wordpress-3-0/ <code> define( 'HEADER_IMAGE_WIDTH', apply_filters( 'yourtheme_header_image_width', 940 ) ); define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'yourtheme_header_image_height', 198 ) ); set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); </code>
|
Since you are using <code> apply_filters </code> you can use <code> yourtheme_header_image_height </code> filter hook to change the height: <code> add_filter('yourtheme_header_image_height','dynamic_height'); function dynamic_height($height){ $custom_height = get_option('dynamic_header_height'); return $custom_height; } </code>
|
Dynamic height in custom header image panel
|
wordpress
|
What I want to do is to create a simple front-end post submit form, for every different type of post I will include in my Wordpress app. For example there will be articles, events, quick messages and those types will have a different design/structure for a user to see. Author will use those forms to post their content. As far as I know, I can have a different template for those types with the <code> if in category </code> function but I am interested in alternative solutions (maybe better). I know that there is <code> page_template </code> to add in the array http://wpengineer.com/1229/puplishing-extend-of-wordpress/ but is there anything else? Also I am having some difficulties to redirect or even echo the posted link (as below). For your concern, I can not echo the <code> $link </code> . Thank you for your help. <code> if(isset($_POST['submit'])){ global $user_ID; $new_post = array( 'post_title' => $_POST['post_title'], 'post_content' => $_POST['post'], 'post_status' => 'publish', 'post_date' => date('Y-m-d H:i:s'), 'post_author' => $user_ID, 'post_type' => 'post', 'post_category' => array(0) ); wp_insert_post($new_post); } </code> I tried this for redirect without luck <code> $pid = wp_insert_post($new_post); $link = get_permalink( $pid ); echo $link; wp_redirect( $link ); </code>
|
you need to get the ID from <code> wp_insert_post </code> and make sure you <code> exit </code> or <code> die </code> so: <code> $pid = wp_insert_post($new_post); wp_redirect( get_permalink( $pid ); die(); </code> As for the second part you can use the WordPress Template Hierarchy and simply name each one of your custom post type designs as <code> single-{post_type}.php </code> for example if your post type is named event then name that file <code> single-event.php </code> and WordPress will know to use that file for displaying all posts of event type.
|
How can I correctly redirect user to the submitted post and define a template for each new post in Wordpress?
|
wordpress
|
I have a plugin that I know I never want to update. I am aware that this is NOT best practice, but in this case it must be done. Is there any way to stop WordPress from prompting me to auto-update a particular plugin (but still alert as normal for all other plugins).
|
T31os's answer was right: Increase the version number inside the plugin's main file.. eg. 99.9 ... and also make that same change inside the readme file for good measure(though i don't think that's actually required).. – t31os
|
Turn Off Auto Update for Single Plugin
|
wordpress
|
In a stackexchange-url ("previous question") I asked (and later worked out) how to style sub menus, I want to expand on that with another question related to styling sub-menus. I have hit an issue were if the parent is the selected page all child pages pick up the same styling, I believe this is because the <code> current-menu-item </code> class gets added to the parent li. If a child element is selected only the child is highlighted (which is correct) Has anyone encountered this before? What is the best way to only have the selected page highlighted and not the child elements of that page? As requested, here is the CSS that is being called to highlight the child menu. <code> .current-page a, .current-menu-item a { background-color: #EE8833; } </code>
|
You can try using the .current-menu-item li a"first-child selector. Here is an example I've used in the past to highlight the current menu item only: <code> #menu .current-menu-item { background:white; } #menu .current-menu-item li a:first-child { color:white!important; } #menu .current-menu-item a { color:black !important ; } </code> You will need to change the #menu to your id or class.
|
Styling issue with custom menus and sub menus
|
wordpress
|
I have a custom menu created using Appearance > Menus which contains top level and child pages. I would like to be able to indent my child level pages to give some sort of visual hierarchy to the content. What is the best way to achieve this?
|
Some digging around led me to find that all the items were marked up with the class <code> sub-menu </code> which I was able to style in the CSS.
|
Styling child custom menu pages
|
wordpress
|
Does anyone know how to display the latest Foursquare checkin for a specific account on a WordPress blog? Ideally I would like to add the function to the theme rather than use a plugin but i'm open to suggestions. Thanks in advance, G
|
Here is a solution for you: First download this nice little class Next, include it and “login” <code> <?php require_once 'foursquare.php'; //Load the foursquare class $foursquare = new fourSquare("username", "password"); //login </code> Then to get the venue’s name use: <code> <?php echo $foursquare->venueName; ?> </code> you can also get the venue's type,venue's icon, venue's location on the map and user’s comment on the venue. its all documented at the link provided above. Update: Since FourSquare changed their API i found a much simpler solution: login to your foursquare account and then head to http://feeds.foursquare.com/ and copy the rss feed url. and use this: <code> // $numCheckins - number of checkins to get function Display_last_checkins($numCheckins = 2){ $feedURL = 'enter your rss feed here'; $feedObject = simplexml_load_file($feedURL . '?count=' .$numCheckins); $items = $feedObject->channel; $checkin = $items->item; echo '<ul>'; $count = 0; foreach ($checkin as $item) { if ($item->link != '') { echo '<li><a href="'. $item->link .'">' . $item->title . '</a><br/></li>'; /* you can use $item->description - user comment $item->pubDate - publish date and time (Wed, 27 Apr 11 16:40:18 +0000) $item->georss:point - location for map (31.613221 34.76874) */ $count++; if ($count == $numCheckins) {break;} } } $echo .= '</ul>'; } </code>
|
Latest Foursquare Checkin function
|
wordpress
|
For security reasons I don't want it to be obvious that I use Word Press. I use the W3 Total Cache plugin and minify HTML, CSS and JS. I may also use a CDN. Is it possible to modify the W3 Total Cache plugin so that it can rewrite the Wordpress directories "wp-content", "wp-admin" and "wp-includes" without actually renaming these directories? I'd ideally like to be able to rewrite W3 Total Cache directories such as "w3tc"
|
This was covered extensively in stackexchange-url ("Steps to Take to Hide the Fact a Site is Using WordPress"). The answer in that question covered renaming the wp-content and the plugin directory. If you prefer rewriting those directories you can use these functions found in the Roots WordPress theme to rewrite the directories relative to your sites root directory. <code> <?php if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) { function roots_htaccess_writable() { if (!is_writable(get_home_path() . '.htaccess')) { add_action('admin_notices', create_function('', "echo '<div class=\"error\"><p>" . sprintf(__('Please make sure your <a href="%s">.htaccess</a> file is writeable ', 'roots'), admin_url('options-permalink.php')) . "</p></div>';")); }; } add_action('admin_init', 'roots_htaccess_writable'); // Rewrites DO NOT happen for child themes // rewrite /wp-content/themes/roots/css/ to /css/ // rewrite /wp-content/themes/roots/js/ to /js/ // rewrite /wp-content/themes/roots/img/ to /js/ // rewrite /wp-content/plugins/ to /plugins/ function roots_flush_rewrites() { global $wp_rewrite; $wp_rewrite->flush_rules(); } function roots_add_rewrites($content) { $theme_name = next(explode('/themes/', get_stylesheet_directory())); global $wp_rewrite; $roots_new_non_wp_rules = array( 'css/(.*)' => 'wp-content/themes/'. $theme_name . '/css/$1', 'js/(.*)' => 'wp-content/themes/'. $theme_name . '/js/$1', 'img/(.*)' => 'wp-content/themes/'. $theme_name . '/img/$1', 'plugins/(.*)' => 'wp-content/plugins/$1' ); $wp_rewrite->non_wp_rules += $roots_new_non_wp_rules; } add_action('admin_init', 'roots_flush_rewrites'); function roots_clean_assets($content) { $theme_name = next(explode('/themes/', $content)); $current_path = '/wp-content/themes/' . $theme_name; $new_path = ''; $content = str_replace($current_path, $new_path, $content); return $content; } function roots_clean_plugins($content) { $current_path = '/wp-content/plugins'; $new_path = '/plugins'; $content = str_replace($current_path, $new_path, $content); return $content; } // only use clean urls if the theme isn't a child or an MU (Network) install if (!is_multisite() && !is_child_theme()) { add_action('generate_rewrite_rules', 'roots_add_rewrites'); if (!is_admin()) { add_filter('plugins_url', 'roots_clean_plugins'); add_filter('bloginfo', 'roots_clean_assets'); add_filter('stylesheet_directory_uri', 'roots_clean_assets'); add_filter('template_directory_uri', 'roots_clean_assets'); } } function roots_add_h5bp_htaccess($rules) { global $wp_filesystem; if (!defined('FS_METHOD')) define('FS_METHOD', 'direct'); if (is_null($wp_filesystem)) WP_Filesystem(array(), ABSPATH); if (!defined('WP_CONTENT_DIR')) define('WP_CONTENT_DIR', ABSPATH . 'wp-content'); $theme_name = next(explode('/themes/', get_template_directory())); $filename = WP_CONTENT_DIR . '/themes/' . $theme_name . '/inc/h5bp-htaccess'; $rules .= $wp_filesystem->get_contents($filename); return $rules; } add_action('mod_rewrite_rules', 'roots_add_h5bp_htaccess'); } ?> </code> You will also need to make sure and remove the W3 Total Cache X-Powered-by headers . <code> <IfModule mod_headers.c> Header set X-Powered-By "W3 Total Cache/0.9.2.3" </IfModule> </code> If your going to use a CDN W3 Total Cache will use the same path structure: <code> wp-content/w3tc/min/xxxxx/default.include.xxxx.css </code> So you will either need to rewrite these using .htaccess on the CDN if you have access or not use minify.
|
How can I hide that I Use Wordpress (with W3 Total Cache)
|
wordpress
|
I figured out with my jquery slider. Need to help (: my query is: <code> <?php $the_query = new WP_Query('showposts=10&orderby=post_date&order=desc'); while ($the_query->have_posts()) : $the_query->the_post(); ?> <?php $imaj = get_post_meta($post->ID, 'manset', true); ?> <?php the_permalink()?> <img src="<?php echo $imaj; ?>" alt="" /> <?php endwhile;?> <?php wp_reset_query(); ?> </code> with this query, the query print all posts. But i would like to display just if the post has "manset" custom field in it. how can i do that ( sorry about my bad english )
|
A quick google search would have directed you to this page: http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
|
query with custom field
|
wordpress
|
I am using the latest version of WordPress with the Twenty Ten theme. How can I add thumbnails to each of my posts? A step-by-step guide would be helpful in this regard.
|
FWIW, as a workaround, Twenty Eleven has this built in.
|
How to add thumbnails to posts?
|
wordpress
|
My site is using WooThemes Statua theme . I'm trying to get my resized slider images to link to their respective full size images (or attachment pages). I asked a similar question on the WooThemes support forums (members login required) and the code they provided links the images to the resized 960px Large image size instead of the Full size images. Here's an example page on my site, using the single.php template, and its code . How can I get the slider images to link to the full size originals or attachment pages?
|
<code> $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full" ); echo '<a href="' . $image[0] . '">Link to Full Size</a>'; </code>
|
Link to full size image or attachment page in photo theme
|
wordpress
|
Sorry if this is a really silly question, but I am very new to Word Press. My question is, can one plugin update the settings of another Wordpress plugin? I suppose this might depend on the plugin and where it stores its settings. I don't know if plugins store their settings in static files or in the database.
|
Simple Answer would be yes. It really depends on the plugin. A good plugin will take use of the many API's that Wordpress has set up for development, such as the settings API. Most plugins will probably store their settings using get_option . A good place to start will be the Wordpress Codex
|
Can Wordpress plugins "Talk to each other"?
|
wordpress
|
I have a web site that I am working on, hendersonvillecameraclub.org. When I use Google to search for the site using 'hendersonville camera club' as the search terms my site is the 6th result. Below the page title, it gives a snippet of the most recent post on the site. My question is, how do I change what information is displayed in the summary? I would prefer to put some static text there that provides a better description of the site. This site is hosted by GoDaddy, not sure if that's relevant information. Thanks!
|
Try an SEO or meta tag plugin that will give you the most options to work with meta for the home page, for post pages, static pages, etc. It's not enough to simply add one metatag to the header template. http://wordpress.org/extend/plugins/search.php?q=SEO&sort=
|
How do I change the web site summary in search results?
|
wordpress
|
I'm using a slightly modified copy of the Multi Site User Management plugin to keeps users synced across a multisite network, but have one problem with it. When a user's role is updated on the main site, the role is NOT updated on the sub site. In order for everything to work correctly, user roles must stay in sync. I've been looking without success, so is there an action that runs when a user is updated? I know about the profile_update and wp_update_user functions / hooks, but neither of these work because the user role is updated via an external function. So I need a new way of always syncing user roles. Any ideas?
|
I've found a way around the problem. It's not a "fix", but rather a way to get around the problem of needing synchronized user roles. Instead of trying to make all user roles match up, I decided to only check the user roles for the main site. see my function below for how I did it: <code> /* * Function to check a specified user from a subsite against * the role of that same user on the main site * * @param int $site_to_check the id of the site to check the user's role from * @param int $user_id the user's id to check */ function cgc_check_for_citizen($site_to_check = 1, $user_id = null) { if(!isset($user_id)) { return false; } $citizen = false; global $blog_id; if($blog_id == 1) { // we're on the main site if(user_can($user_id, 'read_citizen')) { $citizen = true; } } else { switch_to_blog($site_to_check); if(user_can($user_id, 'read_citizen')) { $citizen = true; } restore_current_blog(); } return $citizen; } </code>
|
Update User Role Across Network when Main Site User is Updated
|
wordpress
|
The dropdown menu that Thesis creates is 99% fine, except that it's very unforgiving to users that don't master the use of mouse very easily - old people and people with average to bad vision. I would like to improve its usability using a bit of javascript, allowing the mouse to be a few pixels offside and still keep the submenu open. I tried this in my custom javascript file: <code> var hoverConfig = { over: function(e){ e.preventDefault(); $.log("launch menu"); $('.sub-menu',$(this)).show(); }, timeout: 500, // number = milliseconds delay before onMouseOut out: function(e){ e.preventDefault(); $.log("hide menu"); $('.sub-menu',$(this)).hide(); } }; $('.sub-menu').hide(); $("#menu-main-menu").hoverIntent( hoverConfig ); </code> Firebug logging shows that it works - the show and hide functions are called, but the CSS behaviour still triggers and i don't manage to cancel it so that the javascript behaviour takes the full control. Any idea how i can do that?
|
In fact it works; i just didn't bind the behaviour to the right element. It should be bound to the #mainmenu> li and then it works. Dumb me!
|
Improving the Thesis built-in dropdown menu via javascript
|
wordpress
|
Imagine that a person has a few premium themes that they use for clients. In those premium themes are many different options that can be set. Is it possible to set the theme's options to the most common and preferred choices and then export those options for later importation into other fresh WordPress installs with the same theme? That way one is not merely pointing and clicking their way through the various options over and over again for each new install.
|
The answer is theme depended and since most premium themes have their own framework/options panels then its going to be hard to tell where are the options are saved but in most cases they are saved in the options table in the database. So the tricky part is to know what are the options names. You can look for them in the themes code either by searching for <code> add_option </code> , <code> update_option </code> and <code> register_settings </code> .
|
Where are a theme's options stored and can I export them to be imported into freshly installed themes?
|
wordpress
|
I am trying to create a custom post type with custom metabox array. How can I create this kind a automatic populating post type? I think I have to use two dimension array. But how can I automatically populate my data array? And how can I save this kind array. Could some one point me to right direction? Please take a look at the images. Second img My code so far : <code> <?php //add custom field - price add_action("admin_init", "price"); function object_init(){ add_meta_box("price_meta", "Price fields :", "object", "price_meta", "normal", "low"); } function price_meta(){ global $post; $custom = get_post_custom($post->ID); $price = $custom["price"][0]; ?> <p style="float:left;"><label>Nr :</label><br /> <input type="text" name="priceNr" size="10" value="<?php echo $price; ?>"/> </p> <p style="float:left;"><label>Description :</label><br /> <input type="text" name="priceD" size="50" value="<?php echo $price; ?>"/> </p> <p style="float:left;"><label>Price :</label><br /> <input type="text" name="price" size="20" value="<?php echo $price; ?>"/> </p> <?php } //Save product price add_action('save_post', 'save_detailss'); function save_detailss(){ global $post; $post_id = $post->ID; // to prevent metadata or custom fields from disappearing... if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; update_post_meta($post_id, "price", $_POST["price"]); } ?> </code>
|
Your code make no sense, anyway here is a nice way to do it and you get: <code> function Print_price_fileds($cnt, $p = null) { if ($p === null){ $a = $b = $c = ''; }else{ $a = $p['n']; $b = $p['d']; $c = $p['p']; } return <<<HTML <li> <label>Nr :</label> <input type="text" name="price_data[$cnt][n]" size="10" value="$a"/> <label>Description :</label> <input type="text" name="price_data[$cnt][d]" size="50" value="$b"/> <label>Price :</label> <input type="text" name="price_data[$cnt][p]" size="20" value="$c"/> <span class="remove">Remove</span> </li> HTML ; } //add custom field - price add_action("add_meta_boxes", "object_init"); function object_init(){ add_meta_box("price_meta_id", "Price fields :","price_meta", "post", "normal", "low"); } function price_meta(){ global $post; $data = get_post_meta($post->ID,"price_data",true); echo '<div>'; echo '<ul id="price_items">'; $c = 0; if (count($data) > 0){ foreach((array)$data as $p ){ if (isset($p['p']) || isset($p['d'])|| isset($p['n'])){ echo Print_price_fileds($c,$p); $c = $c +1; } } } echo '</ul>'; ?> <span id="here"></span> <span class="add"><?php echo __('Add Price Data'); ?></span> <script> var $ =jQuery.noConflict(); $(document).ready(function() { var count = <?php echo $c - 1; ?>; // substract 1 from $c $(".add").click(function() { count = count + 1; //$('#price_items').append('<li><label>Nr :</label><input type="text" name="price_data[' + count + '][n]" size="10" value=""/><label>Description :</label><input type="text" name="price_data[' + count + '][d]" size="50" value=""/><label>Price :</label><input type="text" name="price_data[' + count + '][p]" size="20" value=""/><span class="remove">Remove</span></li>'); $('#price_items').append('<? echo implode('',explode("\n",Print_price_fileds('count'))); ?>'.replace(/count/g, count)); return false; }); $(".remove").live('click', function() { $(this).parent().remove(); }); }); </script> <style>#price_items {list-style: none;}</style> <?php echo '</div>'; } //Save product price add_action('save_post', 'save_detailss'); function save_detailss($post_id){ global $post; // to prevent metadata or custom fields from disappearing... if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; // OK, we're authenticated: we need to find and save the data if (isset($_POST['price_data'])){ $data = $_POST['price_data']; update_post_meta($post_id,'price_data',$data); }else{ delete_post_meta($post_id,'price_data'); } } </code> I keep getting people asking me how to get the data to print in the fronend so: <code> $data = get_post_meta($post->ID,"price_data",true); echo '<ul>'; if (count($data) > 0){ foreach((array)$data as $p ){ if (isset($p['p']) || isset($p['d'])|| isset($p['n'])){ echo '<li>Number: '.$p['n'].' Description: '.$p['d'].' Price: '.$p['p'].'</li>'; } } } echo '</ul>'; </code>
|
Custom post type metabox array
|
wordpress
|
I'm working on a project that will require two separate galleries to be displayed on the same post. One gallery is specific to the product and the other is professional generic shots. The content of both galleries will change with every post. I need to figure out how to show two separate galleries on a post and repeat this process daily. The only way that I can think of is to store images in another post (post-b) and insert post-b using either @MikeSchinkel's or @Scribu's post to post connector. What would you do?
|
If possibile, use NextGen Gallery plugin, to manage the gallery, and with the help of custom fields, manage it in the post You can create two custom fields, like: first_gallery second_gallery and fill it with the nextgen gallery ID. You can do a custom metabox with a select box, if you want. The in the frontend code, use <code> $first = get_post_meta($post->ID, 'first_gallery',true); $second = get_post_meta($post->ID, 'second_gallery',true); ... echo do_shortcode('[nggallery id='.$first.']'); echo do_shortcode('[nggallery id='.$second.']'); ... </code> Hope this it helps. Bonus : there are many nextgen gallery plugins that let you change how the gallery is rendered to the user.
|
Ways to show multiple, separate galleries per post?
|
wordpress
|
Are there any possible plugins that could clone an entire Wordpress site and install it in another location? I build sites on one url, then to show the client and move it to another url to show it. At the moment copying the files and database and re-uploading everything and changing urls is a bit of a nightmare! UPDATE: I want them to run off two different databases.
|
http://wordpress.org/extend/plugins/duplicator/ I tried duplicator and it worked out great. A 25min process condensed down into 5mins, really simple to use and has now worked several times for several sites, great plugin!!
|
Plugins to clone wordpress site and move to another url
|
wordpress
|
I am following this page on designing options menus: http://codex.wordpress.org/Administration_Menus What is the significance of the menu_slug ? I ask because when I change this value, the options page changes to You do not have sufficient permissions to access this page. If I change it back to what it was, it's fine. ---EDIT---15/8/2011 This is the code I was changing: <code> function highlighter_menu_() { add_options_page('Highlighter pen options', 'Highlighter Pen', 'manage_options', 'my-unique-identifier', 'highlighter_plugin_options'); } </code> and changed it to <code> function highlighter_menu_() { add_options_page('Highlighter pen options', 'Highlighter Pen', 'manage_options', 'a-unique-identifier', 'highlighter_plugin_options'); } </code>
|
I have found the issue. I was making changes to the plug-in code and transferring it directly (via ftp). I forgot to deactivate and activate the plug-in. Doh!
|
Menu_slug used for creating options page
|
wordpress
|
I created a category-list to show them in a way, my accordion can use. (Custom in the sidebar) I want to add a class named "current" for the currently viewed post and the viewed category should be opened. Do you have any ideas to integrate this in the code? It was hard work to get this to work and now I dont know how to integrate it... Link: http://www.davidgoltz.de/2011/anna-bederke-actor/ (after you click "Portfolio", the menu appears and should show the opened tree with a highlighted post. Here is the code: <code> <div id="category-list"> <ul class="topnav"> <?php $kategorien = get_categories(array( 'child_of' => 0, 'exclude_tree' => 15, 'exclude' => 16, 'orderby' => 'slug', 'order' => 'ASC')); foreach($kategorien as $kategorie) { echo '<li><a href="#" class="category-title">'; echo ($kategorie->name); echo '</a>'; echo '<ul>'; $cat = $kategorie->cat_ID; $posts = get_posts('category='. $cat .'&posts_per_page=-1'); foreach($posts as $post) { ?> <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <li> <? } echo '</ul>'; echo '</li>'; } ?> </ul> </div> </code>
|
Try this: <code> <div id="category-list"> <ul class="topnav"> <?php if (is_single()){ global $post; $pid = $post->ID; $post_categories = wp_get_post_categories( $post->ID ); $cats = array(); foreach($post_categories as $c){ $cat = get_category( $c ); $cats[] = $cat->ID; } $active_cat_count = true; $cat_count = 0; } $kategorien = get_categories(array( 'child_of' => 0, 'exclude_tree' => 15, 'exclude' => 16, 'orderby' => 'slug', 'order' => 'ASC')); foreach($kategorien as $kategorie) { if (isset($active_cat_count) && $active_cat_count){ if (in_array($kategorie->ID,$cats){ $active_cat_count = false; }else{ $cat_count = $cat_count + 1; } } echo '<li><a href="#" class="category-title">'; echo ($kategorie->name); echo '</a>'; echo '<ul>'; $cat = $kategorie->cat_ID; $posts = get_posts('category='. $cat .'&posts_per_page=-1'); foreach($posts as $post) { ?> <li> <a <?php if ($post->ID == $pid){echo 'class="current"';} ?> href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <li> <? } echo '</ul>'; echo '</li>'; } ?> </ul> </div> <?php if (is_single()){ ?> <script> jQuery(document).ready(function(){ $( ".topnav" ).accordion( "option", "active", <?php echo $cat_count; ?> ); }); </script> <?php } </code>
|
Show category-ID in custom category-list
|
wordpress
|
I'm running a multisite. I would like to display "Terms and conditions" when user trying to create a new post. Users should Click "I agree" link and then proceed to create a new post(wp-admin/post-new.php). Is there any good plugin available for this? Or can anyone give me some snippets? Looking forward to it. Thanks
|
Yes there is: Terms Of Use plugin . Also able to add the checkbox to signup pages, works with Formidable forms plugin and enables you to add the checkbox before viewing a (front- or backend) page.
|
How to display terms and conditions in post area?
|
wordpress
|
What's the most efficient way - concerning the database - to add and query extra usermeta fields to a profile? I need to add four additional fields of numeric and text data to a user profile and then query that to compile the data for display in a template. And there are potentially thousands of users. There are lots of examples to store the data in usermeta. But should this amount of data be stored in the usermeta table? Or should I store it all in a new database table? And if so, how do I initialize a new table and then write to it?
|
There are lots of examples to store the data in usermeta. But should this amount of data be stored in the usermeta table? I don't see any reason why you should not use the default user meta data table, after-all that is what it is for, regardless of the amount of users/fields. The user meta function , such as <code> get user meta </code> uses <code> get_metadata </code> with the <code> $meta_type </code> object set to user. http://codex.wordpress.org/Function_Reference/get_metadata If you want to mess around with new tables you can use the <code> $wpdb </code> class and create a new one, this post covers how, http://codex.wordpress.org/Creating_Tables_with_Plugins . There is also a plugin called Pods CMS that allows for the creation of custom database tables for content types, but unless you have a specific reason for doing so, just use the built in user meta tables.
|
What's the most efficient database method to add and query usermeta?
|
wordpress
|
The following words are reserved for use by WordPress functions and cannot be used as blog names: page, comments, blog, files, feed This is the error message that I'm getting. I wanted to use /blog as a sub-site in the network. What I require is that my site has the following structure: <code> Home (only contains links to the other parts) Part 1 Part 2 Blog </code> Would using permalinks solve my problem? I want all my blogs to appear in only the 'Blog' part of the site and nowhere else. Another follow-up query is that, since I'm working on this site on my localhost, I'm using sub-folders. But when I eventually transfer the site on a web host, I want to use sub-domains. I'm mentioning this as I fear that any solution to the above problem can influence this.
|
http://codex.wordpress.org/Create_A_Network#Permalinks /blog cannot be used as a new site name. It is relied on heavily by WP for the main site. Everything added to it automatically has /blog as part of the permalink from my understanding You can check out this discussion http://wordpress.org/support/topic/root-directory-blog-for-wordpress-30-main-multisite to see if it helps you out, gives some further options. The main issue with the /blog is to prevent collisions. I'm not sure of the repercussions of not using it, when using subdomains I'm not sure if you can easily switch from subfolders to subdomains..... I would think that would cause some issues. I think when you transfer over, the existing subsites are not switched.... so if you set it up one way, and try to change, there may be some headaches
|
Not being allowed to use some terms in Add New Site in Wordpress
|
wordpress
|
My theme registers custom menus with this function: <code> function nav_menus() { if ( function_exists( 'register_nav_menus' ) ) { register_nav_menus( array('main-menu' => __( 'Main Menu' ), 'sub-menu' => __( 'Sub Menu' )) ); } } </code> I need to place code into my sidebar, that checks to see if the "main-menu" is active - for example, has a menu assigned to the "Main Menu" theme location. Anyone know how to test for this?
|
You can use the function <code> has_nav_menu('main-menu') </code> . See the WordPress Codex here.
|
How to determine if custom menu is active?
|
wordpress
|
I have a landscaping09 theme. This is what I want: A theme options page with the following options: -> Theme color background change (with colorpicker) or url of the image -> General Navbar color background change (with colorpicker) or url of the image -> Header color background change (with colorpicker) or url of the image -> Set up header height -> Navbar color background change (with colorpicker) or url of the image -> Navbar hover color background change (with colorpicker) or url of the image -> Footer color background change (with colorpicker) or url of the image -> additional css code box please let me know how to do it or any plugin will do these things? please help me.
|
Your not going to get an answer to this, there is no magic wand you can use to change what your asking without working it out yourself, or at the very least supplying some actual code with your question. To change the CSS in a back-end option page you can use the Options API, http://codex.wordpress.org/Options_API , or write a custom CSS file and include it in your header. As Mark already mentioned there is a color picker that comes with WordPress that you can use to fill in your custom field options with color values.
|
How to add Color Picker in Theme Options for the following?
|
wordpress
|
I'm guessing this is a really dumb question, but I'm far more familiar with PHP/WordPress and I'm just getting started with jQuery so I'm not even sure what to search on. Is there a way to pass the output of <code> echo get_blogifo('siteurl') </code> To jQuery? I'm trying to get this to work: <code> $('a.getstarted').attr('href', '<?php echo get_bloginfo('siteurl'); ?>/payroll-deduction-authorization/?plan=basic'); </code> Thanks in advance for your help!
|
Use wp_localize_script() to pass variables to the front end so that you can pick them by javascript. Use it like this: <code> wp_enqueue_script( 'some_handle' ); $data = array( 'some_string' => __( 'Some string to translate' ) ); wp_localize_script( 'some_handle', 'object_name', $data ); </code> And pick it up like <code> object_name.some_string </code> in javascript code.
|
How do I pass WordPress's get_bloginfo('siteurl') to Jquery?
|
wordpress
|
I've been hunting around for a day for this answer and thought I should turn to StackExchange in the hopes someone has an aswer. My goal is to display X images (for example, 4) in the sidebar of this one template, but I'd like it to be dynamic and either pull 4 random images, or the first or last 4 images in the gallery. I'm currently using this code below to manually pull 4 images, but can someone provide code to be a bit more clever about it? <code> <?php echo do_shortcode('[gallery include="317,309,325" columns="1" link="file"]'); ?> </code>
|
Sounds like you need a custom query in order to pull X amount of images. You could do the following (untested): <code> <?php function custom_gallery_display( $number_of_images = 4 ) { //make sure you have access to the WPDB object global $wpdb; //pull 4 random attachments $images = $wpdb->get_results("SELECT ID from wp_posts WHERE post_type = 'attachment' ORDER BY RAND() LIMIT $number_of_images"); //may need to tweak this; //not sure what format the results are returned $image_ids = implode( ',', $images ); //now print with random images echo do_shortcode('[gallery include="' . $image_ids . '" columns="1" link="file"]'); return; } ?> </code> That should do the trick, although it may need a bit of tweaking. You should also check out the documentation http://codex.wordpress.org/Gallery_Shortcode According to it, you can easily create the randomized order by setting the orderby attribute to RAND <code> <?php echo do_shortcode('[gallery include="317,309,325" columns="1" orderby="RAND" link="file"]'); ?> </code> However, if you are forced to use a custom query in order to use X amount of images, you may as well just randomize it at that point, as I did above in the query.
|
Display X images from a gallery in the sidebar
|
wordpress
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.