question
stringlengths 0
34.8k
| answer
stringlengths 0
28.3k
| title
stringlengths 7
150
| forum_tag
stringclasses 12
values |
---|---|---|---|
I've the following navigation: ( example ) <code> <ul id="mainNav"> <li><a href="#" class="watishet">Wat is het</a></li> <li><a href="#" class="hoewerkthet">Hoe werkt het?</a></li> <li><a href="#" class="resultaten">Resultaten?</a></li> <li><a href="#" class="onconavigator">OncoNavigator?</a></li> <li><a href="#" class="ziekenhuizen">Ziekenhuizen?</a></li> </ul> </code> Can I add custom classes to a anchor element inside <code> Wp_list_pages </code> ? because the current <code> wp_list_page </code> doesn't use a class attribute inside a anchor element. I want to add a unique class to each anchor element. For final result, I want to make a tab based horizontal dropdown menu. I looked for couple of WordPress dropdown menu plugins but there wasn't anything out there that fulfill my wishes.
|
Use the Wordpress Menu system, which allows you to set custom classes (Make sure you open up "Screen Options" and check the "CSS Classes" check box to see the settings)
|
Adding custom class names to anchor in wp_list_pages
|
wordpress
|
I noticed that when I changed the WP_Query to ask for a certain category, the page served was <code> category.php </code> . So I'm guessing there's a block of code somewhere that decides which template to serve based on keys in the query. Where is it?
|
The template loader determines which template to load for a given view, there's a filter available to change this though, <code> template_include </code> as seen on the source page linked. Moved from comment to answer.
|
How is WP_Query parsed to determine which template to request?
|
wordpress
|
i'm making a wordpress theme and want to use a single archive.php page in order to present posts under a specific author, a category or tag. Now, i'm doing it like : <code> if (is_author()) { } if (is_category()) { } if (is_tag()) { } </code> I know i can divide this in more templates, but i don't want to repeat myself and i generally prefer to do it in a single php file. So, my question is : How can i get either the category, tag or author in each of these ifs ? It seems that for the author i can use something like : <code> $author = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); </code> and for the category : <code> get_query_var( 'cat'); </code> But is this indeed the way to do it ? What is a safe way to get that information independent of permalinks ?
|
you can use it just like you posted which is safe and would do the job just fine: <code> if (is_author()) { $author = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); } elseif (is_category()) { //this will work in categories tags or custom taxonomy $term_slug = get_query_var( 'term' ); $taxonomyName = get_query_var( 'taxonomy' ); $current_term = get_term_by( 'slug', $term_slug, $taxonomyName ); } else(is_tag()) { //this will work in categories tags or custom taxonomy $term_slug = get_query_var( 'term' ); $taxonomyName = get_query_var( 'taxonomy' ); $current_term = get_term_by( 'slug', $term_slug, $taxonomyName ); } </code> Now after that as been said i would only recommend this way if this theme is not going to be released to the public and is for your own use, if this theme is to be released then i would divide my code in to separate files for easier customization and keeping with theme structure standards.
|
Check if tag, category or author on archive.php
|
wordpress
|
I´m trying to create a function that creates a breadcrumb trail of Page slugs outside of The Loop. These breadcrumbs show the path from the homepage to the current (sub)page. For example, on the page "example.com/attractions/parcs/parc-name" this breadcrumb would be shown: Home > Attractions > Parcs > Parc Name I´ve done a lot of research and found various code snippets that can perform part of the function, but my PHP skills are not good enough to create the whole function myself. This is what I have: Get the post slug in The Loop: <code> $slug = basename(get_permalink()); </code> ( src ) Get the post slug outside of The Loop: <code> global $post; echo $post->post_name; </code> (src: see above) Get posts´parent slug <code> <?php global $post; if($post->post_parent) { $post_data = get_post($post->post_parent); echo $post_data->post_name; } ?> </code> ( src ) Get breadcrumb trail of pages using page titles (this is what I´m using now): <code> if ( is_page() ) { $post = $wp_query->get_queried_object(); if ( $post->post_parent == 0 ) { echo "<li> &raquo; ".the_title('','', FALSE)."</li>"; } else { $title = the_title('','', FALSE); $ancestors = array_reverse( get_post_ancestors( $post->ID ) ); array_push($ancestors, $post->ID); foreach ( $ancestors as $ancestor ) { if( $ancestor != end($ancestors) ) { echo '<li> &raquo; <a href="'. get_permalink($ancestor) .'">'. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</a></li>'; } else { echo '<li> &raquo; '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</li>'; } } } } </code> All ideas, suggestions and solutions are very much appreciated :)
|
Ok, problem solved. I´ll add the script below. Hope it´s useful for someone. <code> if ( is_page() ) { $post = $wp_query->get_queried_object(); if ( $post->post_parent == 0 ){ echo "<li> &raquo; ".ucwords(str_replace("-", " ", $post->post_name))."</li>"; } else { $title = the_title('','', FALSE); $ancestors = array_reverse( get_post_ancestors( $post->ID ) ); array_push($ancestors, $post->ID); foreach ( $ancestors as $ancestor ){ if( $ancestor != end($ancestors) ){ echo '<li> &raquo; <a href="'. get_permalink($ancestor) .'">'. ucwords(str_replace("-", " ", basename(get_permalink($ancestor)))) .'</a></li>'; } else { echo '<li> &raquo; '. ucwords(str_replace("-", " ", basename(get_permalink($ancestor)))) .'</li>'; } } } } // You just missed this bracket, else this is working awesome! </code>
|
Slugs as breadcrumbs for Pages
|
wordpress
|
I'd like a lightweight way to figure out what is invoking a certain action in an effort to provide logic for certain scenarios where I can't help to avoid a function invocation (for example, a new comment firing <code> edit_post </code> ). Is there a way to figure out which action/filter invoked a function?
|
Sure, just use <code> current_filter() </code> .
|
Is there a way to figure out which action/filter invoked a function?
|
wordpress
|
Is it possible to create a month by month archive of pages? I know it can be done with posts but I want to do it with pages. I want it to take the date the page was published so if the page was published in August then it would create a link called "August" which in turn when clicked will show all the pages within August. Is that possible? Or is there a better way I can categorise my pages to show them month by month? UPDATE: I use this plugin - wordpress.org/extend/plugins/advanced-custom-fields . Is there any way I could do it with pages? Is there any fields I could add to a page that could help me hack together an archive?
|
You could probably hack something together, but you should probably understand that, in WordPress, a basic assumption (and operating principle) is that static Pages are not chronological . IMHO, a better approach would be to store the content as Blog Posts , and then to use Categories (or perhaps, a custom taxonomy ) to identify that content, and to display it chronologically. If you have a taxonomy (core or custom) that identifies this content, you can even filter your primary Loop query, so that this content does not output with your "normal" Blog Posts.
|
Create a month by month archive of pages (not posts)
|
wordpress
|
In my custom post type what I am trying to do is say I have select drop down option called party_ad. The value of the options are obtained via an RSS feed. <code> echo '<select name="ad_Tags" id="ad_Tags">'; foreach ($rs['items'] as $item) { echo '<option value="'.$item[title].'" '. selected( $adTags, $item[title]).'>'.$item[title].'</option>'; } echo '</select>'; </code> I can save these data with no problems - however, what I want to be able to save the selected option as a tag to the custom post. I thought about doing it front end, ie if an option is selected then it adds the value to the post tag box, ideally though, I'd like to really do this server side.
|
you can use wp_insert_term() to create the tag and then wp_set_object_terms() to set it as the custom post tag: <code> //get the tag $tag = $_POST['ad_Tags']; //create the tag $term_id= wp_insert_term( $tag, // the term 'post_tag', // the taxonomy array('description'=> 'term description','slug' => 'term-slug') ); //set the tag wp_set_object_terms( $post_id, $term_id, 'post_tag' ); </code>
|
saving meta/custom field to tag
|
wordpress
|
What's the simplest way to add a second html editor to the post/page admin and show the content in a template? What I need is something like a custom field that supports html, but I don't need the options to name the field. And I don't need a visual editor like tinyMCE; just html will do. What I'm thinking of is simply a small text-editor box that sits under the main visual/html editor and shows the resulting html in a template via <code> <?php if ( function_exists('my_extra_editor_content') ) ... </code> with the text/html in a styleable div. Plugins like http://wordpress.org/extend/plugins/custom-field-template/ and http://wordpress.org/extend/plugins/developers-custom-fields/ offer too much in terms of functions and choices.
|
I use Bill Erickson's custom meta boxes or plugin like Secondary HTML Content (probably the easiest solution)
|
Simplest way to add a second html editor to the post/page admin?
|
wordpress
|
I am getting trouble with WordPress comment posting. As per my WP setting there is no approval needed to display the comments under blog after posting. Most of the comments posted display immediately. But some of them do not display and need aproval from the admin / Author.
|
You need to check all of the following options under <code> Dashboard -> Settings -> Discussion </code> : Before a comment appears Before a comment appears An administrator must always approve the comment Comment author must have a previously approved comment Comment Moderation Hold a comment in the queue if it contains _ or more links. (A common characteristic of comment spam is a large number of hyperlinks.) When a comment contains any of these words in its content, name, URL, e-mail, or IP, it will be held in the moderation queue. One word or IP per line. It will match inside words, so “press” will match “WordPress”. Also: do you have any comment-moderation or spam-prevention Plugins active?
|
WordPress Comment posting problem
|
wordpress
|
I have created a custom post type in wordpress and have 90% of the functionality working correctly, but I am having a bit of trouble trying to create a custom listing page template. Currently it is using the default index.php page to bring out all the posts and I have tried to override this by creating a page-post-type.php page but didn't seem to work. What would be the best method for creating a custom post type listing page? Cheers, Jamie.
|
I think you want to create archive page for custom post type, create <code> archive-{post_type}.php </code> and it'll display you custom post type content. Also see codex: http://codex.wordpress.org/Template_Hierarchy#Custom_Post_Types_display
|
List page for custom post type?
|
wordpress
|
I have to add a lot of items in wordpress menu (lot of 2nd level items) is there any bulk menu item creation method available to do it ? is there any way to add wp-ecommerce categories in wordpress custome menu
|
Goto Appearance -> Menus You can see all categories listed here including wp-ecommerce categories. Just create a new menu for your wp-ecommerce categories. Lets call it "ecomcategories". You can call this menu in your theme using this code. <code> <?php wp_nav_menu( array('menu' => 'ecomcategories' )); ?> </code> You can just drag and drop for sub menus. You can create unlimited menus and submenus.
|
Bulk Custom Menu and Wp-Ecommerce
|
wordpress
|
I'm using custom fields in my wordpress default post area. So i don't want wordpress default description box. I mean i dont want this field. Instead of description box i want excerpt box there. Please help me. Thanks
|
you can use simple one liner with remove_post_type_support() : <code> remove_post_type_support( 'post', 'editor' ); </code>
|
How to hide wordpress default description box?
|
wordpress
|
How would I get the top-level parent of a given term? I am using <code> wp_get_object_terms </code> to get taxonomy terms on posts, but instead of showing all tagged terms, I only want to show tagged terms' top-level parents. So if these are my selected terms, I only want to show Breakfast, Lunch and Dinner. <code> x BREAKFAST x Cereal x Eggs LUNCH Hamburger x Pizza DINNER Fish Bass x Salmon Trout Lasagna </code> How can I do this?
|
Thanks to Ivaylo for this code, which was based on Bainternet's answer. The first function ( <code> get_term_top_most_parent </code> ) accepts a term ID and taxonomy and returns the the term's top-level parent (or the term itself, if it's parentless); the second function ( <code> hey_top_parents </code> ) works in the loop, and, given a taxonomy, returns the top-level ancestors of a post's terms. <code> // determine the topmost parent of a term function get_term_top_most_parent($term_id, $taxonomy){ // start from the current term $parent = get_term_by( 'id', $term_id, $taxonomy); // climb up the hierarchy until we reach a term with parent = '0' while ($parent->parent != '0'){ $term_id = $parent->parent; $parent = get_term_by( 'id', $term_id, $taxonomy); } return $parent; } // so once you have this function you can just loop over the results returned by wp_get_object_terms function hey_top_parents($taxonomy, $results = 1) { // get terms for current post $terms = wp_get_object_terms( get_the_ID(), $taxonomy ); // set vars $top_parent_terms = array(); foreach ( $terms as $term ) { //get top level parent $top_parent = get_term_top_most_parent( $term->term_id, $taxonomy ); //check if you have it in your array to only add it once if ( !in_array( $top_parent, $top_parent_terms ) ) { $top_parent_terms[] = $top_parent; } } // build output (the HTML is up to you) foreach ( $top_parent_terms as $term ) { $r = '<ul>'; $r .= '<li><a href="'. get_term_link( $term->slug, $taxonomy ) . '">' . $term->name . '</a></li>'; } $r .= '</ul>'; // return the results return $r; } </code>
|
Get the the top-level parent of a custom taxonomy term
|
wordpress
|
stackexchange-url ("Bainternet") assisted me stackexchange-url ("earler") with the relation AND parameter. What I need to do now is determine how to query multiple vales from a single key. If I try to specify two arrays with the same key the query fails. Is there a way to use an array in the value?Something similar to. <code> 'value' => array( 'Install Manual', 'User Manual' ), </code> I've searched quite a bit with no results. This is where I'm at so far. <code> $documents = array( 'post_type' => 'documents', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'document-type', 'value' => array( 'Install Manual', 'User Manual' ), ), array( 'key' => 'document-status', 'value' => 'current', ) ) ); query_posts( $documents ); get_template_part( 'loop', 'documents' ); wp_reset_query(); </code>
|
Just add <code> 'compare' => 'IN' </code> : <code> 'key' => 'document-type', 'value' => array( 'Install Manual', 'User Manual' ), 'compare' => 'IN' </code>
|
Querying multiple values from a single key
|
wordpress
|
Is there a way to use wp_enqueue_script() for inline scripts? I'm doing this because my inline script depends on another script and i would like the flexibility of inserting it after it's loaded. Also, It's an inline script because i'm passing php variables into the javascript (like theme path, etc) Thanks in advance.
|
Well, you have wp_localize_script(), but that's only for passing data. Otherwise, you can do this: <code> function print_my_inline_script() { if ( wp_script_is( 'some-script-handle', 'done' ) ) { ?> <script type="text/javascript"> // js code goes here </script> <?php } } add_action( 'wp_footer', 'print_my_inline_script' ); </code> The idea is that you shouldn't rely on your inline script being printed exactly after the script it depends on, but later.
|
wp enqueue inline script due to dependancies
|
wordpress
|
I don't see any way of testing which template file is being loaded, if the template file is not a page template. Otherwise I would use is_page_template(). For instance, I am using a home.php template file to pull in the content from multiple pages(don't ask), how would I check that home.php is the template file being used when viewing the sites root url?
|
Just type in some text like "Debug" into the non-Php area of home.php (the part not surrouded by ) and see if it appears. If so, you know that home.php is being used.
|
Is there a way to check which template file is being loaded, if it is not a page template file?
|
wordpress
|
I've designed a grid-based portfolio theme for a photographer; for each portfolio item, I need six different images, all of which have a fixed size. However, no two sizes are alike. Is there a WordPress plugin that will easily allow me to specify a number of different image sizes and choose easily between them when uploading photos? Thanks!
|
Have you looked at add_image_size() ? It allows you to create new custom thumbnail sizes for uploaded images. If you need to create new thumbnails for previously uploaded images, use my Regenerate Thumbnails plugin.
|
Plugin that will let me specify a number of image sizes?
|
wordpress
|
Has anyone used Cartpress before that could give me some pointers? I've installed the plugin but struggling to find all the templates it uses to display everything. I'm using the default theme in WP and have set everything up in that. Things I want to include are: Display 3 top products on the homepage. Adjust the look of how all the products are displayed. Tailor the look of checkout process. Display a basket. I've tried using Dukapress and wpStoreCart but Cartpress seems the easiest to adjust. It's easy enough to change to a different plugin as I'm only just starting out.
|
So basically, I've never found an ecommerce solution yet that just works. And I've tried a lot of them. They often require the cusom creation of templates, as the shops css and the theme css never seem to play right. Everything always looks pretty crappy for me. Now that being said, the easiest I've dealt with is eshop . Well, the easiest in terms of appearance. It just works through the normal post interface. I set up a custom post type and used it for my shop. I like it, but wasn't 100% sold on the back end. Some things were a bit confusing to me, but I'm not an e commerce expert. I've recently began experimenting with jigoshop which has an easier to understand backend, but I'm having trouble with appearance. This plugin sets up its own custom post types for you, and sets up pages for your cart, and shop, etc. It seems pretty solid and thorough, but again...appearance on the front-end. It allows you to turn off the css for the plugin, but my shop seems to be busting right out of my theme. So basically what it comes down to is figuring out the mechanism for your ecommerce plugin. Is it custom post type based? If so it's pretty easy to creat custom templates. But to get what you are after, you'll need to use a combination of templates most likely, maybe custom queries for displaying the right number of products, and custom css. Sorry I can't be more specific. I've just found that every plugin/theme combination is different. And every one of the ecommerce plugins requires a fair amount of customizing through the theme to get right.
|
How to adjust the Cartpress e-commerce plugin?
|
wordpress
|
whenever admin or any other user logs in a top bar menu ads up. Now I made login for everybody, so I do not want this bar. first I added display:none to admin-bar.css, but the main problem is that wordpress is still adding a white line on the top with: html { margin-top: 28px !important; } how to remove this as this is causing some design flaws. Thanks!
|
http://vudu.me/88 Has an article about it. But basically <code> /* Disable the Admin Bar. */ add_filter( 'show_admin_bar', '__return_false' ); </code> or also <code> //REMOVE ADMIN BAR remove_action('init', 'wp_admin_bar_init'); </code> I believe in your functions.php will disable it. Probably a better way than just hiding it thriough css THe reason you still get the gap with the menu hidden is because WP adds this css as well <code> html { margin-top: 28px !important; } * html body { margin-top: 28px !important; } </code> So a margin is added up top.... you could negate that css in yours, but just disabling the bar is probably better if that's what you want to do
|
I want to remove top admin bar from wordpress. How to?
|
wordpress
|
I'm working on a site that is using this PHP script to load a random header image every time it reloads. I would like to use Javascript instead to allow the browser to cache images and improve load times and was wondering if there's any benefit to using the PHP script over some JS script for this scenario.
|
Using PHP sends less code to the end user. (a single img tag instead of all the javascript logic). If you enable browser caching settings correctly (try W3 Total Cache ), once the end user has "seen" all the images, those will all be in their cache, so on the "long tail" JavaScript vs. PHP solution is equivalent.
|
PHP or JS for header image rotator?
|
wordpress
|
I cannot get WPTouch to work with W3 Total Cache. WPTouch admits that there is a known issue with the two, and they send you to a tutorial . The tutorial is out of date, however, and does not work for me. Does anyone have WPTouch working with W3 Total Cache? If so, can you give some directions/instructions?
|
See: http://wordpress.org/support/topic/wptouch-w3-total-cache-must-disable-browser-caching You'll need to add that long list to Rejected User Agents under Page Cache, Minify and CDN. If your concerned about the browser caching issues when switching between mobile vs. normal themes, you'll need to add some query string pattern in the reject URIs field on the page cache settings tab.
|
Getting WPTouch and W3 Total Cache to Work Together
|
wordpress
|
When users insert an image into the content, WordPress automatically wraps the image in a hyperlink that, when clicked, creates an "attachment" page showing only the image inside the theme. Can I insert a code in my theme that tells WP not to create this link?
|
When you insert an image it becomes an attachment, whether you link to that page or not. You can simply select 'none' in the link url field when the image is inserted, it's one of the options in the media panel.
|
How to force unlink on attached/inserted images?
|
wordpress
|
I am using a code to call WP thumbnails and want to add a title="" tag. I would like the title to call the_title... how do I do so? I want to assign the title tribute to the image, not the link. My code: <code> <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-archive' ); } ?> </code>
|
Use the arguments available for <code> the_post_thumbnail( </code> ) function as written in the codex . Edit : just did a test with this and it worked for me: <code> $post_title = the_title( '', '', false);//get the title $attr = array('title' => $post_title);//set the parameter the_post_thumbnail('full', $attr);//call the function </code>
|
Add title="" to A PHP Code
|
wordpress
|
I have several category pages (e.g. example.com/?cat=3) that display only the post titles. I would like to make them display the post as well. What is the easiest way to do this?
|
Category pages or archives? If you're a little more specific you will probably get multiple ideas, but in general, if you've got a loop you can use one of the two following functions: <code> <?php the_excerpt(); ?> </code> will show the custom or default excerpt for the post <code> <?php the_content('Read More &raquo;'); ?> </code> will show the full post with a "Read More" link employed if you've used <code> <!-- more--> </code> in your post to show only part of the post on aggregate templates If you are looking for simple functions for your templates to display content, you should probably read up on the WordPress codex .
|
Change Category Page Display
|
wordpress
|
Can I add a text editor to my plugin menu ? So I can let users edit custom css file? Something like <code> /wp-admin/plugin-editor.php </code> but I want users to be able to edit only one file. The custome css file. Could this be done using Wordpress standard functions ?
|
This will help you http://keighl.com/2010/01/tinymce-in-wordpress-plugins/
|
How to add text editor in plugin menu?
|
wordpress
|
I have created a simple admin menu that allows users to enter in some basic information that is stored in the footer. When they click save the url appends <code> &settings-updated=true </code> Is there a way, using jQuery to show a success/fail message? Can anyone show me how or give me an example? Thanks in advance, George
|
See the top answer on this Stackoverflow question. Basically you need to use: <code> decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]); </code> stackexchange-url ("Get URL parameter with jQuery")
|
Admin menu success message
|
wordpress
|
It's possible to insert posts by users through the front-end by using plugins such as gravity forms or by using wp_insert_post. However, how would one handle the editing of those posts? This has to be in a safe/foolproof/secure way for users.
|
WP User Frontend and Post From Site plugins (among others) allow users to create and edit posts from the front-end. I am sure you can find a lot more — try this .
|
edit posts through front-end
|
wordpress
|
I have a custom post form that sends data to a page which uses wp_insert_post to create a post. I can easily sanitize most data, but I have some troubles with my tags, I retrieve in an array: <code> $tags = $_POST['tags']; </code> Before using these tags as tags_input, how can I successfully sanitize all names? Thanks!
|
If anyone is interested, I solved it like this: <code> $tags = $_POST['tags']; if (count($tags) > 5){ echo 'Niet meer dan 5 tags'; $stop = true; } if (is_array($tags)) { foreach ($tags as &$tag) { $tag = esc_attr($tag); } unset($tag ); } else { $tags = esc_attr($tags); } </code>
|
wordpress sanitize array?
|
wordpress
|
I've just begun setting up the overstand theme to work with my blog, but I've run into a problem. Check out my site: http://beachief.com/ , the problem is pretty obvious. Those two black categories have been like that since I first installed the theme - I have done nothing to change them. I'd like those two areas to stretch out across the entire page. They are both set to use the "latest2" class which is coded to be 465px, but neither are responding to it. What's wrong? You can find the files for the overstand theme here:http://forums.digitalpoint.com/showthread.php?t=2212542 Thanks
|
You should replace this code: <code> ul.latestoneandhalf { float:left; padding-right:15px; width:225px; } </code> With this: <code> ul.latestoneandhalf { float:left; padding-right:15px; width:100%; } </code>
|
Overstand theme set up issue
|
wordpress
|
I do not allow users to login to my blog, but I would like to enable facebook connect for those who do not want to enter their details in the comments fields all the time. How should I start doing it? Enable on wordpress settings user logins, when implement facebook comment and thats it?
|
Try the new beta version of my Simple Facebook Connect plugin. http://plugins.svn.wordpress.org/simple-facebook-connect/branches/new-sfc/ I prefer this comment implementation over others as mine does not create WordPress users directly from Facebook connected users when just used for commenting.
|
I want to enable facebook connect how to do this?
|
wordpress
|
Reading through the documentation you have the ability to setup a WP Network in two ways, Sub-Domains and Sub-Directories. The only explanation they give you is Sub-directory sites It works with the use of the mod_rewrite feature on the server having the ability to read the .htaccess file, which will create the link structure. If you are using pretty permalinks in your blog already, then subdirectory sites will work as well. Sub-domain sites It works using wildcard subdomains. You must have this enabled in Apache, and you must also add a wildcard subdomain to your DNS records. (See Step 2 how to set up.) Some hosts have already set up the wildcard on the server side, which means all you need to add is the DNS record. Some shared webhosts may not support this, so you may need to check your webhost before enabling this feature. I'm looking to find if there is a performance, maintenance or other benefit to use one over the other.
|
I began using Multisite just a few months ago, and am really loving it. You're going to want to use the sub-domain structure if you have a host that supports it. I use a Media Temple Grid Server plan. It will allow you to create a subdomain and then mask it with a symbolic link. i.e. rtgibbons.mynetwork.com would be mapped as rtgibbons.com or whatever URL you want presented. Upon a Google search, I found that as long as you plan to use Domain Mapping, there will be no advantage to either method. http://wordpress.org/support/topic/multisite-subdomain-vs-sub-directory-setup?replies=4 I'd suggest subscribing to the WordPress.org Multisite Forum. There is very good info over there and Andrea_r is very sharp.
|
Benefits or Problems for using Sub-Directory vs Sub-Domain install of WP Network
|
wordpress
|
Was wondering if there was a class or programming technique that would allow me to check for the installation and activation of a particular plugin and if said plugin were not installed, to have it downloaded from WordPress's plugin repository? I have a plugin I would like to require scribu's Post 2 Post plugin and I was wondering how it could be done?
|
I would encourage against this, but I understand what you're trying to do and do something similar myself. How I do it I build themes that depend on plugins, plugins that depend on plugins, and plugins that depend on plugins that depend on other plugins. If I'm controlling both sides of the development, I do things in two pieces ... In the plugin that will be required by something else: <code> add_filter( 'my-cool-plugin-name-installed', '__return_true' ); </code> In the plugin/theme that will require the other plugin : <code> if ( ! apply_filters( 'my-cool-plugin-name-installed', false ) ) add_action( 'admin_notices', 'my-cool-plugin-name_not_installed' ); </code> Then I add a bright "Please install my super-cool plugin" notice to the top of the admin screen with a link to the download page. This gives me a surefire way to check that my dependencies exist and are installed. If the plugin is installed but not activated, the warning still shows up. Another way Another option has already been recommended by @tollmanz. I won't copy-paste his solution, but checking for the existence of a core function of your dependent plugin is a great way to make sure it's there. Once again, if the plugin is installed but inactive, this route will only detect if it's active. Why I do things this way First of all, I don't like other people's tools downloading extra stuff to my site. So I don't force that paradigm on other users. Instead, I prompt them to download the extra code and point them in the right direction. A cleaner way would be to tie in with the automated installer so they could pull down the plugin with a single click. Also, several users of my code are on servers where they can't use the one-click installer (or automated downloads at all). They have to FTP plugins to install them, so a silent download-and-activate-a-dependency system wouldn't work at all. Finally, if you're working with someone else's code, you have 0 control over when they ship new releases, if they introduce bugs, or if they're hacked. So don't automatically install code for which you can't claim responsibility.
|
How would you require and automatically download dependent plugins?
|
wordpress
|
I've inherited a mess of a WP site. I need to be able to take 100+ categories and rearrange parent/child relationships. I need something with a UI that will make this easy. Anyone know of a plugin that does this?
|
Perhaps stackexchange-url ("Scribu")'s Term Management Tools would be of use to you here, it does various tasks including bulk term management.
|
Plugin to assign parent category on multiple taxonomy terms
|
wordpress
|
This stuff is driving me nuts. The following url does NOT exist and should return a 404: http://www.easyjob.net/resume/ However, if I try to access it, I get a 301 to http://www.easyjob.net/r/cover-letter/resume-and-cover-letter/ Even if I add a redirect to the .htaccess to redirect it somewhere else, I still get the * 301 to http://www.easyjob.net/r/cover-letter/resume-and-cover-letter/ again. Anybody knows what's going on? PS this is the .htaccess: <code> AddHandler php5-script .php # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress #/RESUME/ Redirect http://www.easyjob.net/resume/ http://www.easyjob.net/r/ [R=301,NC,L] </code>
|
If you remove your Redirect from the .htaccess file, you could try adding a custom 404.php template file to your theme. I'm not sure exactly what you are asking. Do you want the page to Redirect, or do you want a custom 404 page that displays similar items? To achieve the show similar posts using the 404.php template try this: Create a php file named 404.php Add this to the file and save it, then upload it to your theme directory: <code> <?php get_header(); ?> <div class="container"> <div class="content"> <h2 class="entry-title">Didn't Find What You were Looking For?</h2> <p>Perhaps one of the links below, can help.</p> <?php $rel_tags = get_the_tags(); foreach($rel_tags as $rel_tag) { $rel_tagnames .= $rel_tag->name . ','; } $rel_posts = get_posts('tag=' . $rel_tagnames . '&post__not_in' . $post->ID . '&showposts=5'); if (count($rel_posts)) : ?> <ul> <?php foreach((array) $rel_posts as $rel_post) { ?> <li><a href="<?php echo $rel_post->post_name ?>"><?php echo $rel_post->post_title ?></a></li> <?php } ?> </ul> <style type="text/css"> #return-home { display:block; position:relative; padding:5px; font-size:24px; font-weight:600; color:black; margin-top:40px; } </style> <div id="return-home"> <p> <a href="<?php bloginfo('url'); ?>" title=" <?php bloginfo('name'); ?>">Click to Go to the Home Page:&nbsp;<?php bloginfo('name'); ?></a> </p> <?php else : ?> <?php endif; ?> </div> </div> <?php get_sidebar(); ?> <?php get_footer(); ?> </code> NOTE: You will need to replace the div's I've used with the ones your theme has or it won't look like the rest of your website. Open your index.php file and replace the <code> <div class="container"> </code> and <code> <div class="content"> </code> from my file with your theme's div's.
|
Can Wordpress redirect to a "similar page" in case of 404 error
|
wordpress
|
Am looking for carousel slideshow plugin that is similar to the one implemented here . Any JavaScript slideshow that closely resembles that one would do. It does not even have to be a WordPress plugin, any standalone JavaScript library would also be very useful.
|
there is a plugin (discontinued): http://wordpress.org/extend/plugins/wp-imageflow/ ) and a Nextgen addon: http://wordpress.org/extend/plugins/nextgen-imageflow/ . More samples and the original code (to the best of my knowledge) can be found here: http://finnrudolph.de/ImageFlow/
|
A carousel slideshow plugin in JavaScript
|
wordpress
|
I have been trying and trying to fix jquery issues. i have in my header lots of jquery. I use it for slider and other things that are built into this premade theme. I am unable to add anything that uses jquery because of conflict. i need some help. The board is www.cgwhat.com. The forgot password is jquery and the slider is controlled by jquery also. I wanted to add another plugin but can not because of the conflict. Also with the forgot password that is jquery. I need to know what is wrong and how to fix it . If i remove calls to javascript in header it is fixed. The forgot password works but everything else breaks. <code> <?php wp_enqueue_script("jquery"); ?> <?php wp_head(); ?> <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.equalHeight.js"></script> <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/flashobject.js"></script> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.js"></script> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.jcarousel.js"></script> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.actions.js"></script> <script type="text/javascript"> jQuery(document).ready(function($){ var fC=$('#features-nav .features-nav-item').length; curS=1; var cInt=0; cInt=setInterval(function(){ $('#features-nav .features-nav-item:eq('+curS+')').addClass('current').trigger('click'); curS++; if(curS>=fC) curS=0; },10000);}); </script> </head> </code>
|
At least one issue I can see is that you're including the jQuery framework at least twice. The first line <code> <?php wp_enqueue_script("jquery"); ?> </code> Is the preferred method of including jQuery. Your installation of WordPress happens to include jQuery version 1.4.2. This allows good plugin and theme developers to leverage jQuery and not accidentally include it manually several times. But you also have (on line 6) <code> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.js"></script> </code> Which includes jQuery 1.2.6. Maybe one of your plugins is trying to inject this? Or perhaps this is generated in your theme (in which case you can delete it, assuming your plugins are compatible with the built in version of jQuery which is version 1.4.2. After you resolve that issue, any further javascript errors can be isolated to a specific script or plugin. EDIT: Addition info... Now that you've removed the extra jquery include, a different error has surfaced. Using Firebug or Chrome's debugger or your other favorite JavaScript debugger, you can see that the new error is: <code> $ is not a function (jquery.actions.js, line 18) </code> This means that you are attempting to use the jQuery shorthand selector but have wrapped your document ready using the full "jQuery" object name syntax. In jquery.actions.js, replace each "$" reference with "jQuery". This will get your slider working. But you'll also notice that you have other errors in your JavaScript... <code> pos is null (undo.js, line 367) threads[x] is undefined (_display, line 915) </code> You may or may not care about those errors depending on how they affect your site. I tend to like to eliminate any and all errors for performance and stability. Some browsers will crash worse than others.
|
Jquery conflict
|
wordpress
|
I was encouraged by Dreamhost to go with FCGI, XCache and w3 total cache. But I'm not sure what the optimal settings are, especially re: the Object and Database cache. Any suggestions? Also, I can't get this error message to go away: <code> Recently an error occurred while creating the CSS / JS minify cache </code> Nor can I get log files to show up...
|
Recently an error occurred while creating the CSS / JS minify cache... Frederick Townes, the developer of W3 Total Cache, himself said that the notifications "functionality really gives too many false positives right now and should be disabled." That was 4 months ago, and still holds true today. I have this very same error showing up on some of my setups, but the rest are fine, and all this happens on the very same server. So, I'm afraid, this IS a false positive.
|
Has anyone used the wordpress plugin w3-total-cache on a Dreamhost VPS successfully?
|
wordpress
|
I need to display some HTML only if the post being displayed has a category - not a specific category, just any category at all. I tried <code> if (!is_empty(get_the_category($post->ID))) </code> , but for some reason this isn't working. Has anone else had the same issue?
|
Use <code> has_category </code> instead. <code> if (has_category('',$post->ID)) ... </code> If you want to use it in The Loop, you don't need to specify the ID. <code> if (has_category()) ... </code>
|
Test if post has a category
|
wordpress
|
I don't know if I'm in the right place because is not strictly for Wordpress, I think someone can get some benifit of this question without using Wordpress but in this case I'm using it. So, I'm using a modified theme with some plugin enabled, carousel, and other fancy things. There is a problem with some graphics, when I call the site from a remote host, and it's not cached, it's not quick as it's in localhost so all the images are preload in the same place one above the other and when the JS is ready all go in place, but you see a mess while the site is reading... This is not very nice as you thinking... My intention is to achive a "site is loading" pulsating or a progress bar while the site is ready in background. How to do this?
|
This is NOT a good idea. If you get that kind of behavior, then you didn't properly code your carousel thing / CSS. You should hide the element that contains it, and reveal it in the js hook. But if you really want to go your way, here's how: header.php: <code> ... <body <?php body_class('site-loading no-js'); ?>> <script> document.body.className = document.body.className.replace('no-js','has-js'); </script> ... </code> CSS: <code> body.site-loading.has-js{ background: #fff url('the/loading.gif') no-repeat center center; } body.site-loading.has-js *{ display:none; } </code> javascript, assuming jQuery: <code> jQuery(document).ready(function($){ // do your carousel thing // should be last line $('body').removeClass('site-loading'); }); </code> Needless to tell you that any javascript error after the header code I gave you, will keep your site in "loading" mode forever :)
|
How to preload the entire site with javascript?
|
wordpress
|
I am developing a site for a client, let's call it <code> whatever.com </code> . He wants to have his Tumblr blog at <code> whatever.com/blog </code> . (Tumblr lets you name the URL at which your Tumblr page will be served, and if it's a site root, you adjust your domain's A-Record, which obviously I can't do here.) Right now I have a blank page called <code> blog </code> so that it shows up in the nav using <code> wp_list_pages() </code> , but I'm guessing this won't work unless I do some fiddling elsewhere. Anyone know how to do this?
|
Hmm, given that it's okay to send the visitor to an entirely different site, but you are trying to get it to show up as a page, I would suggest adding it to a menu. You are probably already aware, but when you are modifying menus (Appearance > Menus) there is a box on the left side called "Custom Links," which just like they sound, allow you to add something directly to the menu that can go anywhere. Add an entry using this that goes to the Tumblr blog and use that menu (whether it be primary or secondary) wherever you need to display the pages AND the Tumblr link. This avoids <code> .htaccess </code> conflicts and is the "natural" way to do things, but does restrict it to only being in menus. Might be missing something here on how Tumblr recognizes the URL and the DNS issues, but from the WordPress side of things, that's how I would go about it.
|
How should I set up a Tumblr blog at a WordPress Page?
|
wordpress
|
I read the answer for stackexchange-url ("this post") which says you can do something like this: <code> http://example.com?post_type=car&color=red </code> When viewing $wp_query everything seems to be working fine. That is, I'm getting 'car' post types that have the 'red' term assigned. However, the request uses the 'color' custom taxonomy template. (In my case this is taxonomy.php.) How can I get this request to use the 'archive-car.php' custom post type template instead?
|
Switch the taxonomy.php just like you would the single.php to support specific post custom templates. This is untested code, so it may not work - but, first get the post type $post_type = get_query_var('post_type'); So if $post_type contains post_type = 'car' then include archive-car.php like this: if ( $post_type = 'car' ) get_template_part('archive-car'); elseif ( $post_type = 'boat' ) get_template_part('archive-boat'); elseif ( $post_type = 'bike' ) get_template_part('archive-bike'); else get_template_part('regular-taxonomy'); An better alternative would be if you could establish a template redirect like in this answer, but I don't know if that's even possible. If possible, you'd redirect the taxonomy template based on the value of $post_type. stackexchange-url ("How to quickly switch custom post type singular template?")
|
How can I get this request to use the Custom Post Type page template instead?
|
wordpress
|
Does anyone know any wordpress plugin to display the author's profile & image similar to the image attached
|
here are a few: Author Bio Widget Just Another Author Information Widget User Bio Widget
|
Wordpress author details plugin/widget
|
wordpress
|
I'm getting this error in FireFox: <code> Error: jQuery(domChunk).live is not a function Source File: http://www.bradford.nhs.uk/wp-includes/js/thickbox/thickbox.js?ver=3.1-20110528 Line: 26 </code> This is the function: <code> //add thickbox to href & area elements that have a class of .thickbox function tb_init(domChunk){ jQuery(domChunk).live('click', tb_click); } </code> Thickbox seems to be a build in WordPress feature but the theme we are using uses prettyPhoto.
|
I used jQuery(domChunk).bind instead. This seems to work.
|
Error jQuery(domChunk).live is not a function
|
wordpress
|
I keep getting spammed by the same user, well different name and site listed but always the same email, IP, and comment. the email is <code> [email protected] </code> , the IP is <code> 31.184.238.9 </code> , and the message is long and always the same. I want to do 2 things: How can I block this person from commenting? I have over a hundred pending from them, is there a way to mark them all as spam?
|
In <code> Settings > Discussion > Comment Blacklist </code> . You can blacklist comments based on content, name, url, e-mail, or IP. To mark the comments as spam, what I would do, is to do a search for his IP and then there is a checkbox that will select all, then just mark as spam. Trick is, it only applies to the comments listed on the page, but it is still better to do a few and a lot.
|
How to block a someone from commenting?
|
wordpress
|
As the title says, how can i increase the login expiration period? Running a local install it's a little annoying to have to keep logging in, despite the fact i have the browser remember login credentials it's an extra step i have to perform everytime i fire up the local server. I assume if i increase the cookie expiration period i'll avoid the need to keep logging in(as often). Have googled and searched the forums, but all i found were unresponded to threads and i'm not in the mood for digging through code to work it out. I don't need an in-depth answer, just some pointers on suitable hooks(if any exist for this purpose), i can work out the rest from there. Off to find somewhere cool to sit now, upstairs is roasting hot right now(hot weather here) i think the laptop might just die if i keep it on any longer, i'll be keeping tabs on the question from another system in a cooler area of the house though and looking forward to any pointers you guys have for me.
|
Don't know if this is the best way, but I've been using this in functions.php in my themes: <code> function keep_me_logged_in_for_1_year( $expirein ) { return 31556926; // 1 year in seconds } add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_1_year' ); </code>
|
How can i increase the login expiration length?
|
wordpress
|
I'm using scribu's Query Multiple Taxonomies to filter posts through multiple taxonomies (which works great!). However, I'd like to allow people to perform further sorting on the results based on custom fields which have numeric values (eg. <code> rate_per__private_session </code> or <code> rate_per_group </code> ) by clicking on a link. I thought that something like the following would be all there was to it but clearly it is not. <code> <a href="<?php query_posts($query_string . '&meta_key=rate_per_private_session'); ?>">Sort by Rate per Private Session</a> | <a href="<?php query_posts($query_string . '&meta_key=rate_per_group'); ?>">Sort by Rate per Group</a> </code> How do I do this?
|
I think I got it on my own. The code should be: <code> <a href="<?php echo add_query_arg( 'order_by', 'rate_private' ); ?>">Sort by private</a> <a href="<?php echo add_query_arg( 'order_by', 'rate_company' ); ?>">Sort by company</a> </code> Note: I used another plugin, Custom Query Fields , which has "order_by" query var made available.
|
Sort posts after filtering them through multiple taxonomies
|
wordpress
|
I currently have a static front page and a /blog. My goal is to have the front page be a grid of hand selected images (similar to a portfolio). I would like to be able to easily switch the images are featured on this page without having to change the raw html. Is the best way to do this, using custom fields on a page? Or is there a better way to handle managing featured images on a static page? Thanks!
|
Two categories should do the trick. Featured posts - This category should be applied to posts that you want to show on your home page, with that images grid. You can limit the number of posts (so only the, for example, 6 newest ones would appear) and select the featured image for them on each post's properties. You can limit number of posts easily, and you can also exclude other categories from your home page. Blog posts - a general category with a name such as 'blog' would include every other post you've got on your website. This category would have a visible link on your home page, and would be accesible through www.yousite.com/blog/ I think this would be my way to go.
|
Featured Images on Front Page
|
wordpress
|
I'm interested in installing wordpress and having a static front page and have link to the blog at /blog. How do I install wordpress in the root directory, but have the blog live at /blog I see how I could do it for the blog urls, but do I just change the wordpress url in general settings for this? Thanks.
|
There's a codex on this issue here: http://codex.wordpress.org/Creating_a_Static_Front_Page I haven't been provided all the details of your site from your post. As in what your original site root is from when you installed it. So i'm making an assumption that this is a new install.
|
Help with static front page blog at /blog
|
wordpress
|
Related to stackexchange-url ("this ticket about issues with inflating data"). So far it had been suggested by API's support to request gzip instead of deflate. However I cannot find a way to override WP settings that set deflate with highest priority as accepted encoding for all requests. Related functions - <code> WP_Http_Encoding::is_available() </code> and <code> WP_Http_Encoding::accept_encoding() </code> . Is there any hook or other option to control this that I am missing?
|
Quite an edge case, but the accepted encoding types should be filterable nonetheless. I can see a few situations where fine, granular control over this header would be useful (as in adding an API that uses non-standard encoding). So, while there's no stock hook for this, I have created a Trac ticket for it and submitted a patch . If you voice support on the ticket, maybe we can raise enough noise to get it incorporated into a future release.
|
How to control accept encoding on HTTP API requests?
|
wordpress
|
I'm getting confused trying to implement these custom theme hooks. Trying to wrap my head around that. I thought i understood this. but now after reading code for several hours; it's made it worst. How do i modify the argument being passed in the following? <code> functions.php </code> <code> function theme_content() { do_action('theme_content'); // Initialize my custom hook } function theme_content_alter($arg) { // Do processing if (!$arg) { echo '<h2>default</h2>'; } if ($arg == 'foo') { echo '<div class="content">bar</div>'; } echo apply_filters('theme_content','theme_content_alter', $arg); } add_action('theme_content', 'theme_content_alter'); </code> <code> index.php </code> <code> theme_content($arg = 'foo'); </code> What i'm trying to achieve Being able to override hooks and handle contextual processing inside a functions or a separate file from a require. An example: on a front page i want theme_content() to have no sidebar but on a subpage it'll contain a sidebar, etc. This could be expressed like so: Is this the proper way to do this? I've tried to write it in my theme and haven't been able to figure out why it's not working. My arguments are not being passed in the parameters. What i have done Reviewed several threads on this SE and found them not very helpful for my context: stackexchange-url ("Explanation for apply_filters function and its variables") stackexchange-url ("get_template_part vs action hooks in themes") stackexchange-url ("Difference Between Filter and Action Hooks?")
|
If you want <code> theme_content </code> hook to run with arguments that you pass to <code> theme_content() </code> function you need to write it like this: <code> function theme_content($args) { do_action('theme_content', $args); } </code>
|
Custom theme hooks / filters - passing arguments
|
wordpress
|
<code> Your `warmHome_cutstr` function causes in the inline stylesheet of the gallery to be displayed. See gallery-post.jpg.[http://themes.trac.wordpress.org/attachment/ticket/4560/gallery-post.jpg][1] To solve this, you need to hook into the_content and remove the gallery shortcode. In functions.php: add_filter( 'the_content', 'warmHome_content_filter' ); function warmHome_content_filter( $text ) { $text = strip_shortcodes( $text ); return $text; } </code> the following is my <code> warmHome_cutstr </code> function. how to correct it. i have added the above function. but don't know how to remove the gallery shortcode. <code> function warmHome_cutstr($string, $length) { $string =strip_tags($string); $strcut= ''; if(strlen($string) > $length) { preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $string, $info); $j = 0; for($i=0; $i<count($info[0]); $i++) { $strcut .= $info[0][$i]; $j = ord($info[0][$i]) > 127 ? $j + 2 : $j + 1; if ($j > $length - 3) { return $strcut." ..."; } } return join('', $info[0]); } else { return $string; } } </code>
|
To remove the Gallery Short-code completely add this to your themes function.php file: <code> remove_shortcode('gallery', 'gallery_shortcode'); </code>
|
how to remove the gallery shortcode in wordpress?
|
wordpress
|
How do I skip wordpress's 404 handling and redirect all 404 errors for static files to 404.html? I read and it seems its not possible when using permalinks? The objective is to reduce the server load for 404 errors by not loading php.
|
.htaccess skip WordPress 404 error handling for static files . <code> <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(robots\.txt|sitemap\.xml(\.gz)?) RewriteCond %{REQUEST_FILENAME} \.(css|js|html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ [NC] RewriteRule .* - [L] </IfModule> </code> Note: These rules were generated by the W3 Total Cache plugin* Nginx skip WordPress 404 handling for static files. <code> if (-f $request_filename) { break; } if (-d $request_filename) { break; } if ($request_uri ~ "(robots\.txt|sitemap\.xml(\.gz)?)") { break; } if ($request_uri ~* \.(css|js|html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$) { return 404; } </code>
|
How do I skip wordpress's 404 handling and redirect all 404 errors for static files to 404.html?
|
wordpress
|
Is there any way to get only parent terms from custom taxonomy or category?
|
Yes, just pass in the parent parameter to <code> get_terms </code> when you call it, as Michael pointed out. <code> $myterms = get_terms( 'taxonomy_name_here', array( 'parent' => 0 ) ); </code> Will return all terms that have a parent value of <code> 0 </code> , ie. top level terms.
|
How can I get only parent terms?
|
wordpress
|
For efficiency we are trying to hook some JS scripts only a certain page template of a theme that is to hold a form: page-with-form.php On the theme functions.php we've defined a init_method as such: <code> function my_init_method(){ $dir = get_bloginfo('stylesheet_directory')."/js/jquery.js"; wp_deregister_script('jquery'); wp_register_script('jquery',$dir); wp_enqueue_script('jquery'); $dir = get_bloginfo('stylesheet_directory')."/js/jquery.validate.min.js"; wp_deregister_script('jquery.validate.min'); wp_register_script('jquery.validate',$dir); wp_enqueue_script('jquery.validate.min'); $dir = get_bloginfo('stylesheet_directory')."/js/funcion.js"; wp_deregister_script('funcion'); wp_register_script('funcion',$dir); wp_enqueue_script('funcion'); } </code> We then expected we could just add at the firts line of page-with-form.php page template (before get_header()) : <code> add_action('init', 'my_init_method'); </code> Is this not possible? Are we forced to add an if rule to the functions.php function to detect that we are on that page? Code modifications based on answers: On the page template load the function directly, no need to add_action("init"... <code> my_init_method(); ... get_header(); </code>
|
<code> init </code> is much earlier than page template loading and not appropriate place for enqueues (despite many tutorials and docs using it for that). Hook your function to <code> wp_enqueue_scripts </code> and make sure you are doing that hooking before <code> wp_head() </code> call in template.
|
Conditional wp_enqueue_script on a page
|
wordpress
|
I often need to link to custom taxonomy term archive pages and would love to be able to do so through the AJAX internal link navigator added to the visual editor in 3.1. Is there any way to get this functionality, with either with a plugin or non-colossal changes to the core?
|
Right now there are no hooks to do that from a plugin and the function that makes the search query itself is not pluggable which means that the only way to achieve that is to hack core files. Currently there is an open Trac Ticket asking for some kind of hook.
|
Getting archive pages in WP's AJAX internal link finder?
|
wordpress
|
Is it possible to include an entire flat-file HTML site (.html, folders/ and CSS) inside WordPress? Essentially, I want to host an HTML site, but have access to WP functions and plugins. Not to interested in a iframe solution as that would break the look of the URLs on the browser address bar. Can I include the html site in WP? Or perhaps include WP in the HTML (with some PHP .htaccess extension magic)?
|
First you need site to be processed as PHP, since WP simply won't work otherwise. I think you can do it for non-.php extensions by tinkering with server config. THen see Integrating WordPress with Your Website in Codex. You can load WP core to required degree and use the functions. However I'd consider just migrating site to WP completely.
|
Is it possible to include an HTML flat-file website inside a WordPress theme?
|
wordpress
|
Right now, I have this code: <code> function mr_np_activate(){ // hook uninstall if ( function_exists('register_uninstall_hook') ) register_uninstall_hook(__FILE__,'mr_np_uninstall'); } register_activation_hook(__FILE__,'mr_np_activate'); /** * Delete options * **/ function mr_np_uninstall() { delete_option('my_plugins_options'); } </code> But when I remove my plugin, all my options are there. (I made another plugin just to show my options). How can I delete options when plugin is removed? []'s Homem Robô
|
You could always use an uninstall.php file for the plugin instead. http://codex.wordpress.org/Function_Reference/register_uninstall_hook If the plugin can not be written without running code within the plugin, then the plugin should create a file named 'uninstall.php' in the base plugin folder. This file will be called, if it exists, during the uninstall process bypassing the uninstall hook. When using 'uninstall.php' the plugin should always check for the WP_UNINSTALL_PLUGIN constant, before executing. The WP_UNINSTALL_PLUGIN constant is defined by WordPress at runtime during a plugin uninstall, it will not be present if 'uninstall.php' is requested directly. That file would only need literally one line of code if the only intention is to remove an option. <code> <?php delete_option( 'your-option' ); ?> </code> Not actually addressing your question, just offering an alternative approach for dealing with plugin deactivation. As to the problem, i think the issue is you're trying to add the deactivation callback during the activation hook, which just seems a little backward or incorrect to me, i'd assume deactivation hooks should be registered in the same way as the activation hook, but neither nested inside the other.
|
How can I delete options with register_uninstall_hook?
|
wordpress
|
If I upload a given image like my-image.jpg, then following image resizes occurs: http://www.mysite.com/wp-content/uploads/YEAR/MONTH/my-image-100x100.jpg http://www.mysite.com/wp-content/uploads/YEAR/MONTH/my-image-200x150.jpg http://www.mysite.com/wp-content/uploads/YEAR/MONTH/my-image-500x300.jpg also the original image is uploaded: http://www.mysite.com/wp-content/uploads/YEAR/MONTH/my-image.jpg I have two question about which actions try to: 1 Question Rename image name to a complicated long name like 5702703214_85bfb55948.jpg: <code> http://www.mysite.com/wp-content/uploads/YEAR/MONTH/5702703214_85bfb55948.jpg http://www.mysite.com/wp-content/uploads/YEAR/MONTH/5702703214_85bfb55948-100x100.jpg http://www.mysite.com/wp-content/uploads/YEAR/MONTH/5702703214_85bfb55948-200x150.jpg http://www.mysite.com/wp-content/uploads/YEAR/MONTH/5702703214_85bfb55948-500x300.jpg </code> 2 Question Avoid access to original image uploaded, let access to thumb, medium and large, but deny access just only to the original image uploaded? Thanks in advance
|
create shortened URL function, then add filter on the_content() to replace all img src URL to shortened URL
|
Complicated image name like flickr does and deny access just to original image
|
wordpress
|
Lately I've been reading about MariaDB and Percona Server , two strong alternatives to MySQL that have gained popularity since Oracle bought Sun. As far as I know, both of them could be used with WordPress, but I'd like to know if anyone uses them, and if they really help make our blogs and servers run better than they did with MySQL.
|
I have personally worked with Percona Server and MySQL, not with MariaDB as of yet. Percona provides support for MariaDB, Drizzle, Amazon RDS, and other MySQL products . I learned at Percona Live NYC that Percona gets the latest version of MySQL and injects 30,000 lines of C/C++ that is unique to its Performance Enhancements. MySQL (eh, Oracle) tries to keep up with its own enhancements of InnoDB. Unless your website is very heavily trafficked, there is no decent performance difference you can feel or see. However, if you do have high traffic and you want to stackexchange-url ("compare MySQL, Percona, and MariaDB, I have posted an article in the DBA StackExchange on how to go about doing this").
|
The MySQL alternatives: Do Percona Server and MariaDB work well with WordPress, and do they make WordPress go better?
|
wordpress
|
When you want to associate an image to a post which already has its own featured image, you have to use a custom field : you upload an image just as if you wanted to add an image inside your post, but then you just copy the image URL, click cancel, and put the image URL in the custom field value : burdensome. Is it possible to do that automatically without any need to copy and paste any URL, like having another featured image, but with a specific name and having the properties of a custom field ? I hope my question is understandable.
|
You can add 2nd featured image using Multiple Post Thumbnails plugin, make sure to follow the installation instruction.
|
Add an image box besides featured image?
|
wordpress
|
I'm working on a new Wordpress theme; the default index view displays the excerpts of recent posts. Some posts will be regarding file downloads, and include an image, description, and link to the location where the described files are hosted. The images for these types of posts will be anchored with links(other types of posts may contain images that are not linked). For these types of posts, I would like the images to link to their entry's full post views(single.php) when displayed in excerpts, but for the same images to link to an external download link when displayed as part of the full post view.(The links that point to an external url point to another page that hosts the files, and not to the actual files directly.) I'm not sure how exactly I would accomplish that. Any help would be greatly appreciated!
|
Because I don't have post thumbnails defined, and since posts may or may not contain multiple images, I ended up doing it this way: I turned off tags in excerpts(I had an excerpt plugin enabling tags in excerpt), then I added the following to the function.php file: <code> function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=['"]([^'"]+)['"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //Defines a default image $first_img = "/images/default.jpg"; } return $first_img;} </code> Then I added the following to the main index template file in between the posts title and the excerpt/content: <code> <p><a href="<?php the_permalink() ?>" alt="<?php _e('Read full article', 'theme');?>" title="<?php _e('Read full article', 'theme');?>"><img src="<?php echo catch_that_image() ?>"></a></p> </code> Random note: It's wrapped in a for styling reasons. Thanx again for guiding me in the right direction.
|
Dynamic Image Links Depending on Excerpt/'Single Post' View
|
wordpress
|
I am trying to create two functions, one that catches the first paragraph of some content, and one that catches the rest, but I have hit a bit of a conundrum. I have this in my single.php: <code> <div class='the_content'> <?php the_content(); ?> </div> </code> which produces: <code> <div class="the_content"> <p>The content .....</p> <p>The content .....</p> <p>The content .....</p> </div> </code> each paragraph all nicely wrapped in a <code> <p> </code> tag. I assumed that I could simple break the <code> explode() </code> the content based on the string <code> </p> </code> , theoretically splitting the content into paragraphs, but all the content is in the first resulting array element. I investigated, and there are no <code> <p> </code> tags in either the HTML edit, or indeed the database entry. Both look like: <code> The Content ..... The Content ..... The Content ..... </code> Note: Line breaks present, but not <code> <p> </code> tags. Where does Wordpress add the <code> <p> </code> back in? How does it find the line breaks and how can I hook a function into that? FYI Here is the function that fails, based closely on the <code> the_content() </code> function: <code> function get_first_paragraph(){ $content = $firstcontent = get_the_content(); $content = str_replace(']]>', ']]&gt;', $content); $content = explode('</p>',$content); return $content[0]; } </code>
|
The paragraphs are done by the <code> wpautop() </code> function, hooked to <code> the_content </code> , <code> the_excerpt() </code> & <code> comment_text </code> as well as <code> 'term_description' </code> for taxonomies. The plugin linked by @javipas does an enormous effort to just add this, but it's a good example (+1). You can (modify it a little and) take the following part out of it: <code> // The init function function wpse24553_add_p_the_content() { add_filter( 'the_content', 'wpse24553_p_the_content' ); add_filter( 'the_content_feed', 'wpse24553_p_the_content' ); } add_action( 'init', 'wpse24553_add_p_the_content' ); // The actual modification function function wpse24553_p_the_content( $the_content ) { global $post; $content_by_p = preg_split( '/<\/p>/is', $the_content ); $i = 0; // Set a var to count until the targeted <p> is met - change this to your needs // Set to empty '' if you want to modify every paragraph $targeted_p = 1; static $new_content = ''; foreach ( $content_by_p as $key => $p ) { $i++; // abort and return the modified content if we're beyond the targeted <p> if ( $i > $targeted_p ) { $new_content .= $p; continue; } // Remove empty space at the end of a paragraph, then remove original <p>-tag $p = rtrim( $p ); $p = preg_replace( '/<p>/is', '', $p ); // Wrap replacements in new <p>-tags, so it validates $new_content .= '<p class="paragraph-link"><a name="p-'.$key.'"></a>'; // Prepend the graf with an anchor tag $new_content .= '<a ref="permalink" title="Permalink to this paragraph" href="'.get_permalink( $post->ID ).'#p-'.$key.'">#</a>; $new_content .= $p; $new_content .= '</p>'; } // Return the new content return $new_content; } </code> Notes: The function needs to be placed in your functions.php You need to alter the function and what gets added/removed/modified with a single paragraph by yourself (no use case in the Q). The function currently is not tested.
|
Finding the paragraphs in content
|
wordpress
|
There's a <code> wp_blogs </code> table which is very usefull when you want to get a list of blogs (and this is what I need to do). The problem is that I can't seem to be able to get the blog language from the <code> lang_id </code> field within that table. It just doesn't match the <code> WPLANG </code> option which set in each blog's option table. Yes, I could switch to each blog and do a <code> get_bloginfo('language') </code> , but that's quite expensive when you have a large number of blogs. So what's up with that <code> lang_id </code> field? What is it for?
|
I don't know what the lang_id option is for. AFAIK it is not part of the core WordPress options. If you want to check the language of all blogs you could check the blog's own options table for WPLANG, or use the network's WPLANG option (or fail with a locale you need) in a similar way as WordPress' own get_locale() function. I'd recommend to check out the WordPress source code. You'll see that the get_bloginfo() function is basically a wrapper for getting options or calling other functions to retrieve the requested data. In the case of the 'language' parameter it calls the get_locale() function which resides in wp-includes/l10n.php See: http://phpxref.ftwr.co.uk/wordpress/nav.html?_functions/index.html Looking at the get_locale() function it shows that in order to retrieve the locale/language of a site in a WordPress multisite setup it will: Check if the locale was set and return this after applying the 'locale' filter If the locale variable was not set it will check the WPLANG option in the WordPress default (per-site) options. If the site's own WPLANG option is empty or does not exists it will check the network's options for the WPLANG option. If all fails assume the locale is en_US
|
Getting a blog language (site "lang_id" field vs the WPLANG setting)
|
wordpress
|
I would like the Wordpress page link as shown here go to an external URL instead of going to page. What is the best way to set this up? I'm running Wordpress 3.1.3. Thank you.
|
Goto Appearance -> Menus -> Create a new menu -> Add your link as custom link
|
How do I make Wordpress "Page" link in the top nav bar go to an external URL?
|
wordpress
|
I'm building a WordPress theme framework, that will likely have many options as development progresses. I found a related question: stackexchange-url ("When is it appropriate to create a new table in the WordPress database?"), which indicates that a new table would be more efficient, but I'd like to know more. It makes sense that if it's faster to use a new table for a thousand entries, it must also be faster for tens or hundreds of entries. What's more, the wp_options table can become very cluttered. What are the differences in query execution time, memory usage, and other factors between these two options?
|
It makes sense that if it's faster to use a new table for a thousand entries, it must also be faster for tens or hundreds of entries. Performance is not about the pure number rows – the real amount of data and their structure counts. Usually, you use just the theme mod API . Your theme data is on a predictable place and can easily exported or changed by plugins. The theme mod API stores all data in one single option, so a cluttered options table will not be your problem. But if you put very deep arrays or objects in your theme data the (de-)serialization may slow down reading and writing these options. I’d rather work on my data structures in this case than creating a new table. And I’d use a good caching plugin to decrease database queries. If you opt for separate tables – find a good solution for child themes and multi site installations. Imagine a small network with 100 blogs. Do you create a new table for each blog? Or do all blogs share one table? I would use a separate table only if WordPress’ table schema could not map my data structure. In a theme this is probably not the case.
|
Efficiency of wp_options vs a new table
|
wordpress
|
I have a car database that I want to import into Wordpress as taxonomies. The problem is I can't create 2 taxonomies at once (first is parent, last ones are childs of first). $p = wp_insert_term("Acura", "classified-category", array("description" => "Acura")); $c = wp_insert_term("Acura CL", "classified-category", array("parent" => $p["term_id"], "description" => "Acura CL")); print_r($p); print_r($c); returns: Array ( [term_id] => 13 [term_taxonomy_id] => 4720 ) Array ( [term_id] => 2589 [term_taxonomy_id] => 4721 ) But in Dashboard appears just parent category. The problem is similar to this one: stackexchange-url ("Create two categories at once (parent > child)") Any idea ?
|
The issue is with the taxonomy cache. You have to clear it after you insert the terms in order to see them. I had the same issue, which someone answered for me stackexchange-url ("here"): <code> delete_option("classified-category_children"); </code> Insert that after the term inserts and you should be good.
|
wp_insert_term - parent & child problem
|
wordpress
|
This is a simple question, that's probably been asked before. For internal links between pages, is it better to use a relative link or full permalink? Thank you.
|
It depends on what you're talking about. If you're talking about using just <code> <a href="/page-title">Page Title</a> </code> , then no. It's better to use the full link. However, instead of using <code> http://www.domain.com/page-title </code> , it's better to use <code> <?php echo bloginfo('url'); ?>/page-title </code> . The reason you don't want to use relative links is the way wordpress permalinks work. If you're on a sub-page ( <code> domain.com/about/john </code> ) and you use a relative link to another subpage ( <code> href="/jane" </code> ), it will point to the root URL ( <code> domain.com/jane </code> instead of <code> domain/about/jane </code> . UPDATE The full <code> <a> </code> will be <code> <a href="<?php echo bloginfo('url'); ?>/page-title">Page Title</a> </code>
|
Should I use relative or absolute urls when pointing to internal pages
|
wordpress
|
I'm looking for a list of action tags that are relevant when you: create a post, with any method, so basically using wp_insert_post modify a post, like changing status, title, content, terms, meta, anything related to it; remove a post Are <code> save_post </code> and <code> deleted_post </code> enough for this kind of thing?
|
Yes, 'save_post' and 'delete_post' cover everything, except modifying meta and terms associated to a post. Those hooks can be found in wp-includes: <code> meta.php </code> and <code> taxonomy.php </code> , respectively.
|
Actions to use when flushing cache (when posts are added / deleted / modified)
|
wordpress
|
I'm on Ubuntu and using LAMP for local dev. I've several WordPress installations for different project and tried to set custom permalinks on all of them, but only default permalink setting ( <code> http://localhost/wpinstalation/?p=123 </code> ) works, other settings are giving 404 error. Any idea how can I fix this? George
|
I had the same problem. It sounds like you don't have rewrites turned on in your installation. Find your httpd.conf file, find the following line: <code> #LoadModule rewrite_module modules/mod_rewrite.so </code> And remove the # at the beginning so it looks like this: <code> LoadModule rewrite_module modules/mod_rewrite.so </code> Save and then restart the service. Custom Permalinks should now work. There might be an easier way but I'm not familiar with Linux
|
Custom Permalinks don't work on local LAMP installation
|
wordpress
|
Been trying to ask on Wordpress forums, but no hits. I'm hoping there are more people here that can help me. My custom contact form page used to work, but for some reason, it results in a 404 error when I submit my form. I am using custom permalinks (/%category%/%postname%/) and that has never been a problem before. I started off with WordPress 3.0 and I have updated the WordPress a few times and was wondering if any of those updates could have caused this. If not, what would? I'm still working on my theme, but I haven't touched my contact page template for a long time (I separated it from the other pages). <code> if(isset($_POST['submitted'])) { if(trim($_POST['subject']) === '') { $subject = 'No subject'; } else { $subject = trim($_POST['subject']); } if(trim($_POST['author']) === '') { $authorError = 'A valid name is required.'; $hasError = true; } else { $author = trim($_POST['author']); } if(trim($_POST['email']) === '') { $emailError = 'A valid email address is required.'; $hasError = true; } else if (!preg_match("/^((([a-z]|\d|[!#$%&'*+\-\/=?\^_`{|}~]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])+(\.([a-z]|\d|[!#$%&'*+\-\/=?\^_`{|}~]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])|(\\\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])|(([a-z]|\d|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])([a-z]|\d|-|\.|_|~|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])*([a-z]|\d|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])))\.)+(([a-z]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])|(([a-z]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])([a-z]|\d|-|\.|_|~|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])*([a-z]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])))\.?$/iu", trim($_POST['email']))) { $emailError = 'A valid email address is required.'; $hasError = true; } else { $email = trim($_POST['email']); } if(trim($_POST['message']) === '') { $messageError = 'A message is required.'; $hasError = true; } else { if(function_exists('stripslashes')) { $message = stripslashes(trim($_POST['message'])); } else { $message = trim($_POST['message']); } } if(!isset($hasError)) { $emailTo = get_option('admin_email'); $subject_send = '[ from website ] '.$subject; $body = "$message"; $headers = 'From: '.$author.' <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject_send, $body, $headers); $emailSent = true; } $errorClass = ' class="error"'; } </code> and... <code> <form action="<?php the_permalink(); ?>" id="feedbackform" method="post" novalidate> <p> <label for="author">Name</label> <?php if($authorError != '') { ?><label class="error" for="author"><?=$authorError;?></label> <?php } ?><input id="author" name="author" type="text" value="<?php if(isset($hasError)) echo $_POST['author'];?>" title="Your name is required"<?php if($authorError != '') { echo $errorClass; } ?> /> </p> <p> <label for="email">Email</label> <?php if($emailError != '') { ?><label class="error" for="email"><?=$emailError;?></label> <?php } ?><input id="email" name="email" type="email" value="<?php if(isset($hasError)) echo $_POST['email'];?>" title="Your email address is required"<?php if($emailError != '') { echo $errorClass; } ?> /> </p> <p> <label for="subject">Subject</label> <input id="subject" name="subject" type="text" value="<?php if(isset($hasError)) echo $_POST['subject'];?>" title="The subject is optional" /> </p> <p> <label for="message">Message</label> <?php if($messageError != '') { ?><label class="error" for="message"><?=$messageError;?></label> <?php } ?><textarea id="message" name="message" title="Your message is required"<?php if($messageError != '') { echo $errorClass; } ?>><?php if(isset($hasError)) { if(function_exists('stripslashes')) { echo stripslashes($_POST['message']); } else { echo $_POST['message']; } } ?></textarea> </p> <p> <input id="submit" name="submit" type="submit" value="Send Message" /> <input type="hidden" name="submitted" id="submitted" value="true" /> </p><?php if(isset($emailSent) && $emailSent == true) { ?> <p>Your message has been sent. I will reply as soon as possile.</p><?php } ?> </form> </code>
|
As suggested by Bainternet, prefix all the field names.
|
custom contact form no longer working (because of 3.2?)
|
wordpress
|
I have one shortcode that should be always next to the sidebar: <code> // [shortcode] otuput | default sidebar </code> My theme allows me to set different sidebars for each page. So I have sidebars on a few pages, but not everywhere. What's the best/proper way of achieving this goal? I was thinking about adding <code> dynamic_sidebar($sidebar_name) </code> to the shortcode itself, but it doesn't seem to be smart idea (especially with multiple instances of my shortcode at the same page).
|
I'm still not sure exactly what you're trying to do, but here's one possibility if it's to display something like this: PAGE CONTENT | SHORTCODE/POSTS LOOP | SIDEBAR Do you have control of the shortcode content? If so, you could update it so its output is wrapped in a <code> <div id="shortcodecontent"> --shortcode post-loop output-- </div> </code> . Then add a text widget to your sidebar and insert the [shortcode] within it. If shortcodes aren't rendering when inserted in widgets, add the following line to the functions.php file within your theme: <code> add_filter('widget_text', 'do_shortcode'); </code> Now, the shortcode output will appear first, before any of the other widgets in your sidebar. Using CSS, style the wrapping #shortcodecontent div so that your shortcode widget floats to the left of the other widgets in your sidebar. Hope this helps in some way! Best of luck.
|
How to attach sidebar to shortcode's output?
|
wordpress
|
I'm working on a wordpress site and need to have a widget on the sidebar which has thumbnails, but links to URLs specified per thumbnail rather than the images. It seems simple, but I can't find any plugin to do it in a way a non-developer can from the admin panel. Currently the NextGEN gallery plugin is being used. Is there any way to configure that, or any similar plugin, in that manner? How hard would it be to build a plugin from scratch to achieve this, and do you think that's necessary?
|
You could create your own widget that queries posts from a certain category then displays <code> the_post_thumbnail </code> in an unordered list linking to the post. Example widget (add to functions.php): <code> <?php class c3m_thumbnail_posts extends WP_Widget { function c3m_thumbnail_posts() { $widget_ops = array( 'classname' => 'thumbnail-posts', 'description' => 'Displays post thumbnails' ); $control_ops = array( 'id_base' => 'c3m-post-thumbnail' ); $this->WP_Widget( 'c3m-post-thumbnail', 'Post Thumbnail Widget', $widget_ops, $control_ops ); } function widget( $instance ) { echo $before_widget; ?> <h2>Title Goes Here</h2> <?php $args = array( 'cat' => 16, //Replace with category ID of posts to show thumbnail for 'posts_per_page' => 6 //Replace with number of posts to show use -1 for all ); $thumbnail_query = new WP_Query( $args ); ?> <ul class="sidebar-thumbnails"> <?php while ( $thumbnail_query->have_posts() ) : $thumbnail_query->the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a></li> <?php endwhile; ?> </ul> <?php echo $after_widget; } } </code> To modify what posts are used see WP_Query class in the codex.
|
Widget which displays thumbnails, but links to urls?
|
wordpress
|
For a client we'll need 29,000 terms (all the highschool's in the US) and each term needs 6 meta items (address, phone...). My initial thought was to store the term meta information as suggested in this post but after looking through it again I will be using lots of terms and I wonder if it will overload the options table. Is there a good time to create a new table? Would this qualify? Other thoughts on how to relate the HS that a person attends to the 'post' that will be their academic profile? It was suggested that I make the 'terms' a Custom Post Type. I'm not opposed to that either but I fail to see how I'll relate the CPT to multiple 'authors' since a school will have more than one student that attends it. Because of the multiple ownership of the content terms just seemed to fit better.
|
As the article mentions, using wp_options is not a good idea when you have thousands of terms, mainly because there's: a lot of serialization involved OR long option names (the limit is 64 characters) In this particular case, yes, it's appropriate to create some custom tables. To save time, you can use this plugin (update more recently than Simple Term Meta): http://wordpress.org/extend/plugins/taxonomy-metadata/ Having said that, it looks to me like a custom post type would be better suited for this. Take a look at my Posts 2 Posts plugin for relating highschools to whatever you were planning on relating them to.
|
When is it appropriate to create a new table in the WordPress database?
|
wordpress
|
get_page() unlike Loop returns the post content without html tags. I need tags. How can I fix this? I don't want to change wysiwyg editor, here is the bad solution http://wordpress.org/support/topic/preserve-html-with-get_pages
|
I presume you are getting the page content like so: <code> $page_id = 1; $page = get_page($page_id); $content = $page->post_content; echo $content; </code> If thats the case then you can run the content through the <code> the_content </code> filter: <code> $content = apply_filters('the_content', $content); </code> The will process the content as if it was run through <code> the_content() </code> function.
|
get_page() unlike Loop returns the post content without html tags. How can I fix this?
|
wordpress
|
I have made a custom post type for a child theme. I removed "thumbnail" from the supports array in functions.php and that prevents a featured image meta box from being displayed. However, when in the "add an image" modal dialogue thing, there is still a "Use as featured image" link. Why, oh why? More to the point, does anyone know how to remove? I tried... remove_post_type_support( 'itinerary', 'post-thumbnail' ); ...where itinerary is the name of my custom post type. Any help would be greatly appreciated! Steve
|
Some where in your theme you should have: <code> add_theme_support( 'post-thumbnails' ); </code> Instead of removing support for a post type try only adding support for the post types you want: <code> add_theme_support( 'post-thumbnails', array( 'post', 'movie' ) ); </code>
|
How to remove "featured image" functionality from a custom post type?
|
wordpress
|
My blog have 2 categories: Photos and Texts. I would like do customize the category template so that when it renders Photos post's, I want to show a thumbnail gallery and when it renders Texts post's, I want show only the excerpt. There is an way to do this without hardcoding on category.php? Or, at least, how is the best way to do this? Thank you!
|
create category templates ; i.e. category-photos.php and category-texts.php; starting with a copy of the code from category.php. you will still need to hard-code the changes in each template.
|
How to custom category template based on category?
|
wordpress
|
I'm trying to create <code> <div class="cat-hidden categories"></div> </code> where <code> categories </code> is a list of the categories the current post is posted in. When just using <code> the_taxonomies() </code> , it outputs something like this: <code> <div class="cat-hidden Job Type: &lt;a href='http://www.cirkut.net/wp/libertyguide/genre/early-career/'&gt;Early-Career&lt;/a&gt;, &lt;a href='http://www.cirkut.net/wp/libertyguide/genre/internship/'&gt;Internship&lt;/a&gt;, &lt;a href='http://www.cirkut.net/wp/libertyguide/genre/other/'&gt;Other&lt;/a&gt;, and &lt;a href='http://www.cirkut.net/wp/libertyguide/genre/web-developmentit/'&gt;Web Development/IT&lt;/a&gt;."></div>` </code> Whereas I want it to output something similar to this: <code> <div class="cat-hidden Early-Career Internship Web-Development/IT"></div> </code> That means I'm going to also have to parse the categories that are outputted because I need <code> Web Development/IT </code> to be <code> Web-Development/IT </code> or <code> Web-Development-IT </code> . I'm unsure about the <code> / </code> being in there because I think CSS doesn't allow a <code> / </code> . That's where you experts come along. I am very proficient in HTML and CSS, and know some PHP and Wordpress, but I don't know where to begin. If any more info is needed, please let me know. Thank you!
|
you can use <code> wp_get_post_terms() </code> to get a list of the post categories and just output the category slug which is already phrased for you, something like this: <code> //in your loop echo '<div class="cat-hidden'; $cats = wp_get_post_terms($post->ID,'category'); foreach($cats as $cat){ echo ' '.$cat->slug; } echo '"></div>'; </code>
|
Use the_taxonomies() to create a simple list
|
wordpress
|
I am trying to create a nonce to use with a (public-facing) form. Below is my code: <code> function my_form() { if (isset($_POST['submit'])) { $name = $_POST['name']; $description = $_POST['description']; $output_form = false; if (wp_verify_nonce($_POST['added'], 'add-item') ) { //validate echo 'form submitted with nonce correctly'; } } else { $output_form = true; } if ($output_form) { ?> <form method="post" action=""> <?php wp_nonce_field('add-item','added'); ?> <label>Title:</label><br/> <input type="text" name="name" value="<?php echo $name; ?>"/><br/> <label>Description:</label><br /> <textarea name="description" rows="3" cols="10"><?php echo $description; ?></textarea><br/> <input type="submit" name="submit" value="submit"> </form> <?php } } add_shortcode('PODS FORM', my_form); </code> I can see my form on my page, but when I submit (and fill it our correctly) instead of seeing my 'correct' message I am only seeing blank page.
|
You need to pass the value of the nonce field as first argument to wp_verify_nonce . So, you need to modify the nonce verification part in your code. Also you were using form fields names that conflicts with internal wordpress query vars, you should prefix them with something unique so they do not conflict with wordpress. See following example: <code> function my_form() { if (isset($_POST['pf_submit'])) { $name = $_POST['pf_name']; $description = $_POST['pf_description']; $output_form = false; if (isset( $_POST['pf_added'] ) && wp_verify_nonce($_POST['pf_added'], 'add-item') ) { //validate echo 'form submitted with nonce correctly'; } } else { $output_form = true; $name = ""; $description = ""; } if ($output_form) { ?> <form method="post" action=""> <?php wp_nonce_field('add-item','pf_added'); ?> <label>Title:</label><br/> <input type="text" name="pf_name" value="<?php echo $name; ?>"/><br/> <label>Description:</label><br /> <textarea name="pf_description" rows="3" cols="10"><?php echo $description; ?></textarea><br/> <input type="submit" name="pf_submit" value="submit"> </form> <?php } } add_shortcode('PODS FORM', my_form); </code>
|
Help with forms and nonces
|
wordpress
|
I use custom category templates for a few of my categories. Ex: cat-12.php and so on. I use the Fv Simpler Seo and presently it doesnt seem to support an option to edit category templates. Considering that I use custom category templates, is there a function or a way I include custom meta description and custom title (over riding the default category name that is picked up as the title) without having to use a plugin?
|
for meta description of the category you can use followinf dunction <code> //META DESCRIPTION FUNCTION function seometadescription(){ global $post, $posts; if ( is_single() || is_page() ) : $customDesc = 'meta_desc'; if ( have_posts() ) : while ( have_posts() ) : the_post(); $descriere = get_post_meta($post->ID, $customDesc, true); endwhile; endif; elseif( is_category() ): $descriere = category_description(); elseif( is_front_page() ) : $descriere = 'some words for front page description'; endif; $customMetaDesc = '<meta name="description" content="'.$descriere.'" />'; echo $customMetaDesc; } // end meta desc function </code> $customDesc = is a custom field that I used for post and pages description If you have not ser a page as front page replace is_front_page() with is_home For META keywords I found a function on this web site
|
How to add meta description, keywords, custom title to a category template
|
wordpress
|
Example: video cat id = 4 video cat child category id's = 7,8,9 news cat id = 5 news cat child category id's = 11,12,13 I wanna display choosen categories ( like video and news ) in the different archive.php? Is it possible thanks. ( sorry about my bad Eng ) Thanks for Chris S but its not what i want to do. <code> <?php $catPosts = new WP_Query(); $catPosts->query( array( 'category__and' => array(5,11,12,13), 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC' ) ); while ($catPosts->have_posts()) : $catPosts->the_post(); ?> <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1> <div class="meta"> By <?php the_author() ?> </div> <div class="content"> <?php the_excerpt(); ?> </div> </code> When I wrote the parent category id, i dont wanna write its child category id's. When i choose the parent category id the system should its child category ids in the same archive page.
|
Create 2 pages category-news.php & category-video.php & put this code in them. Then customize the markup for both as you like <code> <?php $children = get_categories('child_of'=>get_query_var('cat')); $cat = array(get_query_var('cat')); foreach($children as $child) $cat[] = $child->term_id; $catPosts = new WP_Query( array( 'category__in' => $cat, 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC' ) ); while ($catPosts->have_posts()) : $catPosts->the_post(); ?> <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1> <div class="meta"> By <?php the_author() ?> </div> <div class="content"> <?php the_excerpt(); ?> </div> </code>
|
Creating archive pages for children categories
|
wordpress
|
Let me preface this by saying that I hardly ever work with WordPress - in fact, the last time I did a site in WordPress was back during 2.2. Yesterday I made quite a mess of everything and asked several questions here trying to get a basic menu plugin working. I now have the plugin fully functional and behaving exactly as I expect, so I decided to make minor changes here and there to add functionality and compatibility - including using the Settings API. However a very short moment into reading tutorials on this API and I became quite confused, then this confusion only deepened as I read on and tried to implement the examples - which was made even more difficult by the fact that my plugin is implemented as a class. Unless I'm doing something wrong, from what I understand to use the Settings API requires the creation of a new function PER SETTING. This means 3-5 functions for the average plugin, and up to hundreds for more advanced plugins. It just seems ludicrous to write this many functions (and develop a naming system to keep from confusing them) when you could just as easily import all applicable <code> $_POST </code> variables into an array and forego the entire mess. Perhaps I'm old-fashioned, but unless there's something to gain from it I don't see the reason to triple or quadruple how much code I'm writing. Here's how I managed options before attempting to add the Settings API: <code> function __construct() { /* constructor stuff */ $this->options = $this->db_options = get_option( 'de-menu-options' ); if( $this->options === false ){ $this->options = $this->defaults; } if (is_admin()) { add_action('admin_menu', array(&$this, 'admin_menu')); } /* more stuff */ // When WordPress shuts down we store changes to options add_action('shutdown', array(&$this, 'update')); } public function admin_menu() { add_options_page('DE Menu Options', 'DE Menu', 'manage_options', 'de-menu-options', array(&$this, 'options')); add_option('de-menu-options', $this->options); } public function options() { if (!current_user_can('manage_options')) { wp_die( __('You do not have sufficient permissions to access this page.') ); } if ( !empty($_POST) && check_admin_referer('de-menu-options') ) { // These options are saved to the database at shutdown $this->options = array( "columns" => $_POST["de-menu-columns"], "maintenance" => $_POST["de-menu-maintenance"] ); echo 'DE Menu options saved'; } ?> <div class="wrap"> <h2>DE Menu Plugin</h2> <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> <?php settings_fields('de-menu-options'); ?> <input type="checkbox" name="de-menu-maintenance" /> <label for="de-menu-columns">Columns:</label> <input type="text" name="de-menu-columns" value="<?php echo $this->options['columns']; ?>" /> <p class="submit"> <input type="submit" name="de-menu-submit" value="Update Options »" /> </p> </form> </div> <?php } function update() { // By storing all changes at the end we avoid multiple database calls $diff = array_diff( $this->options, $this->db_options ); if( !empty( $diff ) ){ update_option('de-menu-options', $this->options); } } </code> Now with the settings API I have something more like the following: <code> function __construct() { /* constructor stuff */ // Do I load options? Will they be loaded for me? Who knows? if (is_admin()) { add_action('admin_menu', array(&$this, 'admin_menu')); add_action('admin_init', array(&$this, 'admin_init')); } /* more stuff */ // Settings API should update options for me... I think } public function admin_menu() { add_options_page('DE Menu Options', 'DE Menu', 'manage_options', 'de-menu-options', array(&$this, 'options')); add_option('de-menu-options', $this->options); } public function admin_init() { register_setting('de-menu-options','de-menu-options',array(&$this,'validate')); add_settings_section('de-menu-main-options', 'Main Settings', 'options_section', 'de-menu-options'); add_settings_field('de-menu-maintenance', 'Maintenance Mode', array(&$this,'options_maintenance'), 'de-menu-options', 'de-menu-main-options'); add_settings_field('de-menu-columns', 'Columns', array(&$this,'options_columns'), 'de-menu-options', 'de-menu-main-options'); } public function options() { if (!current_user_can('manage_options')) { wp_die( __('You do not have sufficient permissions to access this page.') ); } if ( !empty($_POST) && check_admin_referer('de-menu-options') ) { // These options are saved to the database at shutdown $this->options = array( "columns" => $_POST["de-menu-columns"], "maintenance" => $_POST["de-menu-maintenance"] ); echo 'DE Menu options saved'; } ?> <div class="wrap"> <h2>DE Menu Plugin</h2> <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> <?php settings_fields('de-menu-options'); ?> <?php do_settings_sections('de-menu-options'); ?> <p class="submit"> <input type="submit" name="de-menu-submit" value="Update Options »" /> </p> </form> </div> <?php } public function options_section() { echo '<p>' . __('Main description of this section here.','de-menu-lang') . '</p>'; } public function options_maintenance() { echo "<input id='de-menu-maintenance' name='options[maintenance]' type='checkbox' />"; } public function options_columns() { echo "<input id='de-menu-columns' name='options[columns]' type='checkbox' value=".$this->options['columns']."/>"; } function validate($options) { return $options; // I guess? } </code> It's probably painfully obvious from the scrollbars that the code is already longer with just two options. It's like-wise obvious from the comments that I don't entirely understand what I'm doing. Then there's the matter of having 5 new functions (and removing only 1) in order to accomplish all of this. So just what advantage am I gaining from all of this extra work?
|
My point of view is that main purpose and benefit of Settings API is structure . It helps to keep complex settings setups: orderly (logic of registration and sections); secure (nonces, validation callbacks); extensible (hooking into another page or allowing to be hooked into). As with any such structural overhead it benefits more complex use cases and benefits less simple ones. So you do can implement anything Settings API does without using it. The question is if you can accomplish that in as reliable, secure and extensible way.
|
What are the advantages to the Settings API?
|
wordpress
|
I wasn't sure if this was a PHP issue (suited for StackOverflow) or a WordPress issue (suited for StackExchange), however since my issue appears to be with the <code> add_action() </code> function, I have placed the question here. Here's some simplified code which causes the same issue (to avoid re-posting my couple-hundred line plugin): <code> <?php $class = new MyClass(); add_action('init', array($class, 'init')); class MyClass { public static function init() { $this->core(); } public static function core() { echo "I never get this far..."; } } ?> </code> I get the following error: Fatal error : Using $this when not in object context in /home/coupon/public_html/wp-content/plugins/test.php on line 7 If my <code> add_action() </code> call were instead: <code> add_action('init', 'MyClass::init'); </code> Then I would understand this error (since the function was called statically and there is no instance of DEMenu for <code> $this </code> to point to), however I don't understand why this is happening since I used an array and passed an instance of the class. My specific issue is actually related to this problem. I created a custom Walker class then used the <code> wp_nav_menu_args </code> filter to pass my custom Walker. I get this error in <code> class-wp-walker.php </code> on line 185 . The line in particular is: <code> $id_field = $this->db_fields['id']; </code> Any ideas? EDIT - <code> test.php </code> is now functioning properly, but the original issue is not solved... As such here's my plugin's index.php file (simplified): <code> $DEMenu = new DEMenu(); class DEMenu { function DEMenu() { if (is_admin()) { add_action('admin_menu', array(&$this, 'admin')); } else { add_action('init', array(&$this, 'core')); } } public function admin() { /* Not important */ } public function core() { add_filter('wp_nav_menu_args', array(&$this, 'add_walker')); } public function add_walker( $args ) { $args['walker'] = 'DEMenu_Walker'; return $args; } } class DEMenu_Walker extends Walker_Nav_Menu { function __construct() { die("We made it to the constructor!"); } } </code> As mentioned above, I am getting the following error: Fatal error : Using $this when not in object context in /home/coupon/public_html/wp-includes/class-wp-walker.php on line 185 Since the above <code> test.php </code> was failing and since the <code> Walker_Nav_Menu </code> class never has this error normally (not until I added my plugin) I figured the issue was with the one of my <code> add_action() </code> or <code> add_filter() </code> calls. However since it is still failing I'm not entirely sure where the issue is... FINAL EDIT - Carefully re-reading the <code> walk_nav_menu_tree() </code> function, I have found the issue with my walker class... <code> function walk_nav_menu_tree( $items, $depth, $r ) { $walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker; $args = array( $items, $depth, $r ); return call_user_func_array( array(&$walker, 'walk'), $args ); } </code> Since <code> $walker </code> is being set to <code> $r->walker </code> it is a string, not an instance of a class. Therefore the class method is called statically instead of via an instance of the class. Instead of: <code> $args['walker'] = 'DEMenu_Walker'; </code> I should have: <code> $args['walker'] = new DEMenu_Walker(); </code> Task : Call a class method as a hook for a WordPress plugin so that the <code> $this </code> variable is not broken
|
Try: <code> <?php $class = new MyClass(); class MyClass { public function MyClass() { add_action('init', array($this, 'core')); } public static function core() { echo "I never get to here"; } } ?> </code>
|
add_action with a class method is causing fatal errors
|
wordpress
|
I created a custom post type for my blog, to allow easier separation of content. This new post type supports different post formats, but most of them will be galleries. <code> register_post_type('atelier', array( 'label' => 'L'Atelier', 'public' => true, 'supports' => array('title', 'editor', 'post-formats') ) ); </code> I saw that it is possible in Settings -> Writing to set the default post format for posts, is it possible to do the same for my newly created post type?
|
One option would be to modify the global Default Post Format setting, via <code> Dashboard -> Settings -> Writing </code> . Note that this setting is global , so it would set the default for all post types that support Post Formats. If you have no need of post formats for blog Posts, you could simply enable post-format support only for your custom post type, by removing post-format support for blog posts: <code> <?php remove_post_type_support( 'post', 'post-formats' ); ?> </code> (Untested, but I see no reason why it shouldn't work.)
|
How to set a default format for a custom post type?
|
wordpress
|
I have 2 kinds of users... Both uses custom form for registeration.... One is parent user and another is child users. Parent user can register and then login and create child users. I have also given interface in theme where parents can manage child users data created by them. Basically site is based on article for childs helping them in education and question answer.... What i want to do is when parent is login , i have list of his child users, want to give link like Login as child, on click of which parent gets logout and get logged in as child using child credential... Any tips/suggestion how to achive logout and login as different user using script...
|
To login as a user you just need the target user ID and these two functions: <code> wp_set_current_user( $user_id ); wp_set_auth_cookie( $user_id ); </code> If you do this mid-page, make sure you refresh it to reflect the changes.
|
To be able to login as different user
|
wordpress
|
I'm planning on using WordPress to create an arcive of my starred/shared/favourited items on a few services, such as: Twitter Favourites YouTube Favourites Google Reader Starred Items Stack Overflow Starred Questions etc. As the data for each type is different, eg video/article/short text what would be the best way of doing this? Would a custom post type or format for each type be the best way? Or does anyone have any suggestions for any themes or plugins which work in a similar way to save me doing all of this from scratch?
|
Now I would suggest to do it with Post Formats. Before there were Post Formats, I made sth similar to what you're looking to do. Although I am not sure whether it is possible to "grab" You Tube Favorites, others should be possible. I actually integrated a lot of social media feeds using the Feed WordPress plugin and Yahoo Pipes where necessary. You can read more on the linked page.
|
WordPress As A Shared Items Collection
|
wordpress
|
I recently completed a WordPress site design, and I'm just struggling with one bug: when a user clicks the "Search" button without any content in the text field, they are redirected to a list of posts. Is there a way to modify this action? Ideally, if the text field is empty, the user will be redirected to the homepage.
|
The default WordPress action is to redirect to the homepage when the search is blank - just what you want! Do you have any plugins or .htaccess settings that may be changing this?
|
Changing the default WordPress search action
|
wordpress
|
Looking at the Codex for wp_insert_post() it states that this function "...sanitizes variables, does some checks, fills in missing variables like date/time, etc. " (EDIT: I updated the Codex entry to include a more robust example that includes security as well as post meta and category assignment) Just wondering whether I need to do any further sanitization to prevent XSS hacks and the like or whether enough is being done through the function. To be honest, I've checked through the function in core and haven't found any wp_kses() or other sanitization on post_content for example, so I'm a little concerned. All I can see that it does is stripslashes_deep() on the data. So should I be running wp_kses() or anything else when I build my arguments to wp_insert_post()? What's the best practice here? The Codex is pretty cavalier about security in its example. Thanks
|
You don't have to do anything. On WP load: <code> 'init' hook -> kses_init() -> kses_init_filters() </code> Later: <code> wp_insert_post() -> sanitize_post() -> sanitize_post_field() -> 'content_save_pre' -> wp_filter_post_kses() </code> Similarly for post titles, comment text etc. Conclusion: wp_insert_post() is very sanitized. :)
|
How safe / sanitized is wp_insert_posts()?
|
wordpress
|
A continuation to this question: stackexchange-url ("Replacing WordPress menu functionality with a plugin") Since I really rarely work with WordPress (I've done a lot of work with phpBB, myBB, Concrete5, and custom PHP scripts - but my WordPress experience is limited to one or two simple sites) I feel that I might get an answer quicker here than spending 3 hours reading through the documentation. I'm creating a plugin to replace the WordPress menu with my own. So far here is the code for this plugin (it's all in a single PHP file): <code> add_action('init', 'DEMenu::init'); class DEMenu { public static function init() { $DEMenu = new DEMenu(); load_plugin_textdomain ('de-menu', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/'); /* Load CSS with wp_enqueue_style() */ // If in admin page, then load admin page stuff if (is_admin()) { add_action('admin_menu', 'DEMenu::admin'); } // If not on admin page ... else { // Load plugin core - doesn't require a hook $DEMenu->core(); } } public static function admin() { add_options_page('DE Menu Options', 'DE Menu', 'manage_options', 'de-menu', 'DEMenu::options'); // add_option('de_menu_maintenance', 'off'); } public static function options() { if (!current_user_can('manage_options')) { wp_die( __('You do not have sufficient permissions to access this page.') ); } echo '<div class="wrap">'; echo '<p>Here is where the form would go if I actually had options.</p>'; echo '</div>'; } public static function core() { /* Add support for various themes */ add_filter('wp_nav_menu', 'DEMenu::display'); /* If I need to add more actions/filters they will go here... I may enqueue CSS here, too */ } public static function display() { print "Let's see if this displays. I'll add some text to ctrl+F for later"; } } </code> This is mostly the culmination of various bits of advice from the WordPress documentation, plugin development tutorials, and basic OOP practices. Now I'm tasked with drawing the menu from the Dashboard > Appearance > Menus area. How can I access this menu object (as an array or other accessible data type) so that I can work with it? And I do realize it seems silly to completely override the <code> wp_nav_menu() </code> output if I'm just going to be using the same menu, however I can think of no other way to accomplish what I want. EDIT - I have been reading through <code> wp-includes/nav-menu-template.php </code> to learn how <code> wp_nav_menu() </code> gets the list of menu items, as well as how it displays it. I have been trying to essentially emulate the method used by this function only with slight variations to add in the multi-column structure. Here is what I have so far: <code> public static function core() { /* Add support for varoius themes */ add_filter('wp_nav_menu', 'DEMenu::display', 1); /* If I need to add more actions/filters they will go here... I may enqueue CSS here, too */ } public static function display( $args ) { /* The following is blatantly ripped from nav-menu-template.php */ // ***************************************************************** /* Excluded for ease of reading - this is an exact copy of nav-menu-template.php */ // ***************************************************************** // Here we can invoke our custom walker without editing the theme $args->walker = 'DEMenu_Walker'; $items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args ); unset($sorted_menu_items); // ***************************************************************** /* Excluded for ease of reading - this is an exact copy of nav-menu-template.php */ // ***************************************************************** // $nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args ); // // if ( $args->echo ) // echo $nav_menu; // else // return $nav_menu; // Rather than checking if we should echo the output, just return it. // This is a filter, so the output will be echo'd by the calling function return $nav_menu; } </code> Then later (outside of the DEMenu class): <code> class DEMenu_Walker Extends Walker_Nav_Menu { function __construct() { die("We made it to the constructor!"); } } </code> However I am getting the following error: <code> Warning: Attempt to assign property of non-object in /home/coupon/public_html/wp-content/plugins/DE-menu/index.php on line 146 </code> This line number is referring to: <code> $args->walker = 'DEMenu_Walker'; </code> Perhaps there is a far more reasonable solution that I have over-looked, however from what I can tell I need a custom walker class (along with private variables for keeping track of how many items have been displayed and how many items should be displayed per column) and this is the only way to use a custom walker class without editing the theme. However if I'm to use the solution that I'm currently working on then I need to understand why the <code> $args </code> variables is a non-object when <code> wp_nav_menu() </code> clearly has the following line of code near the very beginning of the function: <code> $args = (object) $args; </code> ANOTHER EDIT - I solved the non-object problem. When <code> wp_nav_menu() </code> calls the filter it is calling it like so: <code> $nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args ); </code> I failed to realize that this meant it was passing two arguments. I modified the display function like so: <code> public static function display( $nav_menu, $args ){ </code> And of course modified the <code> add_filter() </code> call like so: <code> add_filter( 'wp_nav_menu', 'DEMenu::display', 1, 2 ); </code> Although now I'm getting all sorts of fun new errors. <code> Fatal error: Using $this when not in object context in /home/coupon/public_html/wp-includes/class-wp-walker.php on line 185 </code> Mind you I have made absolutely no modifications to WordPress core, so I don't understand why there's an error in <code> class-wp-walker.php </code> ... I also don't understand why this error is just now showing up. Any ideas? FINAL EDIT - With help from stackexchange-url ("stackexchange-url I have finally realized that I can use the <code> wp_nav_menu_args </code> filter to pass my own walker class without copying the entirety of the <code> wp_nav_menu() </code> function. I will be using this solution (solving this problem), although as mentioned above - I am having a new problem where my walker class is causing its parent class to throw a fatal error. I will make a new question for that since it's an issue with the Walker class and not with accessing menu items or passing a custom walker. Task: I need each sub-menu (second level or lower) to be divided into 5 columns (either 5 separate <code> <ul> </code> elements or <code> <div> </code> elements wrapped around certain <code> <li> </code> elements).
|
First: Use, for <code> options() </code> , the Settings API ( tutorial ). Second: Take a look at the core function and the available filters. Then take a look at the available filters: <code> $sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args ); $items = apply_filters( 'wp_nav_menu_items', $items, $args ); $items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args ); </code>
|
How do I access the menus produced by Dashboard > Appearance > Menus
|
wordpress
|
I've just discovered the WordPress export/import routine under the tools menu. However, upon testing it for the first time, several values stored in my wp_options table did not transfer over. Is there a way to include those values when exporting/importing a site?
|
Simply read the text, the import/export plugins offer: Upload your WordPress eXtended RSS (WXR) file and we’ll import the posts, pages, comments, custom fields, categories, and tags into this site.
|
WordPress Export/Import for custom options.php values?
|
wordpress
|
I'm running a query on a custom plugin to display all categories and put them into a dropdown (the select parts are outside the loop) which looks like this: <code> <?php $ember_categories = get_categories(); foreach($ember_categories as $ember_category) { echo '<option value="' . $ember_category->cat_ID . '">' . $ember_category->name . '</option>'; } ?> </code> For some reason though, it's only returning my default category (Uncategorized) - even though there are six more added to the system (including one I added afterwards, just as a curiosity). I'm wondering whether I'm doing something glaringly wrong?
|
Try <code> get_categories( array('hide_empty' => 0 ) ); </code>
|
get_categories returns an array with one category
|
wordpress
|
I was wondering if there's some constant telling WordPress not to use the minified versions of scripts but instead load .dev ones. Already tried <code> define('SCRIPT_DEBUG', true); </code> but it only turned off script unification.
|
I use a combination of constants on my local install. <code> define('CONCATENATE_SCRIPTS', false); define('COMPRESS_SCRIPTS', false); // <--- this is likely the one you're after define('COMPRESS_CSS', false); define('SCRIPT_DEBUG', true); </code> I'd imagine the second constant listed above is the one you're after.
|
Force core to use .dev JavaScript files
|
wordpress
|
Google announced Page Speed Service , jumping on bandwagon of all-in-one site optimization and CDN. What are the potential issues, when configuring self-hosted WordPress for it? How will setting up reference domain work with WP? Considering that is required for Google to pull content, but public site URL will be different. Will it be possible to set it up with multisite? Should static caching plugins be left enabled or disabled for better compatibility? How will it work with wp-admin and Ajax? Should those be blacklisted in service settings? PS this is intended to be large reference question, so feel free to edit in your own questions on subject
|
Potential Issues Google's Page Speed service does not work with "naked domains". That is, it will not work with just "example.com". The domain name must have a subdomain in front of it, such as "www.example.com". This is due to a limitation on Google's implementation of the Page Speed service, which requires you to set up a CNAME record in your DNS. This is not a generic limitation of the Page Speed system itself, and you can use the open-source mod_pagespeed to achieve the same ends, if you have that level of access to your webhost. So if you do attempt to use the Page Speed service, migrate your entire site to a subdomain setup first. Note that this will affect subdomain installations of multisite setups. Reference Domains The reference domain is only used for DNS lookups. For example, say I'm moving a site at example.com onto their service. The domain example.com lives on the IP address 1.2.3.4. Now, Google Page Speed service needs to know where your actual site is. To do this, they want you to set up a reference domain at ref.example.com pointing to 1.2.3.4. But, they're only using this to get the IP address. When their system actually contacts your domain, it's talking to 1.2.3.4 but setting the Host: header to example.com, not to ref.example.com. So basically, WordPress sees no difference here. It will behave normally. It need know zero about the reference domain. MultiSite Considerations Multisite will work fine with Google's Page Speed service, however only on a subdirectory setup. Subdomain-based setups will not work at all. Google's Page speed service provides proxy services for one domain/site only. However, a multisite in subdirectory configuration essentially is one domain/site as far as Google cares. If you're using multisite with different subdomain names, Google Page Speed service will not work due to their methodology. The requirement for a CNAME record in the DNS eliminates this. You can, however, use the open-source mod_pagespeed instead, which does the same thing but on your own servers instead of through Google's proxy. If you're using multiple domain names with domain mapping, Google is going to consider that to be completely separate sites and will charge or require setup for them accordingly. Static Caching Static Caching plugins can be used with Google Page Speed service, as in this case Google is really acting as a proxy, not as a full caching service. Google Page Speed service will cache several resources such as images, JavaScript and CSS files. However the actual HTML generated by your page will not be cached. Google will retrieve the normal page generated by your server and re-serve it to your users normally, after running it through their Page Speed tools. The wp-admin and AJAX requests If you do nothing special, the wp-admin section will be run through the Google Page Speed proxy too. Since the normal mod_pagespeed seems to have no effect on the wp-admin code, it is unlikely that Google's service will have any effect at all. The same applies to all AJAX type behavior, mod_pagespeed has had no effect on these in tests.
|
How will self-hosted WordPress work with Google Page Speed Service?
|
wordpress
|
I'm trying to install plugins in my wordpress subsites instead of network activate that plugin. But i'm not seeing any "add new" link in my subsite plugin area. How to install plugins in my individual sites. Am i missing something?. Thanks
|
Install plugin in networ admin as usual for multisite. Do not activate plugin for whole network. Go to admin of individual site and enable plugin there for that site alone.
|
How to install plugins in individual sites on a wordpress network?
|
wordpress
|
I asked this earlier on StackOverflow.com before realizing there was a StackExchange specifically for WordPress. Here is the link to the old question (for moderator deletion): stackexchange-url ("stackexchange-url I'm creating a WordPress plugin for a custom menu layout. I am well aware that I could just as easily implement this menu directly into the theme and I've read up quite thoroughly on the features and limitations of <code> wp_nav_menu() </code> , plus I have already tried and tested every plugin already created for replacing the default WordPress menu. I wish to use a plugin since my client will be implementing this on several different WordPress sites, many of which run on different themes - and most of those are themes which I did not create and I do not wish to re-write their code in case they update the theme in the future. When I've looked into a way to implement the menu into the theme I found that there are only two good methods since there is no hook or filter called at menu display time. The first is to change the theme to look for the plugin (this is similar to the method used by PixoPoint and many other menu plugins): <code> header.php: if(function_exists('pixopoint_menu')){ pixopoint_menu(); } else { wp_nav_menu(); } </code> The second method is a walker class: <code> plugin.php: class my_walker_class Extends Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { /* * Etc. Etc. */ } } header.php: wp_nav_menu( Array( 'walker' => 'my_walker_class' ) ); </code> However as you'll note both of these methods require a modification to the standard header.php file. Ideally I would like to simply replace the <code> wp_nav_menu() </code> function if my plugin is loaded, as this would give my plugin support for the majority of themes without having to edit any of the theme files. Is there a good way to do this? Or is there a better way to write a menu plugin which I am not seeing?
|
Err... There's plenty of filters on the menu system. The 'wp_nav_menu' filter is called on the output of the wp_nav_menu() function call. So if you need to modify the menu output, you can use that. The 'wp_nav_menu_items' filter is called on the resulting array of items (basically all the LI items). If you need to modify the arguments passed into wp_nav_menu, such as to dynamically add your own walker, you can use the 'wp_nav_menu_args' filter for that. There's a lot more filters which are more specific and can probably be used to change things in more subtle ways. These are sorta the main club-like filters that change the whole thing.
|
Replacing WordPress menu functionality with a plugin
|
wordpress
|
Is there an exact opposite funciton to this one: <code> get_the_title(ID) </code> I know there's: <code> get_the_id() </code> But it doesn't seem to accept any arguments. So, basically, I'm looking for something like: <code> $title = 'Something'; get_the_id($title); </code> I already know this solution: <code> global $wpdb; $post_name = get_query_var('name'); $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = $post_name"); </code> But maybe there's something bulit-in that I'm missing?
|
I'm not sure how to get it via the title, but you can get it via the slug (which is often more useful in my experience) using this: http://erikt.tumblr.com/post/278953342/get-a-wordpress-page-id-with-the-slug Just change "$page" to "$post" if you want to return slugs for posts instead of pages. G'luck!
|
How to get page's ID if I know the title only?
|
wordpress
|
I'm trying to migrate a site to WP. We have a whole bunch of pictures, and I have done some research and figured -- I think -- my best bet is a CSV import of the data, storing the relative URL of the image as a custom field. So, I found stackexchange-url ("this") --which looks ideal -- and I implemented it thus (in functions.php with a global call added as I was getting a 'no object' error): <code> function store_cf_featured_image() { global $post,$wpdb; $uploads = wp_upload_dir(); // Get all attachment IDs and filenames $results = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file'"); // Create an 'index' of attachment IDs and their filenames $attachments = array(); foreach ($results as $row) $attachments[ intval($row->post_id) ] = $row->meta_value; // Get all featured images $images = $wpdb->get_results("SELECT post_id, meta_value AS 'url' FROM $wpdb->postmeta WHERE meta_key = 'featured_image'"); // Loop over each image and try and find attachment post foreach ($images as $image) { if (preg_match('#^https?://#', $image->url)) $image->url = str_replace($uploads['baseurl'], '', $image->url); // get relative URL if absolute $filename = ltrim($image->url, '/'); if ($attachment_ID = array_search($filename, $attachments)) { // found attachment, set post thumbnail and delete featured image update_post_meta($image->post_id, '_thumbnail_id', $attachment_ID); delete_post_meta($image->post_ID, 'featured_image'); } } } add_action( 'init', 'store_cf_featured_image' ); </code> However, when I put a link in my custom field 'featured_image', and save it... nothing. No errors, but no nothing. I update the post and come back to it, but the link is still just a link the the custom field and no 'featured image' has been set. Does anyone have any ideas what the issue might be? an am I right in thinking this will store the image as part of built in 'Media Library', now? AlsoAlso: Will I be able to adapt this code to pull in Alt text etc for each image from custom fields. Any input greatly appreciated! Thanks.
|
so you're images are already in a custom field? you could use the Get the Image plugin.... i know it will pull your thumbnail from a custom field and i think it might automatically set it as the featured image, tho it has been a while and i'm not sure of that. http://wordpress.org/extend/plugins/get-the-image/
|
Add url from Custom Field as 'Featured Image'. Code not working
|
wordpress
|
I would like to remove the entire "Media" section from the main WordPress admin navigation ont he left hand side. What I don't want to do is just "hide" it with CSS or a plugin/function like I have done so below, because it's still accessible via the URL. This is crucial users shouldn't see each others uploads by any means. Here's what I currently have, which just hides it. If you went to upload.php in the url, you could still access it. <code> add_action( 'admin_menu', 'remove_menu_links' ); function remove_menu_links() { remove_menu_page('upload.php'); //remove media } </code> Any ideas? A suitable method I believe would be to just direct the user to the dashboard with an error message if they tried to access the upload.php url? Not sure how to do this though.
|
You are indeed correct, before the admin update(i imagine the UI redesign, etc), unsetting items from the menus would in effect prevent access to those pages, that's clearly changed now and requires additional cap checking. This isn't something i've looked into myself(as i've just found out this moment), so i can't speak about methods for doing so.. but it does bother me they've now turned a simple unsetting task into a bigger one that requires conditionalised capability checking(it's just more leg work that was not previously required). Moving on from the revelation: Ok, seeing as the <code> remove_menu_page </code> and submenu equivalents are pretty much pointless now(i mean seriously, what good is making a page simply hidden from view) what i'd suggest is looping over the media submenu items and updating the required caps on the fly(if that's what you need to do). This appears to have the desired outcome... :) <code> add_action( 'admin_menu', 'remove_menu_links' ); function remove_menu_links() { global $submenu; remove_menu_page('upload.php'); foreach( $submenu['upload.php'] as $position => $data ) { $submenu['upload.php'][$position][1] = 'desired cap here'; } } </code> NOTE: If you want the items completely gone / inaccessible, simply use a non-existant cap(or just leave the code as it is above).. Updated version of the above code: Following on your last comment, perhaps it might be smart to do it like this... or something along these lines.. <code> add_action( 'admin_menu', 'remove_menu_links' ); function remove_menu_links() { global $submenu; // Remove media for non-admins if( !current_user_can('manage_options') ) remove_menu_page('upload.php'); // Still need to update cap requirements even when hidden foreach( $submenu['upload.php'] as $position => $data ) { $submenu['upload.php'][$position][1] = 'manage_options'; } } </code> I realise now you do actually still need the <code> current_user_can </code> call, just to deal with conditionalising the removal of the parent item..
|
How do I remove the entire Media section from the main WordPress navigation without just hiding it?
|
wordpress
|
I have to develop a site in Wordpress similar to an already existing site in JSP which handles approx. <code> 50K users a day and 200 users </code> at a time. And in load testing i get that wordpress can handle only <code> 40 users </code> at a time (with <code> Super Cache </code> plugin <code> ON </code> ). Also I have hosted my site on a <code> Shared hosted server </code> . So please suggest me some way or guide me to <code> optimize </code> my wordpress site so that it can also handle the same traffic. Thanks in advance.
|
Reduce the amount of plugins. Check your theme for memory intense stuff or lots of queries. Add this line to your footer or hook it to the <code> shutdown </code> hook to see some basic information: <code> <!-- Time needed to print this page: <?php timer_stop( 0, 3 ); ?> Number of queries needed to process this request: <?php get_num_queries(); ?> --> </code> Then take a look at your site through source code and at the bottom you'll find the html comment containing this basic data. Then start disabling single plugins to see the difference and their impact on performance. Furthermore I'd say the max user restriction is not by wp, but by your shared hosting account.
|
High traffic management in WP
|
wordpress
|
I have a Wordpress Multisite install on our FreeBSD development server. It seems to be stuck at 1MB. I have the following settings in php.ini upload_max_filesize = 100M post_max_size = 100M max_execution_time = 300 All the regular Wordpress installs on the site have a max upload size of 100MB, as expected. Regardless of the values I put in the Multisite install is stuck at 1MB. The Setup: FreeBSD 8.1 PHP 5.3.3 Wordpress Multisite 3.2.1 Moving the site to another server on Rackspace, it has the same issues. Any help on getting this limit raised would be appreciated. If I left any pertinent information out let me know and I'll provide what I can.
|
There is a network admin settings page with a Max upload file size field, make sure this is also set correctly.
|
Multisite stuck at 1MB for max file size
|
wordpress
|
I have been attempting to make this theme work, Kelontong by Tokokoo, as seen here : http://stylishwebdesigner.com/6-free-wordpress-ecommerce-themes-to-create-an-online- marketplace-for-your-product/ However, after uploading the theme to my supervisor's wordpress site, and installing and activating the theme, the homepage displays this message where the photo slideshow should be: Catchable fatal error: Object of class WP_Error could not be converted to string in /home/valeh/vene.com/wp-content/themes/appcloudfree-2/home.php on line 25 When I check that line of code in the file, this is what is shown: <code> <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id" /> </code> Could someone please tell me what is causing this error? Also, I'm not sure if this is related or if the theme is just completely broken, but the theme's panel on the dashboard of my site does not seem to be functioning at all either, it doesn't seem that any of it has a buttonmode, as in i cannot click on any of the buttons.
|
Well the theme you mentioned isn't what you get if you click download. The actual theme Kelontong is a Premium Theme. You can find it here: http://tokokoo.com/portfolio/kelontong/ If you are using Kelontong that you found as a free download, it's probably a "Ripped" version. If this is the case, you probably have more problems than the error you speak of. You should download the plug-in used by the WP Theme Review Team called ThemeCheck . It will display errors, and malicious code (base64, gzdeflate, etc...). Good Luck.
|
Catchable fatal error in appcloud free theme by Tokokoo
|
wordpress
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.