question
stringlengths 0
34.8k
| answer
stringlengths 0
28.3k
| title
stringlengths 7
150
| forum_tag
stringclasses 12
values |
---|---|---|---|
I've added tags and categories to a custom post, but the search bar doesn't find them when I use it. It does find the 'uncategorized' category (default category) that's inherent in wordpress though. The Categories I've entered show up in the sidebar, as well as w/the custom post type (as do the tags I've entered). What am I missing?
|
Perhaps this article will help you... http://new2wp.com/noob/wordpress-search-custom-post-types/
|
Search doesn't find tags or categories in custom post types
|
wordpress
|
This is a sample of the Vote it Up plugin: <code> //Run this to create an entry for a post in the voting system. Will check if the post exists. If it doesn't, it will create an entry. function SetPost($post_ID) { global $wpdb; //prevents SQL injection $p_ID = $wpdb->escape($post_ID); //Check if entry exists $id_raw = $wpdb->get_var("SELECT ID FROM ".$wpdb->prefix."votes WHERE post='".$p_ID."'"); if ($id_raw != '') { //entry exists, do nothing } else { //entry does not exist $wpdb->query("INSERT INTO ".$wpdb->prefix."votes (post, votes, guests, usersinks, guestsinks) VALUES(".$p_ID.", '', '', '', '') ") or die(mysql_error()); } } //Run this to create an entry for a user in the voting system. Will check if the user exists. If it doesn't, it will create an entry. function SetUser($user_ID) { global $wpdb; //prevents SQL injection $u_ID = $wpdb->escape($user_ID); //Check if entry exists $id_raw = $wpdb->get_var("SELECT ID FROM ".$wpdb->prefix."votes_users WHERE user='".$u_ID."'"); if ($id_raw != '') { //entry exists, do nothing } else { //entry does not exist $wpdb->query("INSERT INTO ".$wpdb->prefix."votes_users (user, votes, sinks) VALUES(".$u_ID.", '', '') ") or die(mysql_error()); } } //Returns the vote count function GetVotes($post_ID, $percent = false) { global $wpdb; //prevents SQL injection $p_ID = $wpdb->escape($post_ID); //Create entries if not existant SetPost($p_ID); //Gets the votes $votes_raw = $wpdb->get_var("SELECT votes FROM ".$wpdb->prefix."votes WHERE post='".$p_ID."'"); $sinks_raw = $wpdb->get_var("SELECT usersinks FROM ".$wpdb->prefix."votes WHERE post='".$p_ID."'"); $guestvotes_raw = $wpdb->get_var("SELECT guests FROM ".$wpdb->prefix."votes WHERE post='".$p_ID."'"); $guestsinks_raw = $wpdb->get_var("SELECT guestsinks FROM ".$wpdb->prefix."votes WHERE post='".$p_ID."'"); /* Deprecated $uservotes_raw = $wpdb->get_var("SELECT votes FROM ".$wpdb->prefix."votes_users WHERE user='".$u_ID."'"); $usersinks_raw = $wpdb->get_var("SELECT sinks FROM ".$wpdb->prefix."votes_users WHERE user='".$u_ID."'"); */ //Put it in array form $votes = explode(",", $votes_raw); $sinks = explode(",", $sinks_raw); $guestvotes = explode(",", $guestvotes_raw); $guestsinks = explode(",", $guestsinks_raw); /* Deprecated $uservotes = explode(",", $uservotes_raw); $usersinks = explode(",", $usersinks_raw); */ $uservotes = 0; $usersinks = 0; $initial = 0; //Initial no. of votes [will be placed at -1 when all posts receive votes] </code> (and so on...) I've heard from many people that it is a bad practice to go directly to the mysql database. That the code can break up in future versions of Wordpress. Or it is necessary in some plugins like Vote it Up?
|
Hi @janoChen: The correct answer is: "It depends." In general it is better to use built-in WordPress functions than to use direct SQL when there are built-in functions that can provide you what you need. However, the answers to many of the questions I see here on WPSE are (unfortunately) "you need to use direct SQL for that because WordPress simply doesn't provide a(n efficient) function to provide what you need." In the case of the Vote It Up plugin it is arguable that their choice of direct SQL was correct because there is not an efficient place to store votes in the WordPress database. On the other hand there are those who would argue that they should have used <code> wp_postmeta </code> and <code> wp_usermeta </code> to store that information. Personally I'm on the fence for a voting plugin; I'd actually have to implement one (which I have done but it was almost 2 years ago and have learned much since) to really have an opinion on the best way of doing it. One thing I will say is that, almost whenever possible I prefer to use the built-in tables with WordPress rather than to add new tables. Adding a table has a more significant impact than adding SQL code to access the existing tables. Given that alone I might learn towards using the meta tables for a voting plugin but I honestly I can't state that unequivocally unless and until I actually tried to implement such functionality. UPDATE I just read the code by c.bavota and in some ways it is good, in other ways it troubles me. I like that he is using post meta, but I don't like that he is putting the list of comma-separated user_ids into a post meta field. What happens when a post gets 25,000 votes? Clearly his code does not scale for a high-traffic site. And his code would make it very slow to get a list of all posts voted on by a given user for any site with a large number of posts. If he is going to stuff all user IDs for votes into a meta field he should do in a more scalable way such as storing post IDs in user meta as chances of one user voting 25,000 times, or even 2500 times is pretty small. Or he could store votes by embedding the user ID in the post meta key, i.e. <code> "user_vote_{$user_id}" </code> (though maybe 25,000 meta records would cause problems of its own.) OTOH, if you really need to track votes by user that's where I might argue for a table and direct SQL might make sense. What's more he rolls his own web service instead of using the build-in AJAX functionality for web services. While I don't like that the built-in functionality is not RESTful, I don't think it is a good idea to recreate a web service infrastructure unless you do it right. Doing it right would include built-in security and c.bavota's code doesn't worry about security; no escaping of <code> $_POST </code> values, no using nonces, nothing. And his code could easily under-count votes it two or more people are voting at the same time. What's a bit scary is this guy is selling premium themes and his how-to articles have code that violates several known best practices. But I think he is hardly unique as a theme vendor that has code with security or scalability issues. <sigh>. I left a comment about these issues and suggesting he warn his users immediately and update with better techniques, but it is currently in moderation. Let's hope he publishes it. UPDATE2 Why use functions like <code> update_post_meta() </code> rather than updating the database directly? Several reasons, but much more important for plugins or themes you plan to distribute than for code you write for your own site (though ideally it's helpful for the latter too.): By some small chance WordPress may chance the database structure for meta. They've done it before and might do it again. If you use the built-in functions instead of SQL your code will continue to work but obviously direct SQL code will break on a WordPress upgrade. If you use <code> update_post_meta() </code> it will work for single site and Multisite. Direct SQL code will work for one but not the other. If you use <code> update_post_meta() </code> and someone wants to use a plugin that stores frequently accessed values in MemCached your code will support it, but not if you write direct SQL. In general if a plugin or theme hooks <code> update_post_meta() </code> the hook will work if you use <code> update_post_meta() </code> but not if you use direct SQL. And I'm sure there are other reasons I can't think of right now. Suffice it to say that using the built-in functions offers robustness and flexibility that direct SQL can't match; so only use direct SQL when you can't do it with built-in functions. JMTCW.
|
Is it a bad practice to go directly to the mysql database while developing a plugin?
|
wordpress
|
I use 'constants' a lot. I set them in functions.php like <code> define('mytheme_town', 'Orlando'); </code> and then call them into the theme <code> <?php echo mytheme_town ; ?> </code> . It's simple and easy. But I need them to be site-specific (for multisite) so I thought it might be possible to append the current blog_id to the theme call and declare constants for each MultiSite in functions.php? I don't know how to code that, but what I'm trying to achieve in the theme file this ... <code> <?php echo [current_blog]_mytheme_town ; ?> </code> ..... For example In functions.php // set constants for all multisites that use this theme // awebsite.org : site_id=1 define('1_mytheme_town', 'Orlando'); define('1_mytheme_subject', 'food'); define('1_mytheme_p1', 'This is the first paragraph text'); // adifferentsite.com: site_id=2 define('2_mytheme_town', 'New York'); define('2_mytheme_subject', 'wine'); define('2_mytheme_p1', 'This is the first paragraph text'); // anothersite.net : site_id=3 define('3_mytheme_town', 'LA'); define('3_mytheme_subject', 'Donuts'); define('3_mytheme_p1', 'This is the first paragraph text'); In theme files Call the constants using the current blog_id like so ... <code> <?php echo [current_blog]_mytheme_town ; ?> </code> <code> <?php echo [current_blog]_mytheme_subject ; ?> </code> <code> <?php echo [current_blog]_mytheme_p1 ; ?> </code> I have been trying all day, but I'm just guessing and I don't really know what I am doing. Everything I have tried works, but it simply echos out text of the code 1_mytheme_town and not the constant that is defined in functions.php. Hope you understand what I'm trying to explain.
|
You can access the blog ID you are on by <code> global $blog_id; </code> and then you can use that how you want it to work.
|
How can I append blog_id to ... echo [functions-defined-constant]?
|
wordpress
|
I inserted an excerpt into a Page using the "More" button in WP GUI. I have a custom loop-page.php from which I want to display the excerpt. But it appears to be empty? Is it possible to display excerpts from child pages? <code> $pageChildren = get_pages('sort_column=menu_order&hierarchical=0&child_of='.$post->ID); if ( $pageChildren ) { foreach ( $pageChildren as $pageChild ) { echo '<p>And the title is: '. $pageChild->post_title.'</p>'; print_r($pageChild); if (!empty($pageChild->post_excerpt)){ echo '<p><a href="' . get_permalink($pageChild->ID) . '">' . $pageChild->post_excerpt.'</a> </p> '; } echo '<hr />'; } } </code>
|
Using the "more" tag does not create an excerpt. It simply creates a "Read More" link when displaying the_content() on index pages. Excerpts are created/displayed as follows: To display an excerpt, your template file needs to call "the_excerpt()" rather than "the_content()". Note: you use the equivalent $post-> post_excerpt, which should also work just fine. The "the_excerpt()" template tag then displays the excerpt, which is created as follows: 1) By entering excerpt content into the "Excerpt" field on the Edit Post/Edit Page screen. 2) Automatically, based on number of characters, if no content is added to the "Excerpt" field. EDIT: Okay so I totally missed this at first. Only Posts have the "excerpt" field. Pages don't have the "excerpt" field. So, $post-> post_excerpt will never be populated for Pages (I think). Try running "setup_postdata( $pageChild )" inside your foreach loop, and then replacing "$pageChild-> post_excerpt" with "get_the_excerpt()": <code> foreach ( $pageChildren as $pageChild ) { setup_postdata( $pageChild ); echo '<p>And the title is: '. $pageChild->post_title.'</p>'; print_r($pageChild); echo '<p><a href="' . get_permalink($pageChild->ID) . '">' . get_the_excerpt() .'</a> </p> '; echo '<hr />'; } </code> Does that work?
|
Excerpts for Pages
|
wordpress
|
Is it possible within the current theme file naming hierarchy to define a template for for all pages that are a child of a specific page? For example, in this navigation: About Us Contact Who We Are Message Statement Is there any way to just make a theme file named something like: page-about-us-all.php That would automatically be applied to all pages that are children of About Us? UPDATE I went with a modified version of what Bainternet had suggested. Here's the descendant function I ended up with: <code> function is_descendant($ancestor, $tofind = 0) { global $post; if ($tofind == 0) $tofind = $post->ID; $arrpostids = get_post_ancestors($tofind); $arrpostslugs = array(); foreach($arrpostids as $postid) { $temppost = get_post($postid); array_push($arrpostslugs, $temppost->post_name); } return (in_array($ancestor, $arrpostids) || in_array($ancestor, $arrpostslugs)); } // Example use: is_descendant('about-us'); is_descendant(123); is_descendant('about-us', 134); </code> This allows me to verify it's a descendant using either the ID of the parent or the slug. I was concerned that using only the ID might lead to a problem if a parent page had been accidentally trashed there would be no good way to get that to work again without having to edit the Theme files. With the slug at least there's the option of just hopping in and making a new page with the same slug and hierarchy.
|
I have a handy little custom made conditional function that would do the job for you. The function: <code> function is_child_page($page = NULL){ global $post; if ($page == NULL){ $p = get_post($post->ID); if ($p->post_parent > 0 ){ return true; }else{ return false; } } $args = array( 'child_of' => (int)$page); $pages = get_pages($args); foreach ($pages as $p){ if ($p->ID = $post->ID){ return true; break; } } return false; } </code> Usage: <code> if (is_child_page()){ //this page has a parent page } if (is_child_page(23)){ //this page is a child page of the page with the ID of 23 } </code> Now you ask how can this help you? After you have this function saved in your theme's functions.php file edit your theme's page.php file and add at the very top something like this: <code> if (is_child_page(12)){ include (TEMPLATEPATH . '/page-about-us-all.php'); exit(); } </code> and you are done!!! note: this code is assuming that your about page id is: 12 and your theme file is named: page-about-us-all.php
|
Theme file for all pages that are a child of a specific page
|
wordpress
|
I tried deleting the plugin, reinstalling, and entering a new api key. However, I get this message: The owner of that API Key (username) is not on the access list for this blog (blog id). Stats was installed using a different API key. Is there anyway I can install the Wordpress.com Stats plugin with a new api key?
|
Actually, you should be using the JetPack plugin now, not the stats plugin. Automattic (the team behind WordPress.com) have begun bundling their stats system with a few other features (social network sharing, LaTeX support, to name a couple) and aren't updating the older systems any more . JetPack will use oAuth to connect to your WordPress.com account and will automatically select the right blog. If it doesn't, you should contact their support team directly to ask for help.
|
Installed Wordpress.com Stats with api key and forgot key. How can I register w/ new key?
|
wordpress
|
Here's how I have my code set up in the functions file: <code> register_sidebar(array( 'name' => 'Latest Updates', 'before_widget' => '<span>', 'after_widget' => '</span>', 'before_title' => '', 'after_title' => '' )); register_sidebar(array( 'name' => 'BBRB Loves (Video Width - 200px)', 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '' )); </code> The first <code> register_sidebar </code> function gets called in header.php and the second function gets called in index.php. When I put in opening and closing <code> <span> </code> tags in the second function (i.e. <code> before_widget </code> and <code> after_widget </code> ), the correct tags get outputted. But when I put in the same opening and closing <code> <span> </code> tags in the first function, nothing gets outputted but the default <code> <div class="textwidget">foobar</div> </code> . The only difference between the two is that one is called in the header and the other is called in the index. However, BOTH widgets show up in the dashboard and when I fill them with text, they both get outputted—just not the before/after tags. What am I doing wrong?
|
If I had to venture a guess, the problem is that your first register_sidebar() gets called in functions.php, and hooked into widgets_init, but the second one gets called in the head, and therefore NOT hooked into widgets_init. I don't know the impact of registering a sidebar other than at widgets_init. Is there any particular reason that both calls can't be called in functions.php and hooked into widgets_init?
|
One register_sidebar function works, the other doesn't?
|
wordpress
|
I have registered a custom post type with the right parameters. By that I mean I have added <code> 'taxonomies' => array('post_tag','category') </code> , I have also tried using <code> register_taxonomy_for_object_type('post_tag', 'custom-post-type-name'); </code> I have a custom function in my functions.php to load a basic loop using a conditional, along the lines of. <code> function child_maybe_do_grid_loop() { if( is_tag() || is_category() || is_archive { require(CHILD_DIR.'/custom-tag.php'); } } </code> The content of custom-tag.php is just a very basic loop <code> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <?php the_permalink(); ?>" title="<?php the_title(); ?> <?php endwhile; ?> <?php else : ?> <h2 class="center">Not Found</h2> <?php endif; ?> </code> This works fine for regular posts/page tags but for a custom post type tags I get "Not Found". Any ideas? I assumed a regular simple loop should work with custom posts type tag archives or do I need to put some extra conditionals/query's in there? ** Update toscho's comment made me turn on debugging and in comparison to a working tag page made through a default post, the debug for custom post tag is exactly the same. I even get count => 2 to show up as I incrementally add more custom posts to the same tag, yet the page refuses to return anything, I am at a loss.
|
Down the rabbit hole..... I found a fix. From this post stackexchange-url ("Custom Post Type Archives by Date and Taxonomy") Which let me to this trac ticket http://core.trac.wordpress.org/ticket/14589 and the following <code> function post_type_tags_fix($request) { if ( isset($request['tag']) && !isset($request['post_type']) ) $request['post_type'] = 'any'; return $request; } add_filter('request', 'post_type_tags_fix'); </code> Maybe this didn't make it into 3.1?
|
Custom post type tag archives don't work for basic loop?
|
wordpress
|
i've just created a new post type. It's name is Academias so the first menu option is Academias as well. But I would like to change it to something like See All Academias (just an example), is that possible?
|
The function register_post_type() takes an argument <code> 'labels' </code> . This is an array, one of the possible keys is named … tada! … <code> 'menu_name' </code> . Sample code <code> register_post_type( 'academias' , array ( 'can_export' => TRUE , 'exclude_from_search' => FALSE , 'has_archive' => TRUE , 'hierarchical' => TRUE , 'label' => 'Academias' , 'labels' => array ( 'menu_name' => 'See All Academias' ) , 'menu_position' => 5 , 'public' => TRUE , 'publicly_queryable' => TRUE , 'query_var' => 'academias' , 'rewrite' => array ( 'slug' => 'academias' ) , 'show_ui' => TRUE , 'show_in_menu' => TRUE , 'show_in_nav_menus' => TRUE , 'supports' => array ( 'editor', 'title' ) ) ); </code> Update Now, that I’ve understood your question better, there seems to be only one way to accomplish what you want: hook into <code> attribute_escape </code> . Test Plugin <code> <?php /* Plugin Name: *WPSE13210 */ ! defined( 'ABSPATH' ) and exit; add_action( 'init', 'register_academia' ); /** * Registers te post type academias * * @return void */ function register_academia() { register_post_type( 'academias' , array ( 'can_export' => TRUE , 'exclude_from_search' => FALSE , 'has_archive' => TRUE , 'hierarchical' => TRUE , 'label' => 'Academias' , 'labels' => array ( 'menu_name' => 'See All Academias' , 'name' => 'Academias' ) , 'menu_position' => 5 , 'public' => TRUE , 'publicly_queryable' => TRUE , 'query_var' => 'academias' , 'rewrite' => array ( 'slug' => 'academias' ) , 'show_ui' => TRUE , 'show_in_menu' => TRUE , 'show_in_nav_menus' => TRUE , 'supports' => array ( 'editor', 'title' ) ) ); } add_filter( 'attribute_escape', 'rename_second_menu_name', 10, 2 ); /** * Renames the first occurence of 'See All Academias' to 'Academias' * and deactivates itself then. * @param $safe_text * @param $text */ function rename_second_menu_name( $safe_text, $text ) { if ( 'See All Academias' !== $text ) { return $safe_text; } // We are on the main menu item now. The filter is not needed anymore. remove_filter( 'attribute_escape', 'rename_second_menu_name' ); return 'Academias'; </code> } Not very elegant, but at least a solution … Update 12.05.2010 In ticket 17378 a new parameter <code> all_items </code> was proposed. That should work much better, once it’s part of the core …
|
Post Type Label Name
|
wordpress
|
For example, I used the plugin Vote it Up but it haven't been updated since 2010-5-28. Now I moved to GD star rating which was last updated in January 6, 2011 (and still maintained by he author). Is it not recommendable to stick with plugins that are no longer supported by the author for production sites?
|
As for me key questions here are: Is plugin outdated? Not using approaches and coding practices of current WP versions. When will it become outdated? This can range from months (next WP version changes something relevant) to years (plugin does something simple on using common and basic hooks). Can you handle when it will become outdated? Maybe you can maintain it yourself. Maybe you have budget to hire someone for that. Maybe it will ruin your site.
|
Is it not recommendable to stick with plugins that are no longer supported by the author for production sites?
|
wordpress
|
All of my theme's custom options are preceeded with "mytheme_" + option. For example, mytheme_color1, mytheme_color2, mytheme_body_font_color, etc... I'd like to create a plugin that uninstalls all of the items in wp_options where the option is preceeded with "mytheme_" If you have a reference or example, please share it. Thanks in advance :-)
|
All of my theme's custom options are preceeded with "mytheme_" + option. Not safe enough. Use set_theme_mod() , get_theme_mod() and remove_theme_mod() instead. You’ll find these and more related functions in <code> wp-includes/theme.php </code> .
|
Example of uninstaller routine to remove all custom theme options from wp_options
|
wordpress
|
I am quite new in WP Plugin World. I am trying to develop a plugin in WP 3.1 when I am trying to insert data into my table named " <code> wp_enam </code> " in the following way: <code> $wpdb->insert($wpdb->enam, array('username' => "enam" , 'useremail' => "[email protected]")); </code> it is not working. I try to debug it in following way: <code> $wpdb->show_errors(); $wpdb->insert($wpdb->enam, array('username' => "enam" , 'useremail' => "[email protected]")); $wpdb->print_error(); </code> Now I am getting following message from MR.WP <code> WordPress database error: [Incorrect table name ''] INSERT INTO `` (`username`,`useremail`) VALUES ('enam','[email protected]') WordPress database error: [Incorrect table name ''] INSERT INTO `` (`username`,`useremail`) VALUES ('enam','[email protected]') </code> As you can see the table name is not showing in the mysql query. Is this a correct way to access a table name with <code> $wpdb->my_table </code> ? I am using mysql . Thanks in advance. Edit 1: Looks like <code> $wpdb->tblname </code> do not add the table prefix anymore! As per "Professional WordPress Wrox" by Hal Stern, David Damstra and Brad Williams" (which is a great book ) it should work. The above functionality is explained at this book in the following way: <code> $wpdb->my_custom_table to reference the table in WordPress. This translates to wp_my_custom_table if wp_ is the table prefix. This is the proper way to determine the correct table prefix when working with tables in the WordPress database. </code> ( Page:107 )
|
You can check database function for database here http://codex.wordpress.org/Function_Reference/wpdb_Class . For the table prefix matter you should use <code> $wpdb->prefix . 'enam' </code> and it will return the table prefix. Just add the table name with this. So the total code would be : <code> $yourtablename = $wpdb->prefix . 'enam'; </code> so your total code could be something like: <code> $wpdb->insert($yourtablename , array('username' => "enam" , 'useremail' => "[email protected]")); </code> EDIT: If you need more information you can see THIS article. This is very useful article for creating plugin with database.
|
insert data in database table from plugin with WP3.1
|
wordpress
|
I added a TinyMCE editor to my plugin settings page, but once I move (drag) the metabox, editor's content get lost. (the TinyMCE editor is completely not editable until refresh) Here is how I added TinyMCE editor: <code> add_action( 'admin_head', 'add_tinymce_editor' ); function add_tinymce_editor() { if ( function_exists( 'wp_tiny_mce' ) ) { add_filter('teeny_mce_before_init', create_function( '$a', ' $a["mode"] = "textareas"; $a["editor_selector"] = ""; $a["plugins"] = "safari,inlinepopups,spellchecker"; return $a;') ); wp_tiny_mce( true ); } } </code> Any ideas what can cause this bug and how to prevent/fix it? Thanks.
|
I had a similar problem with radio buttons losing their status when I dragged a metabox on a settings page. I hacked together a workaround and posted it as a reply to the original wordpress trac ticket http://core.trac.wordpress.org/ticket/16972#comment:4
|
Moving/dragging a metabox removes TinyMCE's content
|
wordpress
|
How can a plugin create a page/form in the front end thats not listed in pages (if possible). it should only be accessed through a direct link.
|
See stackexchange-url ("How do you create a “virtual” page in WordPress") for the solution. This should work for your case as well.
|
How can a plugin create a page/form in the front end?
|
wordpress
|
What I'm currently trying to make is an activities stream wich list : The posts, the comments, both mixed between them and ordered by date. My idea is to make two queries, but i don't know how to mix them up. Here are my queries : <code> // Query the posts : $queryPosts = " SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC "; // Query the comments : $queryComments = " SELECT * FROM $wpdb->comments ORDER BY comment_date DESC "; </code> Is that possible with some kind of SQL JOIN ? UPDATE: I tried what was suggested by @scribu about using SQL UNION and it's working well : <code> SELECT ID AS entry_id, post_date AS entry_date, post_content AS entry_content FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' UNION SELECT comment_ID AS entry_id, comment_date AS entry_date, comment_content AS entry_content FROM $wpdb->comments ORDER BY entry_date DESC </code> What I'm trying to do now is access some data which are in the posts table and not in the comments table. Any idea ? Thanks by advance.
|
I believe you're looking for SQL UNION .
|
How to make an activities stream mixing posts and comments?
|
wordpress
|
I'm working on a website where the client wants a static page displaying information about a certain category. Then under the static information she wants all the posts from that category in a 2 column list. So I need to have an alphabetically ordered list linking to all the post in a selected category. I have the code to do this, but I need to be able to break the list up in columns. Here is the code I have displaying the post... <code> <?php if (is_page() ) { $category = get_post_meta($posts[0]->ID, 'category', true); } if ($category) { $cat = get_cat_ID($category); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $post_per_page = -1; // -1 shows all posts $do_not_show_stickies = 1; // 0 to show stickies $args=array( 'category__in' => array($cat), 'orderby' => 'title', 'order' => 'asc', 'paged' => $paged, 'posts_per_page' => $post_per_page, 'caller_get_posts' => $do_not_show_stickies ); $temp = $wp_query; // assign orginal query to temp variable for later use $wp_query = null; $wp_query = new WP_Query($args); if( have_posts() ) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <_li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a><_/li> </code> I know my HTML skills aren't the best, but here is the entire template page... https://gist.github.com/889340
|
Updated answer: Use two floated lists to emulate columns, same approach as previously though. <code> <?php /* Template Name: PageOfPosts */ get_header(); ?> <div id="content"> <div class="t"> <div class="b"> <div class="l"> <div class="r"> <div class="bl"> <div class="br"> <div class="tl"> <div class="tr"> <div class="pad"> <?php while( have_posts() ) : the_post(); ?> <?php $category = get_post_meta( get_the_ID(), 'category', true); $img_style = 'style="width:606;height:34;position: absolute; padding-top:1px; padding-left: 2px; z-index:9999; background: no-repeat;"'; ?> <div class="post" id="post-<?php the_ID(); ?>"> <h1><?php the_title(); ?></h1> <img src="../wp-content/themes/DD4L/images/leafhr.png" <?php? echo $img_style;?>> <br /> <div class="entry"> <?php the_content(); ?> <?php wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?> </div> <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?> </div> <?php endwhile; ?> <br /><br /> <?php if( !empty( $category ) ) : ?> <?php $args = array( 'orderby' => 'title', 'order' => 'asc', 'nopaging' => true, 'ignore_sticky_posts' => true, 'tax_query' => array( array( 'taxonomy' => 'category', 'terms' => array( $category ), 'field' => 'slug' ) ) ); $category_query = new WP_Query( $args ); ?> <?php if( $category_query->have_posts() ) : ?> <?php $total = $category_query->post_count; $quart = $total / 4; if( floor( $quart ) != $quart ) $quart = ceil( $quart ); $counter = 0; ?> <div class="float-container"> <ul class="alignleft"> <?php while( $category_query->have_posts() ) : $category_query->the_post(); $counter++; ?> <li> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> </li> <?php if( $quart == $counter ) : $counter = 0; ?> </ul> <ul class="alignleft"> <?php endif; ?> <?php endwhile; ?> </ul> <div class="clear"></div> </div> <?php endif; ?> <?php endif; ?> </div> <div class="clear"></div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <?php get_sidebar(); ?> <?php get_footer(); ?> </code> See edit revision for previous comments and code.
|
How can I display only the post titles from a selected category in columns?
|
wordpress
|
Hi WordPress Experts please help me i want to get nav_menu_item_id and slug from wp database by given a page template like (store.php) this a page template and how we can get nave menu item id and slug that use this page template
|
Hi @Anjum: I think the function <code> get_nav_menu_id_by_page_template() </code> is what you are looking for? You can place the code for this function in your theme's <code> functions.php </code> file, or in a <code> .php </code> for a plugin you are writing: <code> function get_nav_menu_id_by_page_template($template) { static $nav_menu_id; if (!isset($nav_menu_id)) { global $wpdb; $sql = <<<SQL SELECT menu.post_id AS menu_id FROM {$wpdb->postmeta} AS template INNER JOIN {$wpdb->postmeta} AS menu_id ON menu_id.meta_key='_menu_item_object_id' AND menu_id.meta_value=template.post_id INNER JOIN {$wpdb->postmeta} AS menu ON menu_id.post_id=menu.post_id WHERE 1=1 AND menu.meta_key='_menu_item_object' AND menu.meta_value='page' AND template.meta_key='_wp_page_template' AND template.meta_value='%s' SQL; $nav_menu_id = $wpdb->get_var($wpdb->prepare($sql,$template)); } return $nav_menu_id; } </code> Once you have the <code> get_nav_menu_id_by_page_template() </code> function in your code you can call it in your theme template file like so: <code> <?php $nav_menu_id = get_nav_menu_id_by_page_template('store.php'); ?> </code>
|
How to get nav_menu_item_id and slug from wp database
|
wordpress
|
hey guys, I really really need your help. I have just no idea why that happens. I'm trying to load a wordpress page with the jquery $ajax method. However my browser is crashing all the time when I try to load this page. I've build a kind of ajax search that requests a wordpress page when typing inside of an input field. This is my code. <code> jqXHR_Old = $.ajax({ url: "searchmap", // searchmap means mydomain.com/searchmap dataType: "html", success: function (data) { ... </code> The weird thing is: When i change the url to a static page like <code> url: "searchmap.html" </code> everything works fine. As soon as I choose the dynamically generated Wordpress Template "searchmap" the ajax response throws "301 Moved Permanetly" messages. This is my template that works just fine when I call it in the browser... <code> <div> <h3>Pages</h3> <ul> <?php wp_list_pages('title_li=&depth=0&exclude='); ?> </ul> <h3>Posts</h3> <?php $first = 0;?> <ul> <?php $myposts = get_posts('numberposts=-1&offset=$first'); foreach($myposts as $post) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> <h3>Categories</h3> <ul> <?php wp_list_categories('title_li=&orderby=name'); ?> </ul> </div> </code> Any idea why Firebug or Fiddler responds with "301 Moved Permanently" errors when I load this page with $.ajax() ? My browser keeps crashing, even though I abort each ajax request when typing again. So there are never happening multiple ajax requests. $.ajax requests mydomain.com/searchmap and mydomain.com/searchmap requests the server for all pages, posts and cats. Any ideas? I'm completely clueless!
|
I'm guessing the page your calling executes an wp_redirect with a 301 response somewhere. Dont really have an answer for you but maybe you can try the following. Ajax does not know what type of page your calling from and there might be some strange query_vars loaded that trigger a redirect. Your using a permalink to load the page, can you try using a non-permalink url? do a text-search on your plugin folder for wp_redirect to see if something comes up. Ajax call action. <code> var response; jQuery.post( // see tip #1 for how we declare global javascript variables MyAjax.ajaxurl, { // here we declare the parameters to send along with the request // this means the following action hooks will be fired: // wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit action : 'searchmap', // other parameters can be added along with "action" postID : MyAjax.postID, count : '16' }, function( response ) { jQuery("#div-searchmap").html(response); jQuery("#div-searchmap").show(); } ); </code> If you want to use wp_ajax you will need to add some more. <code> // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php) wp_localize_script( 'my-ajax-request', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); // this hook is fired if the current viewer is not logged in if (isset($_GET['action'])) { do_action( 'wp_ajax_nopriv_' . $_GET['action'] ); } // if logged in: if (isset($_POST['action'])) { do_action( 'wp_ajax_' . $_POST['action'] ); } if(is_admin()) { add_action( 'wp_ajax_searchmap', 'my_searchmap_function' ); } else { add_action( 'wp_ajax_nopriv_searchmap', 'my_searchmap_function' ); } </code> Im using POST variable for my ajax script so it alawys runs in admin, if you write the jquery script with GET you will need to call the norpriv function outside admin. (just figured this out now) U might have to fix the script here and there, it's just an offhand example. the function has to return the data you need. For example: <code> function my_searchmap_function() { // Start output buffer ob_start(); ?> div> <h3>Pages</h3> <ul> <?php wp_list_pages('title_li=&depth=0&exclude='); ?> </ul> <h3>Posts</h3> <?php $first = 0;?> <ul> <?php $myposts = get_posts('numberposts=-1&offset=$first'); foreach($myposts as $post) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> <h3>Categories</h3> <ul> <?php wp_list_categories('title_li=&orderby=name'); ?> </ul> </div> <?php $output = ob_get_contents(); // Stop output buffer ob_end_clean(); $response = json_encode($output); // response output header( "Content-Type: application/json" ); echo $response; // IMPORTANT: don't forget to "exit" exit; } </code>
|
php ajax problem - weird 301 responses!
|
wordpress
|
I'm trying to get the ID of a post in the first loop (using <code> <?php $postid = get_the_ID(); ?> </code> ) and use it in a variable ( <code> $postid </code> ) to exclude that very post from a second loop (using <code> post__not_in </code> ): <code> <?php /** * Replies Loop * * @package bbPress * @subpackage Theme */ ?> <?php if ( ! get_query_var( 'paged' ) ) : ?> <?php $args = array( 'post_type' => 'bbp_reply', 'posts_per_page' => '1', 'paged' => '2', 'post_parent' => $post->ID, 'gdsr_sort' => 'thumbs', 'gdsr_ftvmin' => '1', 'gdsr_order' => 'desc' ); ?> <?php query_posts( $args ); ?> <?php while ( have_posts() ) : the_post(); ?> <div class="most-voted"> <h2><?php the_title(); ?></h2> <?php the_content(); ?> <?php bbp_reply_admin_links(); ?> </div> <?php $postid = get_the_ID(); // capture the id ?> <?php endwhile; ?> <?php wp_reset_query(); ?> <p>________________</p> <?php endif; ?> <?php $default = array( 'post__not_in' => $postid ); ?> <?php if ( bbp_has_replies( $default ) ) : ?> <?php get_template_part( 'pagination', 'bbp_replies' ); ?> <?php while ( bbp_replies() ) : bbp_the_reply(); ?> <div class="topic-entry"> <div class="topic-author"> <?php bbp_reply_author_link( array( 'type' => 'avatar' ) ); ?> <?php bbp_reply_author_link( array( 'type' => 'name' ) ); ?> <?php printf( __( '%1$s', 'bbpress' ), get_the_date() ); ?> </div> <div class="topic-content"> <?php bbp_reply_content(); ?> <span class="like-counter"><?php DisplayVotes(get_the_ID()); ?></span> </div> <?php wp_gdsr_render_article_thumbs(); ?> <?php bbp_reply_admin_links(); ?> </div> <?php endwhile; ?> <?php endif; ?> </code> But for some reason I'm getting this error: <code> Warning: array_map(): Argument #2 should be an array in /home/alex/www/taiwantalk/wp-includes/query.php on line 2104 Warning: implode(): Invalid arguments passed in /home/alex/www/taiwantalk/wp-includes/query.php on line 2104 </code>
|
<code> post__not_in </code> accepts an array so change <code> <?php $postid = get_the_ID(); // capture the id ?> </code> to <code> <?php $postid[] = get_the_ID(); // capture the id ?> </code> and you'll be fine.
|
Error while excluding a post from another loop (using its ID)
|
wordpress
|
A client currently has a website set up with three distinct sub-sites (run off a single WordPress install), each with a slightly different theme (same layout, different colour scheme. I currently have it set up so each sub-site is a page, with all of it's pages as children. The header.php checks which page is the parent and includes the appropriate style. The problem comes with pages that are identical throughout the site, which the client wishes to have accessible from each sub-site as a separate page. For example the about page, should be accessible from /site1/about and /site2/about and use the theme for the site that has requested it, but display the same content on both. I could just create the child pages, and set the rel="canonical" to reference the original, but from a maintenance point of view, it would preferable to have a single page that the content is pulled from on each of the sub sites. And so to the question, how do I get several URLs/pages to pull their content from a single source? EDIT: Here's an example of the desired structure: www.example.com - Displays links to the three main services, as well as general information www.example.com/about - Displays information about the client, styled to match www.example.com www.example.com/service1 - Displays navigation related to the specific service, styled in it's own individual colour, alongside generic links (about, contact) www.example.com/service1/about - Displays the navigation and stylesheet for /service1, but using the content from www.example.com/about (and with a canonical link reference to www.example.com/about) This is then repeated for /service2 and /service3.
|
Hi @Ross Bearman: I'm still struggling with the exact requirements but if I understand correctly I think you can do to accomplish your goals if you use the code I provide you below and then do the following: Create a page for each of your services (which it sounds like you have already done): <code> /service1/ </code> , <code> /service2/ </code> , etc. Create a "base" service page, with a URL of <code> /base-service/ </code> ; don't worry, nobody will ever see this on the outside of the website. Assign <code> /base-service/ </code> as the parent (or grandparent) page for all the "virtual shared" child pages you want replicated under each service. Create any service specific pages that you also might want to have and assign them to the proper page (i.e. "Service 2", for example.) Create a stackexchange-url ("page template in your theme") for your services called <code> page-service.php </code> and make sure each of your service pages uses that page template (this is needed so we can identify which of your pages are meant to be services) . So here's the code for a class that I called <code> Yoursite_SharedChildPages </code> which you can store in your theme's <code> functions.php </code> file, or in a <code> .php </code> file of a plugin that you might be writing for your site: <code> if (!class_exists('Yoursite_SharedChildPages')) { class Yoursite_SharedChildPages { // If wanted we could enhance to allow these values to be defined in an 'init' hook static $PAGE_TEMPLATE = 'page-service.php'; static $ABSTRACT_ROOT = 'base-service'; static function on_load() { // Hook 'request' to route the request correctly add_filter('request',array(__CLASS__,'request')); // Hook 'page_link' to compose URLs correctly add_filter('page_link',array(__CLASS__,'page_link')); } static function request($query_vars) { if (!empty($query_vars['pagename'])) { // If the page URL rewrite matched meaning WordPress thinks it's a Page // Split the URL path by path segments (i.e. by slashes) $pagename = explode('/',$query_vars['pagename']); if ($pagename[0] == self::$ABSTRACT_ROOT) { // If the first path segment is the abstract root we care about if (count($pagename)==1) { // Don't allow anyone to visit this abstract root page $pagename = array('#'); // An invalid page name, so it will 404 } else { // If it is a child page in which case redirect to the first service // This is important so the user can view the page after they edit it $pages = self::get_page_ids_by_template(self::$PAGE_TEMPLATE); if (isset($pages[0]) && $page = get_post($pages[0])) { // Assuming we have at least one page with the page template $pagename[0] = $page->post_name; // then redirect to it the first service found. wp_safe_redirect('/'.implode('/',$pagename).'/'); exit; } } } else if (count($pagename)>1) { // If there are child pages if (get_page_by_path($query_vars['pagename'])) { // If it is an actual child page then just let it pass thru } else { // If a virtual child page then see if parent has the template $parent = get_page_by_path($pagename[0]); $pages = self::get_page_ids_by_template(self::$PAGE_TEMPLATE); if (in_array($parent->ID,$pages)) { // If virtual child of a service page, change parent to the abstract root $pagename[0] = self::$ABSTRACT_ROOT; $query_vars['pagename'] = implode('/',$pagename); // The URL doesn't match a virtual page, will appropriately get a 404 } } } else { $pagename = false; } } if (is_array($pagename)) $query_vars['pagename'] = implode('/',$pagename); return $query_vars; } static function get_page_ids_by_template($template) { // This can be performance optimized but I wouldn't worry about it // until there is a performance issue global $wpdb; $sql = "SELECT post_id FROM {$wpdb->postmeta} " . "WHERE meta_key='_wp_page_template' AND meta_value='%s'"; return $wpdb->get_col($wpdb->prepare($sql,$template)); } static function page_link($link) { $parts = explode('/',$link); if ($parts[3]==self::$ABSTRACT_ROOT) { // This is really only useful for links in the admin. if (!is_admin()) { global $wp_query; if (!empty($wp_query->query_vars['pagename'])) { $pagename = explode('/',$wp_query->query_vars['pagename']); } } else { // If we get a URL that uses the abstract root, assign it the first service. $pages = self::get_page_ids_by_template(self::$PAGE_TEMPLATE); if (isset($pages[0]) && $page = get_post($pages[0])) { // Assuming we have at least one page with the page template $parts[3] = $page->post_name; // then redirect to it the first service found. $link = implode('/',$parts); } else { $link = preg_replace('#^(https?://[^/]+)(/.*)$#','$1',$link); } } } return $link; } } Yoursite_SharedChildPages::on_load(); } </code> And here are some screenshots that can illustrate the steps mentioned above: Let me know if this is not what you were looking for and/or if you run into something that needs to be addressed by this solution in addition to what I have coded. Good luck!
|
How to show the same content on multiple URLs?
|
wordpress
|
I want to add permanently boxes below Visual/HTML editor for each page/post. I've never played with custom fields before, and I'm not sure is it way to go? If yes ten tell me, good people of StackExchange, how to achieve something like that (grey boxes):
|
Your looking for custom meta fields, which you can style anyway you want using CSS. http://codex.wordpress.org/Custom_Fields You would either have to write your own functions to accomplish this or use one of the many custom fields plugins, I would recommend the WPAlchemy MetaBox.
|
Custom options below pages/posts editor?
|
wordpress
|
How to add a random image to a post from gallery and only show one? I know how to add an image and a gallery. I need to have one image from the galley show on the page at random each time the page is loaded. The page should only show one image at a time. Is there a plugin or short code to do this? I know how to make gallery's random, but they show all the images. Answer : <code> $args = array( 'post_type' => 'attachment', 'numberposts' => 1, 'orderby' => 'rand', 'post_status' => null, 'post_parent' => get_the_ID(), 'post_mime_type' => 'image' ); have_posts(); //must be in the loop the_post(); //set the ID $images = get_children( $args ); if ($images) { foreach ( $images as $attachment_id => $attachment ) { echo wp_get_attachment_image( $attachment_id, 'full' ); } } wp_reset_query(); </code>
|
You should use the <code> 'orderby' => 'rand' </code> parameter for the <code> get_children() </code> attachments function. For instance: <code> $images = get_children( array( 'orderby' => 'rand', // this is random param 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => get_the_ID(), ); </code>
|
How to add a random image to a post from gallery and only show one?
|
wordpress
|
I have added a custom button to the tinymce to insert my shortcodes, but I have so many and I want to make a splitbutton instead and I can't figure how. Anyone can help. Here's the code that I've used to create the normal button: in functions.php : <code> /** Hook into WordPress */ add_action('init', 'onehalf_button'); /** Create Our Initialization Function */ function onehalf_button() { if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) { return; } if ( get_user_option('rich_editing') == 'true' ) { add_filter( 'mce_external_plugins', 'add_plugin' ); add_filter( 'mce_buttons', 'register_button' ); } } /** Register Button */ function register_button( $buttons ) { array_push( $buttons, "|", "onehalf" ); return $buttons; } /** Register TinyMCE Plugin */ function add_plugin( $plugin_array ) { $plugin_array['onehalf'] = get_bloginfo( 'template_url' ) . '/js/tinymce_buttons.js'; return $plugin_array; } </code> and in the custom plugin .js <code> // JavaScript Document (function() { tinymce.create('tinymce.plugins.onehalf', { init : function(ed, url) { ed.addButton('onehalf', { title : 'One Half Column', image : url+'/mylink.png', onclick : function() { ed.selection.setContent('[one_half]' + ed.selection.getContent() + '[/one_half]'); } }); }, createControl : function(n, cm) { return null; }, }); tinymce.PluginManager.add('onehalf', tinymce.plugins.onehalf); })(); </code> I've found something here http://tinymce.moxiecode.com/tryit/listbox_splitbutton.php but can't figure out how to implement it into WP. Anyone can help? Thanks.
|
It should be pretty straight-forward, copy the relevant pieces of code from the page you linked to into your existing TinyMCE plugin, update a few strings... done!.. Start with this for your TinyMCE plugin JS and see how you get on.. <code> // JavaScript Document (function() { // Creates a new plugin class and a custom listbox tinymce.create('tinymce.plugins.onehalf', { createControl: function(n, cm) { switch (n) { case 'onehalf': var mlb = cm.createListBox('onehalf', { title : 'My list box', onselect : function(v) { tinyMCE.activeEditor.windowManager.alert('Value selected:' + v); } }); // Add some values to the list box mlb.add('Some item 1', 'val1'); mlb.add('some item 2', 'val2'); mlb.add('some item 3', 'val3'); // Return the new listbox instance return mlb; /* case 'onehalf': var c = cm.createSplitButton('onehalf', { title : 'My split button', image : 'img/example.gif', onclick : function() { tinyMCE.activeEditor.windowManager.alert('Button was clicked.'); } }); c.onRenderMenu.add(function(c, m) { m.add({title : 'Some title', 'class' : 'mceMenuItemTitle'}).setDisabled(1); m.add({title : 'Some item 1', onclick : function() { tinyMCE.activeEditor.windowManager.alert('Some item 1 was clicked.'); }}); m.add({title : 'Some item 2', onclick : function() { tinyMCE.activeEditor.windowManager.alert('Some item 2 was clicked.'); }}); }); // Return the new splitbutton instance return c; */ } return null; } }); tinymce.PluginManager.add('onehalf', tinymce.plugins.onehalf); })(); </code> If something doesn't work please report back with as much info as possible, ie. what you tried, what the result was, what did happen, what didn't ... etc..
|
How i can i add a split button or list box to the WordPress TinyMCE instance
|
wordpress
|
I'm making a WordPress site using the Thesis framework. It has a widgetized footer area. I expect to be changing all the font styles frequently and don't want to have to change them in a few places every time to make the footer widget styles match the body styles. Does anyone know how I can make the footers styles (h3, text, li, a href) be automatically inherited from what I've set for the body styles? Thanks!
|
The footer is a child of the body element. It does already inherit all the styles. Find and remove all the styles which are ruling out the inherited styles. Tools like Firebug or Dragonfly will help you to find these rules.
|
How to make widgetized footer styles be inherited from body?
|
wordpress
|
I've been pounding my head on the pavement for some time now regarding implementing the_editor functionality outside the post/page/cpt editor and retaining the look and feel of the function without having to rewrite a ton of things. The problems I've run into are all problems within WP Core. the_editor and it's surrounding JS scripts that pull in TinyMCE, handle the Visual / HTML tabs, and Media Bar are not meant to be used more than once. Furthermore, the_editor is not self-contained, meaning you've gotta load a number of styles and scripts in the header / footer to enable functionality. My question is, has anyone seen or built a self-contained editor function that standardizes the_editor-like implementation for use by plugins? I hired a developer to put their spin on the script and they ended up needing a new set of PHP functions and replicating many WP Core JS functions. This seemed to me tricky, especially for upgrades. For instance, 3.0 to 3.1 nuked the TinyMCE link button. Am I doomed here or is there someone out there who feels my pain?
|
The solution was actually to contact Andrew Ozz and he was already planning on working on a new TinyMCE API which would allow for the functionality needed here. It's currently in use as of Pods 1.9.6+, and we're hoping that it makes it into WP 3.3 if everything goes right.
|
Replicating the_editor (Media Bar, TinyMCE, Visual/HTML Tabs) functionality without a huge rewrite
|
wordpress
|
I've managed to get my "semi noob proof" site installer plugin 98% complete, but I'm having a slight issue with the theme activation. The plugin is able to copy the theme into the themes directory fine. However, my switch_theme statement that attempts to set it to the active theme is missing something. I'm using... <code> function activate_theme(){ switch_theme('my_theme', 'style.css'); } </code> ...as a trigger statement inside the plugin to activate the newly uploaded theme (its uploaded as part of a function that processes further up in the code from the "activate_theme()" function. My theme, in this instance is called 'my_theme' and that's what I'm using in the theme's style.css I can tell that the switch theme is partially working, since when I click on "Appearance", the default 2010 theme is no longer the active theme, however, the "my_theme" theme is not set to active either. Its as if the process only partially completed and neither 2010 nor my theme are fully activated. So, I still have to manually click "Activate" to finish the process. What could I be missing?
|
I think, you must also set the options <code> template </code> and <code> stylesheet </code> , thats all. I use this via filter to set a theme for testing or on a category, post-type and so on. But you must change the fields in table options for active the theme ready. I hope this help, i dont tested - only my idea.
|
Fully automated theme install and activation via a plugin
|
wordpress
|
When i try to access feeds for tags,categories and authors, i get empty list. If i try to open feeds for the site, i get "Page not found" Empty Feed: http://thinkzarahatke.com/category/advertisement/video/feed http://thinkzarahatke.com/author/amty/feed Page not Found : http://thinkzarahatke.com/feed I had tried fix rss feed plugin. But it dint solved my problem too. Please help.
|
As per @Zeo suggestion, i activated default wordpress theme (Twenty Ten) -> I opened feeds then -> it was getting opened properly. I again to switched my theme without any changes. And it started working. If someone knows then please reason behind this.
|
Empty RSS Feeds
|
wordpress
|
I want to load some of the pages(not wordpress page, a template file other than wordpress's default template file) according to the url came on the address bar. for instance, I have page in my template file ie my_account.php to show my profile pic and other informations from to my wordpress pofile. and it is placed in my defaut theme folder <code> /themes/mytheme/my_account.php </code> When the url is <code> http://mysite/MyAccount/ </code> then I need to load the above page. Something like if <code> http://mysite/register/ </code> then load the register.php from my theme folder. I'm using custome permalinks option. <code> http://mysite/hello_world_post/ </code> So How can I configure and load the template according to the url, how to controll this by using a plugin.
|
You should be able to use template_redirect. I haven't tested it though, should be something like this. <code> function page_redirect() { if ($_SERVER['REQUEST_URI'] == 'your_url') { require(TEMPLATEPATH . '/mY-account.php'); } } add_action('template_redirect', 'page_redirect'); </code>
|
How to load a new template page according to a particular URL?
|
wordpress
|
hey, i have the following page template for a sitemap. <code> <?php /** * Template Name: Sitemap */ ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div> <h3>Pages</h3> <ul> <?php wp_list_pages('title_li=&depth=0&exclude='); ?> </ul> <h3>Posts</h3> <?php $first = 0;?> <ul> <?php $myposts = get_posts('numberposts=-1&offset=$first'); foreach($myposts as $post) : ?> <li><a href="<?php the_permalink(); ?>#b"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> <h3>Categories</h3> <ul> <?php wp_list_categories('title_li=&orderby=name'); ?> </ul> <h3>Tags</h3> <ul> <?php $tags = get_tags(); foreach ($tags as $tag){ $tag_link = get_tag_link($tag->term_id); $html .= "<li><a href='{$tag_link}#b' title='{$tag->name} Tag' class='{$tag->slug}'>"; $html .= "{$tag->name}</a></li>"; } echo $html; ?> </ul> </div> <?php endwhile; endif; ?> </code> It's my intention to not define a header with or or anything like that, because this thing is only used to get loaded via an ajax call. However the output of this thing looks like this <code> <div> <h3>Pages</h3> <ul> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body> <li class="page_item page-item-87"><a href="http://domain.com/account#b" title="Account">Account</a></li> <li class="page_item page-item-67"><a href="http://domain.com/forum-3#b" title="Forum">Forum</a></li> <li class="page_item page-item-107"><a href="http://domain.com/map#b" title="Google Map">Google Map</a></li> <li class="page_item page-item-79"><a href="http://domain.com/contact#b" title="ContaCt">Contact</a></li> <li class="page_item page-item-92"><a href="http://domain.com/login#b" title="Login">Login</a></li> <li class="page_item page-item-93"><a href="http://domain.com/register#b" title="Register">Register</a></li> </body></html> </ul> <h3>Posts</h3> <ul> <li><a href="http://domain.com/test-post#b">Test post</a></li> <li><a href="http://domain.com/lorem-ipsum-test-page#b">Lorem Ipsum Test Page</a></li> <li><a href="http://domain.com/hello-world#b">Hello</a></li> </ul> <h3>Categories</h3> <ul> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><li class="cat-item cat-item-1"> <a href="http://domain.com/category/something#b" title="Show all posts">Something</a> </li></body></html> </ul> </div> </code> Any idea why there is a weird doctype declaration and a <code> <html><body> </code> inserted inside of every <code> ul </code> . Except for the Posts <code> ul </code> . Just weird. Why could that happen and what causes this? I actually use a html5 doctype on my website. Thank you for the help edit: <code> add_filter('wp_list_pages', 'add_hash'); /*Add #hash to wp_list_pages() function*/ add_filter('wp_list_categories', 'add_hash'); /*Add #hash to wp_list_categories() function*/ function add_hash($output) { $dom = new DOMDocument(); $dom->loadHTML($output); $a_tags = $dom->getElementsByTagName('a'); foreach($a_tags as $a) { $value = $a->getAttribute('href'); $a->setAttribute('href', $value . '#b'); } return $dom->saveHTML(); } </code> The new DOMDocument is adding this doctype declaration and the and
|
Search all your theme and plugin files for: <code> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" </code> Disable all plugins and re-enable them step by step. This document type declaration is not part of WordPress’ core files; there is a filter active somewhere. Update Try to remove all filters from the affected functions. Start with wp_list_pages(): <code> remove_all_filters( 'wp_list_pages_excludes', 99 ); remove_all_filters( 'wp_list_pages', 99 ); </code> I still don’t believe that the doctype is nowhere to be found. That is impossible.
|
page template - undefined structure in source code
|
wordpress
|
Ok ,i am not a great fan of the menu of WP, but now it manage this inside pretty ok, i have to make theme that use that menu. Now for styling i am a bit challenge... here is the problem... the menu should look like | page1 | page2 | page 3 | Do you see the problem, the border, let say each will be style with border right 1px that work but first item will need a special class for border left Question. How do i know that it's first or last item in the menu to style it properly... or what is your way to style that type of menu...
|
Are you using CSS3? You could use: <code> ul#navmenuid:first-child { border-left: 1px; } </code> Or you could use (any LI that immediately follows an LI): <code> ul#navmenuid li { border-left: 1px; border-right: 1px; } ul#navmenuid li + li { border-left: 0; } </code> Or you could use (any LI that follow an LI, even if not immediately): <code> ul#navmenuid li { border-left: 1px; border-right: 1px; } ul#navmenuid li ~ li { border-left: 0; } </code> Lots of options via CSS, really...
|
New wp menu menu styling
|
wordpress
|
I am currently building a site using a child theme for the first time. Basically, I have a flash banner the client has already had made, and want to replace the twentyten image banner with the flash. I know how to do this by editing the header.php (I think!) but was wondering if there was a better way to do it - using function.php in my child theme perhaps? It would be nice if the client could update the theme themselves and not worry about the header being changed back. Thanks for any contributions.
|
A child theme is definitely the way to go for the reason you outlined: upgradability. To start with, here is the documentation for creating child themes: http://codex.wordpress.org/Child_Themes You'll want to create the child theme directory and edit the <code> style.css </code> file as described in the Child Theme documentation link above. After that, simply copy the <code> header.php </code> file from the <code> twentyten </code> directory into the directory and modify it to include the Flash element you have. By copying the <code> header.php </code> to a child theme, it will override the parent theme's version and be preserved after an update to the parent theme. This is the block you want to edit, as it creates the header image: <code> <?php // Check if this is a post or page, if it has a thumbnail, and if it's a big one if ( is_singular() && current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) : // Houston, we have a new header image! echo get_the_post_thumbnail( $post->ID ); elseif ( get_header_image() ) : ?> <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" /> <?php endif; ?> </code> I would just delete that entire PHP block, and replace it with the <code> <object> </code> code for your flash element. You'll want to make sure the flash element is exactly 940 pixels across, though, or it might look strange/break the design. The header image PHP block is located on line 68 of my <code> header.php </code> (in the WordPress 3.1 twentyten theme), and it's located directly below the following: <code> <div id="site-description"><?php bloginfo( 'description' ); ?></div> </code> Note that this isn't foolproof. If the twentyten theme gets updated in the future and contains changes you would like to have in the child theme they won't appear here. However, to add a hook which replaces the image header with a Flash one would require modifying the base theme's header.php... a bit of a catch 22. In practice this shouldn't be much of an issue, though. It's also the best way in WordPress to handle this sort of thing. For reference, here are the changes to the file on its Trac page .
|
How to replace the twentyten image header with my flash banner?
|
wordpress
|
How can you trigger a 404 when using custom query vars? I've got re-write rules written for a custom query var, but if you were to request a URL for the query var that should technically be a 404 it returns a normal WP page, but no content, because nothing technically exists for the URL.
|
There is a method specifically for this: <code> function my_parse_query( $wp_query ) { if ( $wp_query->get( 'my_custom_var' ) > 42 ) $wp_query->set_404(); status_header( 404 ); } add_action( 'parse_query', 'my_parse_query' ); </code> That should load the 404.php template in your theme, if you have it. Otherwise, it will fall back to index.php. This will also trigger a HTTP 404 status code.
|
How to trigger 404 for custom query var?
|
wordpress
|
I currently have a plugin that lets me display a random post in a widget. The problem is that if I activate w3 total cache it will only display that post as long as the cache hasn't been cleared. Is there a way to cache everything except this plugin? Sorry if the question is rather newbie, I just installed the plugin but haven't been able to find the answer anywhere. Thanks in advance!
|
You can try fragment caching, from plugin's FAQ: <code> Edit your templates to with the following syntax to ensure that dynamic features remain so: Example 1: <!-- mfunc any PHP code --><!-- /mfunc --> Example 2: <!-- mfunc -->any PHP code<!-- /mfunc --> Example 3: <!--MFUNC --> echo rand(); <!--/mfunc --> Example 4: <!-- mclude path/to/file.php --><!-- /mclude --> Example 5: <!-- mclude -->path/to/file.php<!-- /mclude --> </code> But my personal opinion is just to get rid of overly dynamic stuff. Unless it's key functionality (like in e-commerce) it's usually useless eye candy.
|
Can I ignore caching of a plugin in W3 Total Cache?
|
wordpress
|
I am pretty new to this and hence facing a bit of a problem. Currently I am designing a website on my localhost using WordPress. I noticed that the permalink structure wasn't very appealing in the default mode. I then found that it can be changed through settings and after looking around I found that I wanted <code> %postname% </code> as my custom structure. After making the change all my links seem to be broken! I cannot access any of the pages or posts.. After searching a bit I found that certain changes need to be made in htaccess file. According to http://codex.wordpress.org/Using_Permalinks the content in the file should be : <code> # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress </code> On opening the htaccess file the contents were: <code> # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /wordpress/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wordpress/index.php [L] </IfModule> # END WordPress </code> But neither of the two seem to work.
|
You should never have to touch the mod_rewrite rules. WordPress flushes/rewrites them to .htaccess whenever you save settings on Dashboard -> Settings -> Permalinks. If that's not happening, then something is wrong, either with your file permissions, or your local server setup. Also, it is strongly advised NOT to use %postname% alone as your permalink structure. You will encounter performance issues the larger your site gets, with respect to number of Posts and Pages.
|
Changing permalink of WordPress
|
wordpress
|
I am using a short piece of code(which is modified, originally it was a plugin-Taxonomy Terms List) to display custom taxonomies after the post, When the terms are displayed, it is displayed with a <code> href </code> tag. I don't want the terms to be a link, I just want simple terms text. How can I get that? Here is my current code: <code> if( !function_exists( 'pr' ) ) { function pr1( $var ) { print '<pre>' . print_r( $var, true ) . '</pre>'; } } if( !function_exists( 'mfields_taxonomy_terms_list1' ) ) { function mfields_taxonomy_terms_list1( $c ) { global $post; $o = ''; $terms = array(); $lists = array(); $custom_taxonomy_names = array(); $custom_taxonomies = mfields_get_custom_taxonomies1(); if( !empty( $custom_taxonomies ) ) foreach( $custom_taxonomies as $name => $config ) $custom_taxonomy_names[] = $config->name; if( !empty( $custom_taxonomy_names ) ) $terms = get_terms( $custom_taxonomy_names ); foreach( $custom_taxonomies as $name => $config ) $o.= get_the_term_list( $post->ID, $name, $before = '', $sep = ' | ', $after = '' ); if( is_single() ) return $c . $o; return $c; } add_shortcode('terms1', 'mfields_taxonomy_terms_list1'); } if( !function_exists( 'mfields_get_custom_taxonomies1' ) ) { function mfields_get_custom_taxonomies1( ) { global $wp_taxonomies; $custom_taxonomies = array(); $default_taxonomies = array( 'post_tag', 'category', 'link_category' ); foreach( $wp_taxonomies as $slug => $config ) if( !in_array( $slug, $default_taxonomies ) ) $custom_taxonomies[$slug] = $config; return $custom_taxonomies; } } add_action( 'wp_print_scripts', 'enqueue_slideout' ); </code>
|
You could use get_the_terms() instead: http://codex.wordpress.org/Function_Reference/get_the_terms This just gives you an array of the associated terms. Then use that array to create your own list without links.
|
Remove a href from this code
|
wordpress
|
I am using a function to display the URL on title tag, I coded this function which works properly but I would like to customize it more further. <code> function title_tag() { $a = $_SERVER['REQUEST_URI']; $b = strtoupper($a); $c = str_replace('-', ' ', $b); $d = str_replace('/', ' - ', $c); $e = substr($d, 2); return $e; } </code> This function will display the url on title after inserting this code in title tag. <code> <title><?php echo title_tag(); ?></title> </code> The current code is displaying the title in this format, my title of website: STANFORD UNIVERSITY - MBA IN CALIFORNIA - MBA - But I want to display it in this format, just the change in punctuations STANFORD UNIVERSITY - MBA IN CALIFORNIA, MBA - Just a comma as separator in between How can I have this?
|
<code> function title_tag () { // 0. uppercase string $str = strtoupper ( $_SERVER['REQUEST_URI'] ); // 1. remove trailing and init slash $str = trim ( $str , '/' ); // 2. add search and replace chars; // two array, with same element size, // 1. element of search array will be replaced // with the first element of replace array $search = array ( '-', '/' ); $replace = array ( ' ', ' - ' ); // 3. replace the chars $str = str_replace( $search , $replace , $str ); // 4. replace the last occurance of - for , // $pos finds the position of the last occurance // and fortunately, PHP strings can be manipulated // as arrays, so replace the array element with the // character $pos = strrpos ( $str , '-' ); $str{$pos} = ','; // you're ready return $str; } </code>
|
title tag function
|
wordpress
|
For example, I want to query posts in a page. But I don't want to show them when the user clicks the pagination links. Pretty much like what happens in Youtube. You only see the Top comments in the first page but when you click <code> Next </code> they disappear. Any suggestions to accomplish this? URL example: Query the posts if it is the first page: <code> example.com/taiwantalk/forums/topic/technology-topic-11/ </code> Don't query them if it is the second page or any other: <code> example.com/taiwantalk/forums/topic/technology-topic-11/page/2/ </code>
|
The current page number is available in a global variable <code> $paged </code> . <code> if ( ! isset ( $GLOBALS['paged'] ) or ( $GLOBALS['paged'] < 2 ) ) { // run your code } </code>
|
Querying posts only if the current page is not paged?
|
wordpress
|
This is the code: <code> <?php get_template_part( 'pagination', 'bbp_replies' ); ?> <?php query_posts('gdsr_sort=thumbs&post_type=bbp_reply&posts_per_page=2'); ?> <?php while ( have_posts() ) : the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_content(); ?> <?php endwhile; ?> <?php wp_reset_query(); ?> <?php while ( bbp_replies() ) : bbp_the_reply(); ?> <div class="topic-entry"> <div class="topic-author"> <?php bbp_reply_author_link( array( 'type' => 'avatar' ) ); ?> <?php bbp_reply_author_link( array( 'type' => 'name' ) ); ?> <?php printf( __( '%1$s', 'bbpress' ), get_the_date() ); ?> </div> <div class="topic-content"> <?php bbp_reply_content(); ?> <span class="like-counter"><?php DisplayVotes(get_the_ID()); ?></span> </div> <?php bbp_reply_admin_links(); ?> </div> </code> The first <code> query_posts </code> loop list the 2 most voted replies. The second bbPress loop list all other replies in DESC order. Will I encounter bugs if I have these two loops in a same file template?
|
I would not do it this way, but it should not be a problem. When your template file is executed the "real main loop" already contains the posts for this page. You then execute <code> query_posts() </code> to do a second query, which "hides" the "real" loop, but after you are done you execute <code> wp_reset_query() </code> which makes the "real" loop again the active loop. It would get confusing and lead to errors if you would embed the two loops, thus if you executed another <code> query_posts() </code> in that main <code> where </code> loop. Then you must use get_posts() </code> or a direct <code> WP_Query </code> to prevent errors. Personally, I never call <code> query_posts() </code> myself and always use <code> get_posts() </code> , because it doesn't change any global variables "behind my back".
|
It is possible to encounter horrible bugs if I place a main loop that uses `query_posts` right above the main bbPress loop?
|
wordpress
|
I have a site with about 900 pages that I was using custom permalinks <code> /%year%/%monthnum%/%postname%/ </code> for. I have a custom nav menu with tons of items in it. This combination seems to be simply too much for the server and they keep suspending my account for CPU usage. (I'm pretty sure this is what's causing the problem; I've already ruled out plugin issues). I've decided to change the permalink structure back to default, but it doesn't automatically change the nav menu. So I'm looking at hours of extra work rebuilding the menu after the permalink change. (I originally attempted to make the fix with sql queries, but I can't figure out the nav_menus are put together by WP). Does anyone have a fix for this, a plugin that does it, or a method to do it quickly, or any help at all? The site is http://cumberlandmaine.com
|
Changing the permalink structure back won't reduce your CPU usage that much. That stuff happens on the Apache side of things (using mod_rewrite), and it's pretty fast. It might help a bit, but it's a HUGE pain if you have nice, readable, search-engine friendly URLs at the moment. One of the best ways to reduce CPU usage is to implement caching. If you're getting WordPress to serve static content instead of having the content fetched from the DB and processed every time, you're saving a lot of resources. The two most popular caching plugins are http://wordpress.org/extend/plugins/wp-super-cache/ and http://wordpress.org/extend/plugins/w3-total-cache/ right now. I personally use WP Super Cache, but there are good reasons to look at W3 Total Cache. Depending on the setup, one might end up being a lot better than the other for you. EDIT: I looked at your site as well... It's being served very slowly from your host. This might be because of a lot of plugins, or some less-then-optimal custom code -- but I think it might also be a good idea to look at what other hosting providers could offer you. I use MediaTemple and I love them. However, I also only host one WordPress site per shared hosting instance, and pass the hosting costs on to my clients. I find this to be a better option for something like WordPress which is pretty resource intensive on a site with even moderate traffic.
|
Changing permalinks back to default ( ?p=123 )
|
wordpress
|
My theme has a custom menu assignment... <code> function my_register_my_menus() { register_nav_menus( array('header-menu' => __( 'Custom Header Menu' ) ) ); } </code> ...and I'm creating an "installer" type plugin that, upon activation, I would like to hook into this custom menu and assign some pages to it as if they had been created manually. However, the menu API is pretty new and to date, I've been unable to find any examples of how to do this. I'm hoping someone here can give me some direction, examples or info on how to do it. Thanks in advance :-)
|
You can use <code> wp_nav_menu_{$menu->slug}_items </code> hook and add you link with a callback function, for example if your menu slug is <code> header-menu </code> then something like this: <code> add_filter('wp_nav_menu_header-menu_items', 'add_my_extra_links',10,2); function add_my_extra_links($items, $args) { $newitems = '<li><a title="Test Link" href="http://google.com">Google</a></li>'; $newitems .= '<li><a title="Test Link" href="http://yahoo.com">Yahoo</a></li>'; $newitems .= '<li><a title="Test Link" href="http://bing.com">Bing</a></li>'; $newitems .= $items; return $newitems; } </code> Update I guess you would need to call wp_save_nav_menu_items which is the function used to save the menu items to the database.
|
Can I add pages to my custom menu via script?
|
wordpress
|
I did a pretty thorough search and found a couple of closed (and unanswered) topics on the WP forums. Does anyone know if this is possible? The codex doesn't specify this as an option. Thanks!
|
You use a lowercase y for a 2 digit year. For example (l, F j, Y) --> returns, Friday, September 24, 2004 and (l, F j, y) ---> returns Friday, September 24, 04
|
How do you format the date as a two digit year? (ex. "10.12.10" instead of "10.12.2010")
|
wordpress
|
I am trying to get all products from the wpsc-product post type and then display them by a custom meta field called release_date_year. However, it doesn't appear to be ordering my posts by this custom meta value. I have read through countless blog posts, support posts on the Wordpress forums and a lot of questions and answers here on Wordpress Answers. However, I could not find a solution to my issues. Here is the code that I am using to get the products and then order them by a custom meta field. Ignore the each_connected argument as that is for the plugin Posts to Posts by Scribu. A quick note: I have also tried remove the each_connected part to see if it fixed the issue, but as I suspected, it didn't change a thing. It appears as though the below code gets the products okay, that's not the issue. The issue seems to be that they are being ordered by the date they were published and not the custom meta field value which is a numeric value. <code> $products = new WP_Query(array( 'post_type' => 'wpsc-product', 'nopaging' => true, 'meta_key' => 'release_date_year', 'each_connected' => array( 'post_type' => 'artists', 'nopaging' => true, ), 'suppress_filters' => false, 'orderby' => 'meta_value_num', 'order' => 'asc', )); </code> I then looked at what queries were being run and the following is the result: <code> SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'wpsc-product' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND wp_postmeta.meta_key = 'release_date_year' GROUP BY wp_posts.ID ORDER BY wp_posts.menu_order, wp_posts.post_date DESC </code> Now is it just me or should the 'ORDER BY' part of my query have wp_postmeta.meta_key in it? Because it looks to me it's ordering by the menu order and then the post date descending. The other weird thing is that I am also seeing posts ordered descending instead of ascending. Like I said, I also tried using meta_query in my WP_Query query as I am using Wordpress 3.1 using the following code and it was still ordering posts by post_date: <code> $products = new WP_Query(array( 'post_type' => 'wpsc-product', 'nopaging' => true, 'meta_key' => 'release_date_year', 'meta_query' => array(array( 'key' => 'release_date_year', 'type' => 'NUMERIC' )), 'each_connected' => array( 'post_type' => 'artists', 'nopaging' => true, ), 'suppress_filters' => false, 'orderby' => 'meta_value', 'order' => 'desc', )); </code> Have I incorrectly formatted my WP_Query statement or is something else at play here? I have also confirmed there is data in the wp_postmeta table and there are values for each product there. Update and Solution After some messing around, I found the culprit. A plugin called 'Post Types Order' which was modifying my Wordpress queries and hence causing the suppress_filters argument to be completely ignored, amongst other things like orderby. See my answer below.
|
The plugin ' Post Types Order ' was the culprit. As Scribu pointed out above the plugin is filtering the Raw SQL query which it shouldn't be doing. As a result, the argument ' suppress_filters ' wasn't stopping the query being modified and the ' orderby ' argument was being completely ignored. As to how this behavior can be stopped, I'm not sure. I solved my issue by disabling the plugin as it wasn't even being used. However, you can set the order of your custom post type menus in your register_post_types code instead, using the ' menu_position ' argument which decides where the menu will be placed. Documentation for ordering your post types in the Wordpress admin menu can be found here in the official Wordpress documentation. The lesson learned here is that you should always assume that a plugin has broken something, especially if you are using code from the official documentation that works.
|
Wordpress Orderby Numeric Value Not Working
|
wordpress
|
I am trying to email a custom input <code> <input type="text" name="total" id="total" class="wpcf7-text" readonly="readonly" /> </code> I tried <code> [total] </code> but it does not work. Or isit possible to make a field readonly with WPCF7?
|
Contact form 7 is one of my favorite plugins , now after I've said that you can either create your own module to add a filed of "readonly" by following this tutorial http://blog.ekynoxe.com/2010/09/06/extending-contact-form-7/ or maybe even digging through Contact Form 7 Modules plugin to see how to add new modules, but a much easier solution would be to create a regular text filed and use JQuery to add the readonly attribute <code> $('#inputId').attr('readonly', true); </code>
|
Contact Form 7: Email custom HTML inputs or make a field readonly
|
wordpress
|
What's the best way to use <code> <?php the_post_thumbnail();?> </code> in my loop BUT only show a thumbnail on the FIRST post? Meaning, only the first post in the loop will have it's image shown? Here is an example of a loop that shows the image for ALL posts: <code> <!-- Start the Loop. --> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!-- Display the Title as a link to the Post's permalink. --> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <!-- Display the posts Image thumbnail for the post --> <?php the_post_thumbnail();?> <!-- Display the date and a link to other posts by this posts author. --> <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small> <!-- Display the Post's Content in a div box. --> <div class="entry"> <?php the_content(); ?> </div> </code> Thank you!
|
add a variable before the loop (before the while), for example $first = true; add a check inside the loop for this variable after the use, change the flag Code: <code> <!-- Start the Loop. --> <?php $first = true; ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!-- Display the Title as a link to the Post's permalink. --> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <!-- Display the posts Image thumbnail for the post --> <?php if ( $first ): ?> <?php the_post_thumbnail();?> <?php $first = false; ?> <?php endif; ?> <!-- Display the date and a link to other posts by this posts author. --> <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small> <!-- Display the Post's Content in a div box. --> <div class="entry"> <?php the_content(); ?> </div> </code>
|
Display thumbnail only on the very first post in the loop?
|
wordpress
|
How do I increase Author Role permissions to be able to add Categories? Other solutions welcome. We just need guest authors to be able to add categories while ensuring there is not already a existing appropriate category.
|
The easiest way is to use a plugin like Capability Manager or User Role Editor
|
How would I increase the Author Role to be able to add a new category?
|
wordpress
|
I'm using the following function to get some posts based on their vote (Vote it Up plugin): <code> function top_voted($number){ $a = SortVotes(); echo '<div class="voted">'; $rows = 0; //Now do not include deleted posts $i = 0; while ($rows < $number) { if ($a[0][$i][0] != '') { $postdat = get_post($a[0][$i][0]); if (!empty($postdat)) { $rows++; echo '<div class="fore">'; echo '<div class="votecount" style="width: 1em; color: #555555; font-weight: bold;">'.$a[1][$i][0].' </div><div><a href="'.$postdat->guid.'" title="'.$postdat->post_title.'">'.$postdat->post_title.'</a></div>'; echo '<div class="votecount" style="width: 1em; color: #555555; font-weight: bold;">'.$a[1][$i][0].' </div><div>'.$postdat->post_content.'</div>'; echo '</div>'; } } if ($i < count($a[0])) { $i++; } else { break; //exit the loop } } echo '</div>'; } </code> I would like to only get the posts of a certain post type. I think I have to do something with <code> get_post </code> but I'm not familiar with it. Any suggestions?
|
<code> $the_posts = get_posts(array('post_type' => 'post_type_name')); </code> That will get all posts from the post type called "post_type_name" so replace that with whatever custom post type you are using. I mean this in the nicest possible way, but you should probably read the documentation as this is a pretty well documented feature that isn't too hard to understand. Documentation for get_posts is available here on the Wordpress website with plenty of example code for you to easily understand.
|
Getting only a specific post type with get_post?
|
wordpress
|
I have a custom table inside my wordpress database called test. What if i query this table using mysql_query() instead of using for example $wpdb-> get_results() Will this affect my performance? Ty very much:)
|
Simple and short: mysql_query() = Faster! $wpdb-> get_results() = Safer! But in most cases since <code> $wpdb </code> is a global object and already in the memory using it will be be as fast as <code> mysql_query() </code> . Will this affect my performance? It can affect for better performance changes but they would be minor changes that its just not worth it.
|
Use mysql_query instead of $wpdb query
|
wordpress
|
This is going to sound a little nuts. I have a situation where I'm displaying a list of products that a user selects to move to the products' page. I also have documents and videos that I created custom post types and fields for. I need to run a second loop within the current loop to pull a custom field from a custom post type. If that makes sense? for example this is the product "directory" loop (pardon my hackish techniques) <code> <div id="content" role="main"> <?php $parent = $post->ID; query_posts('post_type=page&order=ASC&orderby=title&post_parent='.$parent);?> <?php while (have_posts()) : the_post(); ?> <?php $model = get_the_title(); ?> <div class="product-selection-container round"> <h2 class="directory-title"><a href="<?php the_permalink() ?>"><?php echo get_post_meta($post->ID, "product-main-title", true); ?></a></h2> <h3>Model <?php echo $model ?></h3><!-- the model --> <?php echo my_excerpts(); ?> <ul class="round"> <li><a href="<?php the_permalink() ?>">Learn More</a></li> <li><a href="">Specification Sheet</a></li> <li><a href="">Video Tour</a></li> </ul> </div> </div> <?php endwhile; ?> </code> And this is the loop I generally use to add documents to the pages (excluding the custom loop template) <code> <?php $documents = array('numberposts' => 5, 'post_type' => 'documents', 'category_name' => $model); query_posts( $documents ); get_template_part( 'loop', 'documents' ); wp_reset_query(); ?> </code> I tried combining the two where I would add the second loop to <code> <li><a href="">Specification Sheet</a></li> </code> but that caused the page to run in a perpetual loop. An alternative option I was looking for was to pull a single custom field from a post type without creating a loop. For example. <code> get post_type => document, meta_key => document-type, meta_value => spec-sheet </code> Any help would be appreciated.
|
I'll presume you are using something like this...to get the custom value you want. Once you are inside the loop. <code> $customfieldvalue = get_post_meta($post->ID, "metakeyname", true); </code> Since you are using $model as the base for a query. You could create a function That will query what you want, and then reset the current query. You could use it wherever you want. Here is a template. <code> function modelquery($model) { global $wp_query, $post, $paged, $post_count; // YOUR QUERY $query_args = array ( 'numberposts' => 5, 'post_type' => 'documents', 'category_name' => $model ); // SAVE CURRENT QUERY $temp = $wp_query; $wp_query= null; // CREATE NEW QUERY $wp_query = new WP_Query(); $wp_query->query($query_args); // THE LOOP, DO WHAT YOU HAVE TO DO HERE while ($wp_query->have_posts()) : $wp_query->the_post(); $customfieldvalue = get_post_meta($post->ID, "metakeyname", true); echo $customfieldvalue; endwhile; // SWAP BACK THE PREVIOUS QUERY $wp_query = null; $wp_query = $temp; wp_reset_query(); } </code>
|
Pull custom fields from custom posts within a loop
|
wordpress
|
I have posts and I have recipes. Recipes is a custom post type. Recipes make use of the category taxonomy and a newly added recipe has been categorized under beer. When I browse the listing page for the category beer I see all my previous posts categorized under beer while the new recipe does not appear. How do I link custom post types through their taxonomies? Or, how can I show all post types under a single category?
|
You can use pre_get_posts hook to add your custom post type to the query <code> function include_recipes( $query ) { if ( $query->is_category ) { $query->set( 'post_type', array('post','recipes') ); } return $query; } add_filter( 'pre_get_posts', 'include_recipes' ); </code>
|
How do I display custom post types through a common taxonomy?
|
wordpress
|
I see that w3 total cache can't offer CSS sprite generation. Is there another plugin that can complement this feature? Thanks. update: I didn't mean that w3 total cache doesn't allow CSS sprites to be used, but that it doesn't generate them automatically as a way to improve sites performance. My question is what plugins DO offer that capability.
|
Are you asking about how to create css sprites? Try http://spritegen.website-performance.org/ if the manual way seems too time-consuming. But yeah, not really a WordPress question.
|
Plugins to generate CSS Sprites?
|
wordpress
|
For some reason a <code> title </code> attribute is not appended to <code> next_post_link </code> and <code> prev_post_link </code> calls in WordPress. How can I add one?
|
Update As I deleted the Repo on GitHub, here's a new answer. <code> add_filter( 'previous_post_link', 'wpse13044_adjacent_post_link_tooltip', 10, 2 ); add_filter( 'next_post_link', 'wpse13044_adjacent_post_link_tooltip', 10, 2 ); function wpse13044_adjacent_post_link_tooltip( $format, $link ) { $previous = 'previous_post_link' === current_filter(); // Get the next/previous post object $post = get_adjacent_post( false ,'' ,$previous ); // Copypasta from cores `get_adjacent_post_link()` fn '' === $title = get_the_title( $post->ID ); AND $title = $previous ? sprint( __( 'Previous Post: %s', 'your_textdomain' ), $title ) : sprint( __( 'Next Post: %s', 'your_textdomain' ), $title ); $format = str_replace( 'rel="' ,sprintf( 'title="%s" rel="' ,$title ) ,$format ); return "<span class='some classes'>{$format}</span>"; } </code>
|
How can I add title attributes to next and previous post link functions?
|
wordpress
|
I'd like to display daily archives differently than monthly/yearly archives. How do I check to see if the archive template is being pulled for a daily archive vs. a monthly/yearly archive?
|
Conditional tags FTW. is_month() : Currently viewing a monthly archive is_day() : Currently viewing a single day archive is_year() : Currently viewing a yearly archive is_time() : Currently viewing a time-based archive (hourly, minute, or even seconds) So to test for each of these conditions, add something like this to your archive.php (or whatever template is being used for your archive pages): <code> // Check what posts were returned in order to find what date the archive is for global $posts; $archivedate = strtotime( $posts[0]->post_date); if (is_day()) { echo "Daily archive: ".date('m/d/Y', $archivedate); } else if (is_month()) { echo "Monthly archive: ".date('F Y', $archivedate); } else if (is_year()) { echo "Yearly archive: ".date('Y', $archivedate); } </code>
|
Displaying year, month and day archives differently
|
wordpress
|
I've got a routine (see below) that creates and inserts several widgets into the active theme's sidebars. However, I need more control over either the order/index the are assigned (ie, one of my widgets need to be at the top of any other widgets in the sidebar) OR, I need to be able to specify a custom css name for the widget. I've inserted a comment to catch the widget titled "my important widget" and apply the index or custom css I'll need to assign to that widget. Are either of these possible? <code> $file_name_widget = $files_widgets->getPathname(); $widget_text = file_get_contents($file_name_widget); $widget_text_label = 'text'; $widget_ops = get_option('widget_text', array()); $widget_id = count($widget_ops) + 1; if($file_name_widget == 'my important widget') { //place code here to make this widget move to the top of any others in the sidebar its assigned to } $widget_ops[$widget_id] = array('title' => $files_widgets->getBasename('.txt'),'text' => $widget_text,); update_option('widget_text', $widget_ops); $sidebar_id = basename($files_widgets->getPath()); $sidebars_widgets = get_option('sidebars_widgets', array()); $sidebars_widgets[$sidebar_id][] = $widget_text_label."-".$widget_id; update_option('sidebars_widgets', $sideb </code>
|
If you want to change the orders, you can use the filter <code> sidebars_widgets </code> , the argument to which is an array of all the widget ids and their locations. You can change the id positions in that array as per your need.
|
How to specify widget order or css name via script?
|
wordpress
|
Ok, i need to setup a shop, my choice, WP, now, the shop should be french and english, with product variation and newsletter tracking, this is the baseline Now, everybody is talking about wp e-commerce from instinct, a company that look serious, but now, there is a paid, a free, a commercial version. There is getshopped.org wich is ? the same or another site, there is wpml that said we will be compatible, but waiting for the new version. On the site, they dont talk about wpml, of state compatibility. No mean to contact without registering.. So here is my question. How can we get strait answer from a company that have a HUGE base of client that use there product. Is it possible to make a multilingual shop with e-commerce and wpml or qtranslate ? and where i can get answer... It's sad to see that even before installing the software, it so difficult to get help... just imagine when i will be on deadline... Tell me from your experience please, and thanks in advance
|
Yes, it is extremely frustrating to find a plugin that works without errors and is still customisable. I have tried the following: Shopp - www.shopplugin.net (very good, but will only support WPML in the next update - unknown release date) Marketpress - http://wordpress.org/extend/plugins/wordpress-ecommerce/ (workes well, but is pretty limited, not sure if the paid version is that much better) WP e-Commerce - getshopped.org (works, but the structure of it is very heavy and caused some errors within my system, not sure if that is the standard. You will need to pay for the Gold Cart Plugin. The free setup is not very usable) The Cart Press thecartpress.com (last time I tried they were still in a very early stage. I will actually try it again now and hope it has improved)
|
WP E-commerce wpml translation or multilingual
|
wordpress
|
People are often confused about how to get data from global objects/vars Question: In which ways can you inspect global variables? This Q was written because it's needed pretty often over here at WA. I just wanted to have it as a fav to link over here (people often don't take a look at github gist links). Feel free to modify the example if something is wrong or you think that the explanation is missing something. If you want to add other useful stuff, please add each as a single answer. Thank you.
|
How to inspect the data: Use this to get an insight view of what you can use from the current request/wp_query. <code> function inspect_wp_query() { echo '<pre>'; print_r($GLOBALS['wp_query']) echo '</pre>'; } // If you're looking at other variables you might need to use different hooks // this can sometimes be a little tricky. // Take a look at the Action Reference: http://codex.wordpress.org/Plugin_API/Action_Reference add_action( 'shutdown', 'inspect_wp_query', 999 ); // Query on public facing pages add_action( 'admin_footer', 'inspect_wp_query', 999 ); // Query in admin UI </code> Btw: <code> // this: global $wp_query; $wp_query; // is the same as $wp_query; // and as this: $GLOBALS['wp_query']; // You can do this with each other global var too, like $post, etc. </code> How to actually get the data: <code> // Example (not the best one) (Object) WP_Query -> post (stdClass) -> postdata (Array) // How to get the data: // Save object into var $my_data = new WP_Query; // on a new object // or on the global available object from the current request $my_data = $GLOBALS['wp_query']; // get object/stdClass "post" $my_post_data = $my_data->post; // get Array $my_post_data = $my_data['post']; </code> Examples stackexchange-url ("List all sidebar names?") (Generate a drop down/select object with all sidebars inside the <code> global $wp_registered_sidebars </code> )
|
How to: inspect global variables in WordPress
|
wordpress
|
I'm using this code to display my menu: <code> <?php $menu_args = array( 'container' => '', 'menu_class' => '', 'menu_id' => 'main-menu', ); wp_nav_menu($menu_args ); ?> </code> It works totally fine, but I don't know how to get rid of all these classes attached to every li in my menu? Example: <code> <li id="menu-item-227" class="menu-item menu-item-type-post_type current-menu-item page_item page-item-77 current_page_item menu-item-227"> </code> It's pretty long, isn't it? I don't need classes and even IDs here at all, since my menu has one already. Any ideas?
|
you can use <code> nav_menu_css_class </code> filter hook to remove the classes: <code> add_filter('nav_menu_css_class' , 'my_nav_menu_remove_class' , 10 , 2); function my_nav_menu_remove_class($classes, $item){ $my_class = array('menu-item-class'); return $my_class; } </code>
|
WP navigation list classes
|
wordpress
|
I've gotten as far as creating my new tab and getting it to show up and I've taken a copy of the gallery screen (I'm making an audio plugin with a playlist feature). The list of media items shows up fine but I can only get it to show just the audio files when I don't pass a post ID into the <code> get_media_items() </code> function like in the media library tab. How I can retrieve a media items list using <code> get_media_items() </code> where the post_parent field is set and the post_mime_type matches 'audio'?
|
The answer ended up being to copy that function and filter the results it returned. It's hacky but until there are more hooks/filters available in that section of the core there's no better way :(
|
How do you filter get_media_items by mime type in a custom media upload tab?
|
wordpress
|
I have a custom loop pulling out videos all assigned to various categories. However there is a category called "new-video" and I need to pull out all videos using my custom loop, but I would like the posts assigned to the category "new-video" to be shown first. So basically the loop will treat the category "new-video" as of high priority and then show the other videos afterwards. I know you can include and exclude categories, but I don't want to exclude anything, merely prioritise. With Wordpress 3.1 *meta_query* was introduced which allows for some pretty customisable queries, but the documentation is sparse and all of my searches thus far have returned nothing I can use. The code I am currently using is the below if it helps: <code> $videos = get_posts(array( 'post_type' => 'videos', 'nopaging' => true, 'each_connected' => array( 'post_type' => 'artists', 'nopaging' => true, ), 'suppress_filters' => false )); </code> Ignore the each_connected stuff, that is there because I am using the plugin Posts to Posts by Scribu.
|
Just run 2 queries, the first to pull just the new-videos and the 2nd to pull everything else but the new-videos. Probably just use WP_Query for the first one to get the new-videos and then alter the loop query for the 2nd one to exclude new-videos.
|
Prioritising and Ordering Posts By Category Name Using A Custom Loop
|
wordpress
|
If I would export a WordPress database, posts and comments etc. are saved to an XML file. Would comment metadata be included in this XML file? I.e. the table <code> wp_commentmeta </code> , mentioned here: http://codex.wordpress.org/Database_Description#Table:_wp_commentmeta . Here: The WordPress eXtended Rss (WXR) Export/Import, XML Document Format Decoded and Explained I found some info on the export file format, and the columns in <code> wp_comments </code> are mentioned, but there's no mentioning of any columns in <code> wp_commentmeta </code> . Edit: Background: I'm planning to write a new commenting system for WordPress, and I'd like to be able to import/export comment data between various blog platforms. (E.g. Blogger and others.) And I think I need to use the comment metadata table. /Edit Kind regards, Magnus
|
My latest export from my blog (WP 3.3.1) now has the commentmeta in the XML. It's in this format: <code> <wp:comment> <wp:comment_id>...</wp:comment_id> ... <wp:comment_user_id>0</wp:comment_user_id> **<wp:commentmeta> <wp:meta_key>name_of_meta</wp:meta_key> <wp:meta_value><![CDATA[value_of_meta]]></wp:meta_value> </wp:commentmeta>** </wp:comment> </code> I was looking for information on it while trying to write an exporter from another system. Not much information available online so I tried an export from a well-used blog--it was there!
|
Is comment metadata included in the export file?
|
wordpress
|
I am trying to mimic the dashboard meta boxes UI in my WP plugin - the small metaboxes. I have already styled them and also the drag & drop feature works as I loaded the following script and style: <code> wp_enqueue_style('dashboard'); wp_enqueue_script('dashboard'); </code> However I also would like to save my custom "postboxes" position (order) and also the open/close state. Any ideas how could this be achieved? Thanks. UPDATE: This is the structure of my postbox: <code> <div class="wrap"> <h2><?php echo get_admin_page_title(); ?></h2> <div class="postbox-container" style="width: 100%"> <div class="metabox-holder"> <div class="meta-box-sortables"> <div class="postbox" id="first"> <div class="handlediv" title="Click to toggle"><br /></div> <h3 class="hndle"><span><?php echo get_admin_page_title(); ?></span></h3> <div class="inside"> <p>first</p> </div> </div> <div class="postbox" id="second"> <div class="handlediv" title="Click to toggle"><br /></div> <h3 class="hndle"><span><?php echo get_admin_page_title(); ?></span></h3> <div class="inside"> <p>second</p> </div> </div> </div> </div> </div> <form style="display:none" method="get" action=""> <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?> <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?> </form> </div> </code>
|
When ordering or closing metaboxes, those actions require nonces, add the following to your code and see if that resolves the problem. <code> <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?> <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?> </code> Additional: You should add metaboxes to your page using <code> add_meta_box </code> and output them using <code> do_meta_boxes </code> passing in the hook for your plugin page as the first arg. This should at least ensure you have registered and output them in the same way WordPress does, and providing you've also output the appropriate nonces, should work. If something still isn't working, view source on your problem page(s) and verify the JS files are being output in the correct order(easier still, compare JS inclusions in your page with a core WordPress page that uses metaboxes, make sure your JS includes(enqueues) appear in the same order).
|
Dashboard like meta boxes in my plugin - how to save their position and open/closed state?
|
wordpress
|
By default WP seems to display all posts of all types in the main RSS feed. You have to add a post_type query variable to show post of a certain type... So how can I turn this: <code> http://site.com/feed/?post_type=book </code> into <code> http://site.com/feed/books/ </code> ? And if possible rewrite <code> http://site.com/feed/ </code> to <code> http://site.com/feed/blog/ </code> , which should display only normal posts...
|
If you set <code> 'has_archive' => TRUE </code> in <code> register_post_type() </code> the post type will have its own feed on <code> /books/feed/ </code> and its items are not included in the main feed. Example plugin <code> <?php /* Plugin Name: WPSE13006 feed for CPT demo */ ! defined( 'ABSPATH' ) and exit; add_action( 'init', 'wpse13006_register' ); // Call wp-admin/options-permalink.php once after activation to make permalinks work function wpse13006_register() { register_post_type( 'wpse13006' , array ( 'has_archive' => TRUE , 'label' => 'wpse13006' , 'public' => TRUE , 'publicly_queryable' => TRUE , 'query_var' => 'wpse13006' , 'rewrite' => array ( 'slug' => 'wpse13006' ) , 'show_ui' => TRUE , 'show_in_menu' => TRUE , 'supports' => array ( 'title', 'editor' ) ) ); } </code> Create one post, publish and view it. If you go up one level to <code> /wpse13006/ </code> now, you’ll find the feed at <code> /wpse13006/feed/ </code> . The post will not show up in the main feed.
|
Nice RSS Feed URLs for each custom post type
|
wordpress
|
As I already told, I'm setting up a Blog for a friend. Next to not being him an administrator stackexchange-url ("but an editor that can make changes to theme options")) I have an additional question. I don't want him to worry about updates as well nor do I want him bothering me, but the problem is, editors do see a slightly changed variant of the update nag. Is there a way to disable those for non-admins? It's just the case that we normally do know about Wordpress updates even before they get packaged and released.
|
You may have to adjust the capability. <code> add_action( 'admin_init', 'hide_update_msg', 1 ); function hide_update_msg() { ! current_user_can( 'install_plugins' ) and remove_action( 'admin_notices', 'update_nag', 3 ); } </code>
|
How can I disable the update notice for non-administrators?
|
wordpress
|
I have a plugin that installs a folder of themes and other plugins into the WP site during plugin activation. I would like to place script into the plugin which will activate one of the themes that the plugin installs. Can someone post a quick example of script that registers and activates a known theme via a plugin's activation script?
|
switch_theme() should work: <code> function myplugin_activate() { switch_theme('default', 'default'); } register_activation_hook( __FILE__, 'myplugin_activate' ); </code>
|
Activate theme via plugin script?
|
wordpress
|
I have a blog on wordpress.com in which I make use of the Twenty Ten theme. For each Post I can set a Featured image. On Wordpress.com that image is then displayed in the header above the menu. I'd like to gain the same for a Wordpress.org setup. How can I do this?
|
Not sure I understand your question completely hakre but here is the code that shows the featured image for twenty-ten in header.php.The image sizing is defined in the functions.php file. It also uses a function called http://codex.wordpress.org/Function_Reference/get_header_image . <code> <?php // Check if this is a post or page, if it has a thumbnail, and if it's a big one if ( is_singular() && current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) : // Houston, we have a new header image! echo get_the_post_thumbnail( $post->ID ); elseif ( get_header_image() ) : ?> <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" /> <?php endif; ?> </code>
|
Use Featured Image of Post as Header Image
|
wordpress
|
Here is what I'm doing: <code> wp_logout(); var_dump(is_user_logged_in()); </code> var_dump returns: <code> bool(true) </code> Why is wp_logout() not logging me out?
|
wp_logout() calls clear_auth_cookie() , which expires all authorization cookies set. It doesn't change the value of the global $current_user variable. So technically you're still logged in for the duration of the script. If you're using <code> wp_logout </code> in your own code, its probably best to <code> exit </code> or <code> wp_redirect </code> immediately afterwards.
|
wp_logout Not Logging Me Out
|
wordpress
|
Basically, I want to allow the user to select which template files he or she wants to use in a post: single-asc.php : <code> <?php $custom_posts = new WP_Query(); ?> <?php $custom_posts->query('post_type=bbp_topic&order=ASC'); ?> <?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?> <div class="content-block-2"> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a> </div> <?php endwhile; ?> </code> single-desc.php : <code> <?php $custom_posts = new WP_Query(); ?> <?php $custom_posts->query('post_type=bbp_topic&order=DESC'); ?> <?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?> <div class="content-block-2"> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a> </div> <?php endwhile; ?> </code> In this example, the user can choose (maybe by clicking a link) to see a post with the <code> single-asc.php </code> template file or <code> single-desc.php </code> template file. (the ASC and DESC example is just for reference, these two templates will have different code) Any suggestions to accomplish this?
|
If the differences in the pages are just query arguments the you can add query vars and use them in the same template: <code> //add your arguments to query vars add_filter('query_vars', 'my_query_vars'); function my_query_vars($vars) { // add my_sortand ptype to the valid list of variables you can add as many as you want $new_vars = array('my_sort','ptype'); $vars = $new_vars + $vars; return $vars; } </code> your query should look like this: <code> <?php $custom_posts = new WP_Query(); ?> <?php $custom_posts->query(array('post_type' => get_query_var('ptype'), 'order' => get_query_var('my_sort'))); ?> <?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?> <div class="content-block-2"> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a> </div> <?php endwhile; ?> </code> and you links for the user should be: ASC: url + ?ptype=bbp_topic&my_sort=ASC DESC: url + ?ptype=bbp_topic&my_sort=DESC Now if your differences in the pages are more then query arguments you can change the template page using <code> template_redirect </code> hook: same as before add your query arg <code> //add your arguments to query vars add_filter('query_vars', 'my_query_vars'); function my_query_vars($vars) { // add my_sort to the valid list of variables $new_vars = array('my_sort'); $vars = $new_vars + $vars; return $vars; } </code> then add a function to the template_redirect hook and create the redirection based of that argument: <code> add_action("template_redirect", 'sort_template_redirect'); // Template selection function sort_template_redirect() { global $wp; global $wp_query; if (isset($wp->query_vars["my_sort"])) { // Let's look for the template file in the current theme if (array_key_exists('my_sort', $wp->query_vars) && $wp->query_vars['my_sort'] == 'ASC'){ include(TEMPLATEPATH . '/single-asc.php'); die(); } if (array_key_exists('my_sort', $wp->query_vars) && $wp->query_vars['my_sort'] == 'DESC'){ include(TEMPLATEPATH . '/single-desc.php:'); die(); } } } </code> and once again you will need to add the args to the link so: ASC: url + ?my_sort=ASC DESC: url + ?my_sort=DESC
|
Is it possible to give the user the chance to select between two single template files to use in a post?
|
wordpress
|
I am wanting to display the number order of a post. I tried using <code> <?php the_ID(); ?> </code> but this just displays the post ID and doesn't seem to do go in sequential order due to post revisions and whatnot. Is there a way to to display if the post is #2 or #3 or #4 and so on? Thanks!
|
Post ID's aren't meant to be sequential. To number your posts sequentially, you'd have to use a meta field. There was discussion of this while back on this question: stackexchange-url ("Change Permalinks Structure to a Sequential Number for Each Post?") And the best answer for what you're looking to do seemed to be a snippet of code posted on the support forums: http://wordpress.org/support/topic/display-sequential-post-numbercount-not-post-id <code> function updateNumbers() { /* numbering the published posts, starting with 1 for oldest; / creates and updates custom field 'incr_number'; / to show in post (within the loop) use <?php echo get_post_meta($post->ID,'incr_number',true); ?> / alchymyth 2010 */ global $wpdb; $querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ORDER BY $wpdb->posts.post_date ASC"; $pageposts = $wpdb->get_results($querystr, OBJECT); $counts = 0 ; if ($pageposts): foreach ($pageposts as $post): $counts++; add_post_meta($post->ID, 'incr_number', $counts, true); update_post_meta($post->ID, 'incr_number', $counts); endforeach; endif; } add_action ( 'publish_post', 'updateNumbers', 11 ); add_action ( 'deleted_post', 'updateNumbers' ); add_action ( 'edit_post', 'updateNumbers' ); </code> (I modified it very slightly to sort by post date, rather than just ID as the initial code did.) It will hook into all post actions (save/publish/delete) and update the 'incr_number' custom field for all posts. So you'll have a performance lag on saving posts when you have a large number in the database, but once the posts are saved, showing the number is as simple as <code> echo get_post_meta( $post->ID, 'incr_number', true ); </code>
|
Display post number not post ID number
|
wordpress
|
<code> <?php $my_query = new WP_Query("cat=1&day=''&posts_per_page=-1"); ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> </code> I'm trying to display all posts from a single day on my homepage, restricted by category. The code above is what I'm using, but I've tried a bunch of variations on listing the current day and can't seem to get it to display posts only from the current day. I'm sure I'm missing something completely obvious, but how do I get this working to restrict posts by date? Although getting the homepage figured out is my first challenge, I also want to have my individual day archives set up in a similar way.
|
You'd have to specify day, month, and year to get today's posts: <code> $my_query = new WP_Query( array( 'cat'=>1, 'year'=>date('Y'), 'monthnum'=>date('m'), 'day'=>date('d'), 'posts_per_page'=>-1 ) ); </code> Leaving day blank just doesn't set that query var, so its not restricting your query at all.
|
How do I display posts by day?
|
wordpress
|
Regarding the <code> WP_USE_THEMES </code> constant, the Codex states: If you are using The Loop inside your own design (and your own design is not a template), set WP_USE_THEMES to false. But what is the actual effect on WordPress from <code> WP_USE_THEMES </code> being set to true or false? I would like to know how it's used by WP.
|
This is only used in <code> template-loader.php </code> , to determine whether it should load a theme file or not. The normal "boot sequence" of WordPress (started in <code> wp-blog-header.php </code> ) loads the plugins, parses the URL, executes a post query based on the URL, and calls the theme. This main post query is typically used in "The Loop". So if you want all the advantages of URL parsing but not display it using the site theme, you can set <code> WP_USE_THEMES </code> to <code> false </code> and it will not execute that final step.
|
What is the constant WP_USE_THEMES for?
|
wordpress
|
What's the best way to check current url for endpoint in a template file? I have a plugin that creates endpoints in author.php ... so now i'm trying to check in author.php so that only certain code is executed if the URL ends in a specific endpoint? <code> example.com/author/username/endpointA </code> <code> example.com/author/username/endpointB </code> The idea is that each endpoint has different content. Thank you!
|
Check out this tutorial for query variables: http://www.rlmseo.com/blog/passing-get-query-string-parameters-in-wordpress-url/ . Essentially what you will be adding is a custom query variable with value either A or B to show different content. I.e. /author/username/contentA is actually index.php?author=username&customqueryvar=contentA.
|
How to check current URL for endpoint in a template file?
|
wordpress
|
I have my own function called breadcrumbs(). In it I call is_author() to determine whether I am on an author page. If true I would like to know which author's page I am on. I tried the_author(), but nothing came up. I looked through the WP codex also. Can someone please help?
|
Call <code> echo $GLOBALS['wp_query']->query_vars['author_name']; </code> and it should show you the author. You can also <code> echo $GLOBALS['wp_query']->post->post_author; </code> or <code> echo $GLOBALS['wp_query']->queried_object->post_author; </code> . hope i didn't mix up with arrays and objects.
|
Breadcrumbs - get the author?
|
wordpress
|
i'm trying to separate categories/subcategories in author.php so they each have their own endpoint link. It's very similar to this question BUT for the life of me I can't enable the plugin provided: stackexchange-url ("How to set up sub-categories for author pages?") The solution provided was this: https://gist.github.com/705545 I've downloaded the file, it's instructions say "enable this plugin" ... but when i put it in wp-content/plugins folder it doesn't show up on the list. I've tried putting it in a folder, and just putting the .php file in plugins folder. But it doesn't show up on the list. How can I enable this? or if you have any other ideas on how to achieve these results i'd greatly appreciate it. Thank you!
|
Hi @Pwn: Add the text "Plugin Name: * in front of the text "Author Endpoints Example." You may need to remove the leading asterisk ("*").
|
How to create rewrite endpoints it in author.php?
|
wordpress
|
I'm planing a custom post type functionality for my theme and need to be able to display more than just one <code> post_type </code> in a admin overview table. That request I imagine might look like <code> edit.php?post_type[]=theme_slide_nivo&post_type[]=theme_slide_other </code> . Haven't actually tried that but i'm pretty confident it won't work. So guys, is it possible to achieve such result without hacking core?
|
I tried it out to get an idea of the problems you will run into. The following code allows you to specify multiple post types with the <code> multi_post_type </code> parameter: <code> add_action( 'pre_get_posts', 'wpse12970_pre_get_posts' ); function wpse12970_pre_get_posts( &$wp_query ) { if ( is_admin() && array_key_exists( 'multi_post_type', $_GET ) ) { $wp_query->set( 'post_type', $_GET['multi_post_type'] ); add_filter( 'the_posts', 'wpse12970_the_posts', 10, 2 ); } } function wpse12970_the_posts( $posts, &$wp_query ) { $wp_query->set( 'post_type', $GLOBALS['post_type'] ); return $posts; } </code> The first problem was that the global <code> $post_type </code> should be a single type, otherwise other functions break. So we "smuggle" the multiple post types in under another name, and remove them again after the query ran. The counter at the top of the list and the custom columns are based on only one post type. If there are many results paging will probably break. If you want to do this, you should create your own list class, a child of <code> WP_List_Table </code> , like <code> WP_Posts_List_Table </code> but then for multiple post types. Because <code> edit.php </code> loads this table by default and I see no way to intercept it, you should create your own replacement of <code> edit.php </code> in your plugin and use that. I think it is doable, and probably interesting, but a lot of work.
|
Get multiple custom type posts at once in edit.php?post_type request
|
wordpress
|
hey guys, I really need you help with this one. I'm using the subscribe2 Plugin (for email subscriptions). I want to show the signup form as a widget. The plugin author recommends doing it the following way. <code> $content = apply_filters('the_content', '<!--subscribe2-->'); $content = remove_filter('the_content', 'page_route'); echo $content; </code> this works fine, except for the fact that I'm additionally using the mingle plugin (kind of a social network plugin). Whenever I'm on a page of the mingle plugin (like /login, /register, /activity, etc.) the widget with the subscribe form suddenly displays the exact same content as the pages itself? Just weird! Any idea why that could happen? Or how I could prevent that! I really need a solution for that! edit: all filters mingle applies... <code> add_filter('get_avatar', array($this,'override_avatar'), 10, 4); add_filter('get_comment_author_url', array($this,'override_author_url')); add_filter('mngl-show-powered-by', array(&$this, 'show_powered_by')); add_filter('the_content', array( &$this, 'page_route' ), 100); add_action('wp_enqueue_scripts', array(&$this, 'load_scripts'), 1); add_action('admin_enqueue_scripts', array(&$this,'load_admin_scripts')); register_activation_hook(MNGL_PATH."/mingle.php", array( &$this, 'install' )); // Used to process standalone requests (make sure mingle_init comes before parse_standalone_request) add_action('init', array(&$this,'mingle_init')); add_action('init', array(&$this,'parse_standalone_request')); add_filter('request', array(&$this,'parse_pretty_profile_url')); add_action('phpmailer_init', array(&$this, 'set_wp_mail_return_path')); add_action('phpmailer_init', array(&$this, 'set_wp_mailer')); add_action('admin_init', array(&$this, 'prevent_admin_access')); add_filter('mngl-activity-types', array( &$this, 'add_activity_types' )); add_filter('mngl-notification-types', array( &$this, 'add_notification_types' )); add_filter('mngl-notification-types', array( $this, 'add_notification_types' )); add_filter('mngl-activity-types', array( &$this, 'add_activity_types' )); add_action('user_register', array(&$this, 'add_default_friends') ); add_filter('mngl-activity-types', array( &$this, 'add_activity_types' )); </code>
|
Its extremely difficult to remove a filter that's added as part of an object. You have get the reference to the original object and pass that as part of the function to remove. Luckily the filter was added at an unusual priority, so you will probably be safe removing all filters at priority 100: <code> remove_all_filters( 'the_content', 100 ); $content = apply_filters('the_content', '<!--subscribe2-->'); echo $content; </code> Just make sure that you don't have anything else essential being added at priority 100... If you have to find only this specific filter to remove, then I'm out of my depth. Anyone else? Edit: I had to figure this one out, since I've actually wondered for a while how to remove a filter that was passed by reference. In this case the class MnglAppController which adds the filter is initiated as a variable: <code> $mngl_app_controller = new MnglAppController(); </code> So to remove it, you have to globalize that variable, and pass it as part of the remove_filter call: <code> global $mngl_app_controller; remove_filter( 'the_content', array($mngl_app_controller, 'page_route'), 100 ); $content = apply_filters('the_content', '<!--subscribe2-->'); echo $content; add_filter( 'the_content', array($mngl_app_controller, 'page_route'), 100 ); </code>
|
problem with implementing widget via the_content()
|
wordpress
|
I've just setup a new Blog for a friend and thought it's better to not give him Administrator Access right away as a pre-caution. I created a new user as Editor therefore. But then I saw that this user can not change the Theme Settings like Background and Header. Is there an easy way to allow the Editor Role to edit any theme settings in Twenty Ten or a Child or it? He should basically be able to do anything an Adminsitor can do reg. the Theme, probably even changing themes.
|
you can add capabilities to the editor role using the role object and add_cap from you functions.php <code> <?php // get the the role object $editor = get_role('editor'); // add $cap capability to this role object $editor->add_cap('edit_theme_options'); ?> </code> you can also remove capabilities: <code> $editor->remove_cap('delete_posts'); </code> just take a look at the list of capabilities and what each one means.
|
How can I allow the Editor Role to change Theme Settings?
|
wordpress
|
I'm suffering from the issue of lots of fake registrations for my site. I'd like to add a captcha for registrations. What is the best plugin that will require a captcha at registration? Recommendations based on real installs are most appriciated! Also: I'm using the most up-to-date install of WP.
|
My favorite captcha plugin is reCaptcha. The captcha images are scans from old, damaged books. A computer identifies possibilities with OCR, then the user, in correctly filling out the captcha, confirms it. It helps digitize whole books this way. It's an initiative by Google. Read about them on their website.
|
What is the best Captcha plugin for registration?
|
wordpress
|
I really need some help, I dont know where else to turn with this request. I'd like to add a shortcode to one of my posts. The template tags get_next_post() and get_previous will not work for me since I dont want post navigation on each post page and I want to control where it displays. In a DIV in an HTML structure I've created in a post. So what I need is to generate shortcodes from get_next_post() and get_previous_post()
|
this is very simple to do... <code> // next function next_shortcode($atts) { // global $post; -unnecessary return '<div class="nav-next">'.next_post_link( '%link', '%title <span class="meta-nav">' . _x( '', 'Next post link', ' ' ) . '</span>',true ).'</div>'; } add_shortcode( 'next', 'next_shortcode' ); //prev function prev_shortcode($atts) { //global $post; -unnecessary return '<div class="nav-previous">'.next_post_link( '%link', '%title <span class="meta-nav">' . _x( '', 'Previous post link', ' ' ) . '</span>',true ).'</div>'; } add_shortcode( 'prev', 'prev_shortcode' ); </code> Goodluck! Here for any question....
|
Making a Shortcode [NEXT] and [PREVIOUS] to place into specific posts for post navigation
|
wordpress
|
I am integrating a payment gateway into a distributed wordpress plugin. The notification page (page that the gateway sends info to after the payment has been made) requires only a message of "success" or "fail" to be printed. In that page, I need access to the database and some org options. Can someone please tell me how to produce such a page (i.e. no menu, no header, no footer and etc.)? The gateway in question is alipay.
|
See http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates Just don't include <code> get_header() </code> , <code> get_siderbar() </code> , <code> get_footer() </code> .
|
Produce a plain page with only a message
|
wordpress
|
I have a custom loop (used in a shortcode) that lists items from custom post type. Everything works fine but "order" for posts doesn't work, no matter what I type as order attribute on post page - items are always displayed the same way (the most recent first and the oldest last). Why doesn't "order" work in my case? The loop looks like: <code> $loop = new WP_Query( array( 'post_type' => 'images', 'paged' => get_query_var('paged') ? get_query_var('paged') : 1, 'posts_per_page' => $per_page, ) ); while ( $loop->have_posts() ) : $loop->the_post(); (my code) php endwhile; </code>
|
Add <code> orderby </code> clause to your query! Here is the complete list of order parameters <code> $loop = new WP_Query( array( 'post_type' => 'images', 'orderby' => 'menu_order', 'paged' => get_query_var('paged') ? get_query_var('paged') : 1, 'posts_per_page' => $per_page, ) ); </code> This query order by the menu order that you have specified in your pages
|
"Order" doesn't work in custom loop?
|
wordpress
|
I am creating a plugin that adds two custom post types, one of which will always be a child of the other. The parent post type is for Events, the child for Performances. Before entering the Loop, I'd like to be able to find a set of Events that have Performances on a specific date. Performance date is stored as a meta field on the Performance post. The Loop would then list each Event matched, like in a standard post archive loop. My preference is to query the Event post type, since that strikes me as easier to manage for pagination, but if there's a better implementation that simply involves querying performances, I am open to that, but I'd like to see if there's a facility for limiting a query based on a field in the child post.
|
Child posts are related to their parents (through the "post_parent" field), and not vice versa. So you would have to query your child post type first, then get the parents of all the results. <code> // obviously these variable names and key names might not apply, // change them as necessary $performances = get_posts( array( 'meta_key' => 'the_performance_date_custom_field', 'meta_value' => $date, 'post_type' => 'performance' ) ); // extract the parent post ID's from each of the returned performances $event_ids = array_map( create_function('$post','return $post->post_parent'), $performances ); $event_ids = array_unique( $event_ids ); // dump any duplicate events // and finally, get the events from their ids $events = get_posts( array( 'post_type' => 'event', 'post__in' => $event_ids ) ); </code>
|
Find Posts based on Child Post value
|
wordpress
|
Update From reading the answers, i think i didn't make myself clear, so i try to post it again. I register taxonomies from data from parsed xml files. The arguments passed should be absolutely correct. What i wanted to know is on which of the arguments of the <code> register_taxonomy() </code> function the <code> sanitize_title() </code> function get's called. I currently got an error and need to figure out which of the parameters is wrong.
|
First: Sorry , if i wasted your time. The problem couldn't have been guessed by anyone and was lying in the middle of my class. I simply build an array where i pushed all needed stuff into. This array was rebuilt before i pushed it into the <code> register_taxonomy() </code> function. There i simply forgot to unset those parts i didn't need anymore. @MikeSchinkel @One Trick Pony - please add some answer here, so i can upvote you for your efforts. Thanks to everybody :)
|
remove sanitize_title() for register_taxonomy()
|
wordpress
|
Using WP3.1 I Have a custom page with a WP_Query and the query gets dynamic variables from the url. And i want safe variables and clean urls. Example: carpage/?carmodel=honda&location=finland TO carpage/honda/finland/ I made add_rewrite_rule in to functions.php and it works, but iam not sure it's safe to use this. Functions.php <code> function fcars() { add_rewrite_rule('carpage/[/]?([a-zA-Z-]*)[/]?([a-zA-Z-]*)$', 'index.php?pagename=carpage&var1=$matches[1]&var2=$matches[2]'); add_rewrite_tag('%var1%', '[a-zA-Z]+'); add_rewrite_tag('%var2%', '[a-zA-Z]+'); } add_action('init', 'fcars'); </code> And in Custom template i get the vars Could someone please help me with this. How can i make this safe to use and is this the right way in WP3.1 What is the right way to make add_rewrite_rule in this case: carpage/honda/finland/ (just hyphens and small letters in url) carpage is the static template page.
|
I think the <code> add_rewrite_tag() </code> is not needed, and can be replaced with adding the variables to the public query vars directly: <code> // Either directly (in your init hook): $wp->add_query_var( 'var1' ); $wp->add_query_var( 'var2' ); // Or via a filter: add_filter( 'query_vars', 'wpse12965_query_vars' ); function wpse12965_query_vars( $query_vars ) { $query_vars[] = 'var1'; $query_vars[] = 'var2'; return $query_vars; } </code> Also, you currently allow one or two slashes in front but none at the back. I think you want to move the <code> /? </code> to the end of the regex. The <code> [a-zA-Z-] </code> part for the slug is also sometimes written as <code> [^/] </code> (everything but a slash), but in this case it probably won't make a difference. I would write the rewrite rule like this: <code> add_action( 'init', 'wpse12065_init' ); function wpse12065_init() { add_rewrite_rule( 'carpage(/([^/]+))?(/([^/]+))?/?', 'index.php?pagename=carpage&var1=$matches[2]&var2=$matches[4]', 'top' ); } </code> The <code> (/([^/]+))? </code> makes the whole group optional, so <code> /carpage </code> , <code> /carpage/honda </code> and <code> /carpage/honda/finland </code> should work, with an optional slash at the end. Because we need an extra group for the <code> / </code> , the variables are in the next capture group, so what was <code> $matches[1] </code> becomes <code> $matches[2] </code> and <code> $matches[2] </code> becomes <code> $matches[4] </code> . If you want to debug your rewrite rules I recommend stackexchange-url ("my Rewrite analyzer plugin"), it lets you play with the URL and see the resulting query variables.
|
Custom page with variables in url. Nice url with add_rewrite_rule
|
wordpress
|
ok - so i'm listing categories and their sub-categories. How can i get the ID of the category that's being shown with a function? ( i know what it is in the admin ) ie /category/events/women-in-art/ women-in-art-ID = ? any help appreciated! Dan.
|
How about get_query_var('cat'). I think that should get the ID of the current category.
|
get listed category's id?
|
wordpress
|
I checked in my list of plugins, and I have nothing that seems like Related Posts or Similar Posts. Yet, at the end of my posts I find two very similar sections titled as such. Any idea how to turn one of them off, and how to understand what plugins are responsible for generating them?
|
Similar posts section has following comment in page source <code> <!-- Similar Posts took 18.313 ms --> </code> which quick search identifies as belonging to Similar Posts plugin. Nothing to identify "Related" section by. I'd try to search sources for that heading.
|
What is generating Similar Posts and Related Posts on my blog?
|
wordpress
|
Some plugins use the <code> 'template' </code> , <code> 'option_template' </code> and <code> 'option_stylesheet' </code> to dynamically serve (alternative) wordpress templates. For example, Nathan Rice's <code> ServeDefaultToIESix </code> . For Example - <code> add_filter('template', 'change_theme'); add_filter('option_template', 'change_theme'); add_filter('option_stylesheet', 'change_theme'); function change_theme() { // Alternate theme return 'AwesomeTheme'; } </code> Above code only works from a wordpress plugin. What i need, is to switch to alternative template, located in one of the subfolders of the current theme(template). Examples: display an alternative HTML5 theme, serve mobile users a minimal version of the site.. etc. I tried to use 'theme_root' and 'theme_root_uri' as below. But that isn't working. <code> // Extra lines to change the theme's root. add_filter('theme_root', 'change_theme_root'); add_filter('theme_root', 'change_theme_root_uri'); // add_filter('template', 'change_theme'); add_filter('option_template', 'change_theme'); add_filter('option_stylesheet', 'change_theme'); function change_theme() { // Display Alternate theme return 'AwesomeTheme'; } function change_theme_root() { // Return the new theme root return WP_CONTENT_DIR . 'themes/OrigTheme/lib/AltThemes'; } function change_theme_root_uri() { // Return the new theme root uri return get_bloginfo('wpurl') . '/wp-content/themes/OrigTheme/lib/AltThemes'; } </code> Is this the correct way of doing it? Or does anyone know of the possible way to do so? Thanks in advance.
|
You could also write your own simple get_template_part alias function: The following allows 3 subfolders for template parts that sit in a theme root folder named devices . <code> <?php // STYLESHEETS function print_device_styles( $client = 'desktop' ) { $client = apply_filters( 'set_theme_client', $client ); wp_enqueue_style( $client.'-css' ); } add_action( 'wp_head', 'print_device_styles', 11 ); // TEMPLATE PARTS function get_device_template_part( $args = array( 'file' => NULL, 'suffix' => 'default', 'client' => 'desktop', 'media' => 'screen' ) { if ( ! $args['file'] ) wp_die( sprintf( __('You have to specify a file name if you want to load a template part with the %1$s function.', 'textdomain', '<pre>get_device_template_part()</pre>' ); $template_path = user_trailingslashit( get_stylesheet_directory().'/devices/templates-'.$args['client'] ); $ui_path = user_trailingslashit( get_stylesheet_directory().'/ui/css-'.$args['client'] ); $ui_suffix = '.css'; // could be switched between '.dev.css' & '.css' // add styles & template directory if ( is_condition_mobile() ) { $args['client'] = 'mobile'; $args['screen'] = 'handheld'; } elseif ( is_condition_tablet() ) { $args['client'] = 'tablet'; $args['screen'] = 'handheld'; } // register styles // wp_register_style( 'mobile-css', /theme_root/ui/css-mobile/mobile.css, false 'handheld' ); wp_register_style( $args['client'].'-css', $ui_path.$args['client'].$ui_suffix, false, $args['screen'] ); // Requires PHP 5.3+ (for lower versions, use a plain function). add_filter( 'set_theme_client', function('set_theme_client') { return $args['client'];} ); // {$template}-{$suffix}.php if ( file_exists( $template_path.$args['file'].'-'.$args['suffix'].'.php' ) ) { require( $template_path.$args['file'].'-'.$args['suffix'].'php' ); } // {$template}.php elseif ( file_exists( $template_path.$args['file'].'.php' ) ) { require( $template_path.$args['file'].'.php' ); } // {$template}-default.php elseif ( file_exists( $template_path.$args['file'].'-default.php' ) ) { require( $template_path.$args['file'].'-default.php' ); } } // CALL THEM in a template file // This will require a file named {$template}-{$suffix}.php from your devices folder // based on your conditional functions that detect your devices // If not found, it will search for a file named {$template}.php // and if it wasn't found it will search for a file named {$template}-default.php get_device_template_part( array( 'file' => 'nav', 'suffix' => 'main' ) ); ?> </code> Feel free to add your conditional device detection to: https://gist.github.com/886501
|
Dynamic template serving, change theme_root using add_filter from current theme
|
wordpress
|
This question is related to my stackexchange-url ("earlier question"), but I think it's specific enough to qualify as a standalone question. I am modifying an existing theme (the Twenty Ten theme that ships with WordPress), and I would like to completely control the colors used. The Admin Screen allows the administrator to select a background color, and this seems to be implemented in one of the actions that are automatically registered to the <code> wp_head </code> hook (listed by Bainternet stackexchange-url ("here")). So I would like to do two things: Remove the Color Options menu from the Admin Screen when my theme is activated. Is this possible and if so, how would I go about doing this? (Links to documentation welcome!) Remove the automatically registered action to wp_head that controls the color. Which action in particular would be responsible for this? (rsd_link, etc?) Thanks for your help.
|
In TwentyTen’s functions.php the custom background is added in twentyten_setup() which is called on the action <code> 'after_setup_theme' </code> . So, in your child theme, the following should remove the option completely: <code> // Higher priority to work after TwentyTen add_action( 'after_setup_theme', 'wpse12934_remove_custom_background', 20 ); function wpse12934_remove_custom_background() { remove_custom_background(); } </code>
|
How to Disable Color Options?
|
wordpress
|
I have 2 older WP blog installs with regular posts that I would like to bring over to a new blog. One of the older installs is for "news" posts and the other is for "blog" posts (I know this was not the best way of setting things up). In my new blog, I have created two custom post types ("news" and "blog") and I would like to import these two older installs into my new install's respective post types. Is there an automated way of doing this (perhaps a plugin) that would save me from manually re-entering all of these posts? I'm assuming that simply importing these will not allow me to mark them as a custom post type and instead would make them generic posts. Thank you! Jake
|
Try importing and then using a plugin ( Post Type Switcher ) to change the type. There are a few other plugins out there for this, I seem to remember one which would convert multiple posts, but I couldn't find it just now.
|
Importing old blog with regular posts into new custom post types
|
wordpress
|
How do I completely remove widget support from a theme/plugin ? Like removing the appearance -> widgets page , and prevent WP from loading widget classes and all widget-related stuff.
|
One option would be to simply flush the widget code out of the sidebar.php file, as well as the header/footer/post pages if they are using widgets. However, take a peek at this code snippet (courtesy of this site ), which you can add to your functions.php file and will disable the widgets. I think this would be a cleaner approach if you're looking to change themes and sill have widgets disabled. <code> <?php add_filter( ‘sidebars_widgets’, ‘disable_all_widgets’ ); function disable_all_widgets( $sidebars_widgets ) { if ( is_home() ) $sidebars_widgets = array( false ); return $sidebars_widgets; } ?> </code> Note that this will only disable the widgets on your home page, so you'll need to find the additional conditionals for individual pages/posts/etc.
|
Completely disabling widgets
|
wordpress
|
How would I grab a photo, that has been added to a post, and use it elsewhere on a site when there have been several photos added to the post? For example, my site has a blog (Wordpress) and a non-blog section. I want to pull one image from my latest post for use in this non-blog section. Keep in mind that there might be multiple photos associated with the post. The trick to me seems to be how to designate one specific photo of however many are associated with a post as "the photo" that will be used in the non-blog portion of the site. Ideas? Suggestions?
|
Well one photo can be assigned as the thumbnail as you can see in the post editor screen. Otherwise as the comment above suggested create a post meta field for example 'my_post_image' and place the id of the image attachment in that field. That is how WordPress saves the post thumbnail (look in the database, something like _post_thumbnail is the meta field name).
|
Special purpose photos with each post
|
wordpress
|
I'm using bbPress. I'm in a single page of the custom post type <code> bbp_topic </code> . As you can imagine this custom post type stores another custom post type called <code> bbp_reply </code> . I'm using the following query to list the most voted replies at the top (like Youtube), helped by the GD start rating plugin: <code> <?php $custom_posts = new WP_Query(); ?> <?php $custom_posts->query('gdsr_sort=thumbs&post_type=bbp_reply&posts_per_page=2'); ?> <?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?> <div class="content-block-2"> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a> <?php the_content(); ?> </div> <?php endwhile; ?> </code> The problem is that the query is listing all the replies from all the <code> bbp_topic </code> custom post type. I need to query something like this: list all the custom post types <code> bbp_reply </code> from this single <code> bbp_topic </code> custom post type you are viewing right now. (I know how to get the ID of the current <code> bbp_topic </code> custom post type: <code> $post->ID </code> but I'm not very sure how to use it). Any suggestions?
|
It appears the topic of a reply is stored in the <code> _bbp_topic_id </code> meta field . Older versions stored this in the <code> post_parent </code> field, but it seems this is deprecated? So you can add <code> '&meta_key=_bbf_topic_id&meta_value=' . $post-ID </code> to your query to get only replies to this topic.
|
Query for bbPress replies to current topic?
|
wordpress
|
This correctly sort posts by thumbs vote ( GD star rating plugin): <code> <?php query_posts('gdsr_sort=thumbs&post_type=bbp_reply&posts_per_page=2&post_parent='.$post->ID); ?> <?php while ( have_posts() ) : the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_content(); ?> <?php endwhile; ?> <?php wp_reset_query(); ?> </code> But this doesn't sort them at all: <code> <?php $custom_posts = new WP_Query(); ?> <?php $custom_posts->query('gdsr_sort=thumbs&post_type=bbp_reply&posts_per_page=2&post_parent='.$post->ID); ?> <?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?> <div class="content-block-2"> <?php bbp_reply_author_link( array( 'type' => 'avatar' ) ); ?> <?php bbp_reply_author_link( array( 'type' => 'name' ) ); ?> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a> <?php the_content(); ?> </div> <?php endwhile; ?> </code>
|
It seems GD Star Rating uses <code> get_query_var() </code> to read query variables, which only reads this global <code> $wp_query </code> variable. <code> query_posts() </code> overwrites the global <code> $wp_query </code> variable, so it works there, but creating a new <code> WP_Query </code> (which is a good practice) will not work. You should contact the plugin author and ask for a fix.
|
Why is that gdsr_sort=thumbs (GD start rating plugin) only works with query_posts and not with WP_Query?
|
wordpress
|
Under Media Settings I edited the Image Sizes to the following: Thumbnail size: 170x80 Medium size: 550x170 Large size: 550x320 ("Crop thumbnails to exact dimensions" is checked) Maximum embed size: Width 1000, Height 1000 My problem is when I upload an image it ignores these dimensions. For example, when I upload a 550x320 image, and then try to add it to a post, it has been cropped to the following sizes (uploads folder shows the same): Thumbnail size: 137x80 Medium size: 292x170 Large size: (unavailable) Original size: 550x320 How can I get these image sizes working correctly?
|
The issue is that WordPress always maintains the aspect ratio on your photos. For a lot of uses, this makes sense. However, if you're trying to line up a bunch of images — some in portrait, others in landscape — it can be a real pain. If you want to fix this, you can register a new image size in your <code> functions.php </code> file in your theme. For example, I just added: <code> add_image_size('yourName', 400, 400, true); </code> The function is defined as follows in /wp-includes/media.php: <code> function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { global $_wp_additional_image_sizes; $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => (bool) $crop ); } </code> You can then ask for the image by using: <code> the_post_thumbnail('yourName'); </code> inside of your theme... but this only works for the featured image. Sadly, the image size option isn't added to the selection box when adding media through the backend. Also, if this does what you're looking for, you can auto-resize any old images you have to the new size by using this plugin: http://wordpress.org/extend/plugins/regenerate-thumbnails/
|
Media > Image Sizes aren't being applied to uploads
|
wordpress
|
I can't get WordPress pretty permalinks to work on my Fedora LAMP server. If I set them and click a page/post link I'll get a ""Oops! This link appears to be broken." The .htaccess file is writable and being updated, mod_rewrite module seems to be loaded in my httpd.conf (See below) The errors in my apache log say simply "Document not found". I'm at the end of my rope! Here's the httpd.conf : <code> ### Section 1: Global Environment # start the rewrite engine (I ADDED THIS) RewriteEngine on ServerTokens OS ServerRoot "/etc/httpd" PidFile run/httpd.pid Timeout 120 KeepAlive Off MaxKeepAliveRequests 100 KeepAliveTimeout 15 <IfModule prefork.c> StartServers 8 MinSpareServers 5 MaxSpareServers 20 ServerLimit 256 MaxClients 256 MaxRequestsPerChild 4000 </IfModule> <IfModule worker.c> StartServers 2 MaxClients 150 MinSpareThreads 25 MaxSpareThreads 75 ThreadsPerChild 25 MaxRequestsPerChild 0 </IfModule> # # Listen: Allows you to bind Apache to specific IP addresses and/or # ports, in addition to the default. See also the <VirtualHost> # directive. # # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses (0.0.0.0) # #Listen 12.34.56.78:80 Listen 80 LoadModule auth_basic_module modules/mod_auth_basic.so LoadModule auth_digest_module modules/mod_auth_digest.so LoadModule authn_file_module modules/mod_authn_file.so LoadModule authn_alias_module modules/mod_authn_alias.so LoadModule authn_anon_module modules/mod_authn_anon.so LoadModule authn_dbm_module modules/mod_authn_dbm.so LoadModule authn_default_module modules/mod_authn_default.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule authz_user_module modules/mod_authz_user.so LoadModule authz_owner_module modules/mod_authz_owner.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.so LoadModule authz_dbm_module modules/mod_authz_dbm.so LoadModule authz_default_module modules/mod_authz_default.so LoadModule ldap_module modules/mod_ldap.so LoadModule authnz_ldap_module modules/mod_authnz_ldap.so LoadModule include_module modules/mod_include.so LoadModule log_config_module modules/mod_log_config.so LoadModule logio_module modules/mod_logio.so LoadModule env_module modules/mod_env.so LoadModule ext_filter_module modules/mod_ext_filter.so LoadModule mime_magic_module modules/mod_mime_magic.so LoadModule expires_module modules/mod_expires.so LoadModule deflate_module modules/mod_deflate.so LoadModule headers_module modules/mod_headers.so LoadModule usertrack_module modules/mod_usertrack.so LoadModule setenvif_module modules/mod_setenvif.so LoadModule mime_module modules/mod_mime.so LoadModule dav_module modules/mod_dav.so LoadModule status_module modules/mod_status.so LoadModule autoindex_module modules/mod_autoindex.so LoadModule info_module modules/mod_info.so LoadModule dav_fs_module modules/mod_dav_fs.so LoadModule vhost_alias_module modules/mod_vhost_alias.so LoadModule negotiation_module modules/mod_negotiation.so LoadModule dir_module modules/mod_dir.so LoadModule actions_module modules/mod_actions.so LoadModule speling_module modules/mod_speling.so LoadModule userdir_module modules/mod_userdir.so LoadModule alias_module modules/mod_alias.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_balancer_module modules/mod_proxy_balancer.so LoadModule proxy_ftp_module modules/mod_proxy_ftp.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_connect_module modules/mod_proxy_connect.so LoadModule cache_module modules/mod_cache.so LoadModule suexec_module modules/mod_suexec.so LoadModule disk_cache_module modules/mod_disk_cache.so LoadModule cgi_module modules/mod_cgi.so # # The following modules are not loaded by default: # #LoadModule cern_meta_module modules/mod_cern_meta.so #LoadModule asis_module modules/mod_asis.so Include conf.d/*.conf User apache Group apache ### Section 2: 'Main' server configuration ServerAdmin root@localhost UseCanonicalName Off DocumentRoot "/var/www/html" <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> <IfModule mod_userdir.c> UserDir disabled </IfModule> DirectoryIndex index.html index.html.var # # AccessFileName: The name of the file to look for in each directory # for additional configuration directives. See also the AllowOverride # directive. # AccessFileName .htaccess <Files ~ "^\.ht"> Order allow,deny Deny from all </Files> TypesConfig /etc/mime.types DefaultType text/plain <IfModule mod_mime_magic.c> # MIMEMagicFile /usr/share/magic.mime MIMEMagicFile conf/magic </IfModule> HostnameLookups Off ErrorLog logs/error_log CustomLog logs/access_log combined ServerSignature On Alias /icons/ "/var/www/icons/" <Directory "/var/www/icons"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> <IfModule mod_dav_fs.c> # Location of the WebDAV lock database. DAVLockDB /var/lib/dav/lockdb </IfModule> ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" <Directory "/var/www/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory> IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8 ReadmeName README.html HeaderName HEADER.html IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t AddDefaultCharset UTF-8 AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-x509-ca-cert .crt AddType application/x-pkcs7-crl .crl AddHandler type-map var AddType text/html .shtml AddOutputFilter INCLUDES .shtml Alias /error/ "/var/www/error/" <IfModule mod_negotiation.c> <IfModule mod_include.c> <Directory "/var/www/error"> AllowOverride None Options IncludesNoExec AddOutputFilter Includes html AddHandler type-map var Order allow,deny Allow from all LanguagePriority en es de fr ForceLanguagePriority Prefer Fallback </Directory> </IfModule> </IfModule> # # Proxy Server directives. Uncomment the following lines to # enable the proxy server: # #<IfModule mod_proxy.c> #ProxyRequests On # #<Proxy *> # Order deny,allow # Deny from all # Allow from .example.com #</Proxy> # # Enable/disable the handling of HTTP/1.1 "Via:" headers. # ("Full" adds the server version; "Block" removes all outgoing Via: headers) # Set to one of: Off | On | Full | Block # #ProxyVia On NameVirtualHost *:80 <VirtualHost *:80> # start the rewrite engine RewriteEngine on ServerName www.example.com DocumentRoot /var/www/html/com_example_www </VirtualHost> </code>
|
Inside of your config you have the following: <code> <Directory /> Options FollowSymLinks AllowOverride None </Directory> </code> You should change it to the following: <code> <Directory /> Options FollowSymLinks AllowOverride All </Directory> </code> The <code> AllowOverride </code> directive is what allows the <code> .htaccess </code> file to be read. If you still have trouble, make sure you change this in the <code> <Directory "/var/www/html"> </code> block as well (depending on where your site is located). Hope this helps!
|
Can't get permalinks working!
|
wordpress
|
I'm trying to customize a theme, and I see that the header.php calls "wp_head()". I can't seem to find an implementation of this in the theme, so I presume there is a default implementation that implements, for example, the Color Options settings as specified on the admin page. So my related questions are: Is there somewhere I can see this default implementation? Can this default implementation be "turned off"? Can the "Color Options" option be disabled in the admin screen for the theme? Please feel free to point me to relevant documentation if that would be easier. I've looked at the reference pages for the wp_head() function and the corresponding wp_head action hook, but they don't seem to provide enough information for me to tackle the questions above. Thanks.
|
Is there somewhere I can see this default implementation? <code> wp_head() </code> function simply triggers the <code> wp_head </code> action hook that runs all callback functions that were added to this hook using <code> add_action('wp_head','callback_function'); </code> So there is no default implementation . Can this default implementation be "turned off"? Like we said before since there is no default implementation you need to find the add_action's that hook to wp_head and remove them using remove_action for example if this is the add_action: <code> add_action('wp_head','callback_function'); </code> then to remove it just add <code> remove_action('wp_head','callback_function'); </code> Can the "Color Options" option be disabled in the admin screen for the theme? I'm assuming that your theme as some kind of options panel that let you chose the color options, so to disable it it depends on the theme it self but it should be in one of the theme files, knowing what theme you are talking about would help. Update there are some action by defult running when wp_head is fired and to remove them just use: <code> remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'feed_links', 2); remove_action('wp_head', 'index_rel_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'start_post_rel_link', 10, 0); remove_action('wp_head', 'parent_post_rel_link', 10, 0); remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); </code> other then that look for <code> add_action('wp_head' ... </code> in theme files and plugins.
|
Where is default wp_head() implemented?
|
wordpress
|
I'm building a website that uses the GD star rating plugin . Right now, I'm using the following code to retrieve two posts of the current page (a custom post type called <code> bbp_topic </code> ) and sort them by vote: <code> <?php query_posts('gdsr_sort=thumbs&posts_per_page=2&post_parent='.$post->ID); ?> </code> I would like now to only retrieve those post that have 1 or more thumbs up. Any suggestions?
|
<code> gdsr_ftvmin=1 </code> is probably the query parameter you need
|
Is there any way of only retrieving posts with one or more thumbs up (GD star rating plugin)?
|
wordpress
|
As the title says, i would like a nice bit of coding to stick in my functions that pre-loads any images that are attached to the next post. This means that whilst my users are browsing, they page will load, but it will actually be loading the next page, so when you click-through, the images should already be there and waiting! Think of it as 'buffering' for image. Couple of things to note: I use the post_thumbnail feature and have different sizes setup through functions.php. I also have a plugin that enables multiple Featured Images per post. I posed this question on stackoverflow (who pointed me here) and was given this code to be placed in the loop; <code> <?php $next_post = get_adjacent_post(false, '', false );// set last param to true if you want post that is chronologically previous $args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_parent' => $next_post->ID); $attachments = get_posts($args); ?> <script type="text/javascript"> $(document).ready(function(){ var images = ''; <?php foreach($attachments as $attachment): $mime = $attachemnt->post_mime_type; if($mime == 'image/jpeg' || $mime == 'image/gif' || $mime == 'image/png'): ?> images += '<img src="<?php $attachment->guid ?>" style="display:none" />'; <? endif; endforeach; ?> if(images != ''){ $(body).append(images); } }); </script> </code> Although to looks like it could be onto a winner, it doesn't seem to be doing the job quite yet. In my page source it returns the following: <code> <script type="text/javascript"> jQuery(document).ready(function(){ var images = ''; if(images != ''){ jQuery(body).append(images); } }); </script> </code> It is possible i am doing something wrong as i am a chronic copy and paster! Anyone got any thoughts on this? Thanks guys!
|
This is what cam of the other piece of code - BIG thank you to @Ivan Ivanic <code> <?php $next_post = get_adjacent_post(false, '', false );// set last param to true if you want post that is chronologically previous //for debug if(!empty($next_post)){ echo 'Next post title is: '.$next_post->post_title; } else { echo 'global $post is not set or no corresponding post exists'; } $args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_parent' => $next_post->ID); $attachments = get_posts($args); // print attachments for debug echo '<pre>';print_r($attachments);echo '</pre>'; ?> <script type="text/javascript"> $(document).ready(function(){ var images = ''; <?php foreach($attachments as $attachment): $mime = $attachment->post_mime_type; if($mime == 'image/jpeg' || $mime == 'image/gif' || $mime == 'image/png'): ?> images += '<img src="<?php echo $attachment->guid ?>" style="display:none" />'; <? endif; endforeach; ?> if(images != ''){ $('body').append(images); } }); </script> </code>
|
Wordpress: Preload next post images
|
wordpress
|
Is there any way of changing the post order, posts number, etc via user click? The same way you can choose displaying questions by time and vote here at StackExchange. How to accomplish that?
|
Check the WP Sort Plugin, it does exactly what you need: http://wordpress.org/extend/plugins/wp-post-sorting/
|
Is there any way of changing the post order via user click?
|
wordpress
|
I have been at this for days now, going through plenty of answers here, guides on using .htaccess, guides on using add_rewrite_rule() within Wordpress and examples throughout the web. I am not sure if there is a malfunction in my regex to detect the correct URL, or a disconnect between what I want to accomplish and what can be accomplished. Basically, I am trying to separate comments from posts (or better yet, comments from content) by forcing them to a separate page "associated" with the content. So for example, <code> http://localhost/wp/2011/02/25/hello-world-2/ </code> is a post, and the comments for that post should appear at <code> http://localhost/wp/2011/02/25/hello-world-2/comments/ </code> . Now, a "little bird" once said that this could be done with the following: <code> RewriteRule ^archives/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/comments/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&comments=1 [QSA,L] </code> (seeing as I do not really need to work inside the /archives/ for my above example to work, I removed it), which I translated into this plugin: <code> <?php /* Plugin Name: Gingah Permalink Rewrite Plugin URI: http://gingahmail.com/wordpress/ Description: Useful Permalink-structures, that required a plugin to work. Version: 1.0 Author: Gingah Author URI: http://gingahmail.com/ */ register_activation_hook( __FILE__, 'gingah_rewrite_activate' ); function gingah_rewrite_activate() { gingah_rewrite(); flush_rewrite_rules(); } register_deactivation_hook( __FILE__, 'gingah_rewrite_deactivate' ); function gingah_rewrite_deactivate() { flush_rewrite_rules(); } add_action('admin_init', 'gingah_rewrite'); function gingah_rewrite() { add_rewrite_rule( '^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/comments/?$', '/index.php?year=$1&monthnum=$2&day=$3&name=$4&comments=1 [QSA,L]', 'top' ); } ?> </code> (based on countless examples just like it, around the web) This does, however, not work. Even though, visiting <code> http://localhost/wp/2011/02/25/hello-world-2/?comments=1 </code> does produce the expected result. So what is going wrong here?
|
WordPress rewrite rules by default are no longer stored in the Apache configuration, but are handled by WordPress itself. This was probably not the case when that forum topic was written (5 years ago), but currently only "external" rules end up in the Apache configuration, all others are stored in the database and handled by the <code> WP::parse_request() </code> function . This means you should leave off the Apache-specific parts in your <code> add_rewrite_rule() </code> call. The following code looks better: <code> add_rewrite_rule( // The beginning `^` is added by WordPress '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/comments/?$', // `$1` should be replaced with `$matches[1]` 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&comments=1', 'top' ); </code> When I tested this with stackexchange-url ("my Rewrite analyzer plugin"), I noticed that <code> comments </code> is not a standard query variable, so remember that you will have to handle that too.
|
Separate page for comments using permalinks and add_rewrite_rule
|
wordpress
|
Hi to all it's a few days that I'm trying to add some new functions to my theme option-panel, you can see my questions here: stackexchange-url ("How to add an export function to a custom Option Theme Page") stackexchange-url ("Add a preview to a Wordpress Control Panel") stackexchange-url ("Modify CSS via Theme Control Panel") What's wrong with it? I'm trying to add a live preview of some modification BEFORE saving them but...I'm not able to add it...I'm almost a completely newbie in JS, I know a little PHP, enough CSS and HTML so here are the reasons of my questions... Anyway my new idea is to add the possibility to DRAG & DROP some DIVs, place them on a map, save their position and show them inside my website. I try to explain it better. Actually in my option-panel I have 10 functions: zona1, zona2, zona3 ..... with 4 values: zona1c = checkbox to choose if you want to show it or not zona1x = X Axys position (it changes LEFT CSS ATTRIBUTE) zona1y = X Axys position (it changes BOTTOM CSS ATTRIBUTE) zona1l = user have to write the URL of the post linked to this point Everything is working so if I write a value inside zona1x and zona1c is set to TRUE it shows the div in my website. But I would like to improve this because sometimes I make mistakes so I don't want to go "live" before everything is good. What I would like you to teach me is how to add a preview of that page then if zona1c is set to true I want to be able to move this DIV inside the preview (that is visible in my admin-panel) choose the right position, drop it and SAVE. Is there any easy or STEP BY STEP (Please, I would like to learn something new) solution for my problem? Thank you very much to all! Let's start with the code: This is my Functions.php : http://pastebin.com/8cVmne1s This is my admin-panel.php: http://pastebin.com/xX8G4Zxr or: <code> <?php /** Declare the themename and shortname -- Ecco il nome del template e la sua abbreviazione **/ $themename = "Appartamenti Acquario"; $shortname = "appaqua"; /** Set the array with all the theme options -- Impostiamo l'array con tutte le opzioni del tema **/ $options = array ( array( "desc" => "<h3>IMPOSTAZIONI GENERALI</h3>", "type" => "title"), array( "name" => "Prima di cominciare", "type" => "section"), array( "type" => "open"), array( "name" => "Link pagina mappa", "desc" => "Inserisci il link alla pagina della mappa", "id" => $shortname."_pama", "type" => "text", "std" => " "), array( "type" => "close"), array( "name" => "General", "type" => "section"), array( "type" => "open"), array( "name" => "Logo URL", "desc" => "Inserisci il link all'immagine del tuo logo", "id" => $shortname."_logo", "type" => "text", "std" => " "), array( "type" => "close"), array( "name" => "Homepage", "type" => "section"), array( "type" => "open"), array( "name" => "Homepage Immagine Slide 1", "desc" => "Inserisci il link alla prima immagine degli slide", "id" => $shortname."_header_img", "type" => "text", "std" => "http://nextube.info/images/ImmijQuery/image-1.jpg"), array( "name" => "Homepage Immagine Slide 2", "desc" => "Inserisci il link alla seconda immagine degli slide", "id" => $shortname."_header_img2", "type" => "text", "std" => "http://nextube.info/images/ImmijQuery/image-2.jpg"), array( "name" => "Homepage Immagine Slide 3", "desc" => "Inserisci il link alla terza immagine degli slide", "id" => $shortname."_header_img3", "type" => "text", "std" => "http://nextube.info/images/ImmijQuery/image-3.jpg"), array( "name" => "Homepage Immagine Slide 4", "desc" => "Inserisci il link alla quarta immagine degli slide", "id" => $shortname."_header_img4", "type" => "text", "std" => "http://nextube.info/images/ImmijQuery/image-4.jpg"), array( "name" => "Homepage Immagine Slide 5", "desc" => "Inserisci il link alla quinta immagine degli slide", "id" => $shortname."_header_img5", "type" => "text", "std" => "http://nextube.info/images/ImmijQuery/image-5.jpg"), array( "name" => "Homepage Immagine Slide 6", "desc" => "Inserisci il link alla sesta immagine degli slide", "id" => $shortname."_header_img6", "type" => "text", "std" => "http://nextube.info/images/ImmijQuery/image-6.jpg"), array( "type" => "close"), array( "name" => "Footer", "type" => "section"), array( "type" => "open"), array( "name" => "Google Analytics Code", "desc" => "Inserisci il tuo codice Google Analytics per tracciare le visite che ricevi.", "id" => $shortname."_ga_code", "type" => "textarea", "std" => ""), array( "type" => "close"), array( "name" => "Social", "type" => "section"), array( "type" => "open"), array( "name" => "Indirizzo Feed", "desc" => "Feedburner è un sistema fornito da Google per ottimizzare la distribuzione dei tuoi feed, inserisci qui il link al tuo feed", "id" => $shortname."_feedburner", "type" => "text", "std" => get_bloginfo('rss2_url')), array( "name" => "Facebook URL", "desc" => "Inserisci il link alla tua pagina Facebook", "id" => $shortname."_facebook", "type" => "text", "std" => "http://facebook.com/pages/Downloadtaky/325661998362"), array( "name" => "Twitter URL", "desc" => "Inserisci il link al tuo account Twitter", "id" => $shortname."_twitter", "type" => "text", "std" => "http://twitter.com/downloadtaky"), array( "type" => "close"), array( "name" => "Punti sulla mappa", "type" => "section"), array( "type" => "open"), /** Copia da qui per aggiungere un nuovo punto - start copy to add a new point on the map **/ array( "name" => "Zona 1", "type" => "section"), array( "type" => "open"), array( "name" => "Attivare zona 1?", "desc" => "Seleziona se vuoi il primo fermaposto", "id" => $shortname."_zona1c", "type" => "checkbox", "std" => "false"), array( "name" => "Zona 1 Nome", "desc" => "Inserisci il nome del primo appartamento", "id" => $shortname."_zona1n", "type" => "text", "std" => "Nome dell'appartamento"), array( "name" => "Zona 1 Asse x", "desc" => "Scegli dove posizionare il primo punto, se attivato asse x", "id" => $shortname."_zona1x", "type" => "text", "std" => "Left:???"), array( "name" => "Zona 1 Asse y", "desc" => "Scegli dove posizionare il primo punto, se attivato asse y", "id" => $shortname."_zona1y", "type" => "text", "std" => "Top:???"), array( "name" => "Zona 1 URL", "desc" => "Inserisci il link al post della zona 1", "id" => $shortname."_zona1l", "type" => "text", "std" => "Indirizzo del post qui"), array( "type" => "close"), /** Copia fino a qui e rinomina progressivamente in zona2, zona3, zona4 ecc -- Copy from here to add a new zone like zone3, zone 4 and so on**/ array( "name" => "Zona 2", "type" => "section"), array( "type" => "open"), array( "name" => "Attivare zona 2?", "desc" => "Seleziona se vuoi il secondo fermaposto", "id" => $shortname."_zona2c", "type" => "checkbox", "std" => "false"), array( "name" => "Zona 2 Nome", "desc" => "Inserisci il nome del secondo appartamento", "id" => $shortname."_zona2n", "type" => "text", "std" => "Nome dell'appartamento"), array( "name" => "Zona 2 Asse x", "desc" => "Scegli dove posizionare il secondo punto, se attivato asse x", "id" => $shortname."_zona2x", "type" => "text", "std" => "Left:???"), array( "name" => "Zona 2 Asse y", "desc" => "Scegli dove posizionare il secondo punto, se attivato asse y", "id" => $shortname."_zona2y", "type" => "text", "std" => "Top:???"), array( "name" => "Zona 2 URL", "desc" => "Inserisci il link al post della zona 2", "id" => $shortname."_zona2l", "type" => "text", "std" => "Indirizzo del post qui"), array( "type" => "close"), array( "name" => "Zona 3", "type" => "section"), array( "type" => "open"), array( "name" => "Attivare zona 3?", "desc" => "Seleziona se vuoi il terzo fermaposto", "id" => $shortname."_zona3c", "type" => "checkbox", "std" => "false"), array( "name" => "Zona 3 Nome", "desc" => "Inserisci il nome del terzo appartamento", "id" => $shortname."_zona3n", "type" => "text", "std" => "Nome dell'appartamento"), array( "name" => "Zona 3 Asse x", "desc" => "Scegli dove posizionare il terzo punto, se attivato asse x", "id" => $shortname."_zona3x", "type" => "text", "std" => "Left:???"), array( "name" => "Zona 3 Asse y", "desc" => "Scegli dove posizionare il terzo punto, se attivato asse y", "id" => $shortname."_zona3y", "type" => "text", "std" => "Top:???"), array( "name" => "Zona 3 URL", "desc" => "Inserisci il link al post della zona 3", "id" => $shortname."_zona3l", "type" => "text", "std" => "Indirizzo del post qui"), array( "type" => "close"), array( "name" => "Zona 4", "type" => "section"), array( "type" => "open"), array( "name" => "Attivare zona 4?", "desc" => "Seleziona se vuoi il quarto fermaposto", "id" => $shortname."_zona4c", "type" => "checkbox", "std" => "false"), array( "name" => "Zona 4 Nome", "desc" => "Inserisci il nome del quarto appartamento", "id" => $shortname."_zona4n", "type" => "text", "std" => "Nome dell'appartamento"), array( "name" => "Zona 4 Asse x", "desc" => "Scegli dove posizionare il quarto punto, se attivato asse x", "id" => $shortname."_zona4x", "type" => "text", "std" => "Left:???"), array( "name" => "Zona 4 Asse y", "desc" => "Scegli dove posizionare il quarto punto, se attivato asse y", "id" => $shortname."_zona4y", "type" => "text", "std" => "Top:???"), array( "name" => "Zona 4 URL", "desc" => "Inserisci il link al post della zona 4", "id" => $shortname."_zona4l", "type" => "text", "std" => "Indirizzo del post qui"), array( "type" => "close"), array( "name" => "Zona 5", "type" => "section"), array( "type" => "open"), array( "name" => "Attivare zona 5?", "desc" => "Seleziona se vuoi il quinto fermaposto", "id" => $shortname."_zona5c", "type" => "checkbox", "std" => "false"), array( "name" => "Zona 5 Nome", "desc" => "Inserisci il nome del quinto appartamento", "id" => $shortname."_zona5n", "type" => "text", "std" => "Nome dell'appartamento"), array( "name" => "Zona 5 Asse x", "desc" => "Scegli dove posizionare il quinto punto, se attivato asse x", "id" => $shortname."_zona5x", "type" => "text", "std" => "Left:???"), array( "name" => "Zona 5 Asse y", "desc" => "Scegli dove posizionare il quinto punto, se attivato asse y", "id" => $shortname."_zona5y", "type" => "text", "std" => "Top:???"), array( "name" => "Zona 5 URL", "desc" => "Inserisci il link al post della zona 5", "id" => $shortname."_zona5l", "type" => "text", "std" => "Indirizzo del post qui"), array( "type" => "close"), array( "name" => "Zona 6", "type" => "section"), array( "type" => "open"), array( "name" => "Attivare zona 6?", "desc" => "Seleziona se vuoi il sesto fermaposto", "id" => $shortname."_zona6c", "type" => "checkbox", "std" => "false"), array( "name" => "Zona 6 Nome", "desc" => "Inserisci il nome del sesto appartamento", "id" => $shortname."_zona6n", "type" => "text", "std" => "Nome dell'appartamento"), array( "name" => "Zona 6 Asse x", "desc" => "Scegli dove posizionare il sesto punto, se attivato asse x", "id" => $shortname."_zona6x", "type" => "text", "std" => "Left:???"), array( "name" => "Zona 6 Asse y", "desc" => "Scegli dove posizionare il sesto punto, se attivato asse y", "id" => $shortname."_zona6y", "type" => "text", "std" => "Top:???"), array( "name" => "Zona 6 URL", "desc" => "Inserisci il link al post della zona 6", "id" => $shortname."_zona6l", "type" => "text", "std" => "Indirizzo del post qui"), array( "type" => "close"), array( "name" => "Zona 7", "type" => "section"), array( "type" => "open"), array( "name" => "Attivare zona 7?", "desc" => "Seleziona se vuoi il settimo fermaposto", "id" => $shortname."_zona7c", "type" => "checkbox", "std" => "false"), array( "name" => "Zona 7 Nome", "desc" => "Inserisci il nome del settimo appartamento", "id" => $shortname."_zona7n", "type" => "text", "std" => "Nome dell'appartamento"), array( "name" => "Zona 7 Asse x", "desc" => "Scegli dove posizionare il settimo punto, se attivato asse x", "id" => $shortname."_zona7x", "type" => "text", "std" => "Left:???"), array( "name" => "Zona 7 Asse y", "desc" => "Scegli dove posizionare il settimo punto, se attivato asse y", "id" => $shortname."_zona7y", "type" => "text", "std" => "Top:???"), array( "name" => "Zona 7 URL", "desc" => "Inserisci il link al post della zona 7", "id" => $shortname."_zona7l", "type" => "text", "std" => "Indirizzo del post qui"), array( "type" => "close"), array( "name" => "Zona 8", "type" => "section"), array( "type" => "open"), array( "name" => "Attivare zona 8?", "desc" => "Seleziona se vuoi l/'ottavo fermaposto", "id" => $shortname."_zona8c", "type" => "checkbox", "std" => "false"), array( "name" => "Zona 8 Nome", "desc" => "Inserisci il nome dell/'ottavo appartamento", "id" => $shortname."_zona8n", "type" => "text", "std" => "Nome dell'appartamento"), array( "name" => "Zona 8 Asse x", "desc" => "Scegli dove posizionare l/'ottavo punto, se attivato asse x", "id" => $shortname."_zona8x", "type" => "text", "std" => "Left:???"), array( "name" => "Zona 8 Asse y", "desc" => "Scegli dove posizionare l/' ottavo punto, se attivato asse y", "id" => $shortname."_zona8y", "type" => "text", "std" => "Top:???"), array( "name" => "Zona 8 URL", "desc" => "Inserisci il link al post della zona 8", "id" => $shortname."_zona8l", "type" => "text", "std" => "Indirizzo del post qui"), array( "type" => "close"), array( "name" => "Zona 9", "type" => "section"), array( "type" => "open"), array( "name" => "Attivare zona 9?", "desc" => "Seleziona se vuoi il nono fermaposto", "id" => $shortname."_zona9c", "type" => "checkbox", "std" => "false"), array( "name" => "Zona 9 Nome", "desc" => "Inserisci il nome del nono appartamento", "id" => $shortname."_zona9n", "type" => "text", "std" => "Nome dell'appartamento"), array( "name" => "Zona 9 Asse x", "desc" => "Scegli dove posizionare il nono punto, se attivato asse x", "id" => $shortname."_zona9x", "type" => "text", "std" => "Left:???"), array( "name" => "Zona 9 Asse y", "desc" => "Scegli dove posizionare il nono punto, se attivato asse y", "id" => $shortname."_zona9y", "type" => "text", "std" => "Top:???"), array( "name" => "Zona 9 URL", "desc" => "Inserisci il link al post della zona 9", "id" => $shortname."_zona9l", "type" => "text", "std" => "Indirizzo del post qui"), array( "type" => "close"), array( "name" => "Zona 10", "type" => "section"), array( "type" => "open"), array( "name" => "Attivare zona 10?", "desc" => "Seleziona se vuoi il decimo fermaposto", "id" => $shortname."_zona10c", "type" => "checkbox", "std" => "false"), array( "name" => "Zona 10 Nome", "desc" => "Inserisci il nome del decimo appartamento", "id" => $shortname."_zona10n", "type" => "text", "std" => "Nome dell'appartamento"), array( "name" => "Zona 10 Asse x", "desc" => "Scegli dove posizionare il decimo punto, se attivato asse x", "id" => $shortname."_zona10x", "type" => "text", "std" => "Left:???"), array( "name" => "Zona 10 Asse y", "desc" => "Scegli dove posizionare il decimo punto, se attivato asse y", "id" => $shortname."_zona10y", "type" => "text", "std" => "Top:???"), array( "name" => "Zona 10 URL", "desc" => "Inserisci il link al post della zona 10", "id" => $shortname."_zona10l", "type" => "text", "std" => "Indirizzo del post qui"), array( "type" => "close"), array( "type" => "close"), ); function appaqua_add_admin() { global $themename, $shortname, $options; if ( $_GET['page'] == basename(__FILE__) ) { if ( 'save' == $_REQUEST['action'] ) { foreach ($options as $value) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } foreach ($options as $value) { if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } } header("Location: admin.php?page=admin-panel.php&saved=true"); die; } else if( 'reset' == $_REQUEST['action'] ) { foreach ($options as $value) { delete_option( $value['id'] ); } header("Location: admin.php?page=admin-panel.php&reset=true"); die; } } add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'appaqua_admin'); } function appaqua_add_init() { $file_dir=get_bloginfo('template_directory'); wp_enqueue_style("functions", $file_dir."/includes/css/functions.css", false, "1.0", "all"); wp_enqueue_script("rm_script", $file_dir."/includes/js/rm_script.js", false, "1.0"); wp_enqueue_script("site_preview", $file_dir."/includes/js/preview.js", false, "1.0"); }; function appaqua_admin() { global $themename, $shortname, $options; $i=0; if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>'; if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>'; ?> <div class="wrap rm_wrap"> <h2><?php echo $themename; ?> Settings</h2> <div class="rm_opts"> <form method="post"> <?php foreach ($options as $value) { switch ( $value['type'] ) { case "open": ?> <?php break; case "close": ?> </div> </div> <br /> <?php break; case "title": ?> <p>To easily use the <?php echo $themename;?> theme, you can use the menu below.</p> <?php break; case 'text': ?> <div class="rm_input rm_text"> <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label> <input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id']) ); } else { echo $value['std']; } ?>" /> <small><?php echo $value['desc']; ?></small><div class="clearfix"></div> </div> <?php break; case 'textarea': ?> <div class="rm_input rm_textarea"> <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label> <textarea name="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id']) ); } else { echo $value['std']; } ?></textarea> <small><?php echo $value['desc']; ?></small><div class="clearfix"></div> </div> <?php break; case 'select': ?> <div class="rm_input rm_select"> <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label> <select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"> <?php foreach ($value['options'] as $option) { ?> <option <?php if (get_settings( $value['id'] ) == $option) { echo 'selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?> </select> <small><?php echo $value['desc']; ?></small><div class="clearfix"></div> </div> <?php break; case "checkbox": ?> <div class="rm_input rm_checkbox"> <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label> <?php if(get_option($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?> <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> /> <small><?php echo $value['desc']; ?></small><div class="clearfix"></div> </div> <?php break; case "section": $i++; ?> <div class="rm_section"> <div class="rm_title"><h3><img src="<?php bloginfo('template_directory')?>/includes/css/images/trans.png" class="inactive" alt="""><?php echo $value['name']; ?></h3><span class="submit"><input name="save<?php echo $i; ?>" type="submit" value="Save changes" /> </span><div class="clearfix"></div></div> <div class="rm_options"> <?php break; } } ?> <input type="hidden" name="action" value="save" /> </form> <form method="post"> <p class="submit"> <input name="reset" type="submit" value="Reset" /> <input type="hidden" name="action" value="reset" /> </p> </form> <div style="font-size:9px; margin-bottom:10px;">Icons: <a href="http://www.woothemes.com/2009/09/woofunction/">WooFunction</a></div> </div> <iframe id="themepreview" name="themepreview" src="<?php echo get_option('appaqua_pama'); ?>/?preview=1"></iframe> <?php } ?> <?php $nonce = wp_create_nonce('site_preview'); ?> <?php add_action('admin_init', 'appaqua_add_init'); add_action('admin_menu', 'appaqua_add_admin'); ?> </code> This is the css stylesheet of the divs I would like to move with DRAG & DROP (only in backend ): http://pastebin.com/pih7yaT1 or: <code> <?php define('WP_USE_THEMES', true); require('./wp-blog-header.php');?> .mappa{width:960px;height:394px;background:url(<?php bloginfo(template_url);?>/mappa/images/mappa.png);margin:0 auto;} #zona1{width:27px;height:27px;background:#000;z-index:10000;position:relative;top:<?php echo get_option('appaqua_zona1x');?>px;left:<?php echo get_option('appaqua_zona1y');?>px;} #zona2{width:27px;height:27px;background:#000;z-index:10000;position:relative;top:<?php echo get_option('appaqua_zona2x');?>px;left:<?php echo get_option('appaqua_zona2y');?>px;} #zona3{width:27px;height:27px;background:#000;z-index:10000;position:relative;top:<?php echo get_option('appaqua_zona3x');?>px;left:<?php echo get_option('appaqua_zona3y');?>px;} #zona4{width:27px;height:27px;background:#000;z-index:10000;position:relative;top:<?php echo get_option('appaqua_zona4x');?>px;left:<?php echo get_option('appaqua_zona4y');?>px;} #zona5{width:27px;height:27px;background:#000;z-index:10000;position:relative;top:<?php echo get_option('appaqua_zona5x');?>px;left:<?php echo get_option('appaqua_zona5y');?>px;} #zona6{width:27px;height:27px;background:#000;z-index:10000;position:relative;top:<?php echo get_option('appaqua_zona6x');?>px;left:<?php echo get_option('appaqua_zona6y');?>px;} #zona7{width:27px;height:27px;background:#000;z-index:10000;position:relative;top:<?php echo get_option('appaqua_zona7x');?>px;left:<?php echo get_option('appaqua_zona7y');?>px;} #zona8{width:27px;height:27px;background:#000;z-index:10000;position:relative;top:<?php echo get_option('appaqua_zona8x');?>px;left:<?php echo get_option('appaqua_zona8y');?>px;} #zona9{width:27px;height:27px;background:#000;z-index:10000;position:relative;top:<?php echo get_option('appaqua_zona9x');?>px;left:<?php echo get_option('appaqua_zona9y');?>px;} #zona10{width:27px;height:27px;background:#000;z-index:10000;position:relative;top:<?php echo get_option('appaqua_zona10x');?>px;left:<?php echo get_option('appaqua_zona10y');?>px;} </code> I hope that someone can help me and please, if you need more info just ask... Thank you very much to all!
|
3 steps: php <code> <?php wp_enqueue_script( 'jquery-ui-sortable'); </code> html <code> <div class="metabox-holder"> <div class="postbox-container"> <div id="my_div" class="meta-box-sortables ui-sortable"> <div class="postbox" id="el1"> <h3 class="hndle"><span>title2</span></h3> <div class="inside">content1</div> </div> [...elements...] <div class="postbox" id="el20"> <h3 class="hndle"><span>title20</span></h3> <div class="inside">content1</div> </div> </div> </div> </code> javascript <code> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery('#my_div').sortable(); }); </code>
|
How to add drag and drop functionalities to a div inside option panel
|
wordpress
|
I'm having an issue with a third party plugin called WP-Calendar, where clicking on the "next" and "prev" links in a small calendar results in a redirect error. This problem only appears to be happening on archive pages, as I have the calendar on the front page of a few MU pages and it does not have the same problem. Clicking the links basically adds the following to the URL: ?month=may&yr=2011 Which changes depending on the current month viewed. This leads me to believe that there's something up with the archive / category page accepting parameters through $_GET. To test this theory I tried ?a=b at the end, and I still got the same redirect error (The page isn't redirecting properly). Anyone know why the archive pages won't accept inputs through the URL? EDIT: Some additional information that I should've mentioned, I've tested all of the plugins and the problem still exists after disabling them. The theme being used is a style modified version of this: http://www.woothemes.com/2008/02/gazette/ . Also the permalink settings are custom to: /%category%/%postname% and category base is . to get an URL such as myurl.com/category to work for a category landing page.
|
As per the discussion in the comments, using <code> . </code> as a value for the "Category base" will send Apache into an infinite loop. Getting rid of the Category base in the URL is actually pretty tricky, just because of the way WordPress expects things to work. It you want to use a single character for this, though, the <code> _ </code> character works just fine.
|
Redirect Problems with Archive Page and GET variables
|
wordpress
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.