question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I want to have my front page, with three columns, each assigned to a different category. Ideally I would like to query to fetch one post, per column, per page where possible, leaving the column empty if not. My current loop simply gets 3 posts at a time. It is reasonable to assume that the 3 will not be one of each category. Here is the loop: <code> &lt;?php global $query_string; parse_str( $query_string, $my_query_array ); $paged = ( isset( $my_query_array['paged'] ) &amp;&amp; !empty( $my_query_array['paged'] ) ) ? $my_query_array['paged'] : 1; query_posts('post_type=post&amp;posts_per_page=3&amp;paged='.$paged); if ( have_posts() ) : while ( have_posts() ) : the_post(); $category = choose_one_category(get_the_category()); switch ($category){ case "Festival News": $left[] = $post; break; case "Industry News": $centre[] = $post; break; case "Other": $right[] = $post; break; } endwhile; ?&gt; &lt;div class="custom-pagination"&gt; &lt;div &gt;&lt;?php previous_posts_link('&amp;laquo; Previous') ?&gt;&lt;/div&gt; &lt;div &gt;&lt;?php next_posts_link('Next &amp;raquo;') ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php endif; ?&gt; </code>
My recommendation would be to use a separate query for each column - getting 1 post per category - and pass the global <code> $paged </code> variable into each. This should exhibit the behavior you described in your question (at least it does on my site). My setup I have a top section that displays the 5 most recent posts from the "featured" category if you're on page 1 only. Then I have a sidebar that displays the first page of posts from each of 3 primary categories, each using their own query with <code> posts_per_page=1 </code> . Then I have the main section that displays all posts normally with 5 posts on each page. The first page returns my featured posts in a slider, the regular post section below it, and the first post from my three core categories in the sidebar. Page 2 hides the "featured" slider, returns the next 5 posts overall in the main section and the second post in each of my core categories. Page 3 and beyond do the same thing. So what you'll need is not one loop over 3 categories, but 3 loops each over a single category and each using the global <code> $paged </code> variable.
How can i call an article from each category and still paginate properly?
wordpress
Does anyone know how to add an admin menu separator? I found this but it did not help. http://lab.yukei.net/wp-code/nav.html?wp-admin/menu.php.source.html Any ideas?
Here's a quick and dirty way to get what you want. Background WordPress stores admin menu sections in a global array called <code> $menu </code> . To add a separator you add an element to the <code> $menu </code> array using an index that is between the indexes of the options that you want to separate. Using the <code> add_admin_menu_separator() </code> function So I've written a function to encapsulate the logic for this I called <code> add_admin_menu_separator() </code> . You'll need to pick an array index number that is higher than the option after which you want to add a separator, and then call the function <code> add_admin_menu_separator() </code> passing said index as your parameter. For example: <code> add_admin_menu_separator(37); </code> The <code> add_admin_menu_separator() </code> function itself Here's the definition of the function <code> add_admin_menu_separator() </code> which you can copy into your theme's <code> functions.php </code> file. Yes it is arcane but then so is the code that creates and uses the global <code> $menu </code> array. (Plans are to eventually deprecate it, thankfully, but that'll probably be a few years.) <code> function add_admin_menu_separator($position) { global $menu; $index = 0; foreach($menu as $offset =&gt; $section) { if (substr($section[2],0,9)=='separator') $index++; if ($offset&gt;=$position) { $menu[$position] = array('','read',"separator{$index}",'','wp-menu-separator'); break; } } ksort( $menu ); } </code> Finding the index into <code> $menu </code> that you need To figure out what index number you need you can do a <code> var_dump() </code> of <code> $GLOBALS['menu'] </code> from within an <code> admin_init </code> hook. Here's a bit of code you can drop into your theme's <code> functions.php </code> file temporarily to see what the values are. This will only work when requesting a URL starting with <code> /wp-admin/ </code> (but be sure to do with with FTP and not the built in theme editor or you'll loose access to your site, at least until you get FTP access to your theme's <code> functions.php </code> file!) : <code> add_action('admin_init','dump_admin_menu'); function dump_admin_menu() { if (is_admin()) { header('Content-Type:text/plain'); var_dump($GLOBALS['menu']); exit; } } </code> See Also: BTW, you might find these links useful in general for working with admin menus: Changing the Order of Admin Menu Sections Latest: <code> wp-admin-menu-classes.php </code> Although my admin menu classes don't currently offer an easy way to add separators I think I'll now add that when I have time.
Add a Separator to the Admin Menu?
wordpress
( Moderator's note: The original title was "How can I create a widget area in the navigation bar (Genesis specific)?"( I'm trying to create a widget area in my navigation bar. I'm attempting to adapt this from Bill Erickson's excellent tutorial here on adding static content to the navigation bar. This is the code I've added to my functions.php file to register and place the widget area: <code> genesis_register_sidebar(array( 'name'=&gt;'Nav Right', 'description' =&gt; 'This is the right section of the navbar.', 'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;', 'after_widget' =&gt; '&lt;/div&gt;', 'before_title'=&gt;'&lt;h4 class="widgettitle"&gt;','after_title'=&gt;'&lt;/h4&gt;' )); //Adding the widget area to the navbar add_filter('genesis_nav_items','navbar_widget',10,1); add_filter('wp_nav_menu_items','navbar_widget',10,1); function navbar_widget() { ?&gt; &lt;div class="nav_right"&gt; &lt;?php if (!dynamic_sidebar('Nav Right')) : ?&gt; &lt;div class="widget"&gt; &lt;h4&gt;&lt;?php _e("Nav Right", 'genesis'); ?&gt;&lt;/h4&gt; &lt;p&gt;&lt;?php _e("This is a widgeted area which is called Nav Right.", 'genesis'); ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php endif; ?&gt; &lt;/div&gt;&lt;!-- end .nav-right --&gt; &lt;?php } </code> However, what I end up with is this: With the widget area outside of the navigation bar (and the links removed from the navigation bar - there should be a Home and About link there). This is the html (when I view source of the page): <code> &lt;body class="home blog logged-in content-sidebar"&gt; &lt;div id="wrap"&gt; &lt;div id="header"&gt;&lt;div class="wrap"&gt;&lt;div id="title-area"&gt;&lt;h1 id="title"&gt;&lt;a href="http://travisnorthcutt.com/gateway/" title="Research Valley International Gateway"&gt;Research Valley International Gateway&lt;/a&gt;&lt;/h1&gt;&lt;p id="description"&gt;Just another WordPress site&lt;/p&gt;&lt;/div&gt;&lt;!-- end #title-area --&gt;&lt;div class="widget-area"&gt;&lt;/div&gt;&lt;!-- end .widget_area --&gt;&lt;/div&gt;&lt;!-- end .wrap --&gt;&lt;/div&gt;&lt;!--end #header--&gt; &lt;div class="nav_right"&gt; &lt;div class="widget"&gt; &lt;h4&gt;Nav Right&lt;/h4&gt; &lt;p&gt;This is a widgeted area which is called Nav Right.&lt;/p&gt; &lt;/div&gt; &lt;/div&gt;&lt;!-- end .nav-right --&gt; &lt;div id="nav"&gt;&lt;div class="wrap"&gt;&lt;/div&gt;&lt;/div&gt; </code> Any suggestions on how to get the new widget area that is created to be within <code> &lt;div id="nav"&gt;&lt;/div&gt; </code> ?
You are adding filter, not an action. I don't know how Genesis hook works, but native <code> wp_nav_menu_items </code> passes (and expects back) markup of custom menu items. Instead of echoing your additional stuff you should append it to input and return. This is clearly how it's done in tutorial you linked to: <code> add_filter('wp_nav_menu_items','follow_icons',10,1); function follow_icons($output) { $follow = 'some stuff'; return $output.$follow; } </code> Upd. Forgot to add about sidebar part. Since sidebars are echoed by definition you will likely have to buffer its output to use in such fashion. Maybe instead of making widget ares literally inside menu it is better to look for hook that allows to do this nearby?
Create a Widget Area in the Navigation Bar for the Genesis Theme Framework?
wordpress
Google Webmaster Tools can see it, but I can't find it. Any idea on how it's generated or where it is the file structure? I don't see the file in my root. My website is at http://mikewills.me and the robots.txt file URL is http://mikewills.me/robots.txt. In the end, Google isn't indexing my site and I am trying to figure out how to edit the robots.txt so that indexing is allowed. I have changed the privacy option to allow indexing, but that hasn't updated the robots.txt.
It's dynamically generated by the function <code> do_robots() </code> , which has both an action ( <code> do_robotstxt </code> ) and a filter ( <code> robots_txt </code> ). If you create a <code> robots.txt </code> file in your WordPress root, it will (probably) be served up when <code> /robots.txt </code> is requested, otherwise processing will fall back on WordPress. Your current file looks like this: <code> User-agent: * Disallow: Sitemap: http://mikewills.me/sitemaps/mikewills-me.xml.gz </code> The first two settings are appropriate for an indexable blog. So, you may just be waiting for Google at this point. Maybe you need to request reconsideration of your site.
Where is the robots.txt stored for a WordPress Multisite install?
wordpress
I have a Contact Form 7 form as a page on my site. I'd like to place the contact form on the sidebar. How can I do this?
Have you tried the options suggested in this WordPress Support thread ? They range from copying the generated code in a Text Widget to parsing the shortcode yourself in your template ( <code> &lt;?php echo do_shortcode('[contact-form 1 "Contact form 1"]'); ?&gt; </code> ).
Contact Form in sidebar
wordpress
I've created a custom post type and custom taxonomy. I can now create a new post and associate it with a custom category. The problem is listing these news post types. This: <code> $loop = new WP_Query( array( 'post_type' =&gt; 'sobeedesce' ) ); while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); the_title(); echo "&lt;br /&gt;"; endwhile;` </code> lists all custom posts ok. But I want to list them by category, so adding <code> 'cat' =&gt; 12 </code> returns nothing. I know my custom category id is <code> 12 </code> and I can confirm that by doing <code> $custom_terms = get_the_terms(0, 'cat_sd'); print_r($loop);` </code> inside the loop. I'm missing something here. Can someone help me? Thanks.
I suppose your custom taxonomy slug is 'cat_sd', right? If so, the right query would be: <code> $loop = new WP_Query( array( 'post_type' =&gt; 'sobeedesce', 'cat_sd' =&gt; 12 ) ); </code>
List Posts of a Custom Post Types Ordered by Terms of a Custom Taxonomy?
wordpress
I have a blog about programming hosted on WordPress.com. To post code snippets I use the SyntaxHighlighter plugin that is installed on that platform, and I'm very happy with it. Now, I'd like to use Windows Live Writer to write my articles, because it's much more convenient than the web-based editor. I found many WLW plugins to post code snippets, but it would take ages to try them all... also, most of them seem to do their own formatting, or need custom CSS (which I'd prefer to avoid because it's not free). Ideally, I'd like to be able to continue using the SyntaxHighlighter WP plugin mentioned above, which allows me to simply paste code between <code> [sourcecode] </code> tags, like so: <code> [sourcecode language="csharp"] public class SimpleGrid : Grid { public IList&lt;GridLength&gt; Rows { get; set; } public IList&lt;GridLength&gt; Columns { get; set; } } [/sourcecode] </code> Which WLW plugins would you recommend ? Is there one that can produce the markup shown in the snippet above ? EDIT: This one does exactly what I want, thanks to jjeaton for the link !
Here is a WLW plugin that seems to do what you want, made specically for WordPress.com hosted blogs.
Best Live Writer plugins to post code snippets on WordPress?
wordpress
I'm looking to create a page within my site that looks like this: Tag/Category: News News Post a News Post b News Post c Tag/Category: Events Event a Event b Event c I'm new to Wordpress. I may not have the wordpress jargon to ask this correctly. Thanks for your help.
Your best bet is to create a page template with the following code. Also you will need to decide if you will use a tag or category. The code below assumes you are using a category. <code> &lt;div class="news"&gt; &lt;?php //The Query wp_query('showposts=5&amp;category_name=News'); //The Loop if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; &lt;h2&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;div class="post_content"&gt; &lt;?php the_excerpt(); ?&gt; &lt;/div&gt; &lt;? endwhile; endif; //Reset Query wp_reset_query(); ?&gt; &lt;/div&gt; &lt;div class="events"&gt; &lt;?php //The Query wp_query('showposts=5&amp;category_name=Events'); //The Loop if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; &lt;h2&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;div class="post_content"&gt; &lt;?php the_excerpt(); ?&gt; &lt;/div&gt; &lt;? endwhile; endif; //Reset Query wp_reset_query(); ?&gt; &lt;/div&gt; </code>
How to make 2 tag feeds show up on 1 page?
wordpress
I am using the new menu system of Wordpress, and here is the result of wp_nav_menu() <code> &lt;div class="menu-main-menu-container"&gt; &lt;ul id="menu-main-menu" class="menu"&gt; &lt;li id="menu-item-28" class="menu-item menu-item-type-post_type current-menu-item page_item page-item-21 current_page_item menu-item-28"&gt;&lt;a href="http://www.bemang.com/"&gt;Trang nhà&lt;/a&gt;&lt;/li&gt; &lt;li id="menu-item-29" class="menu-item menu-item-type-post_type menu-item-29"&gt;&lt;a href="http://www.bemang.com/blog/"&gt;Blog&lt;/a&gt;&lt;/li&gt; &lt;li id="menu-item-30" class="menu-item menu-item-type-post_type menu-item-30"&gt;&lt;a href="http://www.bemang.com/gioi-thieu/"&gt;Giới thiệu&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code> What I want is only this: <code> &lt;li id="menu-item-28" class="menu-item menu-item-type-post_type current-menu-item page_item page-item-21 current_page_item menu-item-28"&gt;&lt;a href="http://www.bemang.com/"&gt;Trang nhà&lt;/a&gt;&lt;/li&gt; &lt;li id="menu-item-29" class="menu-item menu-item-type-post_type menu-item-29"&gt;&lt;a href="http://www.bemang.com/blog/"&gt;Blog&lt;/a&gt;&lt;/li&gt; &lt;li id="menu-item-30" class="menu-item menu-item-type-post_type menu-item-30"&gt;&lt;a href="http://www.bemang.com/gioi-thieu/"&gt;Giới thiệu&lt;/a&gt;&lt;/li&gt; </code> No, wrapping div or ul, I have been trying to few ways and google around but no result :(
The wrapping div is easy. When you use <code> wp_nav_menu() </code> , add this argument: <code> 'container' =&gt; false </code> For the <code> &lt;ul&gt; </code> element, there's an argument called <code> 'items_wrap' </code> . See stackexchange-url ("woodchucky's answer") for more info on that one (and upvote it!).
Remove wrapping div and ul from output of wp_nav_menu
wordpress
So i've installed a plug-in which allows me to enable two-factor authentication for my users. The problem is that to enable the plug-in i have to log in as that user and enable it via their profile page (wp-admin). This isn't a problem except for the fact that there's nothing stopping the users from logging in and disabling the two factor authentication which is an issue. I've looked around at a few issues and none have seemed to work, essentially i want restrict backend access to only a select few (myself and few others). I've tried stealth login and a few some htaccess solutions and none have seemed to work. Any ideas?
You could make it a mu-plugin ('Must Use' plugin). Any PHP file you put into /wp-content/mu-plugins/ will automatically get included in WordPress. You can't deactivate the plugin (unless you have ftp access to the server). If you go with a mu-plugin, make sure to put the functionality into a subdirectory and bootstrap it with a php file in the mu-plugins directory. EDIT After reading the comment, I think I understand the problem better. It sounds like you want to be able to lock people out of the admin altogether. That's not so difficult. Try this: <code> function my_awesome_admin_lockout(){ if( is_admin() &amp;&amp; !current_user_can( 'manage_options' ) ) { wp_redirect( home_url() ); die(); } } add_action( 'init', 'my_awesome_admin_lockout' ); </code> Basically, that locks everybody but admins out of the admin area.
Options for restricting access to wp-admin
wordpress
If I create a home.php file, it seems that WP will use that instead of index.php, so index.php is never used? What are the differences between these two template files (located in the theme folder)? Do they both behave the same way, the only difference being the priority of home.php?
<code> index.php </code> is universal template, it is what any page (home, archive, single post, etc) will use if no other template is available for it. <code> home.php </code> is a template used for main page (on <code> is_home() </code> ) condition. See Template Hierarchy for detailed scheme of how templates are applied.
What's the difference between home.php and index.php?
wordpress
Is there a plugin similar to the Google Sitemap plugin that works for a mutli-site install?
There is Google XML Sitemaps with Multisite support . You can also use the development version of the original Google XML Sitemaps . It seems to be working fine for some people.
Sitemap Plugin for WordPress Network
wordpress
Mark Jaquith's Subscribe to Comments plugin has been a staple of my WordPress site since shortly after I launched it. However, it's not really maintained any more (last updated end of 2007) and it lacks some options (email verification, etc.). infogurke extended Mark's plugin and released a different version with enhancements: All of the original Subscribe to Comments Registration with Double-Opt-In Multi-Language (English and German included) You can define an own css file for the manager interface Fixed many bugs that are still in the original plugin Is it possible to migrate to infogurke's version and maintain the subscriptions in the database? (Found the new plugin via stackexchange-url ("this question").)
Yes, it's possible (and quite easy) to migrate from Mark Jaquith's Subscribe to Comments plugin to Gurken Subscribe to Comments plugin. The steps: Install Gurken Subscribe to Comments (using either FTP or WordPress's plugin manager) Don't activate Gurken StC yet. First deactivate Mark Jaquith's version. Activating the new plugin too soon will fail because both plugins define functions with the same names. Activate Gurken StC. Go in via FTP and delete the <code> /wp-content/plugins/subscribe-to-comments/ </code> folder. Don't use WordPress to delete Mark's version! It might erase your subscription data from the database! (Question and answer inspired by this WordPress Support thread .)
How to migrate from Mark Jaquith's Subscribe to Comments plugin to Gurken's new version?
wordpress
How can I make a list of links of all the taxonomy terms I'm using? For example, I have a taxonomy of Manufacturers with terms of Honda, Ford, etc. I want to list out those terms as links.
My apologies. After some more searching, I found that I could pass the taxonomy as an argument in wp_list_categories. Here is the info via Wordpress Codex.
List taxonomy terms as links
wordpress
I'd like to display a checkbox with the option to subscribe to the site by email I have seen a wordpress blog with the following label next to the said checkbox Subscribe by email to this site The problem is that i cannot see to find the plugin that displays it: i've tried Subscribe2 and Post Notification and Gurken for comment subscriptions. Would you perhaps know what plugin i need to install?
There are often issues with setting up email subscriptions. Hosting providers are very tired of spam and often put harsh restrictions on email rate and volume, especially for cheaper hosting plans. In practice such feature is often implemented with help of external service. FeedBurner is popular for this, because a lot of people use it for feeds anyway and it provides decent email subscription option. See FeedBurner Email Overview and FAQ
New post email alert
wordpress
Does wordpress.com support multiple languages at the same time? I know it does support changing the main language, but I can't find anything about how one would go about setting up multiple languages at the same time. Thanks.
No, wordpress.com does not support multilanguage blogs. The solution would be to make one blog per language and link them via the sidebar. Reference: Multi-language blog on wordpress.com
Blog in multiple languages on WordPress.com?
wordpress
Is there any plugin which can automatically combine all the javascript and css files that are used on a page? While I can combine them manually I would like to avoid them as some plugins add their scripts and css. Also different scripts might be needed on different pages so I do not want to have one large script on every page. I am not looking for gzipping, minifing or cache-control as I already have them implemented. Thanks.
W3 Cache will do this for you
Combining multiple javascript and css files
wordpress
I have 3 different custom post types: 1.) <code> "events" </code> , 2.) <code> "winners" </code> and 3.) <code> "offers" </code> . How would I go about retrieving the first (latest) post in each of these post types on a single web page (i.e a home page). Would I use <code> get_posts() </code> or would I have to manipulate <code> the_loop() </code> ?
Yes, get_posts is the safest way to use multiple loops. It does not mess up with the original query. Another way would be to create new WP_Query objects: <code> $my_query = new WP_Query($args); while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); </code> Note: stackexchange-url ("Why you should not use query_posts()")
Show the First Post from Each of 3 Different Post Types on a Web Page?
wordpress
How do you register a sidebar in a plugin without screwing up the pre-existing registered sidebars? (The ordering of the sidebar registrations, rather than the assigned ID, determines the sidebar data.)
<code> function self_deprecating_sidebar_registration(){ register_sidebar( /* Your arguments here */ ); } add_action( 'wp_loaded', 'self_deprecating_sidebar_registration' ); </code> Most themes will register the sidebar in their functions file, which is included before <code> init </code> but after plugins are loaded. Hooking onto <code> wp_loaded </code> should guarantee that your sidebar is registered after the theme's.
How to register_sidebar() without messing up the order?
wordpress
I have my own private installation of Wordpress I've installed the wordpress.com stats plugin , so I get a stats feature like you get on the free wordpress blogs, its nice and simple, and works well Now on my blog, all I can see on the plugin (on my dashboard) is a login screen, and when I try to login it redirects me to my free blog (which I had to setup to get an API key) Why has my plugin suddenly started requesting a login? It has been working fine for 2 weeks now The login it expects is the login of my free blog, and when I do provide those credentials it redirects me to my free one. Screenshot of what I see on my dashboard : Tried to de-activate and re-activate plugin, no luck
The WordPress.com Stats plugin is broken as of this morning. It doesn't work on any of my sites and if you click this http://twitter.com/search/WordPress%20Stats You'll see lots of people are finding it borked this morning. You may have to wait a few days and try again once the issue is fixed.
WordPress.com Stats plugin is requiring login, and redirecting to WordPress.com on login
wordpress
I'm using the Contact Form 7 Calendar "plugin plugin", but I can't figure out how to make the date field required. The syntax is <code> [datetimepicker your-label] </code> , and in the parent plugin (Contact Form 7), you would just put an asterisk in, like <code> [datetimepicker* your-label] </code> but this doesn't work with the calendar widget... Of course, I could always style it in CSS to appear as if its required, but I kinda need the validation there. I've looked in the plugin's documentation, but this isn't covered, and the author is not responding on the WP Support Forums. Has anyone used the Calendar add-on and been able to make the date field required? Anything I can do to tweak the javascript or whatever is used for validation -- I'm assuming its javascript (I'm sure js is very easy but I've never managed to find the time to learn it)? Or the php (I'm much more comfortable in php), but without breaking on plugin updates...
Apparently the answer is to read the installation instructions properly the first time round. The syntax within a contact 7 form is: <code> [cf7cal inputname] </code> or <code> [cf7cal* inputname] </code>
Making a Contact Form 7 calendar entry "required"
wordpress
I'm writing a plugin that uses Ajax (jQuery with form plugin) via a form submission and the php function returns a JSON response. <code> add_action( 'wp_ajax_bubbly-upload', 'bubbly_upload_submit' ); function bubbly_upload_submit() { // generate the response $response = json_encode( array( 'success' =&gt; true ) ); // response output header( "Content-Type: application/json" ); echo $response; } </code> In Firefox, none of the jQuery response handlers were firing and the save file dialog was opening with the JSON response. I wouldn't have the issue if I returned HTML. However, in either case, a '0' was appended on to the end of my response. After some digging, it looks like jQuery will not trigger a handler if the JSON reponse is invalid. This '0' being added onto the end is causing the JSON to be invalid. If I look into the <code> admin-ajax.php </code> code, I see this: <code> default : do_action( 'wp_ajax_' . $_POST['action'] ); die('0'); break; endswitch; </code> The php docs for die say that if the parameter passed is a string, then it will be printed just before exiting, if it is an integer, it will not be printed. Without hacking the core, is there a way I can avoid this issue and still use JSON? Also, is this a bug, because I don't see how adding a zero to the end of every AJAX response would be desired...
Put the <code> die(); </code> in your function: <code> add_action( 'wp_ajax_bubbly-upload', 'bubbly_upload_submit' ); function bubbly_upload_submit() { // generate the response $response = json_encode( array( 'success' =&gt; true ) ); // response output header( "Content-Type: application/json" ); echo $response; die(); } </code> Reference: WordPress Codex, AJAX in Plugins
Admin-ajax.php appending a status code to ajax response
wordpress
Use case: I have a custom post type of 'show' for a music venue. In the sidebar we want to display any related 'show' to the current one on single-show.php. They will be related by a custom taxonomy of 'genre'. I figured I could dump the custom taxonomy slugs for a post (might be more than one) into a variable then pass that variable into a custom query for the sidebar post. Using get_the_term_list() works if there is a single taxonomy but if there are multiple it breaks (of course). Any thoughts on how to get an array of the custom taxonomy slugs for a give post into a variable?
You can do something like the following: <code> $terms = get_the_terms( $post-&gt;id, 'genre' ); // get an array of all the terms as objects. $terms_slugs = array(); foreach( $terms as $term ) { $terms_slugs[] = $term-&gt;slug; // save the slugs in an array } </code>
Get the 'slug' of a custom taxonomy
wordpress
I've got a custom template page called <code> 'shop' </code> , which is found at the URL <code> http://mysite.com/shop/ </code> . This page lays out all the posts of post_type <code> 'product' </code> like this: <code> &lt;div class="product"&gt; &lt;a name="product-name"&gt;&lt;/a&gt; &lt;img src="path/to/image.jpg" /&gt; &lt;h4&gt;Product name&lt;/h4&gt;` &lt;p&gt;A description of the product.&lt;/p&gt; &lt;/div&gt;` </code> On another page, I've got a link like this: <code> &lt;a href="/shop#product-name"&gt;Buy this product!&lt;/a&gt; </code> I want that link to go to the <code> /shop </code> page, then scroll down to position the page right at the anchor link for this product. But it seems like WordPress' 'pretty permalinks' redirection is getting in the way: as soon as it switches to the <code> /shop#product-name </code> page, the URL gets rewritten to <code> /shop/ </code> and the browser leaves the page scrolled at the top. My <code> .htaccess </code> file is exactly what WordPress generated: it looks like this: <code> # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt; # END WordPress </code> Any help in getting these anchor links to work properly would be much appreciated. ( Moderator Note: Title was originally "My permalinks setup doesn't like anchor links to another page.")
Dumb question, but had you tried: <code> &lt;a href="/shop/#product-name"&gt;Buy this product!&lt;/a&gt; </code>
How can I make internal anchor links work with WordPress's permalinks?
wordpress
I'm trying to use wp-load.php in a page outside of wordpress so I can access all the functions in wordpress. Typically I just include the file like this <code> require( $_SERVER['DOCUMENT_ROOT'].'/blog/wp-load.php' ); </code> But it doesn't seem to be working. Any tips on what can be going on? Thanks, Paul
Including wp-load.php will not setup the WordPress query. See Integrating WordPress with Your Website for the right way.
Problem with using wp-load.php outside of WordPress
wordpress
Does someone know of a simple plugin for showing RSS feeds? I need something dead simple that only show the links and would rather re-use something before rolling one myself.
There is a plugin for this, RSS Icon Widget . However it looks like it hasn't been tested on any version past 2.8. It looks fairly simple, so it could still work. Otherwise the easiest way to accomplish this is to just create a new text widget and write the HTML to display any icon you'd like and link it to your feed. A plugin may even be overkill for this. I believe this is normally something that is built into your theme.
Simple plugin for showing RSS subscription links?
wordpress
I want to embed links to the archive pages with specific search criteria. i.e Links to specific categories, links to specific authors etc etc At the moment I am adding the links using anchor tags, but these will fail if the permalinks change
WordPress can generate these, so you can too. You would need to use the same function that WordPress does. For category it would be something like: <code> $category = get_category_by_slug( 'example' ); $link = get_category_link( $category-&gt;term_id ); </code> Similarly there is <code> get_tag_link() </code> and on deeper level they all really use <code> get_term_link() </code> I didn't play much with authors, but there is <code> the_author_posts_link() </code> and probably some <code> get_ </code> analogue.
how do I encode links to specific archive searches?
wordpress
I have a recruitment website on which I want to display a list of Job Location links. The job location has already been entered into a custom field for each post so I just want to display a list of links that when clicked will show posts with only that custom value entered, ie - England Ireland USA etc.. Click a country link above and see all of the posts that have the country in question added as a custom field value??
I would recommend using a custom taxonomy for this, not a custom field. You can sort and list archives based on a taxonomy far more easily than by custom fields. However, if you want to list based on the custom field, you're going to need to modify the arguments sent to <code> query_posts() </code> on your archive page to pass in the <code> meta_key </code> and <code> meta_value </code> you're searching by. To add your query variable: <code> add_action('init', 'add_custom_meta_url'); function add_custom_meta_url() { global $wp,$wp_rewrite; $wp-&gt;add_query_var('location'); $wp_rewrite-&gt;add_rule('location/([^/]+)','index.php?location=$matches[1]','top'); $wp_rewrite-&gt;flush_rules(false); // This should really be done in a plugin activation } </code> Then, your permalinks for the archive will become something along the lines of <code> http://mycoollocationsite.com/location/england </code> <code> http://mycoollocationsite.com/location/ireland </code> <code> http://mycoollocationsite.com/location/usa </code> ... etc ... Next, you'll need to add whatever value was passed in to your location to the actual query: <code> add_action('parse_query', 'apply_custom_meta_to_query'); function apply_custom_meta_to_query(&amp;$query) { if (isset($query-&gt;query['location'])) { $query-&gt;query_vars['meta_key'] = 'location'; $query-&gt;query_vars['meta_value'] = $query-&gt;query['location']; unset($query-&gt;query_vars['location']); // You don't need this } } </code> I'm assuming you're storing your custom data in a field called <code> location </code> ... so change that if I'm wrong. But this will allow you to filter your archives based on a specific location. If you want to enable date-based archives with this as well that will require some additional rules in my first code block (right now, this would display a list of all posts with a <code> location </code> meta_key). Still, I recommend using a custom taxonomy instead. It's cleaner, more extensible, and requires less custom coding. This is also exactly the situation for which custom taxonomies were created ... so please, don't reinvent the wheel ...
Show links to archive pages based on custom field values
wordpress
I am new to wordpress. I have experience in css \ html \ js and asp.net (and also a bit of php now). I've added to my blog certain areas that are hard coded in html and css. In these areas I'd like to be able to set text based on the admin's input in the panel's page. I want a person who doesn't know html to be able to easily change the content of these hard coded areas. How can this be done? Thank you!
You have two solutions for this: Use Custom Fields This is a very comprehensive guide: The Power of WordPress Custom Fields . There are some very useful plugins like Custom Field Template and Magic Fields which use them. Use Widgets . The Widgets API allows you to easily build your own widgets.
Add custom text to Page Tamplate without need to know html
wordpress
If you use a premium theme service (my skills lie more in coding than artwork), what is a good way to show clients examples of what themes are available to them, without sending them to the theme service site in the first place (ie - without letting them see the original purchase price), but without having to purchase the theme upfront? I know I can make a dummy WP site and use a theme switcher, but I don't want to purchase a bunch of themes that may never be used.
One option would be to display screenshots of the theme in action. Many theme services allow you to view a "demo page" and see how the theme is presented - taking a screenshot of this page and passing it to your client is pretty much the same as presenting a stylized wireframe or stylistic mockup of the final design. If it was an entirely custom site (i.e. you were responsible for the design as well), you'd likely present it this way anyway before investing any time in actual development.
How can you showcase various premium themes to clients without having to pre-purchase the theme?
wordpress
I have a custom menu on a site with multiple languages (WPML plugin) The menu is not being displayed in any languages other than native. Can the menu be translated? Can the menu be shown in all languages without any change to the text? (when it's mostly names that shouldn't be translated)
Yes, the menu can be translated, and, yes, it will be shown in all languages. Does your menu use the WordPress 3 menu feature? If yes, the video here explains how to setup the translation: http://wpml.org/2010/07/wpml-1-8-0-with-multilingual-menus/
menu doesn't show in different languages
wordpress
I realize there have been a few questions which dance around the solution I am after but I believe I am looking for something specific. This is actually a two part question: 1) My goal is to have wordpress operate in network (multi-site) mode and I am trying to figure out a way to essentially "group" specific sites together. I am aware of the "Multi-Network" plugin but I question if this is the best approach for this? The key here is to allow specific users to add/edit the sites within their own sub-network. 2) This is the key question of this post... I would like to know the best approach which would allow me to essentially query posts from within this "sub-network" of sites. So, for example if there are 10 sites within this sub-network and each of them created posts within a custom post type called "news" then I would like the ability to display for example the 10 most recently published posts from this collection of 10 sites. NOTE: I need the ability of being of being able to create multiply sub-networks which in turn means that a query of the latest published "news" can only display posts from those belonging to the correct group. Finally - I do realize solutions exist for doing stuff like this but I am looking for the best approach on both cases which require the LEAST amount of database load/queries. I would also very much like to do this through code in my functions.php file rather than installing plugins which create extra bloat. I am very open to any suggestions and appreciate any response.
I know you said you'd rather not install a plug-in, but that's exactly what you want to do in this situation. Placing the code in your theme's <code> functions.php </code> file requires you to either use the same theme across all sites in the sub-network or maintain multiple copies of the same file. On the other hand, you can create a simple plug-in for the network to encapsulate the functionality, then activate it on the network, and immediately have the functionality available with only one file to maintain. This would actually create less bloat than depending on your <code> functions.php </code> files. The thing to keep in mind here is that you're either going to need to loop through each site on the network to find your posts or perform a custom query. I'd opt for the second routine because, though it's a bit more complicated, it's a single query rather than a different query for each blog. Basically ... you'll need to do the following: Get a list of all the blog IDs in the network/sub-network. If using a vanilla installation, this can be found in the <code> wp_blogs </code> table. Just do a simple <code> SELECT </code> query to load up an array, then you can loop through to add each blog to your main query. Create a loop that adds each blog to a large query. You'll need to be <code> JOIN </code> ing tables together and searching based on <code> blog_id </code> (from <code> wp_blogs </code> ), <code> post_id </code> (from <code> wp_BLOG_posts </code> ), and the custom taxonomy. Like I said, it's not a simple solution (the SQL statement will be very complicated and I don't have time to hack through it at the moment), but it will be a single statement that does all the work. Alternatively ... Get a list of the blog IDs and store it in an array. Iterate through your array querying each blog in the network and appending your matches (posts with a certain taxonomy term) to a separate array. With the alternative method you'll have to run a separate query for every blog in the network. If your network is 10-20 sites this isn't too much of an issue. If your network is 200-500 sites expect some performance issues to start cropping up. Also, you should cache the results of your query if at all possible. If it's being run on multiple page loads (i.e. for a sidebar widget shared across the network) then you only want to run the query when there's new data to get. Otherwise, serve up the cached results so you don't slow down the network.
Querying posts from multiple sites in a network?
wordpress
I have a variable containing some post ID´s. I´d like to output the posts in that variable using the standard wordpress loop. How can I do that? Thanks! Added: <code> &lt;?php /* Template Name: Favorites page */ $favorites = wpfp_get_users_favorites($user = ''); $favorites_query = new WP_Query('post__in' =&gt; $favorites); get_header(); get_sidebar(); ?&gt; &lt;div id="maincolumn" class="alignleft"&gt; &lt;?php get_template_part( 'menu' ); if(!$favorites) { echo '&lt;div class="box content alignleft"&gt;'; echo _e('Du har ingen favoritter', 'deals'); echo '&lt;/div&gt;'; } if($favorites) { echo '&lt;div class="box content alignleft"&gt;'; echo _e('Dette er dine favoritttilbud denne uka. Favorittene dine vil kún være være tilgjengelig i denne nettleseren på denne maskinen.', 'deals'); echo '&lt;/div&gt;'; } while ($favorites_query-&gt;have_posts()) : $favorites_query-&gt;the_post(); $start = get_post_meta($post-&gt;ID, '5Start', true); $stop = get_post_meta($post-&gt;ID, '6Slutt', true); echo print_offer($post_id, $start, $stop); endwhile; if($favorites) { echo '&lt;div class="box content alignleft"&gt;'; wpfp_clear_list_link(); echo '&lt;/div&gt;'; } ?&gt; &lt;/div&gt; &lt;!-- End maincolumn --&gt; &lt;?php get_template_part( 'rightsidebar' ); get_footer(); ?&gt; </code>
An example: <code> $posts_ids = array(2,56,87,23,5); // this is an array of posts IDs &lt;?php $my_query = new WP_Query(array('post__in'=&gt;$posts_ids)); ?&gt; &lt;?php while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt; &lt;!-- Do stuff... --&gt; &lt;?php endwhile; ?&gt; </code>
Outputting posts from post id´s in variable
wordpress
I'm looking for a way to generate a sitemap for display on my site that includes my custom posts. I'm not looking for an xml sitemap generator for search engines -- that is sorted using Google XML Sitemaps and Get Up and Running's patch for that plugin. I'm specifically looking for something to display to users. Normally, I'd use Dagon's sitemap generator, but it does not support custom posts, and the author does not seem to be responding to queries. Any hacks/patches/code snippets/ideas?
Smart Archives Reloaded plugin should work with custom post types (it accepts query_posts/get_posts arguments so quite flexible).
How to generate a sitemap with custom posts (not Google XML)
wordpress
I want to add both custom html that advanced text widgets can't support and the standard sidebar widgets in the same sidebar. However, when I put a sidebar widget into the theme, it removes all the custom html and just displays the widgets in the sidebar. It shouldn't be a tough fix, but I am pretty big php noob who learned wordpress by trial and error. I have attached the code from my sidebar: <code> &lt;div class="sidebar-blog"&gt; </code> <code> &lt;div class="widget-wrap"&gt; &lt;div class="widget"&gt; &lt;h4&gt;Title goes here&lt;/h4&gt; &lt;p&gt;Content goes here&lt;p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="widget-wrap"&gt; &lt;div class="widget"&gt; &lt;h4&gt;Title goes here&lt;/h4&gt; &lt;p&gt;Content goes here&lt;p&gt; &lt;/div&gt; &lt;/div&gt; </code> <code> &lt;/div&gt;&lt;!--end .sidebar-blog div--&gt; </code> Thanks for any help
I suppose you are doing something like this: <code> &lt;?php if ( ! dynamic_sidebar( 'widget-area' ) ) : ?&gt; Your sidebar code goes here. &lt;?php endif; ?&gt; </code> If yes, do this instead: <code> Your sidebar code goes here. &lt;?php dynamic_sidebar( 'widget-area' ); ?&gt; </code>
Adding custom html and standard widgets to sidebar
wordpress
I'm trying to add a custom taxonomy. using the following code: <code> function cities_custom_taxonomies() { register_taxonomy( 'city', // internal name = machine-readable taxonomy name 'post', // object type = post, page, link, or custom post-type array( 'hierarchical' =&gt; false, // true for hierarchical like cats, false for flat like tags 'label' =&gt; 'City', // the human-readable taxonomy name 'query_var' =&gt; true, // enable taxonomy-specific querying 'rewrite' =&gt; true // pretty permalinks for your taxonomy? ) ); } add_action('init', 'cities_custom_taxonomies', 0); </code> As long as I use label name in English, all works fine. Once I try to label it in Hebrew, I don't see the new taxonomy menu. any Idea ?
You can just wrap the english label name with the translation function <code> __( 'City', 'textdomain' ) </code> , and put the hebrew version in your translation file. Reference: http://codex.wordpress.org/I18n_for_WordPress_Developers
custom taxonomies label in hebrew
wordpress
Or to make it easier: you just want to disable the caching in order to see your changes in realtime. Any solution that would allow you to disable caching based on IP, logged user or cookie will be acceptable.
It has this natively: Performance > Page Cache > General > Don't cache pages for logged in users You can always check if you are seeing cached page by looking at page source, W3 outputs status (commented out) at end of page.
How can you develop on a live WordPress installation that is using W3 Total Cache?
wordpress
I'm testing out a shared hosting package with Dreamhost at the moment which is only $2.95 a month for unlimited domains, storage space, bandwidth, mysql databases etc. But I'm currently only running one test site on it and it seems pretty slow. Am I going to run into problems if I host lots of sites on a shared hosting package. Should I be looking at a dedicated server instead? iPage seem to offer a similar package but with lots of extras for $3.50 per month. Have you had any experience with either company? Any advice greatly appreciated. Thanks
We've migrated a lot of people from Dreamhost after their site gets mildly popular, and they notice it's either down or slow. But, we don't offer hosting plans that are as cheap as them as well. I would recommend you check out zippykid.com (our site), page.ly , or wpengine.com if you're interested WordPress hosting that doesn't suck. I'd be willing to give you a coupon if I could get some of your feedback.
WordPress hosting - Shared/dedicated server? Any recommendations?
wordpress
What caching plugin configuration do you recommend and why under the following assumptions: full control of the server configuration running WordPress in multi-site/multi-domain mode most domains are not using <code> www. </code> prefix (cookies) (desire) to be able to disable caching for specific IPs or based on a cookie, when you do changes to the site you don't need caching. Details: I'm using Firefox Google Page Speed plugin to try to optimize the speed of the website. Also please do not guide with generic guidelines, like smaller images. Let's be fair, using more than one caching plugin will bring you more problems than it will solve so please try to give a simple approach.
Basic answer to "what plugin" would probably be W3 Total Cache. It is one of the most functional and actively developed plugins at moment. However complete performance chain is much longer that WordPress plugin alone can handle. Web server (Apache or something else) configuration (response time, time to first byte, headers). Database (time spent processing queries). PHP/WordPress (page generation time, memory consumption). Front-end performance (amount of HTTP requests, bandwidth). Good start would be static caching plugin (like W3) with opcode memory-based cache like APC. But from there there are way more (and way more complex) things you could do, like content distribution networks, alternate web servers, etc.
What is the best caching option for WordPress multi-site on non-shared hosting?
wordpress
I'm trying to build a featured posts with a "tabbed" interface in my homepage. I'm using the "sticky" option of the posts in order to get them out of the main loop and in the "featured tabs". No problem here. The problem is I can't control the stickies order. Is there a way to set the order of sticky posts? A plugin, custom field... Is this stickies approach completely wrong? Thanks
It sounds like you want to use the 'sticky' functionality as a replacement for a tag or a category. Why not just put all the posts you want in a 'tab' category, then call your query for that category. You can use orderby in fancy ways (such as by post_meta($tab = get_posts('category=tab&amp;orderby=date');
featured posts order
wordpress
I am very new to using WordPress and I was wondering what the benefits of using widgets is? Looking here it sounds like they are for people who are not programmers that want to add plugins to their site. Is that correct? or do widgets allow the site to be more robust in some way?
I battled with this very same question. I'm presently developing my own ability to develop WordPress sites. My employer is launching numerous websites on the engine, and is moving me from general PHP work to focused WordPress development. The thing is, these sites will all be managed by other people, and not myself. Using widgets allows the non-programmers to help develop the site without potential of breaking things. For instance, they can move things around in the sidebar, change up the contents of the footer, and so much more. That being said, I wish I could prevent them from doing some types of editing, but permit them to do others. While they can't break the site (to my knowledge), they could really make it ugly.
Why use widgets?
wordpress
I switched to another theme and decided to make a widget of some default code I had in there which shows my delicious posts, twitter posts, su posts and youtube vids in a custom loop (excluding these categories from the main loop). But now...the paging no longer works. I have made this widget: <code> // =============================== EDL Sidebar Posts Widget ====================================== class SidebarPosts extends WP_Widget { function SidebarPosts() { parent::WP_Widget(false, $name = 'Sidebar Posts'); } /** @see WP_Widget::widget */ function widget($args, $instance) { extract( $args ); $title = apply_filters('widget_title', $instance['title']); echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; $title = apply_filters('widget_title', $instance['title']); global $wp_query; $wp_query = new WP_Query(); $wp_query-&gt;set('cat', '1172,14,867'); $wp_query-&gt;set('posts_per_page', 30); $wp_query-&gt;set('offset', $paged*30); $posts = $wp_query-&gt;get_posts(); if ($posts) : foreach ($posts as $post) : the_post(); if (in_category(14)) { echo $this-&gt;createSideBarLine($post, 'http://populair.eu/wp-content/themes/pop/bookmark_info/com/delicious/f.png', false, true, true); } elseif (in_category(1172)) { echo $this-&gt;createSideBarLine($post, '/wp-content/themes/edl/inc/banners/twitter.gif', false, true, true); } elseif (in_category(867)) { echo $this-&gt;createSideBarLine($post, 'http://populair.eu/wp-content/themes/pop/bookmark_info/com/stumbleupon/www/f.png', true, true, true); } endforeach; echo "&lt;p&gt;" . _e('More on the Next Page!') . "&lt;/p&gt;"; wp_link_pages(array('next_or_number'=&gt;'next', 'previouspagelink' =&gt; ' &amp;laquo; ', 'nextpagelink'=&gt;' &amp;raquo;')); else: echo "&lt;p&gt;" . _e('Jump to the frontpage for the list') . '&lt;/p&gt;'; endif; echo $after_widget; } /** @see WP_Widget::update */ function update($new_instance, $old_instance) { return $new_instance; } /** @see WP_Widget::form */ function form($instance) { $title = apply_filters('widget_title', $instance['title']); ?&gt; &lt;p&gt; &lt;label for="&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;"&gt;&lt;?php _e('Title:'); ?&gt; &lt;/label&gt; &lt;input class="widefat" id="&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('title'); ?&gt;" type="text" value="&lt;?php echo $title; ?&gt;" /&gt; &lt;/p&gt; &lt;?php } function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') { $content = get_the_content($more_link_text, $stripteaser, $more_file); $content = apply_filters('the_content', $content); $content = str_replace(']]&gt;', ']]&amp;gt;', $content); return $content; } // // Shows a line in the LifeFeed / IssueFeed / BrainFeed sidebar // widgets // function createSideBarLine($post,$strImage, $boolShowTitle, $boolShowExcerpt, $boolShowContent) { global $wp_query; $strBuffer=""; $strTitle = strip_tags(get_the_title()); $strPermalink = get_permalink($post-&gt;ID); $intId = $post-&gt;ID; $strContent = $this-&gt;get_the_content_with_formatting(); $strContent = str_replace('&lt;p&gt;', '', $strContent); $strEditPostLink = get_edit_post_link(); // if content contains "YouTube" then use YouTube icon if (strstr($strContent, 'YouTube')) { $strImage = 'http://populair.eu/wp-content/themes/pop/bookmark_info/com/youtube/www/f.png'; } $strBuffer.= '&lt;div class="tb-link" id="post-'. $intId . '"&gt;'; $strBuffer.= '&lt;p&gt;&lt;a href="' . $strPermalink; $strBuffer.= '" rel="nofollow bookmark" title="Permanent Link to '; $strBuffer.= $title . '"&gt;'; $strBuffer.= '&lt;img src="'. $strImage . '" align="left" '; $strBuffer.= 'width="12" style="border: 0px none;'; $strBuffer.= 'margin: 0px 10px 0px 0px; display: inline;"&gt;'; $strBuffer.= '&lt;/a&gt;'; if ($boolShowTitle) { $strBuffer.= '&lt;a href="' . $strPermalink; $strBuffer.= '" rel="nofollow bookmark"'; $strBuffer.= 'title="Permanent Link to ' . $strTitle . '"&gt;'; $strBuffer.= $strTitle . "&lt;/a&gt;"; } if ($boolShowExcerpt) { $strBuffer.= $post-&gt;post_excerpt; } if ($boolShowContent) { $strBuffer.= $strContent; } if (is_admin()) { $strBuffer.= '&lt;a href="'. $strEditPostLink . '" class="editpost"&gt;'; $strBuffer.= ' [edit]&lt;/a&gt;'; } $strBuffer.= "&lt;/p&gt;&lt;/div&gt;"; return $strBuffer; } } </code> I think the in the previous theme it could pick up the $paged from the main loop or something now it no longer shows any paging so it always only shows the first 30 items. (see http://edward.de.leau.net/ for the thing, busy converting to swift theme)
Try doing <code> global $paged </code> before using the variable in the widget function.
Paging in a sidebar mini loop
wordpress
I have a wordpress site and want to create a different theme for mobile. I'd like to create a subdomain such as m.domain.com which will use a mobile optimized theme much different than the desktop version theme. I understand multisite will handle the subdomain problem but I want all the content, custom posts, plugins, etc to be in a single site in the admin. Is there anything out there that will allow me to create a mobile subdomain and have a separate theme applied to that subdomained site while keeping the content, posts, plugins in a single site in the admin? Thanks!
try to read this useful article: http://digwp.com/2009/12/redirect-mobile-users-to-mobile-theme/
Create mobile site with same content just different theme
wordpress
This question is related to this question: stackexchange-url ("stackexchange-url When developing a website with custom functionality for a client, particularly a site that will expect lots of traffic, what is better from a performance perspective. To build the functionality into the theme itself or to build it into a plugin? Or is there any performance difference at all?
You're not going to get a noticeable difference doing it one way over another. Slowness comes from what the code is doing. If you're worried about performance, just make sure you're caching external requests whenever you can, that includes calls to the database.
For performance is it better to build custom functionality into the theme or a plugin
wordpress
I'm trying to edit a plugin so that it only shows it's submenu if the user is an administrator but I don't know how to define the value of the variable before the function: <code> function load_view( $name, $params = array(), $print_submenu_navigation = false ) { </code> My code so far is: <code> if (current_user_can('administrator')) { $print_submenu_navigation = true; } else { $print_submenu_navigation = false; } </code> If I put this before the function I get a php error telling me it's expecting a function.
Wrong approach. <code> $print_submenu_navigation </code> will be filled in local scope when function is called with arguments, it's not a matter of global variables. You want something like this when function is called (not defined): <code> load_view( 'name', array(), current_user_can('administrator') ) { </code> Alternatively you can add your snippet inside the function, then input value for <code> $print_submenu_navigation </code> will overwritten with result of your check. And it's shorter to write it like this, function returns boolean: <code> $print_submenu_navigation = current_user_can('administrator'); </code>
Defining the value of a variable before a function?
wordpress
I'm trying to include the post title in a custom post type edit screen. For example if the post is called Biography, I want the edit page title to be 'Edit Biography'. I'm using the below code: <code> function my_post_register() { $mypagetitle = $post-&gt;post_title; $labels = array( 'edit_item' =&gt; __('Edit '.$mypagetitle), </code> Why isn't this displaying the post title?
This will do it: <code> function edit_screen_title() { global $post, $title, $action, $current_screen; if( isset( $current_screen-&gt;post_type ) &amp;&amp; $current_screen-&gt;post_type == 'post' &amp;&amp; $action == 'edit' ) $title = 'Edit ' . $post-&gt;post_title; } add_action( 'admin_head', 'edit_screen_title' ); </code>
Displaying Post Title on Post Edit page?
wordpress
I've decided, that some second level pages I have, should really be blog articles. I want to copy and paste the title and body to an article and then delete the page (is there a better way of doing this?). Now I'm worrying about already existing links to the pages. I don't want them to break ... can I somehow enter the old URL as an alias URL for the article? Or maybe forward from http://mypage.com/level-one/level-two-page/ to http://mypage.com/2010/07/30/level-two-page-as-article/ without showing the olt level-two-page in the navigation?
Use the Vice Versa plugin to change the post type. Redirect the URL per .htaccess: <code> Redirect permanent /old-url /new-url </code>
Migrating a page to be an article
wordpress
Okay, I'm starting out with some AJAX stuff in a wordpress theme 1) I'm building a child theme OFF the thematic framework 2) My child theme has a header.php, index.php, functions.php and style.css (at this stage) In my header.php I have the following (btw: the code is adapted from http://codex.wordpress.org/AJAX_in_Plugins ): <code> &lt;?php if( !is_admin() ) { add_action('wp_ajax_my_special_action', 'my_action_callback'); add_action('wp_ajax_nopriv_my_special_action', 'my_action_callback'); $_ajax = admin_url('admin-ajax.php'); } ?&gt; &lt;script type="text/javascript" &gt; jQuery(document).ready(function($) { var data = { action: 'my_special_action', whatever: 1234 }; jQuery.post('&lt;?php echo($_ajax); ?&gt;', data, function(response) { jQuery('#output').html('Got this from the server: ' + response); }); }); &lt;/script&gt; &lt;/head&gt; </code> Right so that's all cool - and it updates the OUTPUT div on the page with "Got this from the server: 0" I need a PHP function called "my_action_callback" - so in my theme's functions.php I have the following: <code> function my_action_callback() { $whatever = $_POST['whatever']; $whatever += 10; echo 'whatever now equals: ' . $whatever; die(); } </code> This is the ONLY function in my functions.php To make sure the PHP function is working I stick my_action_callback() into my index.php - and it outputs "whatever now equals: 10" as expected. HOWEVER - the AJAX response is always 'Got this from the server: 0' Ajax never seems to get the response from the PHP function. I tried adding .ajaxError() to see if there were any errors - nope. I tried adding the PHP functions to another plugin of mine - nope. What am I missing that jQuery isn't doing the ajax bit for me? Thanks in advance
Put those <code> add_action </code> functions in your <code> functions.php </code> file too. If they're in <code> header.php </code> , WordPress never registers them since header isn't loaded in AJAX. Also, you don't need that <code> is_admin() </code> check. The theme's header will never load in admin. So, your functions file should look like this: <code> add_action('wp_ajax_my_special_action', 'my_action_callback'); add_action('wp_ajax_nopriv_my_special_action', 'my_action_callback'); function my_action_callback() { $whatever = $_POST['whatever']; $whatever += 10; echo 'whatever now equals: ' . $whatever; die(); } </code> And the beginning of that part of your theme's header file should look like this: <code> &lt;?php $_ajax = admin_url('admin-ajax.php'); ?&gt; &lt;script type="text/javascript" &gt; jQuery(document).ready(function($) { </code> Other than that, your code looks like it's good to go!
How to get Ajax into a theme - without writing a plugin?
wordpress
I've been looking into the feasibility of using something like Amazon Web Services for hosting WordPress sites. I was wondering if it was possible and if so what are people's experiences of having done so and what aspects of AWS did you use?
You explicitly mention three services in your question title: EC2, RDS and EBS. If they're the three services you're interested in, then yes, very easily. EC2 + EBS are pretty much the same thing, EBS is simply a persistent storage extension to EC2, and RDS is a full MySQL database - you should be able to get those three services running together very easily. If you were looking to extend to some of the other AWS products, S3 is very easy to implement on WordPress for file uploads - check some of these plugins. SimpleDB, however, has very limited usefulness to us without a rewrite of how WordPress reads and writes to the database. There is an article by Amazon on how to create a plugin which adds tagging functionality that uses SimpleDB as the storage, but that is as much as I could find regarding the use of SimpleDB with WordPress.
Can you host WordPress using Amazon Web Services such as EC2, RDS, EBS etc?
wordpress
How much should I charge for creating a custom WordPress plugin? (working as a freelancer)
The short version: Figure out how much it costs you to eat, go to movies, pay utilities, pay taxes, etc., each month . Divide that by the number of working hours in a month. Congratulations, that's your minimum hourly rate. Get the specs in writing, as detailed as possible. Then figure out how long it will take you to develop, test, and implement the plugin as per the specs. Multiply the number of hours the project will take you times the money you need to live. That's how much you need to charge for your project. At minimum. Get the specs in writing, and don't deviate from them unless your time suddenly is no longer valuable to you or you decide you don't need to eat. Put in writing that deviations from the specs (feature creep) will cost $X per hour additional, where $X is your hourly rate. Keep in mind that if you're freelancing for a living, you will not have work 100% of the time, so your hourly rate will need to encompass the amount of time it takes you to find more work and close a sale. So if you're doing this for a living, go back to the first paragraph and add in the average amount of time it will take you to find work and close a contract, then add that to your hourly rate. That's why many freelancers and contractors will charge less for regular clients or for retainers; they can afford to because they don't have to spend extra time finding the work and negotiating the fees. Also note that there are other people who will charge less than you. If you enjoy your current standard of living, do not compete on price, compete on quality and reputation. So let other people charge less, and make sure your work is good and that you meet deadlines.
How much should I charge for creating a WordPress plugin?
wordpress
I'd like to add some descriptive text underneath the page title on both the list and edit post screens for the default post and also custom post types - e.g. "Below is a list of your recent blog posts." What's the best way to do this?
If you are OK with using javascript, you can try the following in your <code> functions.php </code> file: <code> add_action('admin_footer', 'my_admin_footer'); function my_admin_footer() { $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL ; $message = NULL; if ($uri AND strpos($uri,'edit.php')) { if (strpos($uri,'post_type=page')) { $message = 'My custom message for page list'; } else { $message = 'My custom message for post list'; } } elseif ($uri AND strpos($uri,'post-new.php')) { if (strpos($uri,'post_type=page')) { $message = 'My custom message for add/edit page'; } else { $message = 'My custom message for add/edit post'; } } elseif ($uri AND strpos($uri,'post.php')) { $message = 'My custom message for add/edit post or page'; } if ($message) { ?&gt;&lt;script&gt; jQuery(function($) { $('&lt;div style="margin-bottom:15px; color:#999;"&gt;&lt;/div&gt;').text('&lt;?php echo $message; ?&gt;').insertAfter('#wpbody-content .wrap h2:eq(0)'); }); &lt;/script&gt;&lt;?php } } </code>
Add text to post list/edit screens?
wordpress
I visit http://ltty.wordpress.com/ and want to know the theme name (so that I can use :) for my blog). How can I get it?
This method isn't always fireproof, but you can often look at the source code (right click on white space in the blog), and look for the word "themes." For instance, in the case of ltty.wordpress.com, this line appears: <code> &lt;link rel="stylesheet" href="http://s2.wp.com/wp-content/themes/pub/inove/style.css?m=1285721595g" type="text/css" media="screen" /&gt; </code> The theme is "inove." A quick Google Search reveals this source: http://wordpress.org/extend/themes/inove
How to know the theme name of a wordpress blog?
wordpress
I would like to change the markup created by [gallery] from what is it as standard (dl) to a unordered-list with a difference. Below is the desired markup: <code> &lt;ul&gt; &lt;li&gt;&lt;a href="/path/to/image.jpg"&gt;&lt;img src="/path/to/image.jpg" /&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/path/to/image2.jpg"&gt;&lt;img src="/path/to/image2.jpg" /&gt;&lt;/a&gt;&lt;/li&gt; &lt;!-- And so on, all in one ul --&gt; &lt;/ul&gt; </code> I want the main image source for the link &amp; img, as I want to run the img src through a php cropper script. Is this possible? I'm sure we can crack it!
Thanks for your replies, Jan &amp; Rarst. They pointed me in the right direction. Here's what I ended up with. This disables shortcodes in the content. Perfect for this site &amp; the function gets attached images &amp; spits them out as a list. (I found the function somewhere &amp; slimmed it down a little) <code> // Removed shortcodes from the content add_filter('the_content', 'strip_shortcodes'); // Get attached images &amp; spits out a list of them. function nerdy_get_images($size = 'thumbnail', $limit = '0', $offset = '0') { global $post; $images = get_children( array('post_parent' =&gt; $post-&gt;ID, 'post_status' =&gt; 'inherit', 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'order' =&gt; 'ASC', 'orderby' =&gt; 'menu_order ID') ); if ($images) { $num_of_images = count($images); if ($offset &gt; 0) : $start = $offset--; else : $start = 0; endif; if ($limit &gt; 0) : $stop = $limit+$start; else : $stop = $num_of_images; endif; $i = 0; foreach ($images as $image) { if ($start &lt;= $i and $i &lt; $stop) { $img_title = $image-&gt;post_title; // title. $img_description = $image-&gt;post_content; // description. $img_caption = $image-&gt;post_excerpt; // caption. $img_url = wp_get_attachment_url($image-&gt;ID); // url of the full size image. $preview_array = image_downsize( $image-&gt;ID, $size ); $img_preview = $preview_array[0]; // thumbnail or medium image to use for preview. ?&gt; &lt;li&gt; &lt;a href="&lt;?php echo $img_url; ?&gt;"&gt;&lt;img src="&lt;?php echo $img_preview; ?&gt;" alt="&lt;?php echo $img_caption; ?&gt;" title="&lt;?php echo $img_title; ?&gt;"&gt;&lt;/a&gt; &lt;/li&gt; &lt;? } $i++; } } } </code> This is the call in single.php <code> &lt;ul&gt; &lt;?php nerdy_get_images('medium','0','0'); ?&gt; &lt;/ul&gt; </code> This spits out a list exactly how I wanted it. Once again, thanks guys!
How can I alter the [gallery] markup?
wordpress
I am building a site in WordPress. It has multiple subpages, many of which require different sidebars. So, I have a widgetized theme and I have also created a few sidebar widgets. I have written a conditional statement to show different sidebars on different pages. However, one widgetized sidebar displays on almost all pages despite the conditional statement. The sidebar that is appearing on the desired page can be seen here: http://www.africanhealthleadership.org/about/approach/ The subpage that should have a different sidebar is under Knowledge Resources> Research The code is as follows. I am a total PHP spazz, so I likely did something silly. I have tried single quotes around dynamic_sidebar(2) but that did not work. Thank you for any help. <code> &lt;?php if ( is_subpage('approach') ) { if (!function_exists ( dynamic_sidebar(1) ) ) ; } elseif ( is_subpage('research')) { if (!function_exists( dynamic_sidebar(2)) || !dynamic_sidebar( "Sidebar2") ); } ?&gt; </code>
More easy &amp; elegant (higher maintainability): <code> &lt;?php // Your sidebar should have the wp_meta action hook wp_meta(); // in ex. your functions.php function my_sidebar_content() { // "About" Page if ( is_page('about') ) { // If some widget is added via Admin &gt; Design &gt; Widgets if ( is_active_sidebar( 'widgets-sidebar-default' ) ) { // Display Widgets dynamic_sidebar( 'widgets-sidebar-default' ); } // Default Content before Widgets were added else { _e('default static content', TEXTDOMAIN); } } // "Links" Page elseif ( is_page('links') ) { if ( is_active_sidebar( 'widgets-sidebar-links' ) ) { dynamic_sidebar( 'widgets-sidebar-links' ); } else { _e('default static content', TEXTDOMAIN); } } } add_action( 'wp_meta', 'my_sidebar_content', 10 ); # =================================================== // OR: wp_meta(); // functions.php function load_my_sidebars() { // "About" Page if ( is_page('about') ) { get_template_part( 'sidebar_content', 'default' ); } // "Links" Page elseif ( is_page('links') ) { get_template_part( 'sidebar_content', 'links' ); } } add_action( 'wp_meta', 'load_my_sidebars', 10 ); // in sidebar_content-default.php // If some widget is added via Admin &gt; Design &gt; Widgets // You can add any static content right here before the widgets if ( is_active_sidebar( 'widgets-sidebar-default' ) ) { // Display Widgets dynamic_sidebar( 'widgets-sidebar-default' ); } // Default Content before Widgets were added else { _e('default static content', TEXTDOMAIN); } // You can add any static content right here after the widgets // in sidebar_content-links.php if ( is_active_sidebar( 'widgets-sidebar-links' ) ) { dynamic_sidebar( 'widgets-sidebar-links' ); } else { _e('default static content', TEXTDOMAIN); } ?&gt; </code>
Dynamic Sidebars On Multiple Subpages
wordpress
I am looking for a way to remove all the unessesary text from default worpdress metaboxes. Preferably I would like to ensure that the content is not just hidden through CSS but actually removed from the HTML so it does not even show up in the source. The areas I am interested in removing include: The HELP button on the top right and associating DIV/HTML/text when you click on it On the Dashboard in the Right Now Metabox I want to remove the text related to which theme is being used and the version of wordpress as well as the change theme button. On the "Page Attributes" metabox on the bottom it has the text "Need help? Use the Help tab in the upper right of your screen." I would like for this text to be removed Under the "Excerpt Metabox" there is text which I would like to remove Any other text which you might also know how to remove to cleanup wordpress.
Hi @NetConstructor : Here's an answer to question #1. Not enough time right now to do the rest. 1.) Removing Admin Help Link Button Unfortunately WordPress doesn't provide a hook to let you affect the Help Button on the top right of the admin, but you can use a somewhat dirty hack to achieve what you are trying to accomplish. Now you See It: Now you Don't: By calling the <code> contextual_help </code> and <code> admin_notices </code> hooks, the ones that are called immediately before and immediately after when the help link button is output, respectively, you can capture the output buffer and remove the offending HTML using <code> preg_replace() </code> . The <code> ob_start() </code> / <code> ob_get_clean() </code> pair of functions in PHP are what you need to buffer output and then to capture that buffered output, viola: <code> class RemoveAdminHelpLinkButton { static function on_load() { add_filter('contextual_help',array(__CLASS__,'contextual_help')); add_action('admin_notices',array(__CLASS__,'admin_notices')); } static function contextual_help($contextual_help) { ob_start(); return $contextual_help; } static function admin_notices() { echo preg_replace('#&lt;div id="contextual-help-link-wrap".*&gt;.*&lt;/div&gt;#Us','',ob_get_clean()); } } RemoveAdminHelpLinkButton::on_load(); </code> In general you can use this technique to modify or delete almost any HTML output generated by WordPress by finding the before and after hooks but be aware that it is a very fragile technique; if another plugin has modified the HTML output from what you were expecting your <code> preg_replace() </code> could fail to match. Anyway... 3.) Removing Help Text from Page Attributes Metabox To remove the help text for the Page Attributes metabox doesn't require regular expressions, a simple <code> str_replace() </code> will do. (Note finding the right hooks to use took the most time.) : <code> class RemovePageAttributesHelpText { static function on_load() { add_action('admin_notices',array(__CLASS__,'admin_notices')); add_action('dbx_post_sidebar',array(__CLASS__,'dbx_post_sidebar')); } static function admin_notices() { ob_start(); } static function dbx_post_sidebar() { $match_text = '&lt;p&gt;Need help? Use the Help tab in the upper right of your screen.&lt;/p&gt;'; echo str_replace($match_text,'',ob_get_clean()); } } RemovePageAttributesHelpText::on_load(); </code> There's also another approach you can use when all you want to do it remove text from core and that's to use the <code> 'gettext' </code> hook. The following code removes the help text from the Page Attributes metabox: <code> class RemovePageAttributesHelpText { static function on_load() { add_filter('gettext',array(__CLASS__,'gettext'),10,4); } function gettext($translation, $text, $domain) { if ($text=='Need help? Use the Help tab in the upper right of your screen.') { $translation = ''; } return $translation; } } RemovePageAttributesHelpText::on_load(); </code> Note that I'm cautious to use this hook as it gets called hundreds of times per page load; 577 times just to load the Admin Dashboard in case I just tested, for example. So if you use it be sure not to do anything that is computationally "expensive" such as running a raw SQL query or similar. 4.) Removing Text from the "Excerpt Metabox" We'll use option #2 from technique #3 to strip the help text from the Excerpt Metabox (this one I included the code from technique #3 so this one replaces the code in #3) : <code> class RemoveUnwantedPageEditingText { static function on_load() { add_action('admin_notices',array(__CLASS__,'admin_notices')); add_action('dbx_post_sidebar',array(__CLASS__,'dbx_post_sidebar')); } static function admin_notices() { ob_start(); } static function dbx_post_sidebar() { $html = str_replace('&lt;p&gt;Need help? Use the Help tab in the upper right of your screen.&lt;/p&gt;','',ob_get_clean()); echo str_replace('Excerpts are optional hand-crafted summaries of your content that can be used in your theme.' . ' &lt;a href="http://codex.wordpress.org/Excerpt" target="_blank"&gt;Learn more about manual excerpts.&lt;/a&gt;','',$html); } } RemoveUnwantedPageEditingText::on_load(); </code>
Removing Unnecessary Text from Admin Menu without CSS
wordpress
I have a function that returns an array os posts ids. At the moment, everytime i have a query i have to to this: $ids = agendados(); query_posts(array('post__not_in' => $ids ); Is there a way to maintain the array by calling that on header.php and use this array everytime a do a query_posts? I think that doing on my way its a overload of querys.. Thanks m8s Sorry about my poor english www.zarpa.eu
I don't like using categories for this, as they are supposed to be semantic terms. I do, however, like the idea of the global array. Instead of creating a new query directly, I will filter it through a function that will add the results to a global array and return the results: I add this to functions.php: <code> function nt_globals($args){ global $used; $defaults = array( 'post__not_in' =&gt; $used, ); $query = wp_parse_args( $args, $defaults ); $queryObject = new WP_Query($query); foreach ($queryObject-&gt;posts as $item): $used[] = $item-&gt;ID; endforeach; return $queryObject; } </code> Then I call the function whenever I want a query: <code> $queryObject = nt_globals('posts_per_page=1'); while ($queryObject-&gt;have_posts()): $queryObject-&gt;the_post(); the_title(); endwhile; </code>
Always using the same ARRAY on different querys
wordpress
I'm not sure if I'm blind here, but short of digging directly into the database tables, where would I find the database id for a post or a page?
IDs always show in links in admin area, like /wp-admin/post.php?post= 2164 &amp;action=edit There are also some plugins that simplify this, quick search came up with Simply Show IDs .
Finding the page id
wordpress
For the life of me I cannot seem to get categories to come into existence with my custom post type. I've added the following &mdash; simple &mdash; code to the bottom of my theme's <code> functions.php </code> file, yet see no categories in my custom post from the admin side. <code> register_post_type("customy", array( 'label' =&gt; 'Customy', 'description' =&gt; 'Custom stuff for this site.', 'public' =&gt; true, 'hierarchical' =&gt; true, 'supports' =&gt; array('title', 'editor', 'author', 'thumbnail', 'revisions'), 'taxonomies' =&gt; array('category') )); register_taxonomy_for_object_type('category', 'customy'); </code>
It appears that although <code> register_post_type() </code> will add the new <code> post_type </code> immediately, it seems as though you need to bind up the logic into a function, and add it to the <code> init </code> action for the categories taxonomy to be associated with the <code> post_type </code> . A working example follows: <code> function add_articles_post_type() { register_post_type("article", array( 'label' =&gt; 'Article', 'public' =&gt; true, 'hierarchical' =&gt; true, 'supports' =&gt; array('title','editor','author','thumbnail','revisions') )); register_taxonomy_for_object_type('category', 'article'); } add_action('init', 'add_articles_post_type'); </code>
Custom Post Types and Categories?
wordpress
On creation of a custom post type I'm trying to define capabilities but it's not working. What's wrong with this code? <code> $args = array( 'labels' =&gt; $labels, 'public' =&gt; true, 'publicly_queryable' =&gt; true, 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; true, 'hierarchical' =&gt; false, 'menu_position' =&gt; null, 'supports' =&gt; array('title'), 'capabilities' =&gt; array( 'edit_post' =&gt; 'edit_video', 'edit_posts' =&gt; 'edit_videos', 'edit_others_posts' =&gt; 'edit_others_videos', 'publish_posts' =&gt; 'publish_videos', 'read_post' =&gt; 'read_videos', 'read_private_posts' =&gt; 'read_private_videos', 'delete_post' =&gt; 'delete_videos' ) ); </code>
You code seems to be correct. Try the following instead. <code> $args = array( 'labels' =&gt; $labels, 'public' =&gt; true, 'publicly_queryable' =&gt; true, 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; true, 'hierarchical' =&gt; false, 'menu_position' =&gt; null, 'supports' =&gt; array('title'), 'capability_type' =&gt; 'video' ); </code> Update: You have to do some extra steps before making it work with the members plugin. See this forum post from Justin Tadlock (developer of the members plugin). http://wordpress.org/support/topic/anyone-managed-to-get-custom-post-types-capabilities-working/page/2#post-1593534 This plugin seems to be doing it automatically: http://wordpress.org/extend/plugins/map-cap/
Defining capabilities for custom post type
wordpress
I'm looking for a plugin that enables sharing an article on sites like Facebook, Twitter and LinkeIn. One catch is that I want a plugin that respect the privacy of the user and doesn't include trackware/spyware on the page. Can anyone recommend a good plugin for this? Thank you!
Sociable adds sharing links for any social network sites you want (configurable). To my knowledge, it doesn't add any trackware on the page (I have yet to see an officially hosted plugin do that).
Plugin for sharing on social sites?
wordpress
I'm able to easily include my custom post types into my main loop by making small adjustments with <code> query_posts() </code> , but I'm not sure how I would go about including custom post types in the "Recent Posts" sidebar widget (or any of the other widgets, for that matter). How should I go about expanding "Recent Posts" scope to include more than just the native post type?
You'll have to edit the code for the Recent Posts widget or create your own version based on the default. The code is in the <code> wp-includes/default-widgets.php </code> file around line 513. But since you should never make modifications to core, my recommendation would be to copy the code to create your own My Custom Recent Posts widget and use that on your site. Just drop the new widget class into your theme's <code> functions.php </code> file or use it in a plugin. The only real modification you need to make are to the widget's class name and encapuslated functions and options (so that there aren't any naming conflicts with the original Recent Posts widget. After that, you'll need to edit the call to <code> WP_Query </code> in the <code> widget() </code> constructor so that it includes your custom post type. For this example, I've set <code> post_type </code> equal to <code> array('post, 'page', 'custom-post-type') </code> ... you'll need to modify that to fit your specific use case. Here's the widget's full code for reference: <code> /** * My_Custom_Recent_Posts widget class * */ class WP_Widget_My_Custom_Recent_Posts extends WP_Widget { function WP_Widget_My_Custom_Recent_Posts() { $widget_ops = array('classname' =&gt; 'widget_my_custom_recent_entries', 'description' =&gt; __( "The most recent posts on your site") ); $this-&gt;WP_Widget('my-custom-recent-posts', __('My Custom Recent Posts'), $widget_ops); $this-&gt;alt_option_name = 'widget_my_custom_recent_entries'; add_action( 'save_post', array(&amp;$this, 'flush_widget_cache') ); add_action( 'deleted_post', array(&amp;$this, 'flush_widget_cache') ); add_action( 'switch_theme', array(&amp;$this, 'flush_widget_cache') ); } function widget($args, $instance) { $cache = wp_cache_get('widget_my_custom_recent_posts', 'widget'); if ( !is_array($cache) ) $cache = array(); if ( isset($cache[$args['widget_id']]) ) { echo $cache[$args['widget_id']]; return; } ob_start(); extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('My Custom Recent Posts') : $instance['title'], $instance, $this-&gt;id_base); if ( !$number = (int) $instance['number'] ) $number = 10; else if ( $number &lt; 1 ) $number = 1; else if ( $number &gt; 15 ) $number = 15; $r = new WP_Query(array('showposts' =&gt; $number, 'nopaging' =&gt; 0, 'post_status' =&gt; 'publish', 'ignore_sticky_posts' =&gt; true, 'post_type' =&gt; array('post', 'page', 'custom-post-type'))); if ($r-&gt;have_posts()) : ?&gt; &lt;?php echo $before_widget; ?&gt; &lt;?php if ( $title ) echo $before_title . $title . $after_title; ?&gt; &lt;ul&gt; &lt;?php while ($r-&gt;have_posts()) : $r-&gt;the_post(); ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" title="&lt;?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?&gt;"&gt;&lt;?php if ( get_the_title() ) the_title(); else the_ID(); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php endwhile; ?&gt; &lt;/ul&gt; &lt;?php echo $after_widget; ?&gt; &lt;?php // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); endif; $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('widget_my_custom_recent_posts', $cache, 'widget'); } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['number'] = (int) $new_instance['number']; $this-&gt;flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset($alloptions['widget_my_custom_recent_entries']) ) delete_option('widget_my_custom_recent_entries'); return $instance; } function flush_widget_cache() { wp_cache_delete('widget_my_custom_recent_posts', 'widget'); } function form( $instance ) { $title = isset($instance['title']) ? esc_attr($instance['title']) : ''; if ( !isset($instance['number']) || !$number = (int) $instance['number'] ) $number = 5; ?&gt; &lt;p&gt;&lt;label for="&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;"&gt;&lt;?php _e('Title:'); ?&gt;&lt;/label&gt; &lt;input class="widefat" id="&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('title'); ?&gt;" type="text" value="&lt;?php echo $title; ?&gt;" /&gt;&lt;/p&gt; &lt;p&gt;&lt;label for="&lt;?php echo $this-&gt;get_field_id('number'); ?&gt;"&gt;&lt;?php _e('Number of posts to show:'); ?&gt;&lt;/label&gt; &lt;input id="&lt;?php echo $this-&gt;get_field_id('number'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('number'); ?&gt;" type="text" value="&lt;?php echo $number; ?&gt;" size="3" /&gt;&lt;/p&gt; &lt;?php } } </code>
Including Custom Post Types in "Recent Posts" Widget
wordpress
I need to create a simple widget that has a text input field. I need the widget to create the markup below... <code> &lt;div class="textwidget"&gt; &lt;div class="avatar"&gt; &lt;div class="avatartext"&gt; &lt;p&gt;CONTENTS OF THE TEXT INPUT HERE&lt;/p&gt; &lt;/div&gt; &lt;div class="avatarimage"&gt;&lt;/div&gt; &lt;/div&gt; </code> I've started the process of stubbing out the widget with the code below. I'm just not shure how to code the my_avatar() function... <code> function my_avatar() { //Widget markup goes here. How to pull the widget text entry? } register_activation_hook(__FILE__, 'my_avatar'); class My_Widget_Avatar extends WP_Widget { function My_Widget_Avatar() { $widget_ops = array( 'classname' =&gt; 'widget_avatar', 'description' =&gt; __( "My Avatar Widget" ) ); $this-&gt;WP_Widget('my_avatar', __('My Avatar'), $widget_ops); } } add_action('widgets_init', create_function('', "register_widget('My_Widget_Avatar');")); </code>
Complete code: <code> class My_Widget_Avatar extends WP_Widget { function My_Widget_Avatar() { $widget_ops = array( 'classname' =&gt; 'widget_avatar', 'description' =&gt; __( "My Avatar Widget" ) ); $this-&gt;WP_Widget('my_avatar', __('My Avatar'), $widget_ops); } function widget( $args, $instance ) { extract($args); $text = apply_filters( 'widget_text', $instance['text'], $instance ); echo $before_widget; ?&gt; &lt;div class="textwidget"&gt; &lt;div class="avatar"&gt; &lt;div class="avatartext"&gt; &lt;p&gt;&lt;?php echo $text; ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="avatarimage"&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php echo $after_widget; } function update( $new_instance, $old_instance ) { $instance = $old_instance; if ( current_user_can('unfiltered_html') ) $instance['text'] = $new_instance['text']; else $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed return $instance; } function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'text' =&gt; '' ) ); $text = format_to_edit($instance['text']); ?&gt; &lt;textarea class="widefat" rows="16" cols="20" id="&lt;?php echo $this-&gt;get_field_id('text'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('text'); ?&gt;"&gt;&lt;?php echo $text; ?&gt;&lt;/textarea&gt; &lt;?php } } function lbi_widgets_init() { register_widget( 'My_Widget_Avatar' ); } add_action( 'widgets_init', 'lbi_widgets_init' ); </code>
Create a widget that allows text input
wordpress
WordPress.com has a rather cool feature when you add comments. The two features are: <code> [x] Notify me of follow-up comments via email. [x] Notify me of new posts via email. </code> Is this plugin available somewhere so that I can include it on my privately hosted blog?
http://wordpress.org/extend/plugins/gurken-subscribe-to-comments/ http://wordpress.org/extend/plugins/subscribe2/
Plugin from WordPress.com for comment notification...available?
wordpress
I've tried both Yoast Breadcrumbs and Breadcrumbs NavXT and I can't seem to get either to work with custom post types. Anyone had any luck with this? A single 'News' post on my site displays: Home -> Blog -> My News Post Instead of correctly displaying: Home -> News -> My News Post
Breadcrumb NavXT has Custom Post Type support since 3.6.0. You might encounter some options problem. Please try to reset them or take a look on the development version. Backup your settings first with the export / import settings feature.
Breadcrumbs with Custom Post Types?
wordpress
I am new to wordpress. I am trying to build a custon website based on it. I know some php and quite good html \ css \ js. I wanted to know if it's possible to set a uinque theme for different pages? Thank you!
Yes, it is possible with page templates. See - Codex : Page Templates Codex : Creating Your Own Page Templates
How to set a unique WordPress theme for different pages?
wordpress
How can I change the page that the 'view' action links to on the list post screen for a custom post type? Update I've got it to work with normal post types using the below code but where do I define the custom post type? <code> function change_link($post_url,$post) { return '/video?id='.$post-&gt;ID; } add_filter('post_link',"change_link",10,2); </code>
By adding a filter to the <code> 'post_link' </code> hook . See the <code> get_permalink() </code> function for more info. For custom post types, you can use the <code> 'post_type_link' </code> hook . It's a lot easier if you follow the source code (this is for v3.0): http://core.trac.wordpress.org/browser/branches/3.0/wp-includes/link-template.php#L166
Changing 'view' link for custom post type on list post screen?
wordpress
For one of my custom post types I want a specific user to be able to edit existing posts created by admin but not be able to Add New posts. How can this be done? If I define the user role as not being able to Publish it still allows them to add a new post and submit for review.
You will have to do something like this: <code> function hide_buttons() { global $current_screen; if($current_screen-&gt;id == 'edit-post' &amp;&amp; !current_user_can('publish_posts')) { echo '&lt;style&gt;.add-new-h2{display: none;}&lt;/style&gt;'; } } add_action('admin_head','hide_buttons'); </code> See: http://erisds.co.uk/wordpress/spotlight-wordpress-admin-menu-remove-add-new-pages-or-posts-link for reference
Allow user to Edit Posts but not Add New?
wordpress
I have a custom post type ('post' capabilities) called EVENTS and a custom taxonomy called VENUES (hierarchical). I want to be able to set the post's url to domain.com/my-events/%TAXONOMY%/%POST-TYPE% kind of like category/post-name, but it doesn't seem to work, the URL always render the %TAXONOMY% bit as is leaving the % signs.. Any ideas? ps. @John P Bloch, I'm using your plugin.
My plugin will be adding this functionality in the next release (in beta now). If you want, you can download the beta at http://www.johnpbloch.com/custom-post-permalinks.zip There are still known bugs in that beta version, though. I don't have the time to give you a proper answer on here at the moment (it's a pretty complicated fix); we'll see if I release the new version before I get around to it... ;) EDIT My plugin is now in its release candidate phase. If there are no more bugs found by Thursday morning, I'll release it. I don't anticipate this happening, though. You can find the release candidate at the same url as above. I think that should solve your problem. Taxonomy tags are the taxonomy's name (as registered. This may be different from the label).
rewrite rules for custom post-type with a custom taxonomy
wordpress
How do you know when to add your action to init or wp_head. In particular with regards to scripts and styles, but also any other action.
From Codex Action Reference: <code> init </code> Runs after WordPress has finished loading but before any headers are sent. Useful for intercepting $_GET or $_POST triggers. <code> wp_head </code> Runs when the template calls the wp_head function. This hook is generally placed near the top of a page template between &lt;head> and &lt;/head> . This hook does not take any parameters. Basically <code> wp_head </code> runs when page is already being loaded, while <code> init </code> runs before that. Also don't forget that <code> init </code> fires on admin pages as well and anything front-end related must be excluded from there with <code> !is_admin() </code> check.
when should an action be added to init and when should it be added to wp_head
wordpress
I've created a custom post type called <code> video </code> and I'm using a plugin called <code> Playlist_Order </code> (which changes the <code> menu_order </code> field) to allow the user to use a drag and drop interface to order their videos in a playlist. However, when adding a new post the video appears at the top of the playlist because it's given a default <code> menu_order </code> value of <code> 0 </code> . On creation of a new video post I would like it to appear last in the playlist - i.e. query all <code> video </code> post types, find the largest <code> menu_order </code> value and then set this <code> +1 </code> for the new post. How can I implement this?
Hi @fxfuture : I think what you are looking for is the <code> wp_insert_post_data </code> hook. You can add this code to the bottom of your theme's <code> functions.php </code> file and/or you can add it to a plugin: <code> add_filter('wp_insert_post_data','my_wp_insert_post_data',10,2); function my_wp_insert_post_data($data, $postarr) { $post_type = 'video'; if ($data['post_type']==$post_type &amp;&amp; get_post($postarr['ID'])-&gt;post_status=='draft') { global $wpdb; $data['menu_order'] = $wpdb-&gt;get_var("SELECT MAX(menu_order)+1 AS menu_order FROM {$wpdb-&gt;posts} WHERE post_type='{$post_type}'"); } return $data; } </code>
Define menu_order on Creation of New Custom Post?
wordpress
I am trying to speed up a wordpress site by condensing three wp_queries into one. I have a need to seperate categories, so I am making the call and defining 3 arrays to hold the post using a switch, like so: <code> $new_query = new WP_Query(); $new_query-&gt;query('post_type=post&amp;paged='.$paged); if ( $new_query-&gt;have_posts() ) : while ( $new_query-&gt;have_posts() ) : $new_query-&gt;the_post(); $category = choose_one_category(get_the_category()); switch ($category){ case "Category 1": $cat1[] = $post; break; case "Category 2": $cat2[] = $post; break; case "Category 3": $cat3[] = $post; break; } endwhile; endif; </code> which leaves me with 3 arrays which with the posts nicely sorted. Now I wish to define the variable $post OUTSIDE the loop so that I can use methods like <code> the_date() </code> &amp; <code> comments_number() </code> without having to rewrite those functions, can anyone help? I have tried: <code> foreach ($centre as $new_post){ $post = $new_post; include('front_page_loop.php'); } </code> Where <code> front_page_loop.php </code> is my loop code, but I just get the same post, albeit with different dates
I think <code> setup_postdata($post) </code> (internal) function does that. I failed to find proper documentation for it in Codex (typical), but there are examples with it here and there like in Displaying Posts Using a Custom Select Query . This test snippet seems to work fine for example code you have in question: <code> foreach ( $cat1 as $post ) { setup_postdata($post); printf( 'Post "%s" was posted %s ago&lt;br /&gt;', get_the_title(), human_time_diff( strtotime( get_the_date() ) ) ); } </code>
Is there a way to define the $post var outside the loop?
wordpress
I have defined a custom post type that uses a meta field to store dates. In my functions.php I have the following code which saves the start date. The format of the date that is sent in the <code> startdate </code> form parameter is <code> 2010/12/01 9:00 AM </code> <code> add_action('save_post', 'save_details'); function save_details(){ global $post; update_post_meta($post-&gt;ID, "startdate", $_POST["startdate"]); } </code> I am trying to output a list of all the events with a <code> startdate </code> later than the current time. <code> query_posts(array( 'post_type' =&gt; array('seminar'), 'meta_key=startdate', 'meta_value='.date("Y/m/d h:i A"), 'meta_compare=&gt;' )); </code> This lists out all the events regardless of their start date. What am I doing wrong? SOLVED: For some reason after I changed my code to the following, it just works. <code> $args = array( 'post_type' =&gt; array('seminar'), 'showposts' =&gt; 3, 'meta_key' =&gt; 'startdate', 'meta_value' =&gt; date("Y/m/d h:i A"), 'meta_compare' =&gt; '&gt;', 'orderby' =&gt; 'meta_value', 'order' =&gt; 'ASC' ); $seminars = get_posts($args); </code> I am going to select the answer from @Rarst as the accepted one, because I think I actually had multiple issues going on here, but his addressed the issue related to the title best. @sorich87 had a good point about how I should have been storing the dates as timestamps, but in the end, @Rarst was correct that if I specified a format argument to the <code> date() </code> function which matches the format I used when storing the data into the database, then I should be able to compare the data. Thanks for all the help.
You store date as formatted string, but <code> time() </code> function you take for comparison returns numeric timestamp. So you are trying to make comparison between too completely different formats and it's unlikely WP is smart enough to get that.
How to use query_posts() with a date filter on a custom field?
wordpress
Assuming you have a shared hosting account that enables multiple MySQL databases and multiple domain pointers. How many standard WP-installed websites can it hold without problem? (let's say each website gets around 1000-2000 visitors a day) If this depends on who is the hosting provider, please refer to whom is the one you are speaking of (which will enable the creation of some basic range). motivation: I recently asked a hosting provider to downgrade an account from VPS to share hosting, and they said it was not possible because of the number of websites and number of uniques (the installs are standard). I wish to understand if they are being greedy or just.
Number of installs is not determined by WordPress, it is determined purely by hosting resources and policies. From personal experience even one blog with 1k daily visits can border overusing CPU quotas on crappy shared hosting with overstuffed server. If you want to force this through - request specific resource usage policies and hard numbers on what server load your setup generates.
How many WP websites can go on one shared hosting account?
wordpress
By looking at the source of any of the WordPress pages on my site, I can see there is this stylesheet link: <code> &lt;link rel='stylesheet' id='adoptStyles-css' href='http://mydomain.com/wp-content/plugins//adopt_styles.css?ver=2.9.1' type='text/css' media='all' /&gt; </code> The link is broken - the URL is not served by my WordPress. (the double slash is not the source of the problem) Has anyone seen this before? Where does this link come from? How to remove it/determine the plugin that is adding it?
File with this name comes up in search as part of Adsense Optimizer plugin ( SVN ). Curiously I don't see stylesheet actually being queued in code... Are you using this plugin? Up to date version?
Why is adoptStyles-css stylesheet link added to every page?
wordpress
I have two custom post meta objects that have been applied to all pages and posts in my sites. The names are MyCustomHeader and MyCustomTitle and I have one of these assigned to each post and page in my site. I've just decided to change the names of these two meta objects so that they do not appear in the Custom Fields fieldset. I've done this by placing an underscore character before them. This changes the values to "_MyCustomHeader" and "_MyCustomTitle". In order to account for the sites that have numerous references to the old post meta names, I need to create a routine that runs once (either in the form of a plugin or a script in my theme options that only executes on theme activation) that goes through the WP database and converts every value that was "MyCustomHeader to "_MyCustomHeader" and also "MyCustomTitle" to "_MyCustomTitle". Any help much appreciated. scott
You can run the following sql queries: <code> update wp_postmeta set meta_key=replace(meta_key,'MyCustomHeader','_MyCustomHeader') where meta_key like "MyCustomHeader"; update wp_postmeta set meta_key=replace(meta_key,'MyCustomTitle','_MyCustomTitle') where meta_key like "MyCustomTitle"; </code>
Routine to convert custom post meta from old to new value
wordpress
How would I display html code in only the first level of threaded comments? Example L1 Comment ----L2 Comment --------L3 Comment L1 Comment I have a piece of html code that contains basically reads "Reply to (author name) or post a new comment" and only need it displayed on L1 comments.
You can do this in the comments loop: <code> if( empty( $comment-&gt;comment_parent ) ) { //if the comment does not have a parent, then it is L1 echo 'my-custom-html'; } </code>
How to display html in only the first level of WP comments?
wordpress
What's the difference between marking a comment as spam and trashing it?
In vanilla WordPress the only difference is that trashed comments get deleted automatically after (customizable) time span . Adding plugins to the picture - it might make difference to what/how specific plugin learns from incoming spam.
Comment Spammed vs Trashed
wordpress
When I navigate to... Appearance > Editor > Edit Themes The default file that gets loaded there is my options.css file (which I don't want anyone editing since it styles my theme options panel, not the theme itself.) How can I specify which file gets loaded there? Ideally, I'd like for my theme's current stylesheet to be loaded there. Is there a way that I can specify this in script from functions.php?
Looking at <code> theme-editor.php </code> code it calls <code> get_themes() </code> (fills global <code> $wp_themes </code> variable with themes, including full lists of theme files) and then simply picks first file out of files from current theme. It jumps to CSS because PHP and CSS files are stored separately and when arrays merge CSS comes on top. So you can just rename your file so it isn't first in list. More complex way would be to hook and run <code> get_themes() </code> earlier and then manually rearrange files in <code> $wp_themes </code> . I am not good with admin area, have trouble finding fitting hook to run it conditionally on editor page alone.
How can I tell WP which file to load by default in Appearance > Editor?
wordpress
The code below is contained in a plugin file. It just seeks to execute an update query against the wp database. However, its generating a fatal error. <code> Fatal error: Cannot redeclare ce3_cleanup() </code> Do I need to load a config file to get acess to $wpdb-> query? <code> function ce3_cleanup() { $wpdb-&gt;query("update wp_postmeta set meta_key=replace(meta_key,'cb2_customHeader','_cb2_customHeader') where meta_key like 'cb2_customHeader'"); $wpdb-&gt;query("update wp_postmeta set meta_key=replace(meta_key,'cb2_customTitle','_cb2_customTitle') where meta_key like 'cb2_customTitle'"); } register_activation_hook(__FILE__, 'ce3_cleanup'); ?&gt; </code>
The recommended way to write that function would be: <code> function ce3_cleanup() { global $wpdb; $wpdb-&gt;query( "update $wpdb-&gt;postmeta set meta_key=replace(meta_key,'cb2_customHeader','_cb2_customHeader') where meta_key like 'cb2_customHeader'" ); $wpdb-&gt;query( "update $wpdb-&gt;postmeta set meta_key=replace(meta_key,'cb2_customTitle','_cb2_customTitle') where meta_key like 'cb2_customTitle'" ); } register_activation_hook( __FILE__, 'ce3_cleanup' ); </code>
"Plugin could not be activated because it triggered a fatal error."
wordpress
Most of my WordPress sites to date have been blog content, along with a 1 or 2 level page hierarchy. I'm now looking at developing a site with the customer site map suggests that a hierarchy of 4 levels of page content is required. In terms of WordPress the hierarchy is easy to create, but I'm looking at the ways of providing navigation in the theme for this page hierarchy. One thing I've seen is the Fold page list plug-in, but can't find much else on the subject. I was wondering if anyone has any examples or experiences they can suggest for how best to provide the navigation in the theme for a deep page hierarchy like this? EDIT - To clarify, I haven't currently selected a navigation type, this is part of the question. In a 2 level page hierarchy I normally use a top nav for the 1st level, with dropdown showing the 2nd level of navigation This isn't easily going to extend to 4 levels of navigation (unless we go for multiple menus opening similar to the Windows start button type menus, or the menumatic example in this article ). So I am considering what alternate approaches are available e.g. top level navigation on a top bar, and then a sidebar showing 2nd level navigation headings, with expandable subsections as you drill down to the 3rd and 4th level. E.g. see the 'in action' section at the bottom right of the fold page list plugin webpage However there may well be other good approaches to this, hence the question, to try and understand how other people approach providing navigation within WordPress to a deep hierarchy of page content
menu with non dynamic content if the menu structure is fixed then you can create a fixed menu using the "new" wp menu system (quadrillion weblog postings on that) menu with dynamic content if the menu structure is not fixed you can: a. ask the users to manually maintain the menu after e.g. adding a new category b. try to hook on everything that goes in the menu e.g. a new category and add it to the menu to prevent these manual actions for your users c. choose another "non-wp" menu and fill that dynamically on each page load (obviously with caching). example: to put a counter (67) behind the entries that represent tag pages In case of option (c) I would go to e.g.: http://www.mycssmenu.com/ generate the code for a menu you like, then copy and paste the javascript and css for that menu in your header.php of your theme. (I don't know who owns that site but the GUI system for creating a new menu is absolute very cool). Then replace the content bits (really simple: only the li items) with some code that e.g. queries the amount of categories in a hierarchical loop and replace the li items by dynamic output. --> In that way you have a dynamic menu with dynamic content and you can play with the code to do whatever you like with it in your menu. Example The menu generator generated me .css and .javascript and my example content of the menu. I replaced the example content with calls to a function "taglinklineRounded": <code> &lt;li&gt;&lt;a class="qmparent" href="javascript:void(0)"&gt;ARTS&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;span class="qmtitle" &gt;Listen&lt;/span&gt;&lt;/li&gt; &lt;?php echo taglinklineRounded('music', 'Music') ?&gt; &lt;?php echo taglinklineRounded('radio', 'Radio') ?&gt; &lt;li&gt;&lt;span class="qmdivider qmdividerx" &gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span class="qmtitle" &gt;Look&lt;/span&gt;&lt;/li&gt; &lt;?php echo taglinklineRounded('comics', 'Graphics') ?&gt; &lt;?php echo taglinklineRounded('photo', 'Photo') ?&gt; &lt;?php echo taglinklineRounded('graphics', 'Graphics') ?&gt; &lt;?php echo taglinklineRounded('art', 'Art') ?&gt; &lt;li&gt;&lt;span class="qmdivider qmdividerx" &gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span class="qmtitle" &gt;View&lt;/span&gt;&lt;/li&gt; &lt;?php echo taglinklineRounded('tv', 'TV') ?&gt; &lt;?php echo taglinklineRounded('video', 'Video') ?&gt; &lt;?php echo taglinklineRounded('movie', 'Movie') ?&gt; &lt;li&gt;&lt;span class="qmdivider qmdividerx" &gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span class="qmtitle" &gt;Read&lt;/span&gt;&lt;/li&gt; &lt;?php echo taglinklineRounded('book', 'Book') ?&gt; &lt;?php echo taglinklineRounded('writing', 'Writing') ?&gt; &lt;?php echo taglinklineRounded('news', 'News') ?&gt; &lt;li&gt;&lt;span class="qmdivider qmdividerx" &gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span class="qmtitle" &gt;Specific&lt;/span&gt;&lt;/li&gt; &lt;?php echo taglinklineRounded('scifi', 'Sci-Fi') ?&gt; &lt;?php echo taglinklineRounded('lost', 'LOST') ?&gt; &lt;/ul&gt;&lt;/li&gt; </code> The taglinklineRounded function gives me the amount of entries that have this tag (but obviously any whatever code can be done on the menu structure). In a more dynamic approach you read the categories / whatever other content needs to be in the menu and instead of in the example the hardcoded 'scifi' ... replace it with an echo statement of the output of that categories. (also ofcourse as deep as you want represented in the style choosen). Other idea I guess you can even combine the standard wp menu with the dynamic menu by having certain parts in the menu managed by the users and others dynamic by combining the outputs in a new dynamic menu. Haven't played with that.
Multi-level page hierarchy
wordpress
I needed a way to filter a page/posts content before it was loaded so I could add scripts to the header if a specific shortcode was present. After much searching I came across this on http://wpengineer.com <code> function has_my_shortcode($posts) { if ( empty($posts) ) return $posts; $found = false; foreach ($posts as $post) { if ( stripos($post-&gt;post_content, '[my_shortcode') ) $found = true; break; } if ($found){ $urljs = get_bloginfo( 'template_directory' ).IMP_JS; wp_register_script('my_script', $urljs.'myscript.js' ); wp_print_scripts('my_script'); } return $posts; } add_action('the_posts', 'has_my_shortcode'); </code> which is absolutely brilliant and did exactly what I needed. Now I need to extend it a bit further and do the same for sidebars. It can be by a particular widget type, shortcode, code snippet or anything else that would work to identify when the script needs to be loaded. The problem is I can't figure out how to access the sidebars content before the sidebar is loaded (the theme in question will have several sidebars)
You can use the function is_active_widget . E.g.: <code> function check_widget() { if( is_active_widget( '', '', 'search' ) ) { // check if search widget is used wp_enqueue_script('my-script'); } } add_action( 'init', 'check_widget' ); </code> To load the script in the page where the widget is loaded only, you will have to add the is_active_widget() code, in you widget class. E.g., see the default recent comments widget (wp-includes/default-widgets.php, line 602): <code> class WP_Widget_Recent_Comments extends WP_Widget { function WP_Widget_Recent_Comments() { $widget_ops = array('classname' =&gt; 'widget_recent_comments', 'description' =&gt; __( 'The most recent comments' ) ); $this-&gt;WP_Widget('recent-comments', __('Recent Comments'), $widget_ops); $this-&gt;alt_option_name = 'widget_recent_comments'; if ( is_active_widget(false, false, $this-&gt;id_base) ) add_action( 'wp_head', array(&amp;$this, 'recent_comments_style') ); add_action( 'comment_post', array(&amp;$this, 'flush_widget_cache') ); add_action( 'transition_comment_status', array(&amp;$this, 'flush_widget_cache') ); } </code>
Loading scripts only if a particular shortcode or widget is present
wordpress
At some point, I started getting a message about 311 characters of unexpected output at every plugin activation. The number is always the same, and it happens for every plugin activation, including reactivating plugins that were temporarily deactivated. The exact message: The plugin generated 311 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin. Is this likely to be a problem with a plugin that has extra whitespace in its files or something? I haven't yet gotten any problems with headers already having been sent. Possibly it's related to stackexchange-url ("the weird 404 errors I get in wp-admin"), but that problem was around long before this unexpected output issue.
Basically it goes like this (relevant steps only): <code> plugins.php </code> page calls <code> activate_plugin() </code> function. Function starts output buffering. Includes plugin file. Fires <code> activate_plugin </code> action. Fires <code> 'activate_' . trim( $plugin ) </code> action. Fires <code> activated_plugin </code> action. If buffer is not empty it creates <code> WP_Error </code> object and returns it. <code> plugins.php </code> page checks for error and displays error message. So output happens somewhere between steps 2 and 7. If it comes up for multiple plugins then steps 3 and 5 are safe to exclude, they are plugin-specific. So it is likely something in either <code> activate_plugin </code> or <code> activated_plugin </code> . Also actual unwanted output is passed in <code> WP_Error </code> object but not used (only its length). I'd try to dump hooks first, will take bit of extra code in core a bit to get to that output in <code> WP_Error </code> object.
All new plugins generating 311 chars of unexpected output?
wordpress
Looking for a breadcrumb menu that can be called (preferably from a sidebar widget in header.php) that lists... Home > Parent Post/Page > Current Page/Post or alternately... Home > Parent Category > Current Page/Post or even Home > Grand Parent Category > Parent Category > Current Page/Post
Breadcrumb NavXT will let you do that, it has a built in widget and supports just about everything WordPress can do (breadcrumbs spanning multiple sites in a multi site setup does not work, yet).
WordPress built in breadcrumb trail menu?
wordpress
The script below creates a listing of the categories in the site (excluding those in "uncategorized"). If possible, I'd like to modify it so that it only lists the top level categories (no child categories)... <code> $cat_args = array('orderby' =&gt; 'name', 'show_count' =&gt; $c, 'hierarchical' =&gt; $h); $cat_args['title_li'] = ''; $cat_args['exclude_tree'] = 1; wp_list_categories(apply_filters('widget_categories_args', $cat_args)); </code>
After some trial and error, this is what it took to make it work... <code> $cat_args = array('orderby' =&gt; 'count'); $cat_args['title_li'] = ''; $cat_args['exclude_tree'] = 1; $cat_args['exclude'] = 1; $cat_args['depth'] = 1; wp_list_categories(apply_filters('widget_categories_args', $cat_args)); </code>
List categories and exclude child categories
wordpress
I was surprised to learn that custom taxonomies aren't added as body or post classes like categories and tags are. I'm sure this will be added in a future version of WordPress, but in the meantime I need to add a custom taxonomy to the post class so that I can style post in a certain category in that taxonomy differently. It'd be most elegant to filter the post class and add the taxonomies to it. I found a snippet to pull off a similar trick with the body class, but I haven't been successful in adapting it: <code> function wpprogrammer_post_name_in_body_class( $classes ){ if( is_singular() ) { global $post; array_push( $classes, "{$post-&gt;post_type}-{$post-&gt;post_name}" ); } return $classes; } add_filter( 'body_class', 'wpprogrammer_post_name_in_body_class' ); </code> A bit more crudely, I thought about using the_terms function to create my own classes for the custom posts, something like this: <code> &lt;div class="&lt;?php the_terms( $post-&gt;ID, 'taxonomy', '', ' ', '' ); ?&gt;"&gt;&lt;/div&gt; </code> But then I'd have to filter out the HTML that <code> the_term </code> generates. Am I missing anything obvious here, is there a simpler way to solve this issue?
I found a snippet of code courtesy of mfields that solved this problem for me, here's what I ended up using: <code> &lt;?php // Add custom taxonomies to the post class add_filter( 'post_class', 'custom_taxonomy_post_class', 10, 3 ); if( !function_exists( 'custom_taxonomy_post_class' ) ) { function custom_taxonomy_post_class( $classes, $class, $ID ) { $taxonomy = 'listing-category'; $terms = get_the_terms( (int) $ID, $taxonomy ); if( !empty( $terms ) ) { foreach( (array) $terms as $order =&gt; $term ) { if( !in_array( $term-&gt;slug, $classes ) ) { $classes[] = $term-&gt;slug; } } } return $classes; } } ?&gt; </code>
Add post classes for custom taxonomies to custom post type?
wordpress
This idea is just to protect certain sections of my theme from over-zealous clients. I would like to add pages, that exist in the front end and can be added to the menu (using wordpress 3.0 api) but the page NOT be present in the 'Pages' dialogue in the admin panel, and is thus not user editable.
You can hook into template_redirect like this: <code> function custom_template_redirect() { global $wp; if ($wp-&gt;query_vars['pagename'] == 'my-page-slug') { // check the page slug status_header(200); // a 404 code will not be returned in the HTTP headers if the page does not exists include(TEMPLATEPATH . "/test.php"); // include the corresponding template die(); } } add_action( 'template_redirect', 'custom_template_redirect' ); </code>
Can you call a template file without assigning template to a page in the admin panel?
wordpress
I would like to add some features (via authoring a plugin) to the post editor in wordpress. Is there a way to add a widget to the post editor view? Alternatively is there an existing plugin someone can point me too, that does this so I can see how they do it.
"Widgets" as you're calling them on the post edit screen are actually meta boxes. You can add as many as you want to do whatever you want using the <code> add_meta_box() </code> function. Once you know what they're called, it's fairly straight-forward to do a Google search for examples. Or check out some great tutorials listed in the Codex.
How to add a widget to the post editing view?
wordpress
Using query_posts, how can I order the list of posts so the ones with the most recent comments are at the top? I'm looking for something similar to how Questions here on SE are ordered when you sort by "Active."
I wouldn't use <code> query_posts() </code> . That particular function is meant for making changes to a specific query ... and it's limited enough that you can't get the kind of custom functionality you need out of it. Rather, I'd use a custom query. What you'll want to do is query approved comments sorted by their post/approval date and join that with the posts in your database. If a post doesn't have any comments, it would automatically be filtered out based on this criteria. A very simple pseudo-code example: <code> $qstr = 'SELECT * FROM wp_posts ON (wp_posts.post_id = wp_commnets.comment_post_id) WHERE wp_comments.comment_approved='approved' ORDER BY wp_comments.comment_date'; $my_query = new WP_Query($qstr); while($my_query-&gt;have_posts() ... </code> Basically, you're selecting posts based on specific criteria related to data in the comments table. Using a direct query requires a certain depth of knowledge regarding SQL statements and the WP database structure, though ... so it's not usually my first recommendation, but should work in your case. Just remember that the code above is pseudo-code ... meaning I made it up off the top of my head, it might not work, and you should only use it as a conceptual example. For reference: WordPress Database Structure
Create a Loop with Posts Ordered by Most Recent Comments
wordpress
Is there any tool online that can quickly populate a WordPress3 database with faux information to assist in theme development? Perhaps creating 8 categories, inserting a dozen or so posts into each, adding a thumbnail for each, etc.
Just today read Dummy Content Filler Resources post that has several sets of data and plugins for WordPress listed.
WP Northwind for Theme Development?
wordpress
I'm using query_posts to sort order certain categories. My code look like this: <code> query_posts('category_name=abs&amp;orderby=meta_value_num&amp;meta_key=field_ordering&amp;order=DESC'); </code> This does show post in exact sorting model as I specify. However, query above doesn't display that post doesn't have <code> meta_key </code> 'field_ordering' set in database. My problem is, I don't want to set it on ALL post, but I still can display the data. Any solutions?
Well, you can't sort by field that isn't there. You can modify query conditionally only in those categories which have that field and let default query work in rest. It would be something like: <code> if( is_category('abs') ) query_posts( array_merge( array('orderby' =&gt; 'meta_value', 'meta_key' =&gt; 'field_order', 'order' =&gt; 'Desc' ), $wp_query-&gt;query ) ); </code>
Custom query with query_posts doesn't show post without certain meta_key
wordpress
( Moderators note : Was originally titled "How to get_posts of a custom post type that is in two custom taxonomies?" ) I have a custom post type that has two taxonomies which are separate, one called "Project Type" and one called "Package" . I need to get a list of projects which are of "Project Type" <code> A </code> and "Package" <code> A </code> . I tried using following code: <code> $args = array( 'post_type' =&gt; 'portfolio', 'numberposts' =&gt; -1, 'project_type' =&gt; 'A', 'package' =&gt; 'A' ); $my_posts = get_posts($args); </code> But this gets all the posts that are EITHER in Project Type A OR Package A. Is there any way to say in <code> get_posts() </code> that I want to return only those posts that are in BOTH taxonomies?
As of v1.3, the Query Multiple Taxonomies plugin works great with WP_Query. Your original args work as is. <code> $args = array( 'post_type' =&gt; 'portfolio', 'numberposts' =&gt; -1, 'project_type' =&gt; 'A', 'package' =&gt; 'A' ); </code> Then make a new query and check it: <code> $foo = new WP_Query($args); var_dump($foo-&gt;posts); </code> I tested this on my own custom taxonomy setup, and it only returned posts which matched both terms in the query. Another convenient method of grabbing multiple taxonomy terms with QMT is building simple URL queries: <code> site.com/?post_type=portfolio&amp;package=foo&amp;project=bar </code> I've used this method with the <code> add_query_args() </code> function to create links on a page that modify the current query, refining it by adding additional terms and taxonomies. The syntax also works great with a search input, as multiple words in the input field are posted as foo+bar, which works great with QMT: <code> site.com/?post_type=portfolio&amp;project=alpha&amp;colors=red+blue+green </code> Which returns only posts that meet all these criteria - Type: Portfolio / Project: Alpha / Colors: red + blue + green
Getting the Intersection of Two Custom Taxonomy Terms for a Custom Post Type?
wordpress
What's the best way to completely customize the Edit Post admin screen for a specific custom post type? I have customized it to an extent already on creation of the custom post type - adding additional fields etc, but I want to remove many of the elements such like permalinks, preview post, disable quick editing etc
Some of these questions are answered here: stackexchange-url ("stackexchange-url To remove the permalink metabox: <code> function my_remove_meta_boxes() { remove_meta_box('slugdiv', 'my-post-type', 'core'); } add_action( 'admin_menu', 'my_remove_meta_boxes' ); </code> additionaly, you will have to hide #edit-slug-box with css or javascript. see: stackexchange-url ("stackexchange-url To disable quick edit: <code> function my_remove_actions( $actions, $post ) { if( $post-&gt;post_type == 'my-post-type' ) { unset( $actions['inline hide-if-no-js'] ); } return $actions; } add_filter( 'post_row_actions', 'my_remove_actions', 10, 2 ); </code> To change the preview link, you could use the filter 'preview_post_link', but it works only when the post has not yet been published. So, the solution would be to remove the submit meta box and add your own modified one: <code> function my_replace_submit_meta_box() { remove_meta_box('submitdiv', 'my-post-type', 'core'); add_meta_box('submitdiv', __('Publish'), 'custom_post_submit_meta_box', 'my-post-type', 'side', 'core'); } add_action( 'admin_menu', 'my_replace_submit_meta_box' ); function custom_post_submit_meta_box() { // a modified version of post_submit_meta_box() (wp-admin/includes/meta-boxes.php, line 12) ... } </code>
Customize Edit Post screen for Custom Post Types?
wordpress
Is it possible to control the size of the window that is opened with <code> comments_popup_link() </code> ?
According to docs it is set by function that sets up script for this functionality: <code> comments_popup_script(width, height, 'file'); </code>
How to control size of comments popup window?
wordpress
This is partly a follow up to my earlier question: stackexchange-url ("How can I make a site viewable in multiple languages?"). It turns out the client wants to have the content manually translated, rather than using something like Google's translation tools. With that in mind, my first thought is to use a multisite installation with subdirectories, i.e. site.com/en/, /fr, /cn, etc. Is this the most logical way to achieve the desired result. Keep in mind only the content needs to be in multiple languages, not the admin interface.
no you can use a single instalation of your WordPress and use this plugin WPML for setup your multilangual site. Keep multiple installations for any language is not a good idea.
Should I use a multisite installation to achieve a multi-language site?
wordpress
I recently stumbled upon this blog on " Using IIRF URL Rewriting on IIS6 with WordPress" ( http://john-sheehan.com/blog/using-iirf-url-rewriting-on-iis6-with-wordpress/ ) by John Sheehan as I installed a WordPress site I developed on my Mac OS X running MAMP and then ported the site to a MS IIS6 Windows 2003 Server environment. Going to the home page all works fine but then all my other pages could not be found - 404. My site is setup with PermaLinks in WordPress 3.0.1 where I am using the Custom Structure /http:/www.mysite.com/%postname%/ So an example permalink for one of my pages that cannot be found is http://www.mysite.com/aboutus Reading up on this, I am assuming the reason my pages cannot be found is because of my .htaccess file not being compatible on IIS 6 server as this is an Apache only file. Anyways, to cut a long story short, looking at the site/blog entry above, regarding the use of IIRF URL Rewrite and me being a complete newb to rewriting URLs, I have the following queries: A) To achieve my Permalink Custom Structure of /http:/www.mysite.com/%postname%/ what would my Rule's File look like, so that WordPress on IIS 6 will actually find my pages described above? B) What is the name of this file and where (location) on the Web Server do I place the Rule file? C) Do I need to remove my current .htaccess file within my WordPress directory that holds my site on IIS 6? Any help on this would be much appreciated. Thanks.
Documentation on Using Permalinks suggest this post for setting them up on IIS 6 .
WordPress 3.0.1 on IIS 6 Web Server PermaLink Issues
wordpress
I am currently using on my blog the default comment system with in addition only the "Quote Comments" plugin. I have seen IntenseDebate and it seems it has many interesting features that probably (and hope) will push the visitors to leave more comments. The pros are clear but do you see any drawbacks that should I take into account before decide to install or not IntenseDebate plugin on my blog?
There's an excellent post here which, while it might not be completely balanced (it sets out from the start that it is against external commenting systems), it offers a good view of the cons of such systems. A quick summary of three main points (a mixture of my personal opinions and from the blog post): Comments are stored externally - you no longer have 'possession' of the comments on your blog - they are stored by somebody else, physically away from the rest of your blog Comments are often loaded in via AJAX after the page has loaded, or even after they are in the viewport which can make your site appear slower to your readers Issues with your comments 'provider' may disable comment functionality - if there is a problem on IDs side you will not be able to do anything about it
Are there any drawbacks to install IntenseDebate on my blog?
wordpress
I'm using a child of the <code> twentyten </code> default theme and I want to hide the sidebar on some pages. What is the solution for that?
Actually, Twentyten has a no-sidebar page template already. Modify the template option in the page edit screen: And viola:
How can I hide the sidebar on specific pages?
wordpress
is it possible to create a subcategory.php and use it to manage subcats. or is there a way to get around this. if it is not possible.. is there something like this <code> &lt;?php if(is_subcategory() || child() ) { //do stuff } else { // do else } ?&gt; </code>
I don't think it is possible to create a subcategory.php, but you can do the following in your category.php: <code> $category = get_category( get_query_var( 'cat' ) ); if( !empty( $category-&gt;parent ) ) { // the category has a parent, so it is a subcategory // do stuff } else { // do else } </code>
want to create a subcategory.php to manage subcats
wordpress
When I use the bookmarklet button to test bookmarking . Only some URLs might able to display the post page.For other URLs it is just showing an error: <code> 404. The requested page was not found. </code> I have deactivated all the plugins .But problem not solved .I have changed the theme though . Do any body have Idea on solving this problem? I am not sure how to solve the problem .I copied the screen shots of error here .
Problem resolved by my web-host's executives .They said that they had to white list a code on their servers .
Problem using Press-this book marklet
wordpress
My dashboard( It is multisite Installation ) section for pages and posts conflicts with options when there are morethan 5 data fields . For example : I have these things under my Posts section in dashbpard : Title Author Categories Tags Comments Date Forum-Linked Featured Because of these many fields these options conflicts each other like shown in the screen shot : Edit | Quick Edit | Trash | Preview | Purge from Page Cache It is because of the increased fields like forum-linked ,featured etc . Some times when I install any other related plugins .The number of data fields increases and it becomes more ugly with the editing options . Could any one suggest me a good Idea to fix this ?
Columns can be hidden from view using the screen options tab. On the upper right hand side of the dashboard click screen options Un check any of the columns you want to hide. Normally the edit options are displayed as horizontal text. A plugin or other function has changed this.
Conflicting post edit options under dashboard
wordpress