question
stringlengths 0
34.8k
| answer
stringlengths 0
28.3k
| title
stringlengths 7
150
| forum_tag
stringclasses 12
values |
---|---|---|---|
How can I do that? So far the admin can only add exisiting users.
|
To follow up to xLRDxREVENGEx's answer, here's a screenshot of the checkbox you need to check in the network admin section:
|
I'm a super admin and I want to give an admin the ability to add new users...?
|
wordpress
|
it is causing problem because i did not do it before. I am trying to enqueue style or may be scripts depending on page. But it not working. Here is the code: <code> add_action('init', 'my_enqueue_styles'); function my_enqueue_styles(){ if(is_page('Add Event')){ // also tried slug, page id and wp_reset_query(); bot not worked wp_deregister_style( 'jquery-ui-custom-flick' ); wp_register_style( 'jquery-ui-custom-flick', get_bloginfo('template_directory') .'/styles/jquery.ui/ui.custom.flick.css'); wp_enqueue_style( 'jquery-ui-custom-flick' ); } } </code> I am not doing the conditional right. The script works without the conditional. Thanks! RESOLVED: The problem was with the <code> init </code> action hook. the conditional <code> is_page() </code> is false when <code> init </code> is called. After adding the style to the hook <code> wp_print_styles </code> it worked perfectly.
|
It should work like this. Sidenotes: I don't know why you deregister a stylesheet and register it again. Also: <code> get_bloginfo('template_directory') </code> is now replaced by <code> get_template_directory_uri() </code> . Third: Are your folders really named with dots in between? Maybe this causes problems. And maybe your ui stylesheet is an dependency of the main jquery ui stylesheet. You should also start accepting answers on your questions. Your "accept rate" of 67% will people hold back from answering your Qs. <code> function wpse_16487_enqueue_styles() { if ( is_page('Add Event') ) // also tried slug, page id and wp_reset_query(); bot not worked { wp_register_style( 'jquery-ui-custom-flick', get_template_directory_uri().'/styles/jquery-ui/ui-custom-flick.css', 'jquery-ui' ); wp_enqueue_style( 'jquery-ui-custom-flick' ); } } add_action( 'wp_print_styles', 'wpse_16487_enqueue_styles' ); </code> If something's not working, you should start debugging your wp query: <code> echo '<pre>'; print_r($GLOBALS['wp_query']); echo '</pre>'; </code> and check for the page name/slug to register it.
|
Enqueue Style for a page/pages only
|
wordpress
|
Anyone have recommendations for wordpress plugins that can scale easily and integrates with Wordpress' new custom post types? Not interested in themes as discussed here: stackexchange-url ("Real Estate website with Word Press")
|
Ended up going with something custom in drupal. Seems like the best way to go.
|
Wordpress plugin for real estate that scales?
|
wordpress
|
I'd like to have a static home page and also have a link called "Blog" that lists posts in the "blog" category in chronological order. Would the best way to do this just be to place code in archive.php and do a "switch case" on the category and do a loop on the posts? Just looking for some options before I decide on a strategy and code the solution.
|
wp dashboard > 'Page' > add new > name it 'Home', publish wp dashboard > 'Page' > add new > name it 'Blog', publish wp dashboard > Reading Settings > 'Front page displays' select 'a static page' set 'Front page' to 'Home' page that you have added > set 'Posts page' to 'Blog' page that you should have added. It doesn't seem like you need to create a 'Blog' category. Just let your new 'Blog' page display the posts loop, which will be your index.php theme file.
|
Static home page with "Blog" inside?
|
wordpress
|
When a user enters a page I want to check if he is logged in. How can it be done in the page's template? Or is it possible only in functions.php or a plugin?
|
<code> if (is_user_logged_in()) { echo 'You are logged in. Yay!'; } </code> Codex: <code> is_user_logged_in() </code>
|
Is it possible to use WordPress functions in a page template?
|
wordpress
|
I added a link to a PDF in my custom navigation menu. Is there a way to force it to download instead of open?
|
If you don't mind all PDF attachments been forced to be downloaded then you can use something like this: <code> <?php if (have_posts()) : while (have_posts()) : the_post(); $pdf_title = $post->post_title; $uploads_dir = wp_upload_dir(); $attachment_src = get_post_meta( $post->ID, '_wp_attached_file', true ); $pdf_src = path_join( $uploads_dir['basedir'], $attachment_src ); header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: application/pdf"); header("Content-Disposition: attachment; filename=\"".$pdf_title."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($pdf_src)); ob_clean(); flush(); readfile($pdf_src); endwhile; endif; ?> </code> Put the above code in a file called pdf.php in your current theme folder. Then instead of linking direct to your pdf (http://example.com/wp-content/uploads/2011/01/Guide-to-Owning-a-Listed-Building.pdf), link to the attachment URL: (http://example.com/help-and-advice/attachment/guide-to-owning-a-listed-building/) Doing like the above you can edit the code to do other fancy stuff such as track downloads and add some level of authentication while protecting the actual location of your PDF's.
|
Force PDF download from custom menu?
|
wordpress
|
I'm pretty new to WordPress... I'm trying to set up a few sites, each with their own top level domain name. What I want them to do is share some of the pages, but not others. For example - they would all share Services, Contact, and Team pages; but would each have their own Biography page. When one of the shared pages is updated, they're all updated. I can't figure out if WP multisite is this or not? Thanks for your help.
|
I do not believe this is possible. The only way is to create the page in each site or add a custom link to one main page but doing this will show only that sites theme
|
Multiple sites that share some pages, but not others
|
wordpress
|
I have a custom post type created called 'missions'. When developing the site on my Dedicated Virtual, I had no problems. But I moved the site to a shared hosting grid server (mt) and now receive this error through out the admin. Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'add_mission' was given in /nfs/c08/h02/mnt/125591/domains/mydomain.org/html/wp-includes/plugin.php on line 395 The only place that 'add_mission' is used in my theme code is in the functions when setting up the post type. Here is the code I have for that. <code> add_action( 'init', 'create_mission' ); function create_mission() { register_post_type( 'missions', array( 'labels' => array( 'name' => __( 'Missions' ), 'singular_name' => __( 'Mission' ), 'add_new' => __( 'Add New' ), 'add_new_item' => __( 'Add New Mission' ), 'edit' => __( 'Edit' ), 'edit_item' => __( 'Edit Mission' ), 'new_item' => __( 'New Mission' ), 'view' => __( 'View Mission' ), 'view_item' => __( 'View Mission' ), 'search_items' => __( 'Search Missions' ), 'not_found' => __( 'No missions found' ), 'not_found_in_trash' => __( 'No missions found in Trash' ), 'parent' => __( 'Parent Mission' ), ), 'public' => true, 'menu_position' => 4, 'show_ui' => true, 'capability_type' => 'post', '_edit_link' => 'post.php?post=%d', 'hierarchical' => true, 'rewrite' => array( 'slug' => 'missions', 'with_front' => true ), 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments' , 'page-attributes', 'templates' ), 'menu_icon' => get_stylesheet_directory_uri() . '/assets/imgs/icon_posttype.png', 'register_meta_box_cb' => 'add_mission_metaboxes' ) ); } add_action('admin_init', 'add_mission'); </code> More Info I know that the issue is with my theme, as switching to the twentyten theme removes the error. PHP Version 5.2.14 WordPress 3.1.2 Question Is this a server issue? Or can I fix this through my code? I've searched google and have been unable to find an instance of this error being thrown from a custom post type in wordpress.
|
what's the add action at the bottom doing? It's not required for setting up CPTs, just the setup bit you have running on init.... I believe that is what's throwing the error I have to make it an answer. It was a suggestion, but if it worked for you, I'll make my comment an answer, then you can accept it!
|
Custom Post Type Causes Error: Warning: call_user_func_array()
|
wordpress
|
I've already found out stackexchange-url ("here") how to remove the row-actions from the posts table in wordpress admin. Now I'd like to do the same in the pages table. I've looked in the core files but, well, I just don't get it. Anyone? Here's the code used in functions.php to remove row actions in posts: <code> function remove_row_actions( $actions ) { if( get_post_type() === 'post' ) unset( $actions['edit'] ); unset( $actions['view'] ); unset( $actions['trash'] ); unset( $actions['inline hide-if-no-js'] ); return $actions; } add_filter( 'post_row_actions', 'remove_row_actions', 10, 1 ); </code> Thanks in advance!
|
For non-hierarchical post types the filter is called <code> post_row_actions </code> , for hierarchical it's <code> page_row_actions </code> . If you want to remove all actions you don't have to unset the individual items, you can just return an empty array. <code> add_filter( 'page_row_actions', 'wpse16327_page_row_actions', 10, 2 ); function wpse16327_page_row_actions( $actions, $post ) { if ( 'page' == $post->post_type ) { return array(); } return $actions; } </code>
|
How to remove row-actions from pages table?
|
wordpress
|
I need your recommendation for the best practice here: A custom post type I have created needs a list of attachments at the end of the post content. I have created a series of functions that handle displaying the list of appropriate attachments for a post. I don't want to use shortcode to insert this attachment list, since every post of this post type should have the list I'm looking for a portable, reusable approach My initial approach was to encapsulate the attachment functions into a standalone plugin. But how to integrate the plugin output into the page if I don't use shortcode? My solution was to create my own pseudo-template-tag ("the_attachments()") which is defined in the plugin. Then my custom-post-type.php template page uses this pseudo-template-tag right after the_content() and we get our nice list. But is this really the best approach? Now we have a template that's dependent on an external plugin. If the plugin isn't there, the template "breaks". It's tough to "require" a plugin, from a template perspective because is_plugin_active() is only available at the admin level, and that's probably for a reason (because it's a stupid idea to make a template dependent on a plugin!) So I'm left with either: A) decouple the plugin output from the template, similar to the way a widget works (if so, how do I pass the $post information to that widget?), or B) embed the "plugin" code within the template functions (but is this then truly portable?)
|
<code> <?php // A) // inside your template if ( function_exists( 'the_attachment_stuff()' ) ) { // do stuff } // better/faster if ( class_exists( 'attachment_plugin_class' ) ) { // do stuff } // B) // inside your template do_action( 'the_attachment_suff'); // means setting this inside your plugin // this avoids throwing errors or aborting if the hook isn't in your template add_action( 'the_attachment_stuff', 'your_callback_fn' ); // C) function add_attachment_stuff() { if ( ! is_admin() ) return; // the following is guess and theory... $content = get_the_content(); $content .= the_attachment_stuff(); // in case the attachment_stuff returns instead of echos the result/output. } // @link http://codex.wordpress.org/Plugin_API/Action_Reference // only add on publish, on 'post_save' we would add it multiple times add_action( 'publish_post', 'add_attachment_stuff', 100 ); add_action( 'publish_phone', 'add_attachment_stuff', 100 ); </code>
|
Best practice for including plugin output in a template without using shortcode?
|
wordpress
|
I am building a front end post layout editor using jQuery UI Sortable. The posts are laid out in 300px by 250px boxes over a background image. The posts are created and edited using the WordPress admin but I want to allow the sites administrator to adjust the order of the boxes using a drag and drop interface on the front end. I've got the drag and drop sortable part working but need to come up with a way to save the state (order) of the boxes. Ideally I would like to be able to save the state as an option and build it into the query. The query for the posts is a simple WP_Query that also gets data from custom meta boxes to determine the individual box layout.: <code> $args= array( 'meta_key' => 'c3m_shown_on', 'meta_value'=> 'home' ); $box_query = new WP_Query($args); ?> <ul id="sortable"> <?php while ($box_query->have_posts()) : $box_query->the_post(); global $post; global $prefix; $box_size = c3m_get_field($prefix.'box_size', FALSE); $box_image = c3m_get_field($prefix.'post_box_image', FALSE); $overlay_class = c3m_get_field($prefix.'overlay_class', FALSE); if ( c3m_get_field($prefix.'external_link', FALSE) ) { $post_link = c3m_get_field($prefix.'external_link', FALSE); } else { $post_link = post_permalink(); } ?> <li class="<?php echo $box_size;?> ui-state-default"> <article <?php post_class() ?> id="post-<?php the_ID(); ?>"> <?php echo '<a href="'.$post_link.'" ><img src="'.esc_url($box_image).'" alt="Image via xxxxx.com" /></a>'; ?> <div class="post-box <?php echo $overlay_class;?>"> <?php if ( c3m_get_field( $prefix.'text_display', FALSE) ) { ?> <h2><a href="<?php echo $post_link?>"><?php the_title();?></a></h2> <p><?php echo substr($post->post_excerpt, 0, 90) . '...'; ?></p> <?php } ?> </div> </article> </li> <?php endwhile; ?> </ul> </section> </code> The javascript is just the basic default sortable instructions <code> jQuery(document).ready(function() { jQuery("#sortable").sortable(); }); </code> There are methods available using cookies to save the state but I also need to disable the sortable drag and drop for non admin users so I really need to save to the database. I'm looking for the most creative and usable method and will award a 100 point bounty to the best answer. Update: I got stackexchange-url ("somatic's") answer working with one minor change. ajaxurl doesn't return the value on non admin pages so I used <code> wp_localize_script( 'functions', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); </code> to define the value and changed the javascript line under options to: <code> url: MyAjax.ajaxurl, </code> To limit access to arranging the order to only admins I added a conditional to my wp_enqueue_script function: <code> function c3m_load_scripts() { if ( current_user_can( 'edit_posts' ) ) { wp_enqueue_script( 'jquery-ui' ); wp_enqueue_script( 'functions', get_bloginfo( 'stylesheet_directory' ) . '/_/js/functions.js', array( 'jquery', 'jquery-ui' ), false); wp_localize_script( 'functions', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); } } </code> I'm going to do a little more testing and mark this question as solved and award the bounty.
|
Brady is correct that the best way to handle saving and displaying of custom post type orders is by using the <code> menu_order </code> property Here's the jquery to make the list sortable and to pass the data via ajax to wordpress: <code> jQuery(document).ready(function($) { var itemList = $('#sortable'); itemList.sortable({ update: function(event, ui) { $('#loading-animation').show(); // Show the animate loading gif while waiting opts = { url: ajaxurl, // ajaxurl is defined by WordPress and points to /wp-admin/admin-ajax.php type: 'POST', async: true, cache: false, dataType: 'json', data:{ action: 'item_sort', // Tell WordPress how to handle this ajax request order: itemList.sortable('toArray').toString() // Passes ID's of list items in 1,3,2 format }, success: function(response) { $('#loading-animation').hide(); // Hide the loading animation return; }, error: function(xhr,textStatus,e) { // This can be expanded to provide more information alert(e); // alert('There was an error saving the updates'); $('#loading-animation').hide(); // Hide the loading animation return; } }; $.ajax(opts); } }); }); </code> Here's the wordpress function that listens for the ajax callback and performs the changes on the DB: <code> function my_save_item_order() { global $wpdb; $order = explode(',', $_POST['order']); $counter = 0; foreach ($order as $item_id) { $wpdb->update($wpdb->posts, array( 'menu_order' => $counter ), array( 'ID' => $item_id) ); $counter++; } die(1); } add_action('wp_ajax_item_sort', 'my_save_item_order'); add_action('wp_ajax_nopriv_item_sort', 'my_save_item_order'); </code> The key to displaying the posts in the order you have saved is to add the <code> menu_order </code> property to the query args: <code> $args= array( 'meta_key' => 'c3m_shown_on', 'meta_value'=> 'home' 'orderby' => 'menu_order', 'order' => 'ASC' ); $box_query = new WP_Query($args); </code> Then run your loop and output each item... (first line is the core wp loading animation - you'll want to hide it initially via css, and then the jquery function will display when processing) <code> <img src="<?php bloginfo('url'); ?>/wp-admin/images/loading.gif" id="loading-animation" /> <ul id="sortable"> <li id="{echo post ID here}">{echo title or other name here}</li> </ul> </code> Code inspired by soulsizzle's excellent tutorial.
|
How to save the state of a drag and drop jQuery UI Sortables front end layout editor?
|
wordpress
|
TwentyTen adds some classes to custom menus, for instance: <code> #access #menu-item-262.current-menu-item, #access #menu-item-262.current-menu-ancestor </code> All the top-level links in my primary navigation have the class <code> .current-menu-ancestor </code> when the user is on a child page -- except when I'm viewing content in the custom post type I've built . How do I set the current page in navigation when viewing a custom post type? Thanks...
|
The classes are not added by the Twenty Ten theme, but by the common custom navigation menu code, in <code> _wp_menu_item_classes_by_context() </code> , which is called from <code> wp_nav_menu() </code> . If you want to add extra classes you can do that by either hooking into <code> wp_nav_menu_objects </code> , called once with the whole menu tree, or into <code> nav_menu_css_class </code> , called when rendering each individual item.
|
adding .current* tags to custom post types and taxonomies
|
wordpress
|
I currently use WordPress for most of my projects, the way I manage them is creating a folder for each in my local environment each containing a WP install which in times makes it a paint to maintain, upgrade and takes more space. I was looking at WP Multisite and I was wondering if I could use it to create multiple projects with the same WP installation but ran into a problem, when I finish a project using my current method I just send my client a SQL Dump of my DB, tell them to replace the URL and install all the files/folders to his server and it works fine. But WP Multisite creates an unique folder and DB structure which makes it difficult to do this since most of my clients won't be using MU but regular Wordpress installations. So is there an easy way to "export" a WP MS site to use it on a regular WP install? Or should I stick to having multiple WP copies? Thanks in advance!
|
Export/Import like you would the data for any other WordPress install: On the development site: <code> Dashboard -> Tools -> Export -> All Content </code> (save file) Package up the Theme files as "theme-name.zip" Make note of any custom settings On the live site: Install the custom Theme `Dashboard -> Tools -> Import -> WordPress data file (upload file) Change any custom settings noted above EDIT: If you still want to try a database export, you could try network-enabling one of the many database-backup Plugins in the repository, such as WP-DBmanager, and running it from your dev site.
|
Using WordPress Multisite to manage multiple projects?
|
wordpress
|
Ive been experiencing a problem with the new WordPress 3.1.2 update. When i use <code> add_theme_support(); </code> and register an array of post formats, it registers all of them fine, but when it comes to the video post format, it registers it twice, and gets called post-format-video-2 . This is the way im writing out the code: <code> add_theme_support( 'post-formats', array( 'aside', 'gallery', 'image', 'link', 'video' )); </code> Ive tested this out both on my theme, and the twentyten theme. The problem is exclusive to the video post-format. Its really strange. Additionally when you declare a "posts" format as "video" upon publishing or updating, the post-format meta box adds a new radio button with a new post format without a slug/name. Illustration (where numbers are the radio buttons): Aside Gallery Image Link Video Despite only showing 5 radio buttons, upon updating/publishing, a new radio button appears, and it gets selected (radio button 6) rather than the one I chose (radio button 5). Ive used the <code> add_action( 'after_setup_theme', 'foobar' ); </code> on my theme with no luck. Of-course this comes standard with twentyten. Any ideas?
|
Thanks to @goldenapples and @kaiser for their guidance. Apparently (for some odd reason) i had two terms registered with post-format-video. Im not sure if the following can be a viable solution to the problem, but i fired up Workbench and deleted both rows in the wp_terms table. I then reloaded the local site, created a post under the video post-format, and finally.. its resolved. One "video" post-format was registered both in the post-format meta box and the wp_terms table. I'll leave the intricacies of why this happened and how this worked to the wise. Either way. I reported this problem to the wp hackers list. Thanks guys.
|
Wordpress 3.1.2 Bug: add_theme_support() and video post format registering twice
|
wordpress
|
"Insert search engine here" was pretty useless for this one - I've had a look through <code> wp-includes/functions.php </code> , <code> wp-admin/includes/file.php </code> etc. but not found a reason for the behaviour I'm getting. I'm running multisite, and when I upload a .doc or .pdf I don't have a problem. When I upload a .ppt - regardless of the actual filename or mimetype (i.e. a .ppt renamed to .txt, a .txt renamed to .ppt) - I'm told "Sorry,this file type is not permitted for security reasons" with little other explanation. Do I need to modify the mimes table, add an override (and if so, what's the syntax for this), or is it something in my Apache conf? I've done some funny fiddling to try and lock things down in a few places, possibly blocking .pot files.
|
Found it while digging around in multisite network admin settings: there is a setting called "Upload file types" (in the database it's the row with <code> meta_key </code> = "upload_filetypes" in the <code> wp_sitemeta </code> table) which contains a list of allowed filetypes. Adding "ppt" to the list allows them to be uploaded.
|
Can upload doc and pdf but not ppt - not permitted for security reasons
|
wordpress
|
In BuddyPress, when a user clicks on their username, they are presented with a page that contains a menu: <code> Activity Profile Messages Friends Groups Settings </code> How do I add an item to this menu? How do display this menu inside my template? (The default page template only displays the main navigation.)
|
Here's an example of adding a menu items pointing to custom templates. If you want to link to existing BP elements, you'll need to look up the appropriate action. Add this to <code> functions.php </code> : <code> // Set up Cutsom BP navigation function my_setup_nav() { global $bp; bp_core_new_nav_item( array( 'name' => __( 'Item One', 'buddypress' ), 'slug' => 'my-item-one', 'position' => 30, 'screen_function' => 'my_item_one_template', ) ); bp_core_new_nav_item( array( 'name' => __( 'Item Two', 'buddypress' ), 'slug' => 'my-item-two', 'position' => 20, 'screen_function' => 'my_item_two_template' ) ); // Change the order of menu items $bp->bp_nav['messages']['position'] = 100; // Remove a menu item $bp->bp_nav['activity'] = false; // Change name of menu item $bp->bp_nav['groups']['name'] = ‘community’; } add_action( 'bp_setup_nav', 'my_setup_nav' ); // Load a page template for your custom item. You'll need to have an item-one-template.php and item-two-template.php in your theme root. function my_item_one_template() { bp_core_load_template( 'item-one-template' ); } function my_item_two_template() { bp_core_load_template( 'item-two-template' ); } </code> Hope that helps! More at this article on Themekraft .
|
Add BuddyPress Profile Menu Item
|
wordpress
|
I have 3.1.2 running with the Boldy theme. Site link. I have a menu that has a number of external links listed in the items. By default, these items do NOT load in a new tab/window. There is no option in the Admin --> Appearance --> Menus, to tick a box to say open in new window. How do I get them to do this?
|
In your WordPress admin panel, go to <code> Appearance > Menus </code> . Select <code> Screen Options </code> in the top right corner. Enable the property <code> Link Target </code> . Now you can set your link target element in your external link.
|
Menus - Open items in new tab/window?
|
wordpress
|
Is there a theme or some hack of the categories system that I can use to create a site for a podcast network? I want it similar to This Week in Tech in that all the podcasts will appear on the front page, but also each have their own homepage. I do not think a multi-site installation will be my solution. Each podcast must have its own RSS feed with podcast enclosures. Any ideas on how this could be done? I'm thinking that each podcast would be a category and each podcast home would be a separate category listing page.
|
Any Theme will do, for the most part. Simply install the Blubrry PowerPress Plugin or the podPress Plugin , and away you go!
|
Wordpress for Podcast Network
|
wordpress
|
I am building a template where wordpress is being used primarily as an image CMS, I am pulling the first image from the content section of each post. <code> <img src="<?php echo grab_image() ?>" /> function grab_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)){ $first_img = ""; } return $first_img; } </code> My question is how can I, instead of grabbing it from post_content, grab the first image from the uploaded image gallery? So, the process to add an image would be to upload and then exit out (without inserting into post). I dont know what you call this or what to look for.. attachments? media library? The content area would be used strictly for text along with any extra meta boxes.
|
Use <code> get_children() </code> ( Codex ref ): <code> $images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC' ) ); </code> The first image will be <code> $images[0] </code> . EDIT: And by "first image", I mean, the <code> $ID </code> of the first image, which you can use with any of the myriad image- and attachment-handling functions in WordPress. If you can clarify what you want to do with the image , I can provide more specific, further instruction.
|
Pull images from the gallery
|
wordpress
|
I'm using More Fields plugin, and when I use my functions.php to embed the custom field, I get an odd issue. The field value is followed by a "1" I use this code: <code> //Address add_action( 'woo_post_inside_before', 'my_address' ); function my_address() { global $post; if ( is_single() && in_category('listings') ) { echo more_fields('address', '<h1>','</h1>'); } } </code> But, if I use the following code - their is no "1" <code> //Address add_action( 'woo_post_inside_before', 'my_address' ); function my_address() { global $post; if ( is_single() && in_category('listings') ) { echo meta('address'); } } </code> How do I style the above using the echo meta? Or has anyone ever seen the "1" issue?
|
There is no WordPress function called <code> meta() </code> . Try using <code> get_post_custom() </code> ( Codex ref ) instead. For example: <code> //Address add_action( 'woo_post_inside_before', 'my_address' ); function my_address() { if ( is_single() && in_category('listings') ) { global $post; $meta = get_post_custom(); echo '<h1>' . $meta['address'] . '</h1>'; } } </code> Note: I'm not sure you need to call <code> global $post; </code> in this context? EDIT: updated to add HTML tags.
|
Odd functions.php issue in Wordpress
|
wordpress
|
Since I am pretty new to WP and the whole stuff i ran into a problem. I am using the pretty-well known "Lightword" Theme. And today i've upgraded to the newest version. It's now possible to add/edit the menu items through the theme-settings. Although I like this very much I am not able to display more than one additional menu-item. When I go to "wp-admin/nav-menus.php" I am able to select a menu item in a box (the english titel of the box is probably: "Position in theme") on the left-side. But I am only able to select one. So what can I do to show up all created menus? Thanks for your help
|
You are trying to display multiple menu items, or multiple menus? Each theme supports a certain number of menus. Your's may only support one menu, that is the menu position. You create a menu to go there. From withing the menu creator interface you put all the items you want to appear on your menu. You can even nest items, to create children in your menu. You assign that menu you have created to the position, depending how many your theme supports. Many only support one menu natively. You can only add one menu per position, but that one menu can have as many items as you like. You set up your top level items, and assign children by dragging the items below and slightly to the side of a parent item. For most themes, the children items will behave as dropdowns. If you want to add more, you can code them in, or use a widget. WordPress comes with a custom menu widget which allows you to assign custom menus to it.
|
Lightword Theme - only one menu item
|
wordpress
|
At the moment my users posts are only viewable to them. I would like to implement a system where they can choose to share any post with other users they know. The problem I'm having is, how do I make the connection between users? The best I came up with is to create a table in the db and store their friends by user id's. Example: <code> user_ID 2 friends_ID 5,9,34,85 user_ID 87 friends_ID 67,2,99,100,58,309 </code> I want to be able to retrieve their friends list so I can use it later in various parts of the site. I know this will not be simple, but I am fully open to ideas, suggestions or similar plugin. Thank you all in advance.
|
BuddyPress can be used as a framework - it allows you to friend other users, and is a good place to start from. [Update] This is the structure of the BuddyPress friends table (bp_friends) <code> CREATE TABLE `wp_bp_friends` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `initiator_user_id` bigint(20) NOT NULL, `friend_user_id` bigint(20) NOT NULL, `is_confirmed` tinyint(1) DEFAULT '0', `is_limited` tinyint(1) DEFAULT '0', `date_created` datetime NOT NULL, PRIMARY KEY (`id`), KEY `initiator_user_id` (`initiator_user_id`), KEY `friend_user_id` (`friend_user_id`) ); </code>
|
How to implement friend system for Wordpress?
|
wordpress
|
I'm developing a theme where I'm using theme options to allow users to set various things -- text size, background colour, link colour, etc. The basic code I'm using for the options is in header.php and looks like this: <code> <?php $options = get_option('mytheme_theme_options'); if( isset( $options['backgroundcolour'] ) && ( !empty( $options['backgroundcolour'] ) ) ) printf( "body {background: #%s;}", $options['backgroundcolour'] ); if( isset( $options['linkcolour'] ) && ( !empty( $options['linkcolour'] ) ) ) printf( "a, a:link {color: #%s;}", $options['linkcolour'] ); ?> </code> One of the options I want to set is a border radius for some chunks of content, which requires multiple declarations of the same value to work in all modern browsers: <code> .post {-webkit-border-radius: 8px; -moz-border-radius: 8px; border-radius: 8px;} </code> So, how do I get the PHP above to declare the same value three times in my CSS? I should add that I'm not normally a PHP person; feeling a bit out of my depth here. :) Thanks.
|
Use standard <code> echo </code> or <code> printf </code> with additional parameters. e.g. <code> if(isset($option['borderradius']) && (!empty($option['borderradius']))) { $borderradius = '.post { '; $borderradius .= 'border-radius: ' . $option['borderradius'] . 'px; '; $borderradius .= '-webkit-border-radius: ' . $option['borderradius'] . 'px; '; $borderradius .= '-moz-border-radius: ' . $option['borderradius'] . 'px; '; $borderradius .= '}'; echo $borderradius; } if(isset($option['borderradius']) && (!empty($option['borderradius']))) { printf('.post { border-radius: %spx; -webkit-border-radius: %spx; -moz-border-radius: %spx; }', $option['borderradius'], $option['borderradius'], $option['borderradius']); } </code>
|
Using theme options to change a border-radius value
|
wordpress
|
I need a hook such that when visitor lands on any of the post (not page) , I need to record a hit. How can I find whether the request is for post, and is there any hook to find if the loaded content is post, and if yes, what is post id
|
something like this will work: <code> function record_hit_if_post(){ global $wp_query; if($wp_query->is_single==1) // single post's ID: // $wp_query->post->ID; } add_filter('template_redirect', 'record_hit_if_post'); </code>
|
finding whether request is for post, and post id
|
wordpress
|
I'm developing a a site using the wp e-commerce plugin, and it handles tags in pretty much the same way it would if I were using it for a blog instead of a store. The issue is that I want to use the tags as a secondary kind of navigation menu so that customers can view all items made from a certain material no matter what product category the item is in. My issue is that the theme-functions page within wp e-commerce is causing certain tags to be in huge fonts as these tags are related to more products. What I want to do is be able to display each of the tags as links within <code> <ul> <li> </code> with each tag using the same sized font. I understand some basics of php, but not enough to fully decode the theme functions file and edit it. I have considered waiting until I've got all of the products into the system then handcoding the list of tags, but then if my client wants to add more tags in the future they obviously won't be included. If anyone has any insights or ideas Id be very greatful. I would post the code in question here but its about 200 lines long - but if it's needed in order to find the solution pls tell me so that I can add it.
|
you can use <code> wp_list_categories() </code> to output an unordered list: <code> <?php wp_list_categories( array('taxonomy' => 'product_tag') ); ?> </code>
|
Making tags appear as an Unordered list instead of a 'cloud'
|
wordpress
|
OK so i am drawing a blank. I have setup a WordPress 3.1.2 Network site and want the main site to appear with www.mydomain.com not mydomain.com and i can get that to work but the back-end on the network admin breaks when i go to add a site it gives me the error "Are you sure you want to do this". When i disable the redirect of non-www to www it works fine. I have setup the wp_options table with site home and url of www.mydomain.com so i do not get this at all. I had it working in 3.0 but now 3.1 not working
|
Where are you trying to do the force redirect? I think the best place for this may be in a <code> .htaccess </code> file. Something like <code> RewriteEngine on RewriteCond %{HTTP_HOST} !^www.your_domain.com$ RewriteRule ^(.*)$ http://www.your_domain.com/$1 [R=301] </code>
|
Wordpress 3.1.2 Network Enabled non-www to www
|
wordpress
|
I'm developing an online store using wp e-commerce plugin. Whilst working on it locally the problem didn't occur, but after I started testing it online a large gap began appearing before the top of the page. Using Firebug I've been able to see that the styling causing it is: html {margin-top: 28px !important; } which firebug is telling me comes from a file that has the same name as the page ie: if example.com/products-page is the page being viewed it says that the style in question is being created by http://example.com/products-page on (line63) I have used dreamweaver to search the entire wordpress folder locally for the style causing the error but it doesn't exist - it seems to be only occurring when the site is live online. I considered that possibly something could be getting added at a server level so I uploaded the site to an account on a different host - but same problem. I'm using a reset.css file that would normally overcome this style being recognised - but than !important is what keeps it from being ignored. Any insights or suggestions greatly appreciated
|
This is almost surely your problem Wordpress Admin Bar ..
|
style being attatched to tag from outside of style sheets
|
wordpress
|
Currently I use: <code> query_posts("post_type=listing"); </code> to pull all entries of my custom post type. But I have a taxonomy called status with the values of Available, Pending, Sold. I only want to show Available and Pending on one page, and sold on another. How do I go about this? thanks!
|
There's the "tax_query" argument available since the latest wp release: <code> global $query_string; $args['tax_query'] = array( array( 'taxonomy' => 'status' ,'terms' => array( 'available', 'pending' ) // change to "sold" for 2nd query ,'field' => 'slug' ), ); $args['post_type'] = 'listing'; parse_str( $query_string, $args ); $avail_n_pend = query_posts( $args ); if ( $avail_n_pend->have_posts() ) : while ( $avail_n_pend->have_posts() ) : $avail_n_pend->the_post(); // show result the_title(); endwhile; endif; // use this for testing: /* echo '<pre>'; print_r($GLOBALS['wp_query']->tax_query); echo '</pre>'; */ // rewind for second query rewind_posts(); // second_query $args['tax_query'] = array( array( 'taxonomy' => 'status' ,'terms' => array( 'sold' ) ,'field' => 'slug' ), ); parse_str( $query_string, $args ); $sold = query_posts( $args ); if ( $sold->have_posts() ) : while ( $sold->have_posts() ) : $sold->the_post(); // show result the_title(); endwhile; endif; </code>
|
Query multiple taxonomy in Custom Post Type
|
wordpress
|
and thanks in advance for your help. I've done some searching, and this question has been answered a couple of times with reference to the "posts 2 posts" plugin, but the documentation on that is very "coder-centric" -- I am able to and comfortable getting my hands dirty, but I do require better Step-by-Step documentation than what is available there. :) Here's what I need. I am using gPress to generate "Places" using their custom post type. This is working amazingly well. What I need to do is to be able to add "Events" to a Place. I can use a custom post type to capture all event details, but then I'd like to be able to attach Events to a specific Place, and vice-versa. If someone was viewing the Event post, there would be a somewhat easy way to also pull the Place information related to the Event. Thanks very much -- any plugins or other suggestions are appreciated! Cheers, John
|
stackexchange-url ("Scribu's") posts-to-posts is a great and simple plugin, I'm sure we can help you get it working. The basic usage is pretty straightforward. assuming your custom post types are named <code> 'place' </code> and <code> 'event' </code> , the following code would go into your theme's functions.php file: <code> function my_connection_types() { p2p_register_connection_type( array( 'name' => 'events_to_places', 'from' => 'event', 'to' => 'place', ) ); } add_action( 'p2p_init', 'my_connection_types', 100 ); </code> this will make the meta boxes to assign relationships available in your custom post edit screens. for your single place and event pages, you can create custom templates in your theme following the WordPress template hierarchy <code> single-{post_type}.php </code> , so in your case <code> single-event.php </code> and <code> single-place.php </code> . you can duplicate these from the single.php template. to list connections, we just need a bit of code within theses templates wherever we want to output the list. this would go in the place template and output connected events: <code> <?php $connected = new WP_Query( array( 'connected_type' => 'events_to_places', 'connected_items' => get_queried_object() ) ); echo '<p>Related events:</p>'; echo '<ul>'; while( $connected->have_posts() ) : $connected->the_post(); echo '<li>'; the_title(); echo '</li>'; endwhile; echo '</ul>'; wp_reset_postdata(); ?> </code>
|
Linking Two Post Types
|
wordpress
|
While inside "the loop" in WordPress, is there an easy way to detect if a post is the most recent? A Usage Example: I want to make the first post output an H1 for the title instead of an H2. Or I want the first post to display a thumbnail image (and not the rest). Here is some pseudocode what I'm trying to get across: <code> if (have_posts()): while (have_posts()): the_post(); the_excerpt(); if(is_most_recent()): // do this endif; endwhile; endif; </code>
|
In addition to @Milo Answer (this avoids a senseless query, because we already got every needed information from the current wp_query): <code> if ( have_posts() ) : while ( have_posts() ) : the_post(); $headline_html_tag = $GLOBALS['wp_query']->current_post === (int) 0 && $GLOBALS['paged'] === (int) 1 ? '1' : '2'; the_title( '<h'.$headline_html_tag.'><a href="'.get_permalink().'" title="'.the_title_attribute( array( 'before' => 'Permalink to: ', 'after' => '', 'echo' => false ) ).'">', '</a>'.'</h'.$headline_html_tag.'>', false ); endwhile; endif; </code>
|
While in "the loop", detect if a post is the most recent
|
wordpress
|
For some reason WordPress media manager is only showing 2 images per page? This is happening on 2 separate sites now and I can't get rid of it. Is there a way to manipulate items per page for the wp-admin media library?
|
thanks Jan - it was the 'more fields' plugin and the temp plugin fix is here; http://wordpress.org/support/topic/plugin-more-fields-media-library-only-shows-5-images-at-a-time-and-not-10?replies=10
|
Media library only show 2 items per page?
|
wordpress
|
I want to list all the users of my site and the amount of posts each user has. So far I have the function below, but I don't know how to pull in each user's ID to use in the count_user_posts... <code> <ul> <?php foreach ( get_users('order=DESC&orderby=post_count') as $user ) : ?> <li style="color:#fff;"><span style="font-weight:bold;"> <?php echo $user->display_name; ?></span> as <?php echo $user->user_nicename; ?> (<?php echo $user->post_count; ?> Posts)<br /> <?php echo 'Posts made: ' . count_user_posts(1); ?> </li><br /> <?php endforeach; ?> </ul> </code> I have foreach function going, but count_user_posts requires an integer I don't pull in each individual user ID to grab their post amount. I would appreciate some help with this. I know it's probably something simple... I'm kind of new to php :D. Thanks a lot.
|
WordPress has a wp_list_authors function with the option to list post count. <code> <?php $args = array( 'orderby' => 'post_count', 'optioncount' => true); wp_list_authors( $args ); ?> </code> EDIT: While it's possible to do it the way you're doing it and use count_user_posts(), this will trigger a query to retrieve users, then additional queries to get each user's count. this is a very inefficient way to do this and may have a significant impact on performance if you have a lot of authors. A better way is to select users, and count the posts all in one query. If you look in <code> wp-includes/author-template.php </code> you'll see the query <code> wp_list_authors </code> generates to do this.
|
How to list users and their post amount?
|
wordpress
|
I am new to wordpress, so if this question was already answered I apologize in advance. I have a search form in wordpress which looks like this: <code> <form action="wordpress/action.php" id="search_form" method="get"> <label for="s" class="hidden"></label> <input type="text" size="30" id="s" name="s" value=""> <input type="submit" value="Search" id="searchsubmit"> </form> </code> The file action.php looks up a given string (in this case a name) in a database and returns an array of "similar" written names. After hitting the submit button I want the results to be proposed in a clickable proper list to the user. I thought of listing the items in the same widget. Here the structure I was thinking of. <code> SEARCH FIELD HERE | SUBMIT BUTTON HERE John Doe John Dö Johnny Doe etc. </code> Then the user can click the prefered name and information to this name will be shown in the main part of the page. Is there something that already realizes that? Or do I have to write that on my own. In the second cas: What would be the best approach for that? Update I was thinking about using sessions to store the result of a query of a user. Redirecting to the same page would let php read the list and print it to the widget. Would this be a usable approach? Well, I still need to know where to tell php to echo inside the text widget, though...
|
While looking for possible pointers I found the SearchAutocomplete plugin , which seems to do what you want. You can see it in action at the site of the author .
|
Displaying search results in the widget itself?
|
wordpress
|
Is possible to get current-menu-item as a php variable? I'm listing the category museums via the menu item 'museums we support' so i'd like the get 'museums we support' bit and display it somewhere? Any help appreciated!
|
This is possible by filtering <code> wp_nav_menu_objects </code> , which is the easiest place to check which item is the current menu item, because WordPress already added the classes for you. <code> add_filter( 'wp_nav_menu_objects', 'wpse16243_wp_nav_menu_objects' ); function wpse16243_wp_nav_menu_objects( $sorted_menu_items ) { foreach ( $sorted_menu_items as $menu_item ) { if ( $menu_item->current ) { $GLOBALS['wpse16243_title'] = $menu_item->title; break; } } return $sorted_menu_items; } </code> You can now use this new global variable instead of the normal title. Simple example: <code> add_filter( 'single_cat_title', 'wpse16243_single_cat_title' ); function wpse16243_single_cat_title( $cat_title ) { if ( isset( $GLOBALS['wpse16243_title'] ) ) { return $GLOBALS['wpse16243_title']; } return $cat_title; } </code> Of course, this only works if you display the menu before you display the title. If you need it earlier (maybe in the <code> <title> </code> element?), you should stackexchange-url ("first render the menu and then display it later").
|
How to get current-menu-item title as variable?
|
wordpress
|
Here is what i'm having problems with... I want to link a youtube video to start playing in a lightbox/fancybox when a person clicks an image. Kind of like this site has - http://www.adroll.com/ - if you click the "Click to Play" (which is an image) a window will open (although not lightbox/fancybox) and video will start autoplaying. Would preferably want to do it with the least possible programing needed. I can do some basic editing but don't really know how to write any PHP/javascript
|
Follow Tip #4: http://fancybox.net/blog . or I use Easy FancyBox for my wordpress sites. In the WP Admin, under Settings > Media you can edit the settings for Fancybox and it has a way to autodetect Youtube embeds.
|
Linking an image to open a youtube video in lightbox/fancybox in wordpress
|
wordpress
|
I got this error message when I was installing a plugin: "Unable to locate WordPress Content directory (wp-content)". I found a solution here: http:// wordpress.org/support/topic/cannot-find-content-directory-wp-content They suggested adding the following code to the wp-config.php file: <code> if(is_admin()) { add_filter('filesystem_method', create_function('$a', 'return "direct";' )); define( 'FS_CHMOD_DIR', 0751 ); } </code> This solution worked for me. My questions are: a) What does this code do? b) If I run into the same error on the production server is it safe to use this code? Thank you. -Laxmidi
|
The first part ( <code> add_filter() </code> ) tells WordPress to use the direct-write method. The second part ( <code> define() </code> ) tells WordPress to apply <code> 0751 </code> permissions to any directory it creates. More information here . I would not consider using the Direct Write method to be safe to use in a live, public, shared-hosting environment. Also, it might not - and in fact probably won't - work in a shared-hosting environment.
|
What Does this Code Snippet Do?
|
wordpress
|
I am using wordpress 3.1. and I have to reorganize categorize my posts. For this purpose, I am willing to remove some categories. Therefore, after login to admin section of my blog, I go to post > posts > I select the articles I want to edit > I select edit option from "Bulk Action" select box > I select new categories and put some tags as well. But it adds tags only. It doesn't remove previously assigned categories. Please let me know if there is any plugin to do the same work. Or some other alternative.
|
Bulk category update (wordpress inclusive) just for adding more categories or to remove a category which is among all selected posts.
|
Bulk category update is not updating
|
wordpress
|
I'm setting up a widget that allows to add an image to a sidebar / widget area. Basically I have a dropdown that allows the user to select one of the available sizes inside the theme's <code> functions.php </code> file using <code> add_image_size() </code> . Apart from the obvious ( renaming all the <code> add_image_size() </code> ) is there a way to get the size so that I can display that as well as the name? This is my current drop down code: <code> <?php $sizes = get_intermediate_image_sizes(); $available_size = '<select name="' . $this->get_field_name('image') . '" >' . "\r\n"; $available_size .= '<option value="0" selected="selected">Choose</option>' . "\r\n"; foreach ( $sizes as $size ) { if ( $instance['size'] == $size ) : $available_size .= '<option value="' . $size . '" selected="selected">' . $size . '</option>' . "\r\n"; else : $available_size .= '<option value="' . $size . '">' . $size . '</option>' . "\r\n"; endif; } $available_size .= '</select>' . "\r\n"; echo $available_size; ?> </code>
|
<code> <?php global $_wp_additional_image_sizes; print '<pre>'; print_r( $_wp_additional_image_sizes ); print '</pre>'; </code>
|
get_intermediate_image_sizes Get the Size Names but How Do I Get the Sizes?
|
wordpress
|
<code> //Geo Map add_action( 'woo_post_inside_after', 'my_geo_mashup' ); function my_geo_mashup() { global $post; if ( in_category('listings') ) { echo GeoMashup::map(); } } </code> Works to embed my map tag only on my single posts categorized as "listings" But, the embedded tag is also showing within the index of posts (thumb, title, meta, excerpt) and I need to remove it from the loop of posts and have it only show on the single.php thoughts?
|
<code> if ( is_single() && in_category('listings') ) { </code>
|
functions.php conditional tag - only show in single.php?
|
wordpress
|
I am looking to embed several shortcodes into my post template, but I want the tags to be conditional to a specific category (and subcats). I've looked through the codex, but I'm unsure where to start.
|
If you're embedding the code directly into the template file, why bother with shortcodes? Simply extract the code from the <code> add_shortcode() </code> function call, and add it to your template, wrapped in an appropriate conditional tag, such as <code> in_category() </code> , e.g.: <code> if ( in_category( $cat ) ) { // put shortcode code here } </code> Note: the <code> $cat </code> argument can be an ID, name, or slug.
|
hard code shortcode only on specific category
|
wordpress
|
I'd like my frontpage to display a list of my lastest blog posts merged with my latest "Products" custom post type posts. From the documentation i gather this should work: <code> query_posts( array('post_type' => array('post', 'product') ) ); while (have_posts()) : the_post(); the_title(); the_excerpt(); endwhile; </code> But that turns a weird list, made of pages ! Note that I've put it outside the loop. What am i doing wrong?
|
almost! when doing it outside of the loop, you have to reset the query as in: <code> wp_reset_query(); </code>
|
Query for multiple post types does not work
|
wordpress
|
I have a custom post type (CPT) called <code> property </code> . I have registered a featured property <code> metabox </code> for it as explained in this question "stackexchange-url ("How do I create a featured post within a custom post type?")". So a featured property has got <code> meta_key='property_featured' </code> and <code> meta_value=on </code> . What I would like to do is to display all <code> property </code> posts, but order them by <code> meta_key='property_featured' </code> . So that featured properties will appear first in the list on the first page. Similar behavior as <code> Sticky Posts </code> functionality. And all the rest <code> property </code> posts will be ordered by date created. Also, I need to make sure that pagination is working correctly - treating all the <code> property </code> posts alltogether. I use custom pagination code explained here . (Hope that makes sense). I have tried to specify arguments for WP_Query. However, if I specify: <code> 'meta_key' => 'property_featured', 'orderby' => 'meta_value' </code> then only <code> property </code> posts with that key are displayed as opposite to all <code> property </code> posts. If I delete <code> meta_key </code> from arguments then the query doesn't know what to sort them by. How do I display all the <code> property </code> posts, making sure that <code> featured </code> ones appear first and all other <code> property </code> posts order by published date? Many thanks, Dasha
|
<code> <?php // query posts $query_property = query_posts( array( 'orderby' => 'date meta_value' // orderby date AND meta value ) ); // First loop $query_feat = $query_string.'&meta_value=on&meta_key=property_featured'; // Offset for second loop $query_all = $query_string.'&offset=3&meta_key=property_featured'; // First loop if ( $query_feat->have_posts() : while ( $query_feat->have_posts() ) : # etc.... // do stuff endif; // Second loop if ( $query_all->have_posts() : while ( $query_all->have_posts() ) : # etc.... // do stuff endif; ?> </code>
|
Display all custom post type posts and order them by an optional meta_key
|
wordpress
|
I looked 2 days now but I couldn't figure out how this is done: I created a new page in wordpress. This is easy. Then I see, that I can put content into the page. This is easy too. But how can I edit the page and add let's say the googlemaps api to it. I know there is a plugin but for some technical reasons I need to use the normal include of google maps. =) The name of my page is "About". I can't find any about.html or about.php in my wordpress folder.
|
Your best bet is to create a new "physical page" and save it in your theme root folder as a template called something suchlike tpl_aufwind.php like this: <code> <?php /* * Template Name: Aufwind * * */ ?> </code> you will need that code above at the very top of the tpl_aufwind.php so that it shows up in wp-admin dashboard > > pages > > Page Attributes (right sidebar) > > Template Create Your Own Wordpress Template your options then if you need to add google maps the normal way is to hardcode it in (or if you know of a plugin where you can use a shortcode try that), but if you are using shortcodes or wish to show more on the page than just the Google Maps api then add a wp loop either above or below your hardcode so at least something on the page can be edited via the admin pages panel
|
After creating a new page, filling the page with structure
|
wordpress
|
I understand its advantage for something which will be released in public, but does it do any good for a developer by saving efforts as the code evolves over time? Like right now, I am hardcoding the table name in my queries, what if I was to change the name or something?
|
The purpose of <code> dbDelta() </code> is both to create and update tables. If you don't need updates then you can skip it. For keeping track of name you can simply follow WP convention and save name of your table in field of <code> $wpdb </code> object. Also note that you should consider there is possibility of code running on multisite. Even if you are not releasing it you might need to run it that way one day and then you are in for a painful refactoring if all table-related stuff is hardcoded.
|
Advantages of dbDelta
|
wordpress
|
I just installed WordPress 3.1.2, I got `Notice: automatic_feed_links is deprecated since version 3.0! Use add_theme_support( 'automatic-feed-links' ) instead. in /works/web/elements/wp-includes/functions.php on line 3303 I also got an error about Cannot open stream or something about <code> wp-cron.php?doing-cron </code> or something Its WordPress's own code, plus from a fresh install, this should not happen right? UPDATE The error I got was <code> Warning: fopen(http://elements/wp-cron.php?doing_wp_cron): failed to open stream: HTTP request failed! in /works/web/elements/wp-includes/class-http.php on line 1063 </code> Running WordPress 3.1.2 fresh install
|
it sounds like even though its a fresh install of WP 3.1.2 that you are also using an existing theme that is using a deprecated function (you havent said so but im presuming), if so paste this into your themes functions.php file (if your theme doesnt have one just create one and save it in your themes root folder).. <code> if(function_exists('add_theme_support')) { add_theme_support('automatic-feed-links'); } </code>
|
Getting Warnings & Notices from Fresh WordPress 3.1.2 install
|
wordpress
|
Running Wordpress 3.1.2 (newly updated, installed as 3.0 about a year ago) with subdomain multisite & using the Sunrise domain mapping plugin. The frontend is fast, the backend (wp-admin) is very slow on the network admin site (www.example.com/wp-admin) but runs at "normal speed" on one of the subdomain backends (foo.example.com/wp-admin). The server is our own, Ubuntu 10.04 with mod_security (which I've heard can slow things down). Is there anything I can do to speed up the backend or run a trace somehow?
|
I ended up enabling WP_DEBUG and found an error - something about <code> fsockopen() </code> not being able to connect to my host (I didn't write it down and now can't reproduce it) - and found that it was a DNS issue;- my subdomain (foo.example.com) was resolving to the correct IP (10.0.0.1) but the primary domain wasn't. I'm in the process of cloning & replacing a live server, external IP 10.0.0.1, internal IP 192.168.0.1; the new server has internal IP 192.168.1.1 (different subnet) and the external IP is accessed via a second interface. Adding the correct DNS entry in <code> /etc/hosts </code> fixed the problem: <code> 10.0.0.1 example.com www.example.com </code>
|
wp-admin slow in multisite
|
wordpress
|
I'm looking for a plugin that could help me managing more precisely medias. I'd like to be able to manage folders and sub-folders. I found out the ImageManager plugin but it's kind of outdated (http://soderlind.no/archives/2006/01/03/imagemanager-20/) so if anyone can help ;) PS : working on WP 3.1.1
|
You might give NextGEN Gallery Plugin a try. While not specifically intended for sub-folder management of media, the end result is the same, since images added to galleries are organized by folder.
|
Managing media by folder
|
wordpress
|
I have this very basic scheme to build my first plugin, but now I have one problem: when I put a hook to add_action on point 1 works, but i need to get the color from shortcode function, so, when i put the code at point 2 don't works. <code> class myclass { public function init() { global $shortcode_tags; add_shortcode( MYSHORTCODE, array( 'myclass', 'shortcode' ) ); // * point 1 return; } public function shortcode( ) { // want to run add_action here // i need to get the color from shortcode that part is done // question is how i can run add_action from here and pass // the variable to function globalcolor (point 3), then run it in wp_head? // * point 2 } function globalcolor($color) { echo '<style>body{color:' .$color . '}</style>' . "\n"; // * point 3 } } add_action( 'init', array( 'myclass', 'init', ) ); the code to add: add_action( 'wp_head', array( 'myclass', 'globalcolor' ) ); </code> Any ideas? and sorry for my bad english.
|
The main problem is you are using static callbacks while you should be passing on the object so you have access to your class properties. You can fire off the initialization like this: <code> class Myclass { public function __construct() { // Object method call, instead of a static one add_action('init', array($this, 'init')); } public function init() { // add_shortcode(...); } } // Trigger constructor new Myclass; </code> On another note, instead of hard-coding styles in the <code> <head> </code> , you may prefer to customize the body classes instead. The filter <code> body_class </code> is available for that (stackexchange-url ("related example")).
|
plugin development: problem with functions
|
wordpress
|
In the latest version of WP it's gone. Why?
|
It seems that it still exists, you just have to enable showing it, with screen options http://theandystratton.com/2011/wordpress-3-1-admin-bar-and-i-cant-see-custom-fields
|
Where did the Add New Custom Field go?
|
wordpress
|
I am developing a plugin. I want to know difference between <code> get_bloginfo('url'); </code> and <code> get_site_url(); </code> I got same output, then what's the difference?
|
<code> get_bloginfo('url') </code> calls <code> home_url() </code> calls <code> get_home_url() </code> reads option <code> home </code> <code> get_bloginfo('wpurl') </code> calls <code> site_url() </code> calls <code> get_site_url() </code> reads option <code> siteurl </code> <code> get_bloginfo('siteurl') </code> and <code> get_bloginfo('home') </code> are deprecated arguments and return <code> get_bloginfo('url') </code> ( <code> siteurl </code> argument is documented wrong in Codex as equal to <code> wpurl </code> , it's not in current code) The difference is that these two function chain to different options, which are typically same. It would be more appropriate to compare <code> get_bloginfo('url') </code> to <code> get_home_url() </code> or <code> get_bloginfo('wpurl') </code> to <code> get_site_url() </code> . Then the answer is that these functions are on different level in chain. Typically the deeper function is - the more flexible it is and the less filters output passes through.
|
What is difference between get_bloginfo('url') and get_site_url()?
|
wordpress
|
I've read several examples of how to do this but I still can't get it to work - each time I use get_posts() it seems to only keep and display the first set of results. loop.php <code> function home_index() { global $post; echo '<ul>'; $args = array( 'numberposts' => 3, 'offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'gp_news', 'post_status' => 'publish', 'meta_key' => '_thumbnail_id', 'meta_value' => 1, 'meta_compare' => '>=' ); $myposts = get_posts( $args ); foreach( $myposts as $post ) { setup_postdata($post); echo '<li>'; if ( has_post_thumbnail() ) { the_post_thumbnail( 'homepage-thumbnail' ); } ?> <h1>news <a href="<?php the_permalink(); ?>" title="Permalink to <?php esc_attr(the_title()); ?>" rel="bookmark"><?php the_title(); ?></a></h1> <?php the_excerpt(); ?> <a href="<?php the_permalink(); ?>">Continue...</a> <?php echo '</li>'; } $args = array( 'numberposts' => 1, 'offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'gp_competitions', 'post_status' => 'publish', 'meta_key' => '_thumbnail_id', 'meta_value' => 1, 'meta_compare' => '>=' ); $myposts = get_posts( $args ); foreach( $myposts as $post ) { setup_postdata($post); echo '<li>'; if ( has_post_thumbnail() ) { the_post_thumbnail( 'homepage-thumbnail' ); } ?> <h1>competition <a href="<?php the_permalink(); ?>" title="Permalink to <?php esc_attr(the_title()); ?>" rel="bookmark"><?php the_title(); ?></a></h1> <?php the_excerpt(); ?> <a href="<?php the_permalink(); ?>">Continue...</a> <?php echo '</li>'; } echo '</ul>'; } </code>
|
So I finally figured out 2 ways of doing it. The first way is... <code> global $wp_query; $args = array( array( 'numberposts' => 3, 'offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'gp_news', 'post_status' => 'publish', 'meta_key' => '_thumbnail_id', 'meta_value' => 1, 'meta_compare' => '>=' ), array( 'numberposts' => 1, 'offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'gp_competitions', 'post_status' => 'publish' ) ); echo '<ul class="hp_minifeatured">'; $temp_query = clone $wp_query; for($index = 0; $index < count($args); $index++) { $myposts = new WP_Query( $args ); if($myposts->have_posts()) { while($myposts->have_posts()) { $myposts->the_post(); echo '<li>'; if ( has_post_thumbnail() ) { the_post_thumbnail( 'homepage-thumbnail' ); } ?> <p><?php echo($args[$index]['post_type']); ?></p> <h1><a href="<?php the_permalink(); ?>" title="Permalink to <?php esc_attr(the_title()); ?>" rel="bookmark"><?php the_title(); ?></a></h1> <?php the_excerpt(); ?> <a href="<?php the_permalink(); ?>">Continue...</a> <?php echo '</li>'; } } } $wp_query = clone $temp_query; echo '</ul><div class="clear"></div>'; </code> ...but this results in using multiple queries. Another way is... <code> global $wpdb; global $post; $querystr = "(SELECT wp_posts.* FROM $wpdb->posts wp_posts, $wpdb->postmeta wp_postmeta WHERE wp_posts.ID = wp_postmeta.post_id and wp_posts.post_status = 'publish' and wp_posts.post_type = 'gp_news' and wp_postmeta.meta_key = '_thumbnail_id' and wp_postmeta.meta_value >= 1 ORDER BY wp_posts.post_date DESC LIMIT 3) union (SELECT wp_posts.* FROM $wpdb->posts wp_posts, $wpdb->postmeta wp_postmeta WHERE wp_posts.ID = wp_postmeta.post_id and wp_posts.post_status = 'publish' and wp_posts.post_type = 'gp_competitions' and wp_postmeta.meta_key = '_thumbnail_id' and wp_postmeta.meta_value >= 1 ORDER BY wp_posts.post_date DESC LIMIT 1)"; $pageposts = $wpdb->get_results($querystr, OBJECT); if ($pageposts) { foreach ($pageposts as $post) { setup_postdata($post); echo '<li>'; if ( has_post_thumbnail() ) { the_post_thumbnail( 'homepage-thumbnail' ); } ?> <h1><a href="<?php the_permalink(); ?>" title="Permalink to <?php esc_attr(the_title()); ?>" rel="bookmark"><?php the_title(); ?></a></h1> <?php the_excerpt(); ?> <a href="<?php the_permalink(); ?>">Continue...</a> <?php echo '</li>'; } } </code>
|
Displaying multiple post types on home page
|
wordpress
|
Is there any free starter theme to make mobile websites using WordPress?
|
Yes, there are a few - did you search for them? Here are the top results from Google: WPTouch Carrington Mobile WordPress Mobile Pack
|
Free starter theme to make mobile websites?
|
wordpress
|
I would like to expand only the active part of the sidebar menu and hide the parts which have nothing to do with the actual selection. Just like how its done on every Explorer like file manager, or how it is with accordion menus. In the default TwentyTen theme, this is the class definition for the active submenu: <code> menu-item menu-item-type-post_type menu-item-object-page current-menu-ancestor current-menu-parent current_page_parent current_page_ancestor </code> and this is the one for a non-active submenu: <code> menu-item menu-item-type-post_type menu-item-object-page </code> So I'm thinking about using something like: <code> li .menu-item ul .sub-menu { display: none; } li .current-menu-parent ul .sub-menu { display: inherit; } </code> Would something like this work? It must be a fairly common problem, but I have not found a single solution with Google. To have an idea why it’s important to make the menu smaller, here is the site I'm working on where the menu is overly complicated: http://kek.org.hu/kozossegikertek
|
I use just such a menu in my Oenology Theme. Feel free to use the sidebar menu CSS to suit your needs! Rather than try to post it all here, I'll just link to the Oenology GitHub repository . EDIT: Here's where the sidebar navigation menu style definitions start .
|
how to hide submenus for the not active pages
|
wordpress
|
I want to sync post edits on two sites. Test environment, not production. Single direction (site A to site B, but not backwards). Basically I edit post at my local test stack and same post (part of test content set) at remote server should be updated with identical copy of resulting content. I know that XML-RPC server is implemented in WordPress... But WordPress itself is not a XML-RPC client and I have no idea how easy would it be to make it into one (I am usually wary of XML-anything :) So should I go with XML-RPC and implement client functionality or that is not worth the time and I should build custom form or something at remote server to catch changes?
|
WordPress already has a XML-RPC client class implemented. It's in the same file as the server part: <code> class-IXR.php </code> located in <code> wp-includes </code> . The following code will generate a new post. You could wrap this in a function and attach it to the <code> save_post </code> / <code> update_post </code> action hook. To sync both parts, you could check for the post-slug or submit the same post-id to the post in the second blog. <code> $rpc = new IXR_Client('http://second-blog-domain.tld/path/to/wp/xmlrpc.php'); $post = array( 'title' => 'Post Title', 'categories' => array('Category A', 'Category B'), 'mt_keywords' => 'tagA, tagB, tagC', 'description' => 'Post Content', 'wp_slug' => 'post-slug' ); $params = array( 0, 'username', 'password', $post, 'publish' ); $status = $rpc->query( 'metaWeblog.newPost', $params ); if(!$status) { echo 'Error [' . $rpc->getErrorCode() . ']: ' . $rpc->getErrorMessage(); exit(); } </code>
|
WordPress as XML-RPC client?
|
wordpress
|
I'm still very novice at PHP so any help is greatly appreciated. Typically I have found the codex to be very helpful but it appears custom walkers may be outside its scope. I'd like to have thumbnails show in a custom nav menu which I have in a theme. From what I understand I need to create a custom walker to accomplish this. I've placed this <code> wp_nav_menu( array( 'container_class' => 'menu-stamp', 'theme_location' =>'stamp-menu' , 'walker' => new Thumbnail_Walker) ); </code> in my theme menu location and inserted the 3 thumbnail lines below the item output section below <code> /* * Create HTML list of nav menu items. * Replacement for the native Walker, using the description. * * @see stackexchange-url * @author toscho, http://toscho.de */ class Thumbnail_Walker extends Walker_Nav_Menu { /** * Start the element output. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. May be used for padding. * @param array $args Additional strings. * @return void */ function start_el(&$output, $item, $depth, $args) { $classes = empty ( $item->classes ) ? array () : (array) $item->classes; $class_names = join( ' ' , apply_filters( 'nav_menu_css_class' , array_filter( $classes ), $item ) ); ! empty ( $class_names ) and $class_names = ' class="'. esc_attr( $class_names ) . '"'; $output .= "<li id='menu-item-$item->ID' $class_names>"; $attributes = ''; ! empty( $item->attr_title ) and $attributes .= ' title="' . esc_attr( $item->attr_title ) .'"'; ! empty( $item->target ) and $attributes .= ' target="' . esc_attr( $item->target ) .'"'; ! empty( $item->xfn ) and $attributes .= ' rel="' . esc_attr( $item->xfn ) .'"'; ! empty( $item->url ) and $attributes .= ' href="' . esc_attr( $item->url ) .'"'; // insert thumbnail // you may change this $thumbnail = ''; if( $id = has_post_thumbnail( (int)$item->object_id ) ) { $thumbnail = get_the_post_thumbnail( $id ); } $title = apply_filters( 'the_title', $item->title, $item->ID ); $item_output = $args->before . "<a $attributes>" . $args->link_before . $title . '</a> ' . $args->link_after . $thumbnail . $args->after; // Since $output is called by reference we don't need to return anything. $output .= apply_filters( 'walker_nav_menu_start_el' , $item_output , $item , $depth , $args ); } } </code> I get an error for unexpected } at the end of the thumbnail code so its wrong but I'm not sure why.
|
Add a semicolon ; after <code> get_the_post_thumbnail( $id ) </code> : <code> get_the_post_thumbnail( $id ); </code>
|
wordpress custom walker for thumbnails with custom menu
|
wordpress
|
the question is simple :) I am making a theme that i will use in lots of sites. So, i don't want to go all the site and ftp the files every time i fix a bug or do a theme upgrade. Is there any way i can make a update system like the plugins hosted in wordpress plugin directory. Looking forward to your answer. Thanks! Solved: Thanks Chip Bennett for his excellent link. The update library for themes is now available in that site. You can find it here: http://w-shadow.com/blog/2011/06/02/automatic-updates-for-commercial-themes/ Always consider donation if you see some excellent work that made available for free.
|
You can also hook into the core update routine. (I'm looking for tutorial links, but my Google-fu is failing me this morning.) EDIT: See if this tutorial helps. It explains how to implement automatic upgrades for private/commercial (i.e. non-repository-hosted) Plugins.
|
Making update notification functionality for my themes
|
wordpress
|
I noticed that huffingtonpost.com and some other websites are using tags instead of categories for blog structure. For example the last tag in this post (like every post) is redirecting to "technology news" section of the menu. Is it OK to use tags instead of categories in the wordpress menu? what's the advantage of doing this with tags?
|
There is neither inherent advantage nor inherent disadvantage in using Tags versus Categories. Tags and categories are merely taxonomies , which are used to describe content. Tags and Categories don't actually provide site "structure", though their index pages can be added to custom Nav Menus. The primary difference between Categories and Tags is that Categories can be hierarchical, whereas Tags cannot.
|
Using Tags Instead of Categories for site structure
|
wordpress
|
In buddypress when a user wants to delete their own account --> is possible to delete all their attachments entries and images uploaded using media? Note: Images are not attached to posts, because im not letting users create normal posts, they only can upload images using media. Thanks in advance.
|
As media uploads are simly files with no related data stored, you can't do that unless you extend the user data and save the file names, etc. as user meta data. Simple answer: No, it doesn't work.
|
Delete all user attachments
|
wordpress
|
On my site, I am working on categorizing pictures based on what is in them and am having trouble listing the categories that apply to the post. For instance: A post might include a picture of an ice cream cone with three flavors of ice cream. My category hierarchy for this post might be: Flavors -> Vanilla, Mint Chip, Chocolate Style -> Cone However, I cannot seem to get a list that includes just children of 'flavors' or 'style', without listing all checked categories. Essentially I am hoping to have two, nicely organized lists, where one lists the flavors and the other lists the style. Just I don't want them both in the same list. Is this possible? -get_categories seems to have the proper arguments, but I have not been able to work it out. -the_category seems like it is close, but it doesn't allow for excluding a particular category from a list
|
Having two separate taxonomies may make sense for you in this case.
|
How do I list all child categories that apply to current post?
|
wordpress
|
Hi does anybody know where i can find a PayPal API tutorial that can help to point me in the right direction, What im needing is something that when payment is verified by paypal it bounces through some code to update_user_meta and also a few fields in a custom table in wp database. Information that i can find via google is pretty vague in what im requiring. regards Martin
|
Try working through the source code of a plugin such as PayPal Framework . From your question, the WP side is fairly trivial, but you should study general PayPal tutorials to understand the API, for example, here's the first search result from Google for PayPal API tutorial: Using PayPal's IPN with PHP Also some additional helpful info can be found here .
|
Paypal API and Wordpress
|
wordpress
|
With Disqus, can I allow the most 'liked' or 'favorited' comments to rise to the top, sort of like YouTube? If not, are there any other commenting systems that have this functionality built in?
|
You can use other plugins to do this too. Here are some I can think off: IntenseDebate Comment Rating Comments Vote I would suggest you use IntenseDebate by Automattic which means it will always be up-to-date and most compatible with your site.
|
disqus: comments that've been liked the most rise to the top...like youtube?
|
wordpress
|
This is probably a stupid question, but I am setting up a finnish Wordpress installation. The "custom fields" section in the "write post" section is gone; I gather it is hidden by default. That is a great step, but my finnish is a bit rusty, it's my first WP install, and I can't for the life of me find the switch to turn it on. Where do I do this? Edit: Martin shows a way to do this on a per-post basis, thanks for that. In my case, it would be useful to always show custom fields, so extra brownie points for anybody who can give me a hint on how to do that. I can't find any documentation on this.
|
Per default some meta boxes are hidden. These boxes are stored in an array which you can find in <code> wp-admin/includes/template.php#get_hidden_meta_boxes() </code> . There is a filter, and therefore a chance for a plugin: <code> <?php # -*- coding: utf-8 -*- /* Plugin Name: Enable Custom Fields per Default Version: 1.0 Required: 3.1 Author: Thomas Scholz Author URI: http://toscho.de License: GPL */ ! defined( 'ABSPATH' ) and exit; add_filter( 'default_hidden_meta_boxes', 'enable_custom_fields_per_default', 20, 1 ); /** * Removes custom fields from the default hidden elements. * * The original ( wp-admin/includes/template.php#get_hidden_meta_boxes() ): * array( * 'slugdiv', * 'trackbacksdiv', * 'postcustom', <-- we need this * 'postexcerpt', * 'commentstatusdiv', * 'commentsdiv', * 'authordiv', * 'revisionsdiv' * ) * * It has no effect if the user has decided to hide the box. * This option is saved in "metaboxhidden_{$screen->id}" * * @param array $hidden * @return array $hidden */ function enable_custom_fields_per_default( $hidden ) { foreach ( $hidden as $i => $metabox ) { if ( 'postcustom' == $metabox ) { unset ( $hidden[$i] ); } } return $hidden; } </code> As you can see, it is quite simple to enable more fields.
|
How to activate "custom fields" section in WP3
|
wordpress
|
I'd like to modify the comments list (comments left by users) on WP site using BuddyPress. In comments.php I narrowed it down to the following code: <code> <?php wp_list_comments( array( 'callback' => 'bp_dtheme_blog_comments' ) ); ?> </code> Any clue where I can find bd_dtheme_blog_comments , and the best way to modify it? Thank you.
|
Just search though your source code to find the function definition? It's in <code> plugins/buddypress/bp-themes/bp-default/functions.php </code> , and you can create your own version in your theme that should override the supplied one.
|
How to modify the comments list in WP & BuddyPress?
|
wordpress
|
I would like to remove blog posts from the home page if they belong to a certain category. How can I go about this in Buddypress (preferably without a plugin)?
|
If you mean filtering the home page activity stream by blog post category, it's not possible using any of the buit in BuddyPress template tags, functions or queries. I struggled with this same issue for months and finally gave up. If someone can prove me wrong I would love to hear the solution. If your not using the activity stream on your home page you can just use the WP_Query class to filter the posts. My use case for filtering the blog posts in the activity stream was to have separate activity stream pages for each post category. The closest thing I could find was the BuddyPress Links Plugin which creates a links post type that uses categories and is integrated into the BuddyPress activity stream but it required to much customization to get it to work how I wanted. Boone Gorges's (BuddyPress Lead Developer) reply to a support forum topic about using custom post types with BuddyPress: There isn’t really any support built into BP for custom pay types, but supporting them is no different from supporting other kinds of custom content in BP. See the BuddyPress Skeleton Component for some guidance on integrating custom content into BP navigation, etc. In the next couple weeks I might whip up a new plugin to provide a framework for custom post type support in BP (front end editing, integration into nav menus, etc). I’ve had to do stuff like this for a couple clients in the past few months and I think I have a sense of some good strategies. I also spoke with Boone at length at a WordCamp about adding custom meta or categories to any of the BuddyPress components and using the meta to filter the activity stream. He said it can be done but it would have to be completely coded from scratch and is not something nativly supported by BuddyPress. He also said the best way to accomplish this would be to create a new custom BuddyPress component.
|
Filter Home Page Posts in Buddypress
|
wordpress
|
I have a function that redirects users to the login page (home) if they're trying to access any other page without being logged in, here's how it works: <code> function restrict_access_if_logged_out(){ if (!is_user_logged_in() && !is_home()){ wp_redirect( get_option('home') ); } } add_action( 'wp', 'restrict_access_if_logged_out', 3 ); </code> Really simple and works fine, the problem is that is that I need to redirect them to the url they were trying to go to after they successfully log in, exactly like the WordPress backend works. Is there a way to do this? Thanks in advance!
|
Thanks all, I kind of used a bit of what everyone recommended so in the end my code looks like this: <code> function restrict_access_if_logged_out(){ if (!is_user_logged_in() && !is_home()){ wp_redirect( get_option('home') . '?redirect_to=' . esc_url($_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]) ); } } add_action( 'wp', 'restrict_access_if_logged_out', 3 ); </code> And on my login form (I'm hardcoding my login form in my aplication thanks @Ashfame for letting me know about wp_login_form I had no idea it existed) I added this when user credentials are fine and they're ready to login: <code> if (isset($_REQUEST['redirect_to'])){ wp_redirect($_REQUEST['redirect_to']); } else { wp_redirect(get_bloginfo('url') . '/groups/'); } </code> Thanks a lot for your help, I voted up everyone!
|
Redirect user to original url after login?
|
wordpress
|
In this website: http://alexchen.info/brianfunshine/ I have a navigation menu taken from the twentyten theme. I want to make some links clickeable and some not (some don't have to behave like a link). I have accomplished this with some CSS but it doesn't work in all browsers. The links are dinamically generated with: <code> wp_nav_menu </code> Any suggestions?
|
Create a custom menu item in the admin panel with a dummy URL, foo.com or whatever. Add it to the menu, then delete the target URL and save. The menu item will be rendered without an href attribute and will be unclickable.
|
Making some links generated from the wp_nav-menu function unclickeable?
|
wordpress
|
hey guys, I have no idea how to solve the following problem. I'd love to have a page-template that lists all it's child-pages but with the content. e.g. Imagine I have a page called "WORK. And "Work" has childpages like "Work 01", "Work 02", "Work 03", etc. I don't just want "WORK" to list the names of the childpages as a navigation, but rather just show all the pages under each other! Any idea how to solve that? Thank you.
|
You would need to create a page template and query those pages directly. <code> $args = array( 'post_type' => 'page', 'post__in' => array(430,436,433), //The Page IDs you want to query 'order' => 'ASC' ); $page_query = new WP_Query($args); </code> If you wanted to do this automatically and get the child pages of the current page you could use something like this: <code> <?php // Set up the arguments for retrieving the pages $args = array( 'post_type' => 'page', 'numberposts' => -1, // $post->ID gets the ID of the current page 'post_parent' => $post->ID, 'order' => ASC, 'orderby' => title ); $subpages = get_posts($args); // Just another WordPress Loop foreach($subpages as $post) : setup_postdata($post); ?> <h4><?php the_title(); ?></h4> <?php the_content(); ?> <?php endforeach; ?> </code>
|
Help with a custom page template - listing contents of childpages?
|
wordpress
|
I'm using the function echo time_ago() that displays the time like this: 5 days ago what's the best way to change it to 5d ago ? My research led me to human_time_diff() function located in "formatting.php" So I have tried directly editing the function located at /wp-includes/formatting.php but when I change "hours" to "h" and so on... it goes crazy and gives me errors. I know modifying the core isn't the best way, so any ideas? Thank you.
|
There is no filter for output of that function. You can fork (copy/rename/edit) it or add wrapper that will replace strings in output like this: <code> function short_time_diff( $from, $to = '' ) { $diff = human_time_diff($from,$to); $replace = array( 'hour' => 'h', 'hours' => 'h', 'day' => 'd', 'days' => 'd', ); return strtr($diff,$replace); } </code> PS afterthought - actually strings are localized so there is translation filter to use... But stuff to replace is to generic and that will risk breaking it elsewhere.
|
Modify human_time_diff() to shorten "days" to "d" and "hours" to "h" etc
|
wordpress
|
Does anyone know how to publish your own bookmarklet in a blog like wordpress or blogger? All of them seem to format the bookmarklet removing the javascript or messing it up. E.g., pasting this in wordpress blog: <a href="javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g> f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){$.hide()});" title="Run"></a> results in <a href="//ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){$.hide()});">Run jQuery Code</a>
|
Create a clickable link on http://jsfiddle.net/ and link to it.
|
Your own Bookmarklet in a blog
|
wordpress
|
Hey guys, When adding an image to a page or post wordpress is automatically adding a paragraph tag as parent holding the image. since there is no parent selector in CSS I'd love to find a solution to apply a specific classname to those paragraphs holding an actual image. Any idea if I can use add_filter() to apply a classname to each p that holds an image?
|
You could use jQuery if you don't mind to rely on JavaScript for adding the class. <code> $(document).ready(function() { $('p:has(img)').addClass('image'); }); </code> Update: the <code> .has() </code> method is probably faster, see this jsperf.com test . <code> $(document).ready(function() { $('p').has('img').addClass('image'); }); </code>
|
Apply class to every paragraph that holds image?
|
wordpress
|
This is my query, it shows the posts that have meta_key as extra1 and meta_value as test <code> <?php $customkey1 = 'extra1'; ?> <?php $customvalue1 = 'test'; ?> <?php query_posts('meta_key=' . $customkey1 . '&meta_value=' . $customvalue1); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php the_title(); ?> <?php endwhile; ?> <?php endif; ?> </code> My question is how can I still show the posts that have extra1 as metakey and test as metavalue but also the posts that have extra2 as metakey and test2 as metavalue in the same query. A combination of two or more variables.
|
If you are using WP 3.1, I would recommend using the <code> meta_query </code> parameter with the WP_Query class. <code> $args = array( 'meta_query' => array( array( 'key' => $customkey1, 'value' => $customvalue1, 'compare' => '=' ), array( 'key' => $customkey2, 'value' => $customvalue2, 'compare' => '=' ) ) ); $query = new WP_Query( $args ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); the_title(); endwhile; endif; </code> The meta_query parameter allows for very powerful queries with metadata. Sources: http://codex.wordpress.org/Function_Reference/WP_Query#Custom_Field_Parameters
|
How can I combine this php statement to get the results of multiple variable inputs?
|
wordpress
|
Preamble I'm finding myself building more and more WP sites "from scratch" as it were (ie: ignoring any theme designs out there and just creating a design wireframe purely on the needs of the client. Then I go out and either shop around a theme that has the right basic structure, or I start with TwentyTen and fork a child theme from there. Recently I've been getting the advice that maybe TwentyTen is not the best place to start as a base / parent theme because it's been stuffed with every technique possible in order to be a good learning platform. But maybe it's not the easiest or most efficient to customize (it has individual template.php pages for almost every part of the template hierarchy AND it has every template-part.php imaginable. And using existing themes (whether free themes, or themes from services like ThemeForest) is a bit of a crap-shoot - in terms of coding standards, usage of templates, template-parts or hooks, incompatibilities, etc etc. So that's not ideal either. Ideally, I'd like to whittle my starting choices to a small handful of really well-built, highly versatile, extremely barebones (light on design) themes that I could fork child themes from and adapt to my wireframe and design specs. Getting to the question What are your favourite barebones themes for forking off child themes? Why do you like them? thanks so much for your advice!
|
Bare bone themes are great, personally I prefer them over frameworks. I have noticed that 'liking' one over another comes down to how it feels, so I would suggest trying several out until you find one. For instance a lot people like WordPress boilerplate but I could not get the hang of it. My current favorite is Handcrafted WP, since it very similar to my own custom theme that was also based on Toolbox. Here are some worth checking out: Roots Handcrafted WP WordPress Shell ToolBox HTML5 reset TwentyTen Five Boilerplate HTML5 Boilerplate Starker HTML5 Starkers HTML5 V3 WP-Skeleton Bones rtPanel
|
Opinions and recommendations on the best barebones base theme
|
wordpress
|
Hey everyone. I'm not sure if what I'm experiencing is a result of a bug (due to the recent upgrade to 3.1.2) or poor coding. Ever since i upgraded to version 3.1.2 ive been experiencing a problem with two loops on my index page. Here's what I've got for my index page <code> <?php if ( ! is_paged() && is_front_page() ) { echo '<h6 class="sec1 title">FEATURE</h6>'; $sticky = get_option( 'sticky_posts' ); if ( isset( $sticky[0] ) ) { $args = array( 'posts_per_page' => 3, 'post__in' => $sticky, 'ignore_sticky_posts' => 1); $featured_query = new WP_query( $args ); while ($featured_query->have_posts() ) : $featured_query->the_post(); get_template_part( 'content', 'featured' ); endwhile; } // endif sticky } // endif is_paged ?> <?php $sticky = get_option( 'sticky_posts' ); echo '<h6 class="sec1 title">LATEST ARTICLES</h6>'; $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; $query_args = array( 'posts_per_page' => 10, 'paged' => $paged, 'post__not_in' => $sticky ); query_posts($query_args); if (have_posts() ) : while (have_posts() ) : the_post(); get_template_part( 'content', get_post_format() ); ?> <!--<?php trackback_rdf(); ?>--> <?php endwhile; else: ?> <div class="box"> <p> <?php _e( 'Sorry, no posts matched your criteria.' ); ?> </p> </div> <?php endif; ?> // Navigation comes over here </code> Say for example the first loop (sticky posts) - which IS NOT paged, yields 3 posts , and the second loop (all other posts) - which IS paged, yields 10 posts . The problem I'm experiencing is that when i move to the next page, the last 3 posts from the second loop on page 1 get repeated at the the top of page 2. Note: The first loop is only on page 1, and doesn't get repeated on the second page, which is what i intended. Note 2: I assume that the second loop is considering - in some odd way, the posts from the first loop as one of its own. But it still shows 10 posts on the first page + 3 posts from the first loop. So in essence its: PAGE 1: Loop 1: 3 posts (3 unique posts) Loop 2: 10 posts (10 unique posts) PAGE 2: Loop 1: Doesn't execute - as intended, due to ( ! is_paged() ) Loop 2: 10 posts (7 unique, 3 duplicated from the last 3 (from the second loop) on the first page) So this is what i tried, i removed the ( ! is_paged() && is_front_page ) condition along with the entire first loop, and the problem got resolved. What am i doing wrong?
|
I tried reverting back to the older version 3.0.x, but the problem remained the same. The answer can be found here: stackexchange-url ("stackexchange-url
|
Wordpress loop problem: Multiple loops, index.php and is_paged causing duplicate posts on next page
|
wordpress
|
I'm working on a script that will drop articles directly into the wordpress database, using wp_insert_posts(). However, I have networking enabled and the wp_insert_post() reference page has no documentation relating to using wp_insert_post() to upload to a specific site on the network. How can I do this with wp_insert_posts()? Or is their another function which does this?
|
When using function like <code> wp_insert_post() </code> It will work on the currently active blog, meaning that if you are on a blog in your network with blog_id of 2 the the post you insert using <code> wp_insert_post() </code> will be inserted to that blog. Now if you want to insert the post to a specific blog you can use <code> switch to blog() </code> function which will tell WordPress that "the current blog is" so you can use <code> wp_insert_post() </code> to insert to that specific blog. Then to tell WordPress that what is the real current blog you can use <code> restore_current_blog() </code> so: <code> switch to blog($wanted_blog_ID); ... ... your wp_insert_post() stuff ... ... restore_current_blog(); </code> take a look at WPMU Functions to understand more about the available functions in a network.
|
Using wp_insert_post() with Networking enabled
|
wordpress
|
im trying to implement uploading via a meta box without using the media manager, but i want it to add as a post attachment. im currently doing it just uploading and saving to the server. <code> <?php define("THUMB_DIR", WP_CONTENT_DIR . '/plugins/meta-upload/thumbs/'); define("THUMB_URL", WP_CONTENT_URL . '/plugins/meta-upload/thumbs/'); // this needs to be implemented function fileupload( $label ) { ?> <tr> <td class="left_label"> <?php echo $label; ?> </td> <td> <form name="uploadfile" id="uploadfile_form" method="POST" enctype="multipart/form-data" action="<?php echo $this->filepath.'#uploadfile'; ?>" accept-charset="utf-8" > <input type="file" name="uploadfiles[]" id="uploadfiles" size="35" class="uploadfiles" /> <input class="button-primary" type="submit" name="uploadfile" id="uploadfile_btn" value="Upload" /> </form> </td> </tr> <?php } //this needs to be added too function fileupload_process() { $uploadfiles = $_FILES['uploadfiles']; if (is_array($uploadfiles)) { foreach ($uploadfiles['name'] as $key => $value) { // look only for uploded files if ($uploadfiles['error'][$key] == 0) { $filetmp = $uploadfiles['tmp_name'][$key]; //clean filename and extract extension $filename = $uploadfiles['name'][$key]; // get file info // @fixme: wp checks the file extension.... $filetype = wp_check_filetype( basename( $filename ), null ); $filetitle = preg_replace('/\.[^.]+$/', '', basename( $filename ) ); $filename = $filetitle . '.' . $filetype['ext']; $upload_dir = wp_upload_dir(); /** * Check if the filename already exist in the directory and rename the * file if necessary */ $i = 0; while ( file_exists( $upload_dir['path'] .'/' . $filename ) ) { $filename = $filetitle . '_' . $i . '.' . $filetype['ext']; $i++; } $filedest = $upload_dir['path'] . '/' . $filename; /** * Check write permissions */ if ( !is_writeable( $upload_dir['path'] ) ) { $this->msg_e('Unable to write to directory %s. Is this directory writable by the server?'); return; } /** * Save temporary file to uploads dir */ if ( !@move_uploaded_file($filetmp, $filedest) ){ $this->msg_e("Error, the file $filetmp could not moved to : $filedest "); continue; } $attachment = array( 'post_mime_type' => $filetype['type'], 'post_title' => $filetitle, 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $filedest ); require_once( ABSPATH . "wp-admin" . '/includes/image.php' ); $attach_data = wp_generate_attachment_metadata( $attach_id, $filedest ); wp_update_attachment_metadata( $attach_id, $attach_data ); } } } } add_action('admin_menu', "post_upload_box_init"); add_action('save_post', 'post_save_thumb'); function post_upload_box_init() { add_meta_box("post-thumbnail-posting", "Dark Toob Thumbnail", "post_upload_thumbnail", "post", "advanced"); } function post_upload_thumbnail() { global $post; ?> <script type="text/javascript"> document.getElementById("post").setAttribute("enctype","multipart/form-data"); document.getElementById('post').setAttribute('encoding','multipart/form-data'); </script> <?php $thumb = get_post_meta($post->ID, 'custom_thumbnail',true); if ( $thumb ) { ?> <div style="float: left; margin-right: 10px;"> <img style="border: 1px solid #ccc; padding: 3px;" src="<?php echo THUMB_URL . $thumb; ?>" alt="Thumbnail preview" /> </div> <?php } else { ?> <div style="float: left; margin-right: 10px; width: 200px; height: 150px; line-height: 150px; border: solid 1px #ccc; text-align: center;">Thumbnail preview</div> <?php } ?> <div style="float: left;"> <p> <label for="thumb-url-upload"><?php _e("Upload via URL, or Select Image (Below)"); ?>:</label><br /> <input style="width: 300px; margin-top:5px;" id="thumb-url-upload" name="thumb-url-upload" type="text" /> </p> <p> <p><label for="thumbnail"><?php _e("Upload a thumbnail"); ?>:</label><br /> <input id="thumbnail" type="file" name="thumbnail" /> </p> <p><input id="thumb-delete" type="checkbox" name="thumb-delete"> <label for="thumb-delete"><?php _e("Delete thumbnail"); ?></label></p> <p style="margin:10px 0 0 0;"><input id="publish" class="button-primary" type="submit" value="<?php _e("Update Post"); ?>" accesskey="p" tabindex="5" name="save"/></p> </div> <div class="clear"></div> <?php } function post_save_thumb( $postID ) { global $wpdb; // Get the correct post ID if revision. if ( $wpdb->get_var("SELECT post_type FROM $wpdb->posts WHERE ID=$postID")=='revision') $postID = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE ID=$postID"); if ( $_POST['thumb-delete'] ) { @unlink(THUMB_DIR . get_post_meta($postID, 'custom_thumbnail', true)); delete_post_meta($postID, 'custom_thumbnail'); } elseif ( $_POST['thumb-url-upload'] || !empty($_FILES['thumbnail']['tmp_name']) ) { if ( !empty($_FILES['thumbnail']['name']) ) preg_match("/(\.(?:jpg|jpeg|png|gif))$/i", $_FILES['thumbnail']['name'], $matches); else preg_match("/(\.(?:jpg|jpeg|png|gif))$/i", $_POST['thumb-url-upload'], $matches); $thumbFileName = $postID . strtolower($matches[0]); // Location of thumbnail on server. $loc = THUMB_DIR . $thumbFileName; $thumbUploaded = false; if ( $_POST['thumb-url-upload'] ) { // Try just using fopen to download the image. if( ini_get('allow_url_fopen') ) { copy($_POST['thumb-url-upload'], $loc); $thumbUploaded = true; } else // If fopen doesn't work, try cURL. if( function_exists('curl_init') ) { $ch = curl_init($_POST['thumb-url-upload']); $fp = fopen($loc, "wb"); $options = array(CURLOPT_FILE => $fp, CURLOPT_HEADER => 0, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_TIMEOUT => 60); curl_setopt_array($ch, $options); curl_exec($ch); curl_close($ch); fclose($fp); $thumbUploaded = true; } } else // Attempt to move the uploaded thumbnail to the thumbnail directory. if ( !empty($_FILES['thumbnail']['tmp_name']) && move_uploaded_file($_FILES['thumbnail']['tmp_name'], $loc) ) $thumbUploaded = true; if ( $thumbUploaded ) { if ( !update_post_meta($postID, 'custom_thumbnail', $thumbFileName) ) add_post_meta($postID, 'custom_thumbnail', $thumbFileName); } } } </code>
|
You may want to take a look at Steve Taylors plugin and his approach here Dominik "ocean90" Schilling - the author of the (new in 3.5) media library, has a GitHub repository where he shows off some demos. In short, you might not be able to implement a drag&drop style media uploader in a meta box with his tutorials, but it should be possible... somehow.
|
upload image in a meta box
|
wordpress
|
DO you use links in your wordpress and why? Isn't it much easier to use you browser's bookmarks? I don't get the idea of having links at all! Please enlight me!
|
Links are not supposed to be bookmarks, they are more of a convenient way to integrate links in site. The feature is kinda underused (I think blogrolls it single most common usage for it and seems to start to fade) and so under-appreciated. Really there are plenty of stuff you can do with links, for example I wrote a post how to use them to display banners .
|
Do you use links?
|
wordpress
|
I'm using Wordpress 3.1.2, and have three blogs in a wordpress network. I would like to change some settings for a specific plugin, but have the changes applied to all the blogs on the network. I can't change plugin settings on the "Network Admin", and instead have to do it on the "Site Admin" page for each individual blog. I'm looking for the ability to change settings "sitewide" as is done, for example, by this outdated plugin .
|
It really depends on the plugin developer now on how they incorporate settings the other option is to try and put it inside the /wp-content/mu-plugins but im not sure if that will allow you to have only a master setting you could also try hard coding it in the plugin files. What plugin is it i might be able to better help you
|
Network-Wide Plugin Settings Management
|
wordpress
|
I'd like to pull data from a mySQL database and put it in some tables in a WP page. I'm using WP 3.1.1. Imagine that I've got a table of sales figures that I want to pull from a mySQL database and then display them in a table on a WordPress page. I know just enough php to make a db connection, pull the data, and echo it out. But, I'm not sure what is the best way to do this in conjunction with WordPress. a) Is it okay if I put my tables in the WordPress database? (This way I could use the WP's database connection). Would they cause some sort of conflict? Would they be over-written when I upgrade WP? b) Where should I put my php code? Can I just plop the php in the WP's HTML editor when I create a new page? If not, should I just make a php file and include it somewhere? If so, where would I put the include line? c) Is there a plugin that allows you to pull data from a database? I've seen some table plugins, but the data had to be input by hand or pulled from XML. Unfortunately, I've got too many tables to input the data by hand. Any suggestions? Thank you! -Laxmidi
|
Yes, you can store your data in your own tables in WordPress database. There are few things that you need to take care of: Make sure your data can't be really represented using the built-in Wordpress content types. Prefix your tables with WordPress Prefix + your prefix. WordPress table prefix is $wpdb-> prefix. Use the global $wpdb to query your custom tables, don't make a new connection. Now to answer your questions: Yes, it is okay to store data in custom database tables. It won't conflict if you prefix your table names. There are many places to put your PHP code. But don't put your PHP code in the HTML editor. i) You can create your own plugin and for that you can put the code in plugin file which can be stored in wp-content/plugins/ directory. ii) You can write your code in your theme's functions.php file. You don't need a plugin to query tables in Wordpress. Just read about $wpdb .
|
Using Dynamic Data Pulled from a MySQL Table in a WordPress Page
|
wordpress
|
I am trying to using jquery ui tabs with ajax calls to run a function. Here is the code i am using: <code> function ajax_load_user_feed(){ if(isset($_GET['type'])) $type = $_GET['type']; if(isset($_GET['userid'])) $userid = $_GET['userid']; if(!$type && !$userid){ $type = 'error'; show_feed($type); die(); } else { $user_info = get_userdata($userid); show_feed($type, $user_info); die(); } } add_action('wp_ajax_load_user_feed', 'ajax_load_user_feed'); function show_feed($type, $user){ if($type == 'rss'){ echo '<div>Show rss Feed</div>'; } elseif($type == 'twitter'){ echo '<div>Show twitter Feed</div>'; } elseif($type == 'facebook'){ echo '<div>Show Facebook Feed</div>'; } elseif($type == 'error'){ echo '<div class="feed_error">Something is wrong with the request!</div>'; } } </code> The html for jqurey ui tabs: <code> <div class="tabs"> <ul id="social-media-activity-button" class="tabs"> <?php if($author->feeds): ?> <li class="activity-blogs"><a title="activity_feed" href="<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php?action=load_user_feed&type=rss&userid=<?php echo $author->ID; ?>">Blogs</a></li> <?php endif; if($author->twitter): ?> <li class="activity-twitter"><a title="activity_feed" href="<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php?action=load_user_feed&type=twitter&userid=<?php echo $author->ID; ?>">Twitter</a></li> <?php endif; if($author->facebook): ?> <li class="activity-facebook"><a title="activity_feed" href="<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php?action=load_user_feed&type=facebook&userid=<?php echo $author->ID; ?>">Facebook</a></li> <?php endif; ?> </ul> <h2 class="dotted">Activity Feed</h2> <div id="activity_feed"> </div> </code> What i am trying to do here is calling admin-ajax.php file to call the function <code> load_user_feed(); </code> function. Now the code is works for logged in users only. I mean when users logged in the see the feeds but logged out users are seeing only <code> -1 </code> in output. Here is the page: http://citystir.com/author/designdons/ There must be some good way to call ajax with jquery ui tabs. Waiting for your help. Thanks!
|
Your ajax hook <code> add_action('wp_ajax_load_user_feed', 'ajax_load_user_feed'); </code> is for logged in users only, if you want none logged in users (guests or visitors) then add: <code> add_action('wp_ajax_nopriv_load_user_feed', 'ajax_load_user_feed'); </code> and you should be fine.
|
How to make ajax call in wordpress in right way?
|
wordpress
|
I've installed Easy Post Types created a custom post type: Attractions created an Attraction: (joes-cafe) created a category set: attraction-type (cafe) copied single.php to single-attractions.php added the category: cafe to wp-navigation-menu But when I visit the menu item, I get a 404, when i search for the cafe by name, i see an excerpt, but clicking its title gives me a 404! Any Clues? What am i doing wrong? I am using a Thematic child theme, and i duplicated single-attractions.php as single-attraction.php just in case, because i found the distinction confusing... Thanks, Tim
|
The rewrite rules need to be flushed when you add a custom post type, this can be done by visiting the permalinks admin page.
|
Easy-Post-Type is visible in search, but 404 when clicked
|
wordpress
|
I have a problem when i want to upgrade Wordpress or install plugin via the Admin. It's say that I don't have the permission to write. but I can upload images and other things... but i cannot install plugin and/or update plugin/WordPress. I know that my user server is not the file owner but is part of the group owner.
|
I find the answer to my question <code> define('FS_METHOD', 'direct'); </code> core.trac.wordpress.org/ticket/10205 thanks @xLRDxREVENGEx for the tip for upgrading manually but when you make a theme framework and you want to update you parent theme framework in the admin you need to apply the <code> define('FS_METHOD', 'direct'); </code>
|
Upgrading WordPress (File permission group owner)
|
wordpress
|
I've set 2 new roles for my site using the "Members" plugin - "sellers" and "buyers". Each role should have its own registration page and login. A visitor can register as both a buyer and a seller but he can only be logged in as one of them. So, if a visitor has logged in as a seller and then goes to the buyer page he'll be able to login as a buyer and when he does so he will automatically be logged out as a seller. I've searched for hours for a plugin that will give me the option to do this but couldn't find one. Sounds like a pretty common configuration in websites with different role registrations. Does a plugin such as this even exist? And if not how can this be done?
|
Creating two separate registration for different roles is easy: <code> //create a hidden field for role add_action('register_form','add_hidden_role_field'); function add_hidden_role_field(){ if (isset($_GET['role'])){ echo '<input id="user_email" type="hidden" tabindex="20" size="25" value="'.$_GET['role'].'" name="role"/>'; } } add_action('user_register', 'register_role'); //save the the role function update_role($user_id, $password="", $meta=array()) { if (isset($_POST['role'])){ $userdata = array(); $userdata['ID'] = $user_id; $userdata['role'] = $_POST['role']; //only allow if user role is my_role to avoid a few new admins to the site if (($userdata['role'] == "seller") or ($userdata['role'] == "buyer")){ wp_update_user($userdata); } } } </code> and now you can link each role with "its own" registration form: <code> seller: http://example.com/wp-login.php?action=register&role=seller buyer: http://example.com/wp-login.php?action=register&role=buyer </code> but as Milo commented: "if someone registers as a buyer, there's no way they can log in as anything but buyer with their credentials" which means that they would have to use a different email to register the other role. Update this is an update with an example to show how you can use the same fore but with different fields for each role. So you just need to change the functions a bit: <code> //create a hidden field for role and extra fields needed add_action('register_form','add_hidden_role_field'); function add_hidden_role_field(){ if (isset($_GET['role'])){ $user_type = $_GET['role']; echo '<input id="user_email" type="hidden" tabindex="20" size="25" value="'.$_GET['role'].'" name="role"/>'; } if (isset($user_type) && $user_type == "seller"){ //add extra seller fields here eg: ?> business name: <input id="user_email" type="text" tabindex="20" size="25" value="" name="business_name"/> business address: <input id="user_email" type="text" tabindex="20" size="25" value="" name="business_address"/> <?php } if (isset($user_type) && $user_type == "buyer"){ //add extra buyer fields here eg: ?> buyer name: <input id="user_email" type="text" tabindex="20" size="25" value="" name="buyer_name"/> <?php } } </code> this way only the fields needed by the specific role are shown. Next is if you want to have some kind of validation to these extra fields you can use <code> register_post </code> hook for example: <code> add_action('register_post','my_user_fields_validation',10,3); function my_user_fields_validation($login, $email, $errors) { global $firstname, $lastname; //get the role to check if (isset($_POST['role'])){ $user_type = $_POST['role']; } //check the fields according to the role if (isset($user_type) && $user_type == "seller"){ //check sellers fields if ($_POST['business_name'] == '') { $errors->add('empty_business_name', "<strong>ERROR</strong>: Please Enter in a Business name"); } if ($_POST['business_address'] == '') { $errors->add('empty_business_address', "<strong>ERROR</strong>: Please Enter in Business address"); } } if (isset($user_type) && $user_type == "buyer"){ //check buyers fields if ($_POST['buyer_name'] == '') { $errors->add('empty_buyer_name', "<strong>ERROR</strong>: Please Enter in a Buyer name"); } } } </code> then if every thing is fine just save the fields in the user meta based on the role <code> add_action('user_register', 'update_role'); //save the role function update_role($user_id, $password="", $meta=array()) { if (isset($_POST['role'])){ $userdata = array(); $userdata['ID'] = $user_id; $userdata['role'] = $_POST['role']; $user_type = $_POST['role']; //only allow if user role is my_role to avoid a few new admins to the site if (($userdata['role'] == "seller") or ($userdata['role'] == "buyer")){ wp_update_user($userdata); } if (isset($user_type) && $user_type == "seller"){ //save sellers fields update_user_meta($user_id, 'business_name', $_POST['business_name']); update_user_meta($user_id, 'business_address', $_POST['business_address']); } if (isset($user_type) && $user_type == "buyer"){ //save sellers fields update_user_meta($user_id, 'buyer_name', $_POST['buyer_name']); } } } </code>
|
Separate registration and login for different roles
|
wordpress
|
I'm looking for a slider plugin that allow me to insert additional buttons in a slider, not the next and prev neither numbers, I mean buttons to redirect users to a different page, etc... I would appreciate your info! Regards
|
You should look for sliders that allow you to insert HTML content inside your slides. jQuery Cycle is a good example, look at non-image content: http://jquery.malsup.com/cycle/int2.html
|
Sliders with buttons
|
wordpress
|
hey guys, it's weird and I've never experienced that before. I've created a new blog and a custom theme. I'm using <code> <?php echo date("H:i"); ?> </code> in my theme. The time that's put is 2h earlier. e.g. if it's actually 16:00 o'clock the date generated with date() is 14:00. I don't know why that happens? I'm using the german wordpress version with the german language pack. Also doesn't make a difference when putting <code> setlocale(LC_ALL, 'de_DE'); date_default_timezone_set('Europe/Berlin'); </code> into wp-config.php. any idea how I could solve that? the time set in my wordpress settings is UTC+2 which is the correct time.
|
This could probably make exquisite debugging session, but taking in account it's Friday evening - just use <code> date_i18n() </code> instead and let WordPress deal with a huge mess that time/date issues usually are.
|
wrong php date()?
|
wordpress
|
I'm trying to add a stylesheet to the options page for my plugin - code looks like this: <code> add_action( 'admin_print_styles-rps-paypal', 'rps_paypal_add_css' ); function rps_paypal_add_css() { wp_enqueue_style( 'rps_paypal', plugins_url( '/rps_paypal/css/rps-paypal.css' ) ); } add_action( 'admin_menu', 'rps_myplugin_add_page' ); function rps_myplugin_add_page() { add_options_page( 'My PayPal Plugin', 'My PayPal Plugin', 'manage_options', 'rps-paypal', 'rps_myplugin_option_page' ); } </code> Can't figure out why it's not showing up...
|
the call to add_options_page will return the string literal to use for your RSS, so it should look something like this: <code> $page = add_options_page( ... ); add_action( 'admin_print_styles-' . $page, 'rps_paypal_add_css' ); </code> More info here: http://codex.wordpress.org/Function_Reference/wp_enqueue_style
|
wp_enqueue_style for plugin options page
|
wordpress
|
Well my question is quite simple, I would like to populate a field with the value of a variable that have been passed via a $_GET Request. thanks
|
Take a look at Contact Form 7 Dynamic Text Extension
|
Wordpress Contact Form 7: populate the value of a field dynamically with PHP
|
wordpress
|
So I have this code: <code> <?php wp_list_categories(array( 'show_option_all' => 'All Categories', 'orderby' => 'ID', 'order' => 'DESC', 'use_desc_for_title' => 0, 'child_of' => 0, 'exclude' => '', 'exclude_tree' => '', 'include' => '', 'hierarchical' => 1, 'title_li' => NULL, 'show_option_none' => NULL, 'number' => NULL, 'taxonomy' => 'category' ));?> </code> And the first item, <code> show_option_all </code> , produces the following link: <code> <li><a href="http://mywebsite.com">All Categories</a></li> </code> That is, it is calling <code> index.php </code> or <code> home.php </code> when what I would like is for it to call the <code> category.php </code> template, where I would expect it to produce a link like this: <code> <li><a href="http://mywebsite.com/categories/all">All Categories</a></li> </code> Or something. Am I missing something?
|
Isaac, I guess this derived from the <code> wp_dropdown_categories() </code> function which is supposed to work like a filter on a page -- display posts from a certain category or display posts from all categories. So <code> wp_list_categories </code> does the same but in a list of links instead of a dropdown menu, so it's still intended to filter posts by category, meaning "All categories" will link to posts from all the available categories, which is actually "removing the filter", thus pointing at your home page or blog page. You can create a page template to display the posts in the fashion you like and link to that page manually, disabling <code> show_option_all </code> in your function call.
|
Does "show_option_all" in wp_list_categories do anything?
|
wordpress
|
I would like to introduce page-hierarchy navigation in my WordPress blog using subpages. So each page may have sub-pages, but I'd like that when a visitor clicks on a page header he will be redirected to a specific subpage. For example, say my hierarchy is: <code> 1. Movies 1.1 General 1.2 Westerns 1.3 Animated 2. Music 2.1 General 2.2 Classic 2.3 Country </code> What I want is that when someone clicks on "Movies" he will reach "Movies/General". Can this be achieved using plugins alone? If not, what's required?
|
Using WordPress custom nav menus create a menu and add the "General" page 2 times. The first as the parent and the second as the first child then add the rest of the pages as childs under the first General. Change the title in the first general to movies then on the front end when a user clicks movies they will got to the general page.
|
Directing a page to a default subpage
|
wordpress
|
When uploading images via the media manager there are a couple of set sizes available such as thumb, medium and large. I do know how to add additional sizes, but I have yet to get it to insert an image with width='x%'. the concept is that i am building an adaptive theme and I never want the inserted image to be larger than the container even upon browser resize, By manually editing the inserted image code to include widths with a %, then it works just fine. However trying to get my users to remember this is downright impossible. What I would like would be a button to insert an image into a post with a set % (percentage) instead of a set pixel width. possible?
|
I guess what you're looking for is the <code> $content_width </code> global that would basically limit the width of your images, used in functions.php. Some more info here: http://mainstreetopen.com/wordpress-26-and-full-width-images/
|
Set Image width='x%' (percentage width not pixel width) when inserted via the media manager?
|
wordpress
|
I'm studying TwentyTen, under the assumption that it contains the best practices for writing themes and modifying them using child themes. I'm noticing what looks like a really redundant practice, which is to overload not the base template file (eg: attachment.php) but instead to overload the template-part file (eg: loop-attachment.php). Can someone explain the benefit of this approach? If you look at attachment.php, for example, inside TwentyTen, it's really nothing more than a shell - gets header, creates some divs, then calls the REAL attachment file using get_template_part - then displays the footer. And then if you look at single.php, it's almost exactly the same deal. I can understand wanting to define an outer structure once, and then using different parts of the loop as internals, but that's not what TwentyTen is doing, since it redefines this outer structure over and over in all these different template files. Can someone either confirm that the approach taken in TwentyTen is overkill and just obfuscates theme overloading, or point me to some good examples where this technique can actually make your life easier. Right now I'm feeling I should ignore the whole get_template_part thing, and just overload the base template file. Thanks!
|
TwentyTen was designed to help understand the WordPress theming system and that is why it has more lines of comments then actual code. So looking at TwentyTen you need to understand that they tried to include every file in the Template Hierarchy (eg: attachment.php, single.php, page.php) and every template tag there is (including: <code> get_template_part() </code> which is relatively new). The best practices would be to use as much theme files and template parts as you can if the theme you are designing / developing is to distributed to make the life of the people who use it as easy as possible in customizing it for there needs, but if its just for your own use then a single index.php with 3-4 template parts would be fine if you know what you are doing. For example I've recently had a client that wanted to use EvoLve theme which is a beautifully designed but very badly developed. I needed to create custom templates for a custom post type and i can tell you that the it wasn't nice at all and i had to do some major reverse engineering to get it done. but then again it depends on what you like to do with the theme (share or self use) and even then its up to you.
|
TwentyTen: Overloading template.php files vs. get_template_part
|
wordpress
|
I'm about to embark on creating a new WP that, at the core, will rely on a custom post type. I'm building this plugin for a client, but plan to make it flexible enough to release in the future. My client has a specific need for the plugin and I ultimately want it to be flexible enough to meet the needs of many users. As such, I plan to create an admin area where a user can enter the various args that would go into the <code> register_post_type </code> function. My thoughts in doing so are that the end user will be able to leverage the power of my plugin while also being able to preciously control the custom post type that the plugin generates. I like the idea of easily giving this control over to non-technical users; however, my concern is that I could invite a number of potential issues by doing so. For instance, imagine that a user uses the interface to name the custom post type "whirly-doos", but later thinks that's a dumb name and decides to call it "howdy-doos". This could potentially orphan their previous custom post types. So...my questions are: is this a good way of going about building this plugin? How would you implement the plugin and maintain a nice balance between customization and stability? Thanks in advance!
|
I would not give them control over the actual name of the post type. What if they rename it to revision or attachment? Big time site wreckage potential there. I'd say stick with the more "trivial" things; basically, only those things that don't go into the database: labels, rewrite settings (although that could be potentially hazardous in the hands of an uneducated user), menu icon, menu position, exclude from search, and supports. I think allowing GUI management of those things would give the user the most flexibility without compromising stability.
|
Building plugin with changeable custom post type values...advice needed
|
wordpress
|
I'm creating a parent theme and several child themes. But how can I prevent the parent theme from ever being used?
|
Not using the current system. In order to serve as a valid Template for a Child Theme, the Parent Theme must exist, and be a valid Theme. That's because the Parent Theme's template files must be accessible via <code> locate_template() </code> , in order for the Child-Parent fallback to work properly. Note: if this core Trac ticket is implemented, then you'll be able to filter <code> locate_template() </code> , which would conceivably enable you to put your Parent Theme in a separate location, not accessible by <code> Dashboard -> Appearance -> Themes </code> .
|
Child themes: disabling the parent
|
wordpress
|
With the help of the internet and you lot, I have been stumbling about to create a worpress site here . So at this stage, its not exactly a default install. - Im running the boldy theme from Site5. - Have made some tweaks to the underlying PHP, but nothing that I can think that would cause this issue. Issue : Slugs setup normally for categories: But the URL it takes me too is a 404. http://www.dekho.com.au/category/screencasts/ All my categories are broken, except my case studies category . - This uses a Portfolio template to display posts in that category (part of Boldy theme) Im sure I had both the 'portfolio' and the other category links working at the same time. What have I missed?
|
Here's what I think is causing the problem: <code> <?php query_posts($query_string . '&cat=-98, 101, 102'); ?> </code> should be: <code> <?php query_posts($query_string . '&cat=-98,-101,-102'); ?> </code> The way it is now, it's telling WordPress re-run the old query, but give me nothing from category 98, AND only pull posts from categories 101 and 102. I'm guessing you want it to be re-running the original query, leaving out 98, 101, and 102.
|
Category Slugs = 404s?
|
wordpress
|
I normally work ahead of schedule and sometimes need to contact people when a certain post reaches publication. Is there any plugin that will do this? It would need to be customisable for each post as most posts I don't need this reminder, and for the ones where I do need it I would need to write something different each time.
|
Would you consider using a specific category or tag to use on posts that require notification? If so, you could use Peter's Collaboration E-mails plugin which can automatically notify you (or other specific users) when a post is set to Pending, Scheduled, or Published. In the plugin settings, you can define specific categories, post tags, authors, etc which defines certain notifications. The settings shown above should alert me when any posts in the category Apple are submitted or published.
|
Notification when certain posts are published
|
wordpress
|
I have a bunch of widgets that I load from php files, like so: I added a PHP CODE widget and inside wrote: <code> <?php include '/wp-content/themes/myTheme/parts/block1.php'; ?> </code> This worked well on my localhost, but for some reason it stopped working when I uploaded that website online (and switched the home and site_url of course). Any ideas?
|
The correct way to load a PHP file in the theme directory is to use the locate_template function. <code> <?php locate_template(array('parts/block1.php'),true,false); ?> </code> The true makes it automatically require it. The false makes it not require_once it.
|
Including PHP files doesn't work outside of Localhost
|
wordpress
|
I'm working on a new WP site. The WordPress installation has already been done on a live server by the ISP and now I need to skin it. I am wondering if I should bring the site down to my local machine and work off that. Having to upload constantly would be rather annoying. I'm a little concerned that I will screw soemthing up. Or... that, even if the local installation goes smoothly, when I re-upload to the live server there will be some conflicts. So what exactly are the steps once I've downloaded everything into a localhost folder?... create a database in phpMyAdmin? Do I go to wp-config.php in my browser? What other files would need to be modified? I will be using MAMP. I'm very hazy on the database side of things! Is there any danger that my databse setting would interfere with the live installation? e.g Do they have to have the same name? I just don't want to have to approach the ISP guys if I mess up their installation! Thanks!
|
If the other answers make sense I apologise for how patronising my answer must sound - but if they don't make sense perhaps my N00B style answer will :) You can't mess up the installation of wordpress on your live server if you are simply developing a theme on the localhost installation (a skin is known as a theme when it comes to wordpress) Once you have developed the theme on localhost you then Zip the theme up and upload it through the themes management menu in your live wordpress installation. There are other ways to do it, but I find this way far easier and less prone to user errors. BUT - you don't do it by downloading everything from your live site to localhost try reading this page http://codex.wordpress.org/Installing_WordPress_Locally_on_Your_Mac_With_MAMP or google " install wordpress locally MAMP " This should walk you through the steps to install it Creating the theme you want - that's a whole other kettle of fish, but again try using google to look for some tutorials to help you walk through it - or find a theme that you love that someone else has already created Hope this helps even if only a little
|
Installing WordPress locally
|
wordpress
|
I have a function like the following: <code> <?php echo my_custom_function( array( 'category_url'=>'My Special Category' ) ); ?> </code> It pulls data from the "My Special Category" and displays it. I want to put a conditional statement around it that says if, and only if, that category has stuff to display, to display it. There are more than one category_url's so wrapping it with an if statement and just using my_custom_function doesn't work because of the array, it throws the error: "Missing Argument 1". Any idea on how to make this function only echo if it exists AND if the argument is equal to itself? PHP noob question. ;) Thanks!!
|
The following function shows you some "best practice" example ;) It includes error handling, checking for emtpy array values, parsing input args with defaults, cares about if you want to echo the result, etc. You even got a filter for your child themes defaults. :) The function in your functions.php file: <code> function wpse15886_check_cat( $args = array( 'cat_url', 'other_args_for_the_output', 'echo' => false ) ) { // Abort if no 'cat_url' argument was given if ( ! isset( $args['cat_url'] ) ) $error = __( 'You have to specify a category slug.' ); // check if the category exists $given_cat = get_category_by_slug( $args['cat_url'] ); if ( empty( $given_cat ) ) $error = sprintf( __( 'The category with the slug %1$s does not exist.' ), $args['cat_url'] ); // check if we got posts for the given category $the_posts = get_posts( array( 'category' => $args['cat_url'] ) ); if ( empty( $the_posts ) ) $error = __( 'No posts were found for the given category slug.' ); // error handling - generate the output $error_msg = new WP_Error( __FUNCTION__, $error ); if ( is_wp_error( $error_msg ) ) { ?> <div id="error-<?php echo $message->get_error_code(); ?>" class="error-notice"> <strong> <?php echo $message->get_error_message(); ?> </strong> </div> <?php // abort return; } // Set some defaults $defaults = array( 'key a' => 'val a' ,'key a' => 'val a' ,'key a' => 'val a' ); // filter defaults $defaults = apply_filters( 'filter_check_cats', $defaults ); // merge defaults with input arguments $args = wp_parse_args( $args, $defaults ); extract( $args, EXTR_SKIP ); // >>>> build the final function output $output = $the_posts; $output = __( 'Do what ever you need to do here.' ); $output = sprintf( __( 'Manipulating some of the parsed %1$s for example.' ), $args['other_args_for_the_output'] ); // <<<< end build output // just return the value for further modification if ( $args['echo'] === false ) return $output; return print $output; } </code> Note that i haven't tested the function, so there might be some misstypings and else. But errors will lead you. The usecase: <code> $my_cats = array( 'cat_slug_a' ,'cat_slug_b' ,'cat_slug_c' ); if ( function_exists( 'wpse15886_check_cat' ) ) { foreach ( $my_cats as $cat ) { $my_cats_args = array( $cat ,'other_args_for_the_output' // this could also be another array set in here ,'echo' => true ); // trigger the function wpse15886_check_cat( $my_cats_args ); } } </code>
|
If function exists, and array is met, echo function?
|
wordpress
|
I am using custom post types "listings" and I have a category called "type" and 3 sub cats, "available", "pending", "sold". I want to display an image/icon on each post in the loop (not the single-listings.php) but the archive view, that corresponds to it's category. Take a look at woothemes' Estate for an example. They have an image over the featured image that says "on show". Any thoughts on how to go about this? or a plugin that might do something similar? thanks! I found this code reference: <code> <?php $cats = get_the_category(); echo $cats[0]->category_name;?>"> </code> And then it said to style using the category as a class in the css, but no go. It returns nothing - wondering if custom post type cats need to be handled differently?
|
You can use the conditional with <code> in_category </code> . http://codex.wordpress.org/Function_Reference/in_category For example after your loop: <code> <?php if (in_category('type')) { ?> <img src="<?php echo get_stylesheet_directory_uri();?>/images/custom.gif" alt="" class="customicons"/> </code>
|
Category Icon on custom post type
|
wordpress
|
All of my posts in one category (i.e. Location) have two custom fields: latitude and longitude. I would like to return an XML or JSON of all those posts (title, latitude, longitude) for use as Google Maps markers. I can't simply call out to a stand-alone php file to return my data as I would like to access my data through $wpdb. What is the best solution?
|
The best solution is to create a custom XML page template in the exact format you need. If you look at the code below taken from the WordPress XML exporter you can see that the data it returns contains the normal stuff we see in a typical WordPress loop. <code> echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n"; ?> <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. --> <!-- It contains information about your blog's posts, comments, and categories. --> <!-- You may use this file to transfer that content from one site to another. --> <!-- This file is not intended to serve as a complete backup of your blog. --> <!-- To import this information into a WordPress blog follow these steps. --> <!-- 1. Log into that blog as an administrator. --> <!-- 2. Go to Tools: Import in the blog's admin panels (or Manage: Import in older versions of WordPress). --> <!-- 3. Choose "WordPress" from the list. --> <!-- 4. Upload this file using the form provided on that page. --> <!-- 5. You will first be asked to map the authors in this export file to users --> <!-- on the blog. For each author, you may choose to map to an --> <!-- existing user on the blog or to create a new user --> <!-- 6. WordPress will then import each of the posts, comments, and categories --> <!-- contained in this file into your blog --> <?php the_generator('export');?> <rss version="2.0" xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/" > <channel> <title><?php bloginfo_rss('name'); ?></title> <link><?php bloginfo_rss('url') ?></link> <description><?php bloginfo_rss("description") ?></description> <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate> <generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator> <language><?php echo get_option('rss_language'); ?></language> <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version> <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url> <wp:base_blog_url><?php bloginfo_rss('url'); ?></wp:base_blog_url> <?php if ( $cats && ($terms == 'all' || $terms == 'cats')) : foreach ( $cats as $c ) : ?> <wp:category><wp:category_nicename><?php echo $c->slug; ?></wp:category_nicename><wp:category_parent><?php echo $c->parent ? $cats[$c->parent]->name : ''; ?></wp:category_parent><?php wxr_cat_name($c); ?><?php wxr_category_description($c); ?></wp:category> <?php endforeach; endif; ?> <?php if ( $tags && ($terms == 'all' || $terms == 'tags')) : foreach ( $tags as $t ) : ?> <wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name($t); ?><?php wxr_tag_description($t); ?></wp:tag> <?php endforeach; endif; ?> <?php do_action('rss2_head'); ?> <?php if ($post_ids) { global $wp_query; $wp_query->in_the_loop = true; // Fake being in the loop. // fetch 20 posts at a time rather than loading the entire table into memory while ( $next_posts = array_splice($post_ids, 0, 20) ) { $where = "WHERE ID IN (".join(',', $next_posts).")"; $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); foreach ($posts as $post) { setup_postdata($post); ?> <item> <title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title> <link><?php the_permalink_rss() ?></link> <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate> <dc:creator><?php echo wxr_cdata(get_the_author()); ?></dc:creator> <?php wxr_post_taxonomy() ?> <guid isPermaLink="false"><?php the_guid(); ?></guid> <description></description> <content:encoded><?php echo wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded> <wp:post_date><?php echo $post->post_date; ?></wp:post_date> <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt> </item> <?php } } } ?> </channel> </rss> <?php } </code>
|
Return XML of Post Metadata
|
wordpress
|
When the_content print attachment images (attachment template) it automatocally displays the picture. Is there a hook to specify the width and height of the image displayed?
|
I believe this is what your looking for. The complete code can be found in twentyten's loop-attachment.php template. Look for the <code> <p class="attachment"> </code> tag. There are two filters there. One for width and the other for height (currently set to 900px for both). <code> <?php if ( wp_attachment_is_image() ) : $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) ); foreach ( $attachments as $k => $attachment ) { if ( $attachment->ID == $post->ID ) break; } $k++; // If there is more than 1 image attachment in a gallery if ( count( $attachments ) > 1 ) { if ( isset( $attachments[ $k ] ) ) // get the URL of the next image attachment $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID ); else // or get the URL of the first image attachment $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID ); } else { // or, if there's only 1 image attachment, get the URL of the image $next_attachment_url = wp_get_attachment_url(); } ?> <p class="attachment"><a href="<?php echo $next_attachment_url; ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php $attachment_width = apply_filters( 'twentyten_attachment_size', 900 ); $attachment_height = apply_filters( 'twentyten_attachment_height', 900 ); echo wp_get_attachment_image( $post->ID, array( $attachment_width, $attachment_height ) ); // filterable image width with, essentially, no limit for image height. ?></a></p> <div id="nav-below" class="navigation"> <div class="nav-previous"><?php previous_image_link( false ); ?></div> <div class="nav-next"><?php next_image_link( false ); ?></div> </div><!-- #nav-below --> <?php else : ?> <a href="<?php echo wp_get_attachment_url(); ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php echo basename( get_permalink() ); ?></a> </code>
|
How to specify width and height in the_content for image attachments
|
wordpress
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.