question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
Is it possible to make a "page, not a blog post" the main entry on your site? I'd like to be able to create a summary of the latest content as the first page the user visits on my site. I'm using Wordpress 3.0.3
yes, it's a simple setup in your wordpress settings, so, go to your Admin area => Settings => Reading and select to use a Static Page as a Front Page, from the drop down menu select the page you want to use and put inside the content you want/need, just don't put a Loop inside.
Making a wordpress page the index on the site?
wordpress
My client wants me to install a plugin from here: http://www.maxblogpress.com/plugins/mpo/ that optimizes how WP pings. If you read the article, the version he mentioned were 2.1 and 2.3, if I am not wrong. Does this issue still exist?
I'd stay away from this particular plugin, as far as I remember this developer requires registration and forces email subscription on you. As for issue itself - does your client has particular issue to worry about pings at all?
Wordpress ping spam issue with Ping services?
wordpress
I'd like the user to install WP and have the default content loaded automatically but i don't want to have to write in in PHP in the wp_install_defaults(); I'd much rather export an xml file each time i make a change to the default and just bundle that with the install. Thanks.
have a look at the file wp-admin/includes/import.php, you'll find the necessary functions in there.
How to import WP XML file automatically on installation?
wordpress
How do you replace the default title for first comment? Mr WordPress on Hello world! I could not able to locate this in theme's comments.php file I want to edit the title 'Mr wordpress on Hello world' to Admin on -Site Name- How can I replace the default text created with about us page? This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress. to It is the page about your self.Feel free to edit the page Some times I cannot able to locate certain content(As I mentioned above comment.php and default about us page) in core files when perforimg search .is there any way to find certain content or code overall?
I can only answer your first two questions as I do not know anything about multisites. The default comment and content in the 'About Us" page is not coming from the theme files, but rather the database. They are the default posts/pages/comments accessed by the backend not by the theme files. To get to this content and replace it login to the admin via youraddress.com/wp-admin and locate the about page in pages > about us. The comments are under the "Comments" section. Simply delete the page or replace the content.
Replacing the default content created while the site creation
wordpress
In WordPress, I'm trying to create a Custom Post Box that will allow one post to be manually connected to another post. The easiest way to illustrate this request was to mockup what I would like the final Post Box to look like. That mockup can be viewed here » http://cl.ly/3hI3 Requirements: The Post Box needs to resemble the "Categories" Post Box, in that it has tabs at the top and checkboxes. Each tab at the top of this Post Box needs to be a Post Category (as illustrated in the mockup.) If I could manually control this so that the tabs were managed by a Custom Menu (ie. "Post Connections Menu"), that would be ideal. The checkboxed list of items needs to be posts that have already been categorized to that specific category. Thank you very much for any help / insight you can throw my way!
Hey Mike -- does it need to be connected to another post , or can it be a custom taxonomy or custom field?
How do I create a Custom Post Box that Connects Different Posts Together
wordpress
Currently my theme calls upon <code> get_comments_link() </code> to create the standard anchor #comments to link to the comments below the post, as does the <code> get_comments_pagenum_link() </code> function on paginated comments. I would like to replace the #comments anchor in these functions with any other string, without of course changing WP's core php files. A simple <code> add_filter </code> to completely replace core functions (other than in pluggable.php) doesn't seem to be possible. Are there any other ways of achieving this small change to the output of a core function, that use PHP (rather than say Java)? Is there a way here of using an <code> add_filter </code> with <code> str_replace() </code> perhaps? This will be useful for foreign language sites, and for redirecting comments to another page with a url request, for example.
So the solution to the <code> get_comments_pagenum_link() </code> function is straightforward enough: <code> add_filter('get_comments_pagenum_link' , 'new_get_comments_pagenum_link'); function new_get_comments_pagenum_link($content) { $content = str_ireplace('#comments' , '#other', $content); return $content; } </code> Which filters the output of <code> get_comments_pagenum_link() </code> to replace #content with #other , or any other string you might choose. For the <code> get_comments_link() </code> function, which can't be filtered, I have simply discovered that my WordPress theme uses it already within its own comments link function, and so have filtered this theme function instead, using the same method shown above.
Changing the comments link produced by the get_comments_link() and get_comments_pagenum_link() functions
wordpress
I have a problem with WP that need your help. Some of my posts have content that was applied "wp_autop" filters already. This filter turned all double break lines into <code> &lt;p&gt; </code> tag. I want to the opposite thing: turn all <code> &lt;p&gt; </code> tag into double break lines. Do you have any suggestions? Thank you.
I just ran into this situation. Here is a function I used to undo wpautop. I might be missing something, but this is a good start: <code> function reverse_wpautop($s) { //remove any new lines already in there $s = str_replace("\n", "", $s); //remove all &lt;p&gt; $s = str_replace("&lt;p&gt;", "", $s); //replace &lt;br /&gt; with \n $s = str_replace(array("&lt;br /&gt;", "&lt;br&gt;", "&lt;br/&gt;"), "\n", $s); //replace &lt;/p&gt; with \n\n $s = str_replace("&lt;/p&gt;", "\n\n", $s); return $s; } </code>
Is there un-wp_autop function?
wordpress
I have this code on my functions.php for getting shorturl over bit.ly <code> function bitly() { global $post; $bitly = file_get_contents('http://api.bit.ly/v3/shorten?login=USER&amp;apiKey=KEY&amp;longUrl='.urlencode(get_permalink($post-&gt;ID)).'&amp;format=txt'); echo $bitly; } </code> but, sometimes i got error like this "Function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in functions.php on line 614" Line 614 is code from above. What i want is to handle that error and not show it for users. But instead of showing bit.ly short url, if error 404 is there, i want to show default wp.me url for users or if not possible wp.me then whole url. EDIT I fixed this with this code <code> function bitly() { global $post; $bitly = wp_remote_retrieve_body (wp_remote_get('http://api.bit.ly/v3/shorten?login=USERNAME&amp;apiKey=APIKEY&amp;longUrl='.urlencode(get_permalink($post-&gt;ID)).'&amp;format=txt')); if( is_wp_error( $bitly ) ) { echo wp_get_shortlink($post-&gt;ID); } else { echo $bitly; } } </code>
I agree that this is PHP rather than WP question. To bring it closer to WP I do suggest to take a look at following functionality: HTTP API is highly suggested for making HTTP requests; <code> add_post_meta() </code> and related meta functions to store post-specific information; <code> the_shortlink() </code> function, that is suggested template tag to use for natvie short link functionality (and hook into for third party).
file_get_contents - failed to open stream
wordpress
I'm creating a theme that uses only the homepage. When a button is clicked, the content for that section is loaded into a div on the homepage via AJAX (script below). <code> $.ajaxSetup ({ cache: false }); var ajax_load = "&lt;center&gt;&lt;img src='&lt;?php bloginfo("template_url"); ?&gt;/images/loading.gif' alt='Loading...' /&gt;&lt;/center&gt;"; var loadUrl = "http://localhost:8888/cnNew/?portfolio=portfolio-test"; $("#ourTeam").click(function(){ $("#main") .html(ajax_load) .load(loadUrl + " #content"); }); </code> All of the .js files are being loaded in via wp_enqueue_script: <code> function my_init() { if (!is_admin()) { // comment out the next two lines to load the local copy of jQuery wp_deregister_script('jquery'); wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js', false, '1.4.3'); wp_enqueue_script('jquery'); wp_enqueue_script( 'galleria_plugin', get_bloginfo('template_directory') . '/js/galleria.js', array('jquery') ); } } add_action('init', 'my_init'); function my_scripts() { wp_enqueue_script( 'carousel', get_bloginfo('template_directory') . '/js/carousel.js', array('jquery') ); wp_enqueue_script( 'backstretch', get_bloginfo('template_directory') . '/js/jquery.backstretch.min.js', array('jquery') ); wp_enqueue_script( 'nivo_slider', get_bloginfo('template_directory') . '/js/jquery.nivo.slider.pack.js', array('jquery') ); wp_enqueue_script( 'tabify', get_bloginfo('template_directory') . '/js/jquery.tabify-1.4.js', array('jquery') ); wp_enqueue_script( 'mouse_wheel', get_bloginfo('template_directory') . '/js/scroll/jquery.mousewheel.js', array('jquery') ); wp_enqueue_script( 'scroll_pane', get_bloginfo('template_directory') . '/js/scroll/jquery.jscrollpane.min.js', array('jquery') ); } add_action('template_redirect', 'my_scripts'); </code> THE ISSUE: Since the page isn't refreshing and the content is being loaded into a DIV via AJAX when a button is clicked, i'm guessing, the content that is being loaded in that uses jQuery and other .js files is coming in broken because the .js files have already loaded without that content being on the page. I need to find a way to "refresh" the already loaded .js files so that the newly loaded content doesn't come in broken. Or am I approaching this in the wrong way? I'm a novice when it comes to AJAX since this is the first time i've used it. I was given this: http://www.wphardcore.com/2010/5-tips-for-using-ajax-in-wordpress/ as a reference but I found it hard for me to follow. Thanks for the help!
So if you say there are no errors, I'm assumming that your problem is the AJAX request changing the DOM, and your scripts being loaded before that. If the document changes, you'll need to tell your scripts that, so they will fire their events on the new content. So: Either you reload all scripts again after the AJAX updated the document (then you should put your script tags inside the element that's being changed) - this is ugly Or use live() , or livequery() in your scripts to scan for document changes. For eg: <code> $(".bla").click(function(){ ... }) </code> should be changed to <code> $(".bla").live('click', function(){ ... } </code> from the jquery API, live(): Description: Attach a handler to the event for all elements which match the current selector, now and in the future . update: The tabify script is initiated in the document.ready section in the header this way: $('#caseSections').tabify(); and is used on secondary pages (the pages that are loaded via ajax into the homepage via a button click). So tabify will be applied to the #caseSections selector from the initial document. I assume that this works. Your prooblem is that it stops working after the AJAX updates the page, right? Solutions: Since it's not set to be fired on a particular event, you'll need to install &amp; enqueue the livequery script I mentioned above. Then change <code> $('#caseSections').tabify(); </code> with: <code> $('#caseSections').livequery(function(){ $(this).tabify(); }); </code> Simply call <code> $('#caseSections').tabify(); </code> again after the AJAX completes, in the "success" function.
Loading dynamic content with AJAX breaking jQuery
wordpress
I'd like to give users a little welcome message on their first login to the admin area. Once they hide the message it should not appear again. I noticed admin_notice is a hook but don't know where to start. Thanks.
something like: <code> add_action('admin_notices', 'my_notice'); add_action('wp_ajax_hide_my_notice', 'hide_my_notice'); function hide_my_notice(){ check_ajax_referer('hide-my-notice'); $user = wp_get_current_user(); // update status for this user $seen_notice = get_option('my_notice'); $seen_notice[$user-&gt;ID] = true; update_option('my_notice', $seen_notice); exit; } function my_notice(){ $user = wp_get_current_user(); $seen_notice = get_option('my_notice'); // already seen it? if(isset($seen_notice[$user-&gt;ID]) &amp;&amp; $seen_notice[$user-&gt;ID]) return; ?&gt; &lt;div class="updated fade below-h2"&gt; &lt;p&gt; Hi &lt;?php print esc_attr($user-&gt;user_login); ?&gt;! Duuuuuude, whatz upp??? &lt;a class="hide-me"&gt; X &lt;/a&gt; &lt;/p&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; // this should go in a javascript file; // use wp_localize_script() to send variables from PHP to it jQuery(document).ready(function($) { $('a.hide-me').on('click', function(){ $.ajax({ url: '&lt;?php print admin_url("admin-ajax.php"); ?&gt;', type: 'GET', context: this, data: ({ action: 'hide_my_notice', _ajax_nonce: '&lt;?php print wp_create_nonce('hide-my-notice'); ?&gt;' }), success: function(response){ $(this).closest('div').remove(); } }); }); }); &lt;/script&gt; &lt;?php } </code> You can also use options cookies or transients to store the notice status
Add a notice to users upon first login to the admin area
wordpress
Does anyone know of a galley plug-in which would have this kind of functionality? <code> ------------------------------------------- | | | | | | | | | | &lt;-image shows whatever thumbnail is clicked | | | | | | | | | | ------------------------------------------- ----- ----- ----- ----- ----- ----- | | | | | | | | | | | | &lt;-thumbnails | | | | | | | | | | | | ----- ----- ----- ----- ----- ----- </code> Ideally, it would allow separate galleries on each page. And load the pictures when you click a thumbnail, without reloading the whole page.
Photospace http://wordpress.org/extend/plugins/photospace/ If you want to just use jquery I recommend http://www.twospy.com/galleriffic/ galleriffic.
Plug-in for gallery with thumbnails?
wordpress
what are the differences between wp_users and wp_usermeta tables? i use wp-email-login plugin and i just noticed that if a user change his email in the profile page it saved in the wp_usermeta table and not in the wp_users table, this is a problem cause the user have to use the first email to login successful, if he use the new (changed) email he can't get access. does anyone here can explain me why and how i can save the user email in the wp_users table? thanks a lot
wp_users is the primary table, with a fixed list of columns. wp_usermeta is an additional table for storing arbitrary information (custom fields). The wp_users table already has a user_email column, so I don't know why the plugin uses wp_usermeta. I guess the best person to ask would be the plugin author himself.
what are the differences between wp_users and wp_usermeta tables?
wordpress
Hoping to benefit from the experience of others. This question is really multiple potential questions so I'm hoping someone can steer me to the best solution to keep me from all the trial and error. Background So I have set up a WordPress v3.0.3 site currently with about 20 users and about 25 pages of content and I realize I needed a discussion forum for which I think the P2 Theme will work really well. I installed another copy of WordPress in the <code> /discuss/ </code> subdirectory and then went about trying to share the user tables by setting <code> CUSTOM_USER_TABLE </code> and <code> CUSTOM_USER_META_TABLE </code> only to find that setting those constants are not sufficient because of issues with the <code> COOKIE_DOMAIN </code> and <code> COOKIE_PATH </code> , issues with capabilities that would require hacking core to fix , and it seems lack of support from the core team for multiple sites with the same user tables. So I fear heading down a rabbit hole of lost time trying to make this work. So I thought maybe Multisite would be the solution which is unfortunately something that I've had very little experience with yet. However it seems that I can't just convert to multisite (stackexchange-url ("according to @EAMann")) but instead need to create a new install and then rebuild from there. Not knowing what that will break (i.e. will my users roles and capabilities transfer? Will the members plugin I'm using work? Are there any other concerns?) I'm also afraid to take that path unless I know it'll work well. Summary So in summary, what's the best way to get a site set up to have a main site and to use the P2 Theme for discussions in a subdirectory of the main site, to be able to use one user database and ideally to have a single login? (though single login is the least important consideration at the moment.) Thanks in advance for the help.
"However it seems that I can't just convert to multisite" I have no idea why he told you that, because it is possible. I mean,.... it's kind of the whole point of why multisite was merged in - so existing sites could just turn it on. User roles on the main site will stay exactly the same. there may be a couple plugins that don;t like the network, but... if they are used on your main blog, you're probably fine. If one is broken, there's likely a replacement. I mean, multisite is pretty common now, most of the plugin issues are worked out. A good way to check, if it's the membership plugin you're worried about is to go to their site and/or support forums and ask them. ;) The only "catch" right now is this: You want a subfolder install. In that setup, the main blog will get a /blog/ stuffed in the permalinks to prevent conflicts with site urls and page urls. this can mess up your permalinks (obviously). But you can ALSO disable it after installation. Go to Super Admin -> Sites and click edit on the main site. Remove it in any of the fields. Presto, problem solved and you now have multisite on your existing blog. So to answer your last question - just enable multisite. If you're really nervous, make a backup of your site, install it locally, and do it there as a test run.
Shared User Tables on 2 WordPress Sites; "Main" Site and "Discuss" using P2?
wordpress
I was editing a wordpress theme. Where i need to replace default wp login link with custom login link. Problem is, <code> comment_reply_link() </code> function is returning the default link. And i dont want to edit wp-include/comment-template.php Is there any other way, so that without manipulation of any wordpress file i can replace the default login url. I already had tried <code> apply_filters('login_url', $login_url,get_permalink()); </code> before <code> calling comment_reply_link() </code> . But it is not filtering resulting URL.
you can simple make a check if user is logged in and show him the reply button, if is not you can show him a custom link to your login file. something like this: <code> &lt;?php if ( !is_user_logged_in() ) : ?&gt; &lt;a href="&lt;?php bloginfo('url'); ?&gt;/login"&gt;&lt;?php _e('Reply', 'artdev'); ?&gt;&lt;/a&gt; &lt;?php else : ?&gt; &lt;?php comment_reply_link() ?&gt; &lt;?php endif ?&gt; </code>
How to edit comment_reply_link
wordpress
Just found this site via the WP-Hackers List, been using WordPress for years (make a living partially thanks to it) and never stumbled on this site! Posted this on the WP-Hackers list, but didn't find a solution. I know WordPress 3.1 has removed the nofollow attribute from the comment Reply link (WordPress 3.1 beta looks good), but was working on something theme wise that should also work with removing the nofollow attribute from the link for WordPress 3.0.3 and below, but can't get it working. from /wp-includes/comment-template.php <code> } else { $link = "&lt;a rel='nofollow' class='comment-reply-link' href='" . get_permalink($post-&gt;ID) . "#$respond_id' onclick='return addComment.moveForm(\"$add_below-$post-&gt;ID\", \"0\", \"$respond_id\", \"$post-&gt;ID\")'&gt;$reply_text&lt;/a&gt;"; } return apply_filters('post_comments_link', $before . $link . $after, $post); </code> In WordPress 3.1 rel='nofollow' has been removed from the above code. I'm trying to achieve the same at theme level for WordPress 3.0.3 and below. Basically adding this code to the comments loop as a test works: <code> $comment-&gt;comment_content = str_replace('nofollow', 'Test One',$comment-&gt;comment_content); </code> This removes the text nofollow from a comments body. I tried <code> $comment_reply_link-&gt;reply_text = str_replace('Reply', 'Test Two',$comment_reply_link-&gt;reply_text ); </code> As another test to replace the anchor text of the Reply link to confirm I'm on the right track. Didn't work. and <code> $comment_reply_link-&gt;link = str_replace('nofollow', '',$comment_reply_link-&gt;link ); </code> to delete the nofollow part of the rel attribute. Didn't work either Tried a variety of permutations with no joy. Any ideas? David
functions.php: <code> function remove_nofollow($link, $args, $comment, $post){ return str_replace("rel='nofollow'", "", $link); } add_filter('comment_reply_link', 'remove_nofollow', 420, 4); </code>
Editing the Comment Reply Link
wordpress
i'm building a widget to login from the sidebar and print errors if any, so everything is working fine except that when i login it returns an error: Warning: Cannot modify header information - headers already sent..... the code of the widget: <code> &lt;?php // Custom Login/Meta Widget function widget_artdev_meta() { ?&gt; &lt;?php global $user_ID, $user_identity, $user_level ?&gt; &lt;?php if ( $user_ID ) : ?&gt; &lt;div class="widget"&gt; &lt;h2&gt;Control Panel&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;Identified as &lt;strong&gt;&lt;?php echo $user_identity ?&gt;&lt;/strong&gt;. &lt;ul&gt; &lt;?php if ( $user_level &gt;= 10 ) : ?&gt; &lt;li&gt;&lt;a href="&lt;?php bloginfo('url') ?&gt;/wp-admin"&gt;Dashboard&lt;/a&gt;&lt;/li&gt; &lt;?php endif // $user_level &gt;= 10 ?&gt; &lt;?php if ( $user_level &gt;= 1 ) : ?&gt; &lt;li&gt;&lt;a href="&lt;?php bloginfo('url') ?&gt;/wp-admin/post-new.php"&gt;Write an article&lt;/a&gt;&lt;/li&gt; &lt;?php endif // $user_level &gt;= 1 ?&gt; &lt;li&gt;&lt;a href="&lt;?php bloginfo('url') ?&gt;/profile"&gt;Profile &amp;amp; personal options&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="&lt;?php echo wp_logout_url( $_SERVER['REQUEST_URI'] ); ?&gt;" title="Exit"&gt;Exit&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php elseif ( get_option('users_can_register') ) : ?&gt; &lt;?php if ( 'POST' == $_SERVER['REQUEST_METHOD'] &amp;&amp; !empty( $_POST['action'] ) &amp;&amp; $_POST['action'] == 'log-in' ) : global $error; $login = wp_login( $_POST['log'], $_POST['pwd'] ); $login = wp_signon( array( 'user_login' =&gt; $_POST['log'], 'user_password' =&gt; $_POST['pwd'], 'remember' =&gt; $_POST['rememberme'] ), false ); endif; ?&gt; &lt;div class="widget"&gt; &lt;h2&gt;Identification&lt;/h2&gt; &lt;?php if ( $error ) : ?&gt; &lt;p class="error"&gt; &lt;?php echo $error; ?&gt; &lt;/p&gt;&lt;!-- .error --&gt; &lt;?php endif; ?&gt; &lt;ul&gt; &lt;li&gt; &lt;form action="&lt;?php the_permalink(); ?&gt;" method="post"&gt; &lt;label for="log"&gt;Customer ID &lt;input type="text" name="log" id="log" value="&lt;?php echo wp_specialchars(stripslashes($user_login), 1) ?&gt;" size="22" class="input_text_login alignright" /&gt; &lt;/label&gt; &lt;label for="pwd"&gt;Password &lt;input type="password" name="pwd" id="pwd" size="22" class="input_text_login alignright" /&gt; &lt;/label&gt; &lt;input type="submit" name="submit" value="Login" class="button" style="margin-right:35px; width:70px;" /&gt; &lt;input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /&gt; Remember me &lt;input type="hidden" name="action" value="log-in" /&gt; &lt;input type="hidden" name="redirect_to" value="&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;"/&gt; &lt;/form&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="&lt;?php bloginfo('url') ?&gt;/wp-login.php?action=lostpassword"&gt;Recover password&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="&lt;?php bloginfo('url') ?&gt;/register"&gt;Register&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php endif // get_option('users_can_register') ?&gt; &lt;?php } if ( function_exists('register_sidebar_widget') ) register_sidebar_widget(__('&amp;rarr; Login/Meta Widget','artdev'), 'widget_artdev_meta'); ?&gt; </code> anyone out there can help? i can't understand where the problem is...! thanks a lot! Philip
Don't use both <code> wp_login() </code> and <code> wp_signon() </code> . They do the same thing, but first one is deprecated Use the 2.8 widget API Put <code> wp_signon() </code> inside a function that you hook on the <code> init </code> tag (You can handle the errors in the <code> widget() </code> function)
Sidebar login widget with error print, returns an error
wordpress
i asked this question previously, which solved my problem, but further i am having still problem with it, i have a function to display tweets of a user which fetch from a custom field, the custom field code is working perfect, cause when i <code> echo the get_post_meta </code> in my single.php i get the value which is input now the question is when i try to fetch the value from custom field to a twitter function the tweets are not coming, here is my code: <code> function tweet(){ $doc = new DOMDocument(); if ( $meta =get_post_meta($post-&gt;ID, 'dbt_Username', true) ) { $feed = "http://twitter.com/statuses/user_timeline/$meta.rss"; $doc-&gt;load($feed); $outer = "&lt;ul&gt;"; $max_tweets = 5; $i = 1; foreach ($doc-&gt;getElementsByTagName('item') as $node) { $tweet = $node-&gt;getElementsByTagName('title')-&gt;item(0)-&gt;nodeValue; $tweet = substr($tweet, stripos($tweet, ':') + 1); $tweet = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '&lt;a href="$1"&gt;$1&lt;/a&gt;', $tweet); $tweet = preg_replace("/@([0-9a-zA-Z]+)/", "&lt;a href=\"http://twitter.com/$1\"&gt;@$1&lt;/a&gt;", $tweet); $outer .= "Twiter Updates by:".get_option('tweetID')."&lt;li&gt;". $tweet . "&lt;/li&gt;\n"; if($i++ &gt;= $max_tweets) break; } $outer .= "&lt;/ul&gt;\n"; return $outer; } } add_action('admin_menu', 'tweet_fetch1'); function append_the_content1($content) { $content .= "&lt;div class='post'&gt;&lt;p&gt;".tweet(get_post_meta($post-&gt;ID, 'dbt_Username', true))."&lt;/p&gt;&lt;/div&gt;"; return $content; } add_filter('the_content', 'append_the_content1'); </code>
So many issues here... First, I'm not sure what this line is doing: <code> add_action('admin_menu', 'tweet_fetch1'); </code> If you don't actually have a function called tweet_fetch1 that runs when the admin loads, you should remove this add_action. And if you do have such a function, why is your add_action in this location? The first step to avoiding problems is clean, readable, commented code the groups functions and hooks them logically. Second, in both of your functions, you're trying to reference $post-> ID where no post object is available. You can usually make it available by globalizing it. <code> global $post; </code> Third, your function called "tweet" accepts no arguments, yet when you call it from inside your append_the_content1() function, you're trying to pass it the meta value for dbt_Username. <code> $content .= "&lt;div class='post'&gt;&lt;p&gt;".tweet(get_post_meta($post-&gt;ID, 'dbt_Username', true))."&lt;/p&gt;&lt;/div&gt;"; </code> This is incorrect...and unnecessary, as you then grab the same meta value (again) from inside the tweet() function using get_post_meta. You need to remove the argument (the stuff between the parentheses) when you call the tweet() funciton. Like so: <code> $content .= "&lt;div class='post'&gt;&lt;p&gt;".tweet()."&lt;/p&gt;&lt;/div&gt;"; </code> Lastly--though this is just a suggestion, and isn't strictly something wrong with your code--I don't know what all that preg replacing is for. If you're trying to link to the original tweet, you can pull the URI right out of the twitter feed. Also, you can make links inside tweets clickable with WordPress' handy make_clickable() function. Your problem here isn't with get_post_meta--it's with PHP. No disrespect, but it would help you out tremendously to brush up on the basics so that you can better understand the code you're writing, and the answers people are giving you.
get_post_meta() problem again
wordpress
I'm registering taxonomy in my functions.php file: <code> register_taxonomy("our_gallery_types", array("gallery"), array("hierarchical" =&gt; true, "label" =&gt; "Categories", "singular_label" =&gt; "Category", "rewrite" =&gt; true)); </code> And it works perfectly. But I want also to automatically create two terms in this taxonomy, how would i do that? When you run Wordpress for the very first time and click Posts there is "Uncategorized" category. I want to do exactly the same for my taxonomy, so my users won't get confused and won't have to create categories for their own. How do i achieve that?
use wp_insert_term() (after you register the taxonomy) You can also check if a term exists() before doing that, to save some useless db queries...
Create terms when registering taxonomy?
wordpress
currently I have 3 parent page types with multiple child pages under each. Feature * feat 1 * feat 2 .. Creative * creat 1 * creat 2 ... Info * info 1 * info 2 ... I have been successful with pulling the children page content onto the parent page, but now I want to get the children of Feature and Creative onto Creative Parent page. here is what I am using to get the child pages of Featured parent page. <code> &lt;div id="folio-menu"&gt; &lt;div class="inner"&gt; &lt;?php $projectpage = get_pages('child_of=14&amp;sort_column=post_date&amp;sort_order=desc'); $count = 0; foreach($projectpage as $page) { $content = $page-&gt;post_content; if(!$content) continue; if ($count == -1) break; $count++; $content = apply_filters('the_content', $content); ?&gt; &lt;div class="thumb-container"&gt; &lt;div class="thumb"&gt;&lt;a href="&lt;?php echo get_permalink($page-&gt;ID); ?&gt;"&gt; &lt;?php echo get_image ("thumbnail",1,1,1,$page-&gt;ID);?&gt;&lt;/a&gt; &lt;/div&gt;&lt;p class="smalltitle"&gt;&lt;?php echo $page-&gt;post_title ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;/div&gt; </code> I tried to list both parent page id's in 'child_of=14,15&amp;...' but it did not work. Thanks!
Like AmbitiousAmoeba mentioned, you'll need to perform a few <code> get_pages </code> calls to lookup the pages for each child, merge the results together, and iterate over those results. I worked up an example for you, because it's fiddly trying to merge arrays when they have matching indexes, the only thing you should need modify are the <code> child_of </code> parameters, and of course add back in your surrounding HTML.. Updated example Uses <code> array_merge </code> instead, i mistaken thought it wouldn't work for with numeric keys(it does though, as Rarst kindly pointed out in the comments).. <code> $args = array( 'child_of' =&gt; 174, 'sort_column' =&gt; 'post_date', 'sort_order' =&gt; 'desc' ); $child_pages = get_pages( $args ); $args['child_of'] = 143; $second_page_group = get_pages( $args ); $child_pages = array_merge( $child_pages, $second_page_group ); $args['child_of'] = 146; $third_page_group = get_pages( $args ); $child_pages = array_merge( $child_pages, $third_page_group ); unset( $second_page_group, $third_page_group, $args ); if( !empty( $child_pages ) ) foreach( $child_pages as $_my_page ) { $title = apply_filters( 'the_title', $_my_page-&gt;post_title ); //$content = apply_filters( 'the_content', $_my_page-&gt;post_content ); //$content = str_replace( ']]&gt;', ']]&amp;gt;', $content ); $link = apply_filters( 'the_permalink', get_permalink( $_my_page-&gt;ID ) ); ?&gt; &lt;div class="thumb-container"&gt; &lt;div class="thumb"&gt;&lt;a href="&lt;?php echo $link ?&gt;"&gt; &lt;?php //echo get_image( "thumbnail", 1, 1, 1, $_my_page-&gt;ID );?&gt;&lt;/a&gt;&lt;/div&gt; &lt;p class="smalltitle"&gt;&lt;?php echo $title ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php } </code> Old example Might aswell leave the old example in place <code> // Setup base args for each get_pages call $args = array( 'child_of' =&gt; 174, 'sort_column' =&gt; 'post_date', 'sort_order' =&gt; 'desc' ); // Perform the first query to get pages $child_pages = get_pages( $args ); // Count the results $c = count( $child_pages ); // Update the child_of arg to another ID $args['child_of'] = 143; // Perform the second call to get children pages $second_page_group = get_pages( $args ); // If there were pages in the first group if( $c ) // Add them into the first array returned foreach( $second_page_group as $k =&gt; $p ) { $child_pages[$c] = $p; $c++; } else // Else fill the array with the results of the second query $child_pages = $second_page_group; // Cleanup unset($second_page_group); // Count the results again $c = count( $child_pages ); // Update the child_of arg to another ID before the final get_pages call $args['child_of'] = 146; // Make the third call $third_page_group = get_pages( $args ); // If we have results, add these into that array if( $c ) foreach( $third_page_group as $k =&gt; $p ) { $child_pages[$c] = $p; $c++; } else // Else fill the array with the results of the final query $child_pages = $third_page_group; // Cleanup unset($third_page_group); if( !empty( $child_pages ) ) foreach( $child_pages as $_my_page ) { $title = apply_filters( 'the_title', $_my_page-&gt;post_title ); //$content = apply_filters( 'the_content', $_my_page-&gt;post_content ); //$content = str_replace( ']]&gt;', ']]&amp;gt;', $content ); $link = apply_filters( 'the_permalink', get_permalink( $_my_page-&gt;ID ) ); ?&gt; &lt;div class="thumb-container"&gt; &lt;div class="thumb"&gt;&lt;a href="&lt;?php echo $link ?&gt;"&gt; &lt;?php echo get_image( "thumbnail", 1, 1, 1, $_my_page-&gt;ID );?&gt;&lt;/a&gt;&lt;/div&gt; &lt;p class="smalltitle"&gt;&lt;?php echo $title ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php } </code> Hope that helps...
Child page from 2 different parent pages
wordpress
I'm working on a site based on a fluid width css template which sets a max-width on images to the width of the column containing them, and I need to remove the inline width and height dimension attributes that WordPress adds to images. I'm doing it with my featured images with this filter: <code> add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10, 3 ); function remove_thumbnail_dimensions( $html, $post_id, $post_image_id ) { $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html ); return $html; } </code> I know I can apply the same filter to the_content , if necessary. But is there a better way of doing this?
Thanks all! The image_send_to_editor filter was the one I was looking for... thanks @t31os for pointing it out. Here's my functions now. <code> add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 ); add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 ); function remove_thumbnail_dimensions( $html ) { $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html ); return $html; } </code> This removes inline dimension attributes from images retrieved with <code> the_post_thumbnail() </code> , and prevents those attributes from being added to new images added to the editor. Doesn't remove them from images retrieved through <code> wp_get_attachment_image </code> or other related functions (no hooks in there), but those cases can be processed in the templates files when necessary.
Filter to remove image dimension attributes?
wordpress
I'm in a pickle and unfortunately, have almost zero working understanding of mod_rewrite/apache stuff. Here's what's going on: I've got a hierarchal custom post type with parents and children. On my test server, before I can see any of the custom posts, i needed to go to the permalinks settings page and hit refresh. Then I can see parents. When I hit it again, I can see children, and I'm golden. On the actual server (my friend's shared hosting account) -- I follow the same process and the parent's come through -- but not the children. I know it's not a plugin issue, because it's true with them all turned off, and also on the test server with them all turned on. The child posts DO come through when i have the settings at default permalinks -- so I know the posts are actually getting created. I'm thinking it has to be something on the shared server -- any ideas what to look for? It's so weird that parent's work but children don't... Thanks! martin --Since it's working on the test server, I'm pretty sure my code is right -- but just in case, this is how i'm registering them: <code> register_post_type('book', array( 'label' =&gt; __('Books'), 'singular_label' =&gt; __('Book'), 'public' =&gt; true, 'show_ui' =&gt; true, '_builtin' =&gt; false, // It's a custom post type, not built in! '_edit_link' =&gt; 'post.php?post=%d', 'capability_type' =&gt; 'post', 'hierarchical' =&gt; true, 'rewrite' =&gt; array("slug" =&gt; "book"), // Permalinks format 'query_var' =&gt; false, 'supports' =&gt; array('title', 'editor', 'comments','thumbnail','page-attributes') )); add_action( 'init', 'create_book_taxonomies', 0 ); function create_book_taxonomies() { register_taxonomy( 'format', 'book', array( 'hierarchical' =&gt; true, 'label' =&gt; __('Formats', 'series'), 'query_var' =&gt; 'format' ) ); } </code> -cheers, mc.
So it turns out the difference between the working site and the broken site was actually in the code (thank god). 'query_var' needs to be set to => "true". There's still a little funkiness, where posts with the same name (but different parents and thus different permalinks) seem like they auto direct to the earliest instance -- but that's fixable by adding a prefix in the permalink edit section of the write screen. For ease of others, here's how I'm registering the post type: register_post_type('book', array( 'label' => __('Books'), 'singular_label' => __('Book'), 'public' => true, 'show_ui' => true, '_builtin' => false, // It's a custom post type, not built in! '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => true, 'rewrite' => array("slug" => "book"), // Permalinks format 'query_var' => false, 'supports' => array('title', 'editor', 'comments','thumbnail','page-attributes') )); add_action( 'init', 'create_book_taxonomies', 0 ); function create_book_taxonomies() { register_taxonomy( 'format', 'book', array( 'hierarchical' => true, 'label' => __('Formats', 'series'), 'query_var' => 'format' ) ); } Cheers, M
Custom Post Type Child Won't Come Through With Pretty Permalinks
wordpress
I'm looking for some options for creating a horizontal flyout/rollover menu from the WordPress categories listing when category items have child nodes. Ideally, all in css, but I can include javascript or enqueue jQuery too.
A lot of themes have a menu like this. The CSS I'm usually using (I left the visual stuff like colors out): (assumming the container is a div and its class is <code> .nav </code> ) <code> /* 1st level items are layed out horizontally */ .nav li{ position:relative; float:left; } /* level 2+ */ .nav ul ul{ position:absolute; z-index:15; display:none; width:300px; top:20px; } /* level 3+ */ .nav ul ul ul{ top:10px; left:280px; } /* 2nd level+ items vertically */ .nav li li{ float: none; } /* when mouse over a list item, show its child nodes */ .nav li:hover ul, .nav li li:hover ul, .nav li li li:hover ul, .nav li li li li:hover ul{ display:block; } /* related to the above property, hide the child's child nodes :) */ .nav li:hover ul ul, .nav li:hover ul ul ul, .nav li:hover ul ul ul ul{ display:none; } </code> You can also use superfish on the list to apply some nice effects to the menu and to make it work in IE 6.
Making a horizontal flyout menu from WordPress category listing
wordpress
The <code> get_blog_list() </code> function has been deprecated from v3.0. How does one get a list of blogs in a multisite blog?
Trac has some discussion and code for possible replacement in future version, ticket #14511 new function - wp_get_sites($args) .
How to Get a List of Sub Blogs without Using get_blog_list()?
wordpress
The going through the mu functions source I come across references to two different ids for sub-blogs - site id and blog ids. In what context is each used?
site_id = the ID of the parent site (the domain, eg. wordpress.com) blog_id = the ID of the parent site's blog(s) (usually sub-domains, eg mary.wordress.com)
What is difference between blog id and site id?
wordpress
I am having a wordpress blog at http://thelazy.info/ . By default, only one post is displayed on the page. I want to increase the default content on the main page to 5-10 posts with a small ting of comments. Is there some plugin or setting to do that in buddypress/wordpress.
By default, only one post is displayed on the page I can see several posts on your main page(6 total), please clarify what you mean. with a small ting of comments. Sorry, what? More details/clarification please. Would have liked to have posted this as a comment but i'm not sure if you can quote properly there.. (feel free to down vote if anyone feels this is a misuse of the answer). Based on the minimal information provided here's one possible solution. Show latest comment after each post on the index. Assumes <code> is_home() </code> is true and applicable for the use case. After the <code> &lt;?php if( have_posts() ) ?&gt; </code> line, but before <code> &lt;?php while( have_posts() ) : ?&gt; </code> .. .. put the following code. <code> &lt;?php if( is_home() ) $_comment_walk = new Walker_Comment; ?&gt; </code> Then, just before the closing part of the while loop, that's this part <code> &lt;?php endwhile; ?&gt; </code> , place the following.. <code> &lt;?php if( is_home() ) : ?&gt; &lt;div style="border:3px solid #000;padding:10px"&gt; &lt;?php $_last_comment = get_comments( 'number=1&amp;post_id=' . get_the_ID() ); $_comment_walk-&gt;paged_walk( $_last_comment, 0, 1, 1, array( 'style' =&gt; 'div', 'avatar_size' =&gt; 40, 'max_depth' =&gt; 1 ) ); ?&gt; &lt;/div&gt; &lt;?php endif; ?&gt; </code> NOTE: The div with the big border is just to make the box standout so you can see the result easily, remove or add to the code as you like and of course feel free to re-position it elsewhere inside the post loop if you like..(i assumed after the post was appropriate). Why did i use the comment walker? The comment gets output the same as it would in a single post instance, and the walker takes care with sanitizing for you. Why did i set the walker before the while loop? So we reuse that same walker instance, rather then creating a new one with each post iteration Hope that helps... :)
Summary and Comments on Main landing Page
wordpress
I'm facing a strange problem: <code> &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'ff', 'orderby' =&gt; 'menu_order', 'order' =&gt; 'ASC', 'posts_per_page' =&gt; 10 ) ); while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); ?&gt; (...) &lt;?php endwhile; ?&gt; </code> This code displays all posts of "ff" type. Works fine. But I do not want to list all posts of this type, I just want the ones that are in "ff_show" category (so the slug/term is "ff_show). Codex tells me that I should use 'category_name' but when I do the loop is always empty: <code> &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'ff', 'category_name' =&gt; 'ff_show', 'orderby' =&gt; 'menu_order', 'order' =&gt; 'ASC', 'posts_per_page' =&gt; 10 ) ); </code> I've tried typing everything after 'category_name', nothing works. The funny thing is when I use category instead of category_name - it ALWAYS shows all the posts. No matter what ID I give. Am I doing something wrong? I'm sure about my category name, it is exactly as I said. When I login to my panel admin and go to categories and hover over one of them it points to: http://localhost/wordpress/wp-admin/edit-tags.php?action=edit&amp;taxonomy=frontpage_categories&amp;post_type=ff&amp;tag_ID=19 BUT 'cat' => '19' shows nothing. :/
Are you absolutely sure <code> ff_show </code> is correct slug? I have suspicions about that underscore... <code> category </code> is not valid query argument at all, it is probably simply discarded. Had you tried this query with id instead of slug? <code> cat </code> argument. Edit. Wait, you are trying to query custom taxonomy? Category arguments have no relation to it at all. Try <code> frontpage_categories =&gt; ff_show </code> (quick guess, don't remember specifics of querying custom stuff. again - not my area). Yeah, found it at last Custom Taxonomies > Querying by Taxonomy
Displaying posts of given category
wordpress
I have this loop in my wordpress site which displays the latest posts with their titles, I want to display the post content after the title. I normally retrieve it with the function get_the_content but I cannot make it work in this case. This is the loop: <code> while ( $q_query-&gt;have_posts() ) { $q_query-&gt;next_post(); $question = get_post($q_query-&gt;post); $loophtml = $loophtml . "&lt;li&gt;&lt;span class='list-question-title'&gt;" . "&lt;a class='list-answer-link' href='" . get_permalink($question-&gt;ID) ."'&gt;" . $question-&gt;post_title . "&lt;/a&gt;&lt;/span&gt;"; $loophtml = $loophtml . "&lt;span class='list-number-answers'&gt;" . get_comments_number($question-&gt;ID) . " comentarios&lt;/span&gt;&amp;nbsp;&amp;#183;&amp;nbsp&lt;a href='" . get_permalink($question-&gt;ID) ."'&gt;Comentar&lt;/a&gt;"; $loophtml = $loophtml . "&lt;/li&gt;"; } </code> Anyone knows how I could do it? Thanks
try this instead: <code> ... global $post; while ($q_query-&gt;have_posts()){ $q_query-&gt;the_post(); $loophtml .= "&lt;li&gt;&lt;span class='list-question-title'&gt;" . "&lt;a class='list-answer-link' href='" . get_permalink() ."'&gt;" . get_the_title() . "&lt;/a&gt;&lt;/span&gt;"; $loophtml .= get_the_content(); $loophtml .= "&lt;span class='list-number-answers'&gt;" . get_comments_number() . " comentarios&lt;/span&gt;&amp;nbsp;&amp;#183;&amp;nbsp&lt;a href='" . get_permalink() ."'&gt;Comentar&lt;/a&gt;"; $loophtml .= "&lt;/li&gt;"; } wp_reset_query(); ... </code>
How do I display the function the_content in this loop?
wordpress
The following url resolves to the category template: http://localhost/author/myusername/?category_name=somecategory I have a <code> category-somecategory.php </code> template and just a generic <code> author.php </code> template. Is there any way to make such a url use the <code> author.php </code> template instead of the <code> category-somecategory.php </code> ? If not how can I filter on both category and author and force it to use the author template?
You could change the template loaded by hooking onto <code> template_include </code> , checking if <code> is_author </code> and <code> is_category </code> are both set, then switch the template for inclusion to the author template instead. Give this a shot.. <code> add_filter( 'template_include', 'my_template_setter' ); function my_template_setter( $template ) { if( is_author() &amp;&amp; is_category() &amp;&amp; is_archive() ) $template = get_author_template(); return $template; } </code> You can do any number of conditional checks here before modifying which template gets loaded. WordPress has several template fetching functions available already, i've used one in the example, but here's a list for quick reference... <code> get_404_template() get_search_template() get_taxonomy_template() get_front_page_template() get_home_template() get_attachment_template() get_single_template() get_page_template() get_category_template() get_tag_template() get_author_template() get_date_template() get_archive_template() </code> Hope that helps..
How to control template resolution if both Author and Category filter in place?
wordpress
I'm trying to add code to my themes functions.php to display fields created with the Cimy user extra fields plugin in the dashboard users.php. I know that I need to use manage_users_columns, but beyond that I'm stuck. Anyone familiar enough with the plugin to help me get the proper fields to display?
I hacked my way into figuring this out. Here's the code for reference: <code> function theme_column_userfield( $defaults ) { $defaults['theme-usercolumn-userfield'] = __('fieldname', 'user-column'); return $defaults; } function theme_custom_column_userfield($value, $column_name, $id) { if( $column_name == 'theme-usercolumn-userfield' ) { return get_cimyFieldValue($id, 'fieldname'); } } add_action('manage_users_custom_column', 'theme_custom_column_userfield', 15, 3); add_filter('manage_users_columns', 'theme_column_userfield', 15, 1); </code>
show cimy user fields in users.php with manage_users_columns
wordpress
I am using Multi-site installation. I don't want all the widgets appear under widgets.php on dashboard .So I tried to find a way to remove or hide unnecessary widgets . SO that the new sub-sites under my Multi-site created won't have much widgets. So the users don't get confuse with lot of widgets . I tried to find the files related to widgets .But I didn't able to find such pages in both wp-admin/includes/widgets.php and wp-admin/widgets.php I also tried to find in themes files .But failed .Could any one help me to find these ? Or Do I have a chance to hide them using functions.php? Thanks in advance !
Add this to your functions.php file: <code> function jpb_unregister_widgets(){ unregister_widget('WP_Widget_Pages'); unregister_widget('WP_Widget_Calendar'); unregister_widget('WP_Widget_Archives'); unregister_widget('WP_Widget_Links'); unregister_widget('WP_Widget_Meta'); unregister_widget('WP_Widget_Search'); unregister_widget('WP_Widget_Text'); unregister_widget('WP_Widget_Categories'); unregister_widget('WP_Widget_Recent_Posts'); unregister_widget('WP_Widget_Recent_Comments'); unregister_widget('WP_Widget_RSS'); unregister_widget('WP_Widget_Tag_Cloud'); unregister_widget('WP_Nav_Menu_Widget'); } add_action( 'widgets_init', 'jpb_unregister_widgets' ); </code> This will get rid of all default widgets. If you want to keep a certain widget, remove that line from the function above.
How to hide or remove unwanted widgets on Multisite installation?
wordpress
I have a custom post type that is just a paginated post and acts as a slideshow. How can I make it so that the reader can choose an option to have the slideshow advance automatically to the next page after some preset interval (like 10 seconds)?
Hi @matt: To achieve what you are asking you need to add some code to queue up a Javascript file and then the Javascript file itself. You can put the code that follows in your theme's <code> functions.php </code> file. You'll note it uses <code> is_admin() </code> to avoid loading the Javascript code in your <code> /wp-admin/ </code> console; you should also add a criteria to avoid loaded it except on the pages where you need (however I wasn't sure how to limit it since your question didn't explain enough specifics to do so): <code> add_action('init','action_init_page_auto_advance'); function action_init_page_auto_advance() { if (!is_admin()) { // Make this if() limited to just the pages you need. $ss_url = get_stylesheet_directory_uri(); wp_enqueue_script('jquery'); wp_enqueue_script('page-auto-advance', "{$ss_url}/js/page-auto-advance.js", array("jquery") ); } } </code> The prior code loads a file called <code> page-auto-advance.js </code> that you'll place in a subdirectory of your theme named <code> /js/ </code> and here's that file. Note it assumes you have "next" links on your site in the format of <code> &lt;a rel="next" href="..."&gt;...&lt;/a&gt; </code> : <code> jQuery(document).ready(function($){ var href = $("a[rel='next']").attr("href"); if (href!=undefined) setTimeout('window.location.href = jQuery("a[rel='next']").attr("href");',5000); }); </code> The prior Javascript will advance the page every five seconds (5000 = 5 x 1000 milliseconds) if it finds a link with a <code> rel="next" </code> on the page. One thing to be aware of is you might find that it advances when you don't want it to but with this code hopefully you'll have a starting point that will let you fine-tune it.
Script to Automatically Advance to the Next Page of a Paginated Post
wordpress
How to set the menu active state for a custom posttype and category, given a custom taxonomy term? I have a custom taxonomy: region, a custom posttype: business, and use the categories taxonomy. My custom primary menu consists of the region terms. When I select a region, the corresponding menu item is highlighted OK. The region page shows a listing of relevant categories. Now, when I select a category on this page the corresponding menu item is not highlighted. In turn, the category page shows a listing of businesses. Also, when I click on a business, the corresponding menu-item is not highlighted. So, how to set the menu active state on a category page and on a business post, given a custom taxonomy term? I do have a session variable region available on these pages.
When you create a custom menu item for the custom post type archive you have to include the entire url and not just '/your-custom-post-type-name'. If you use the entire url the wordpress url rewrite function will check it against all the other menu items as well as against all your pages and so on. What you end up with in the menu parent is something like 'current-menu-ancestor current-menu-parent current_page_parent current_page_ancestor'.
Set menu active state for custom posttype and category, given custom taxonomy term
wordpress
How to rewrite permalinks for a custom posttype and custom taxonomy? I have a custom taxonomy: region, and a custom posttype: business. Now, how to rewrite the permalink, so that for a category, the fixed "category" part is replaced with the custom taxonomy term: <code> /%region%/%category%/ </code> for a business: <code> /%region%/%category%/%business%/ </code> I'm stuck with this. However, I did manage to rewrite the permalink for a region to <code> /%region%/ </code> : <code> add_action( 'init', 'region_init' ); function region_init() { // set labels $labels = array( 'name' =&gt; _x( 'Regions', 'taxonomy general name' ), 'singular_name' =&gt; _x( 'Region', 'taxonomy singular name' ), 'search_items' =&gt; __( 'Search Regions' ), 'popular_items' =&gt; __( 'Popular Regions' ), 'all_items' =&gt; __( 'All Regions' ), 'parent_item' =&gt; __( 'Parent Region' ), 'parent_item_colon' =&gt; __( 'Parent Region:' ), 'edit_item' =&gt; __( 'Edit Region' ), 'update_item' =&gt; __( 'Update Region' ), 'add_new_item' =&gt; __( 'Add New Region' ), 'new_item_name' =&gt; __( 'New Region Name' ) ); // create a new taxonomy register_taxonomy( 'region', 'business', array( 'labels' =&gt; $labels, 'label' =&gt; __('Region'), 'sort' =&gt; true, 'args' =&gt; array('orderby' =&gt; 'term_order'), 'show_in_nav_menus' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; '', 'with_front' =&gt; false ) ) ); } add_action('init', 'my_rewrite'); function my_rewrite() { global $wp_rewrite; $wp_rewrite-&gt;add_permastruct('typename', 'typename/%year%/%postname%/', true, 1); add_rewrite_rule('typename/([0-9]{4})/(.+)/?$', 'index.php?typename=$matches[2]', 'top'); $wp_rewrite-&gt;flush_rules(); // !!! } </code>
The Custom Post Permalinks (Wordpress Plugin) from John P. Bloch did the trick for me. Great /flexible plugin!
Rewrite permalinks for custom posttype and custom taxonomy
wordpress
I'm trying to output a unique widget ID inside my mult-instance widgets. So far the following hasn't worked. Is there a unique ID and how do I call it? Thanks. <code> function widget($args, $instance) { // outputs the content of the widget extract( $args ); $widget_id = $instance['widget_id']; ?&gt; &lt;?php echo $widget_id ; ?&gt; &lt;?php } </code> Thanks.
You can get the instance ID with <code> echo $this-&gt;id; </code> ( <code> $this </code> is the class instance) The only time you can't get this id is from the <code> form() </code> function, right after you just dropped the widget (stackexchange-url ("here")'s the reason why)
Calling the widget id of a mult-instance widget from inside the widget?
wordpress
I have a vertical menu using the superfish script that shows categories in a custom 'productcategory' taxonomy. This menu has multiple levels, and is hierarchical.At the bottom of each branch of the tree we have the end category which represents a range of products, which the client does not want to show in this menu. I am using this code to display it: <code> &lt;ul class="frontcatlist sf-menu"&gt; &lt;?php $a = array( 'title_li' =&gt; '', 'taxonomy' =&gt; 'productcategory', 'depth' =&gt; 2 ); wp_list_categories( $a ); ?&gt; &lt;/ul&gt; </code> This is what I currently have in terms of what is showing and what isnt. left being the main categories, and each line being 1 step down to its children: Those in the red are the categories that are not shown in the menu, This is not what my client needs however. While I could produce a menu that fits the requirements using the native Wordpress 3 menus, that would require manual intervention, intervention that is undesirable, both from a usability perspective, and from the clients wishes. Since some main categories have subcategories that should be shown and some dont, the depth parameter will not suffice. Instead this is what I need, with the top level categories always showing: Im not sure how to do this, and the only clue I have is a custom walker class to output custom html, during which I might be able to filter out the ones I dont want ( any categories with a parent that has no children) . But I could not see any sufficient examples or articles on the subject, and I'd rather not loose the classes and markup wordpress provides If anybody has any thoughts, or knows of tutorials forum posts or articles of use, I'd much appreciate it =)
I've made some progress based on walker classes but havent gotten ti working quite as needed because wordpress doesnt appear to handle the root nodes of the taxonomy tree in the same way as the child ones. As a result, it prunes the end menu items, but if the parent of that node is a root level node, it prunes the node and leaves an empty ul element behind, <code> &lt;ul&gt;&lt;/ul&gt; </code> . The code that fixes this issue on child nodes does not work for a root node, resulting in the whole structure flattening with no submenus <code> class Post_Category_Walker extends Walker_Category { private $term_ids = array(); function __construct( /*$post_id,*/ $taxonomy ) { // fetch the list of term ids for the given post $this-&gt;taxterms = get_terms( $taxonomy); $this-&gt;noshow = array(); } function isdisplayable( $element, &amp;$children_elements, $args ){ $id = $element-&gt;term_id; if(in_array($element-&gt;term_id, $this-&gt;noshow)){ return false; } $display = true; if($element-&gt;parent != 0){ $display = false; if ( isset( $children_elements[ $id ] ) ) { $display = true; } } if($depth == 0){ $display = true; } return $display; } function hasChildren( $element/*, &amp;$children_elements*/){ foreach($this-&gt;taxterms as $term){ if($term-&gt;parent == $element-&gt;term_id){ return true; } } return false;//(isset($children_elements[$element-&gt;term_id])); } function display_element( $element, &amp;$children_elements, $max_depth, $depth=0, $args, &amp;$output ) { $display = $this-&gt;isdisplayable( $element, $children_elements, $args ); $id = $element-&gt;term_id; if($element-&gt;parent != 0){ if($this-&gt;hasChildren($element)){ //isset( $children_elements[ $id ] ) ) { $endnode = true; //print_r($children_elements[ $id ]); foreach($this-&gt;taxterms as $child){ if($child-&gt;parent == $element-&gt;term_id){ if($this-&gt;hasChildren($child)){ $endnode = false; break; } } } if($endnode == true){ //$children_elements = NULL; unset( $children_elements[ $id ] ); $newlevel = false; $args[0]['has_children'] = 0; } } }else{ // Wordpress separates out the terms into top level and child terms, // making the top level terms very costly as it passes in an empty // array as the children_elements unlike the other terms //if($this-&gt;hasChildren($element)){ foreach($this-&gt;taxterms as $term){ if($term-&gt;parent == $element-&gt;term_id){ if(!$this-&gt;hasChildren($term)){ $this-&gt;noshow[] = $term-&gt;term_id; unset($newlevel); $args[0]['has_children'] = 0; } } } //} } if ( $display ) parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); } } $a = array( 'title_li' =&gt; '', 'taxonomy' =&gt; 'productcategory', 'walker' =&gt; new Post_Category_Walker('productcategory') ); wp_list_categories( $a ); </code> A temporary workaround is to remove them via the following jquery snippet: <code> $("ul").each( function() { var elem = $(this); if (elem.children().length == 0) { elem.remove(); } } ); </code>
Controlling Taxonomy Category listings to hide and unhide specifics
wordpress
this is a silly question, but i dont know, can anyone help me out in this i want to <code> echo get_post_meta() </code> on a url, but i am getting parse error i am having a function, where in the between of url one field can be filled by the value of custom field here is the code <code> ($doc-&gt;load('http://twitter.com/statuses/user_timeline/' . . '.rss')); </code> the space between <code> . . </code> there i want to echo the value of my get_post_meta value, but if i write something like this <code> ($doc-&gt;load('http://twitter.com/statuses/user_timeline/' .echo get_post_meta() . '.rss')); </code> i know this step is wrong, then too i tried, i get parse error how can i echo it???
Remove the echo. In PHP, you only use echo when you want to send the result as text to the browser. If you want to use the value in PHP (like you are trying to do), then you leave out the echo and add $post-> ID, 'meta_field_you_want', true to get_post_meta();
echo get_post_meta()
wordpress
Im building a directory site and for each business listing I wanted to include a printable coupon. I would want users to be able to click the coupon image (or link) and a printable version of the coupon to show up. I looked around for solutions but couldn't find anything that could help. Any help would be appreciated. Thanks a lot.
You might be probably looking for a plugin that offer's groupon-like functionality ( “Groupon 1.0 started on a WordPress blog.” ). By googling I learned that there is a plugin called WP Coupon (Wordpress Plugin) ( review ). No idea if it fits in what you need, but it looks like it does what you're looking for. But it's probably additionally worth to checkout if groupon and other similar fast growing sites do offer a webservice so that actually the job is already done: Groupon API
How to add coupon printer?
wordpress
Currently I have the loop listing posts between two dates using the <code> posts_where </code> filter: <code> function filter_where( $where = '' ) { $where .= " AND post_date &gt;= '2000-01-01' AND post_date &lt;= 2004-12-31' "; return where; } add_filter('posts_where', 'filter_where'); query_posts($query_string); while (have_posts()) : the_post(); the_content(); endwhile; </code> In a <code> meta_key </code> called <code> original_date </code> I have stored a different date for each post that I wish to use instead of the <code> post_date </code> . How do I correctly call up this <code> meta_key </code> into the <code> $where </code> query to fulfil the same purpose as the <code> post_date </code> ? <code> $where .= " AND [meta_key=original_date] &gt;= '2000-01-01' AND [meta_key=original_date] &lt;= '2004-12-31' "; </code> For example, the following SQL query doesn't seem to work, even though correct values ( <code> 2001-10-29 </code> , <code> 2004-11-03 </code> , etc.) are present in the <code> original_date </code> <code> meta_key </code> of the posts: <code> global $wpdb; $where .= " AND (SELECT meta_value FROM $wpdb-&gt;postmeta WHERE meta_key='original_date' ) &gt;= '2000-01-01' AND (SELECT meta_value FROM $wpdb-&gt;postmeta WHERE meta_key='original_date' ) &lt;= '2004-12-31' "; </code> whereas the following works fine on the same posts using their <code> post_date </code> as reference: <code> $where .= " AND post_date &gt;= '2000-01-01' AND post_date &lt;= 2004-12-31' "; </code> Perhaps the <code> meta_value </code> array needs to be stripped of some extraneous material in order to format the results into the same form as <code> post_date </code> ? How can we approach this?
Thanks to stackexchange-url ("AmbitiousAmoeba") for the answer. The following improved code solves the problem: <code> function filter_where( $where = '' ) { global $wpdb; $where .= " AND (($wpdb-&gt;postmeta.meta_key = 'original_date' AND $wpdb-&gt;postmeta.meta_value &gt;= '2000-01-01') AND ($wpdb-&gt;postmeta.meta_key = 'original_date' AND $wpdb-&gt;postmeta.meta_value &lt;= '2004-12-31')) "; return where; } add_filter('posts_where', 'filter_where'); query_posts($query_string); while (have_posts()) : the_post(); the_content(); endwhile; </code>
How to correctly call custom field dates into a posts_where filter using SQL statements
wordpress
I have a bunch of pages and I only want to include 2 or 3 pages on my main menu. How would I do that? Currently my code looks like this: <code> wp_page_menu('include=156,572,542&amp;sort_column=menu_order&amp;echo=0'); </code> If I am going to insert <code> exclude=x pages </code> , it wouldn't make sense because there's just too many of them. Please no plugin recommendation. I've tried some but they conflict with other things I do in this regard. UPDATE Here's the full function: <code> function main_nav() {?&gt; &lt;div id="access"&gt; &lt;div id="sub-access"&gt; &lt;div id="sub-sub-access"&gt; &lt;div class="skip-link"&gt;&lt;a href="#content"&gt;"&gt;&lt;?php _e('Skip to content', 'thematic'); ?&gt;&lt;/a&gt;&lt;/div&gt; &lt;?php echo preg_replace('/&lt;ul&gt;/', '&lt;ul class="sf-menu"&gt;', wp_page_menu('include=11,13,7,9,4&amp;sort_column=menu_order&amp;echo=0'), 1);?&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;!-- #access --&gt; &lt;?php } add_action('thematic_header','main_nav',9); </code> It's a custom version of Thematic's thematic_access() function. I don't know why it's behaving this way. I tried it on a new installation, it doesn't work still.
try <code> ... echo preg_replace('/&lt;ul&gt;/', '&lt;ul class="sf-menu"&gt;', wp_page_menu( array( 'include' =&gt; '11,13,7,9,4', 'sort_column' =&gt; 'menu_order', 'echo' =&gt; 0)), 1); </code> or <code> ... echo preg_replace('/&lt;ul&gt;/', '&lt;ul class="sf-menu"&gt;', wp_page_menu( array( 'include' =&gt; array(11,13,7,9,4), 'sort_column' =&gt; 'menu_order', 'echo' =&gt; 0)), 1); </code> btw, there are better ways to add classes to html tags than using regexes like this...
Exclude all pages except a few?
wordpress
I've posted a bug-report about this a few months ago (on WordPress trac (Widget Instance Form Update Bug)) and I thought I'd try writing about it here too. Maybe someone has a better solution to this issue than me. Basically the problem is that if you drop a widget into a sidebar, the widget form doesn't get updated until you manually press save (or reload the page). This makes unusable all the code from the <code> form() </code> function that relies on the widget instance ID to do something (until you press the save button). Any stuff like ajax requests, jQuery things like colorpickers and so on will not work right away, because from that function it would appear that the widget instance has not yet been initialized. A dirty fix would be to trigger the save button automatically using something like livequery: <code> $("#widgets-right .needfix").livequery(function(){ var widget = $(this).closest('div.widget'); wpWidgets.save(widget, 0, 1, 0); return false; }); </code> and add the <code> .needfix </code> class in <code> form() </code> if the widget instance doesn't look initialized: <code> &lt;div &lt;?php if(!is_numeric($this-&gt;number)): ?&gt;class="needfix"&lt;?php endif; ?&gt; ... &lt;/div&gt; </code> One drawback of this solution is that if you have lots of widgets registered, the browser will eat lots of CPU, because livequery checks for DOM changes every second (tho I didn't specifically test this, it's just my assumption :) Any suggestions for a better way to fix the bug?
I did battle with a similar situation recently. Ajax in widgets is no joke! Need to write some pretty crazy code to get things to work across instances. I'm not familiar with live query, but if you say it checks the DOM every second, I might have a less intense solution for you: <code> var get_widget_id = function ( selector ) { var selector, widget_id = false; var id_attr = $( selector ).closest( 'form' ).find( 'input[name="widget-id"]' ).val(); if ( typeof( id_attr ) != 'undefined' ) { var parts = id_attr.split( '-' ); widget_id = parts[parts.length-1]; } return parseInt( widget_id ); }; </code> You can pass this function a selector or jQuery object and it will return the instance ID of the current instance. I could find no other way around this issue. Glad to hear I'm not the only one :)
Update widget form after drag-and-drop (WP save bug)
wordpress
i have a code which is use to display twitter tweets but the problem is, it is displaying before the content of post, i know the problem is with echo, cause it is echoing first and then the post is coming, so the post comes after the tweets, when i tried to make the echoes to return then the tweets are not coming here is my code <code> function append_the_content1($content) { //if(get_option('tweetID')!=null){ $content .= "&lt;div class='post'&gt;&lt;p&gt;".tweet(get_option('tweetID'))."&lt;/p&gt;&lt;/div&gt;"; return $content; //} //else{ //return $content; //} } add_filter('the_content', 'append_the_content1'); function tweet(){ $doc = new DOMDocument(); if (get_option('tweetID') != null) { if($doc-&gt;load('http://twitter.com/statuses/user_timeline/'.get_option('tweetID').'.rss')) { $output = "&lt;ul&gt;"; # number of &lt;li&gt; elements to display. 20 is the maximum $max_tweets = 5; $i = 1; foreach ($doc-&gt;getElementsByTagName('item') as $node) { # fetch the title from the RSS feed. # Note: 'pubDate' and 'link' are also useful (I use them in the sidebar of this blog) $tweet = $node-&gt;getElementsByTagName('title')-&gt;item(0)-&gt;nodeValue; # the title of each tweet starts with "username: " which I want to remove $tweet = substr($tweet, stripos($tweet, ':') + 1); # OPTIONAL: turn URLs into links $tweet = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '&lt;a href="$1"&gt;$1&lt;/a&gt;', $tweet); # OPTIONAL: turn @replies into links $tweet = preg_replace("/@([0-9a-zA-Z]+)/", "&lt;a href=\"http://twitter.com/$1\"&gt;@$1&lt;/a&gt;", $tweet); $output = "Twiiter Updates:&lt;li&gt;". $tweet . "&lt;/li&gt;\n"; if($i++ &gt;= $max_tweets) break; } $output = "&lt;/ul&gt;\n"; return $output; } } } </code>
Functions can only return one value. Change all the <code> echo </code> statements in your <code> tweet </code> function to concatenate a string, then return the string at the end of the function.
echo or return?
wordpress
Currently I am working on adding a breadcrumb without a plugin to a site. I found several possibilities on how to do that, but what I specifically want is to take one Page out of the trail. My current trail is as follows: home - products - productgroup - productsubgroup - productname What I want it to become is: home - productgroup - productsubgroup - productname Does anyone have experience with this particular challenge? I'm on the latest WP version and I am using a child theme of Twenty Ten. More info on the breadcrumb I am using: http://www.bloggingtips.com/2009/02/22/create-a-breadcrumb-trail/
Based on the code your used my guess is it would be as simple as adding a <code> unset($bcarray[0]); </code> to their code on line 15. Here is the code in it's entirety: <code> function write_breadcrumb() { $pid = $post-&gt;ID; $trail = "&lt;a href='/'&gt;Home&lt;/a&gt;"; if (is_front_page()) : // do nothing elseif (is_page()) : $bcarray = array(); $pdata = get_post($pid); $bcarray[] = " &amp;raquo; ".$pdata-&gt;post_title."\n"; while ($pdata-&gt;post_parent) : $pdata = get_post($pdata-&gt;post_parent); $bcarray[] = " &amp;raquo; &lt;a href='".get_permalink($pdata-&gt;ID)."'&gt;".$pdata-&gt;post_title."&lt;/a&gt;\n"; endwhile; $bcarray = array_reverse($bcarray); unset($bcarray[0]); foreach ($bcarray AS $listitem) : $trail .= $listitem; endforeach; elseif (is_single()) : $pdata = get_the_category($pid); $data = get_category_parents($pdata[0]-&gt;cat_ID, TRUE, ' &amp;raquo; '); $trail .= " &amp;raquo; ".substr($data,0,-8); endif; return $trail; } </code> -Mike
delete a page from a breadcrumb trail
wordpress
I am writing a plugin for the back end but I need to add javascript that is created in a for loop to the head of the page. How do i do this? Steve
Hi @Steve Clark: I think what you are looking for is here (Look for the section entitled "Load Scripts only on pages where needed"): <a href="stackexchange-url What is the best way to add custom javascript files to the site?
Adding custom Javascript to the head tag in Admin
wordpress
my question may look like stackexchange-url ("Pagination not working with custom loop"), but there is a different. I use the custom loop for display flash game. I want to make a pagination on page games by category. category.php : <code> &lt;?php if ($cat) { $cols = 2; $rows = 4; $paged = (('paged')) ? get_query_var('paged') : 1; $post_per_page = $cols * $rows; // -1 shows all posts $do_not_show_stickies = 1; // 0 to show stickies $args = array( 'post_type' =&gt; 'game', 'category__in' =&gt; array($cat), 'orderby' =&gt; 'date', 'order' =&gt; 'DESC', 'paged' =&gt; $paged, 'posts_per_page' =&gt; $post_per_page, 'caller_get_posts' =&gt; $do_not_show_stickies ); $wp_query = new WP_Query($args); begin_roundblock(get_cat_name($cat), 'games-pages-category', null); if (have_posts()): echo '&lt;div class="games-list-block-content"&gt;'; /* Begin Breadcrump*/ echo '&lt;div class="breadcrumb"&gt;'; if(function_exists('bcn_display')) { echo '&lt;div class="breadcrumb-text"&gt;'; echo 'Go Back:'; bcn_display(); echo '&lt;/div&gt;'; } echo '&lt;/div&gt;'; /* End Breadcrump*/ $i = 0; while (have_posts()) { the_post(); $class = 'game-info'; if ($i % $cols == 0) $class .= ' clear'; echo '&lt;div class="'.$class.'"&gt;&lt;a href="'.get_permalink().'"&gt;'; the_post_thumbnail(array(60, 60), array('class' =&gt; 'game-icon')); $title = get_the_title(); if (mb_strlen($title) &gt; 7) $title = mb_substr($title, 0, 6).'...'; echo '&lt;span class="game-title"&gt;'.$title.'&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;'; $i++; } ?&gt; &lt;div class="navigation clear game-info-last-row"&gt; &lt;?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?&gt; &lt;/div&gt; //For default WP &lt;div class="navigation"&gt; &lt;div class="alignleft"&gt;&lt;?php next_posts_link('« Older Entries') ?&gt;&lt;/div&gt; &lt;div class="alignright"&gt;&lt;?php previous_posts_link('Newer Entries »') ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php else: ?&gt; &lt;h2 class="center"&gt;Not Found&lt;/h2&gt; &lt;p class="center"&gt;Sorry, but you are looking for something that isnt here.&lt;/p&gt; &lt;?php get_search_form(); ?&gt; &lt;?php endif; end_roundblock(); } ?&gt; </code> I got the pagination links, also I tried to use the wp-pagenavi plugin and it's right calculate the number of my post's(game's) to display with right number of pages. But when I clicked on link "Older Entries" (or any page in case pagenavi plugin) it's go to main page, but url is "http://mydomain/category/category_name/page/2". I try to use many other plugin's, but all the same. Doe's anybody could help me with it? Thanks.
If this is the main loop you use to display posts on your page, you should not execute a new loop but modify the existing loop that WordPress will execute anyway. This way you can be sure that all extra query parameters will be taken into account. Here we want to display posts of type <code> game </code> and limit the number of posts on the page. You can do this with the following code: <code> add_action( 'pre_get_posts', 'wpse5477_pre_get_posts' ); function wpse5477_pre_get_posts( &amp;$wp_query ) { if ( $wp_query-&gt;is_category() ) { $wp_query-&gt;set( 'post_type', 'game' ); $wp_query-&gt;set( 'posts_per_page', 2 ); } } </code>
Pagination with custom loop
wordpress
this rss feed question was resolved but now when i tried this code <code> &lt;a href="&lt;?php echo get_post_comments_feed_link($feed); ?&gt;"&gt;RSS feed of this post&lt;/a&gt; </code> on my archives page,then i am getting the wrong url feed what i want is when i click on the this feed, then i should get all the feeds of that current page which means, my url is this <code> http://mbas.in/location/mba-in-ghana </code> where location is my custom taxonomy, if i write this in url <code> http://mbas.in/location/mba-in-ghana/feed </code> then i get all the feeds of that page, but if i write the code and i click on the link then it is giving me feeds of this url <code> http://mbas.in/university-ghana-business-school/emba/feed </code> this is the first post of my that page, what is the problem with this?
Not entirely sure. This is template tag and should be used in Loop, but for single post page it works fine most of the time even outside of Loop. Seems to from quick test. Disregard that. The issue is you were forgetting to <code> echo </code> it. :) Also there is specialized template tag for comment feeds: <code> get_post_comments_feed_link() </code> . and is there any plugin where as soon as i publish a new post, automatically the rss feed is also created of it??? Not sure what you mean here. When post is published it automatically appears in main site's feed.
rss feed code help
wordpress
I have created a page template for the front page of a site I am building using WordPress. I am displaying the 3 latest posts on this page and all works fine except for the display of the author of the post. I am using the following code <code> &lt;?php $recentposts=get_posts('showposts=3'); if ($recentposts) { foreach($recentposts as $post) { //setup_postdata($post); ?&gt; &lt;div class="fifthFloat"&gt; &lt;h3&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Link to &lt;?php the_title_attribute(); ?&gt;"&gt; &lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt; &lt;p&gt; &lt;?php $postContent = $post-&gt;post_content; if(strlen($postContent) &gt; 50) { $postContent = substr($postContent, 0, strrpos(substr($postContent, 0, 60), " ")) . " ..."; } echo $postContent; ?&gt; &lt;/p&gt; &lt;p&gt;Posted &lt;?php the_time("jS M Y"); ?&gt; by &lt;?php the_author(); ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php } } ?&gt; </code> and I have also tried the following <code> $user_info = get_userdata($post-&gt;post_author); echo $user_info-&gt;first_name; echo $user_info-&gt;last_name; </code> but both result in an empty string.
Any reason this is commented out? <code> //setup_postdata($post); </code> This function setups global variables for current post and author data is pulled from one of those.
the_author() returns empty string
wordpress
I'd like to rename files during upload and set their names to the post slug the files are being attached to, plus some random characters (a simple incremental counter will de just fine) to make the filenames different. In other words, if I'm uploading/attaching images to the post whose page slug is "test-page-slug", I'd like for the images to be renamed on the fly to <code> test-page-slug-[C].[extension] </code> : test-page-slug-1.jpg test-page-slug-2.jpg etc, it doesn't matter what the original filenames were. There's this plugin, Custom Upload Dir : With this plugin you can construct paths from additional variables like: post title, ID, category, post author, post date and much more. How can I do the same to filenames?
You'll want to hook in to the wp_handle_upload_prefilter filter (which I can't find any documentation on, but seems pretty simple). I've tried this out locally, and it seems to work for me: <code> function wpsx_5505_modify_uploaded_file_names($arr) { // Get the parent post ID, if there is one if( isset($_REQUEST['post_id']) ) { $post_id = $_REQUEST['post_id']; } else { $post_id = false; } // Only do this if we got the post ID--otherwise they're probably in // the media section rather than uploading an image from a post. if($post_id &amp;&amp; is_numeric($post_id)) { // Get the post slug $post_obj = get_post($post_id); $post_slug = $post_obj-&gt;post_name; // If we found a slug if($post_slug) { $random_number = rand(10000,99999); $arr['name'] = $post_slug . '-' . $random_number . '.jpg'; } } return $arr; } add_filter('wp_handle_upload_prefilter', 'wpsx_5505_modify_uploaded_file_names', 1, 1); </code> In my testing, it seems like posts only have a slug if you have pretty permalinks enabled, so I've added a check to make sure there is a slug before renaming the file. You'll also want to consider checking the file type, which I haven't done here--I've just assumed it's a jpg. EDIT As requested in the comment, this additional function alters some of the meta attributes for the uploaded image. Doesn't appear to let you set the ALT text though, and for some reason the value you set as the "caption" is actually assigned as the description. You'll have to monkey with it. I found this filter in the function wp_read_image_metadata(), which is located in wp-admin/includes/image.php. It's what the media upload and wp_generate_attachment_metadata functions rely on to pull metadata from the image. You can take a look there if you want some more insight. <code> function wpsx_5505_modify_uploaded_file_meta($meta, $file, $sourceImageType) { // Get the parent post ID, if there is one if( isset($_REQUEST['post_id']) ) { $post_id = $_REQUEST['post_id']; } else { $post_id = false; } // Only do this if we got the post ID--otherwise they're probably in // the media section rather than uploading an image from a post. if($post_id &amp;&amp; is_numeric($post_id)) { // Get the post title $post_title = get_the_title($post_id); // If we found a title if($post_title) { $meta['title'] = $post_title; $meta['caption'] = $post_title; } } return $meta; } add_filter('wp_read_image_metadata', 'wpsx_5505_modify_uploaded_file_meta', 1, 3); </code> Edited 04/04/2012 to pull post ID from the REQUEST obj rather than checking the GET and POST successively. Based on suggestions in the comments.
Rename files during upload using variables
wordpress
Basically we're (ab)using Category to determine whether a post is a News post or a Blog post, and so it's not a category in the traditional sense to the outside world. I'd like the category to not be indexed by feed-readers/crawlers, only the tags. I found an easy way to do it with an easy change to 1 function in the core, but I'd rather avoid that if possible. Is there a way to do that without modifying core? (Specifically <code> get_the_category_rss </code> in <code> wp-includes/feed.php </code> ) EDIT: What I mean specifically is to not list the category in the feed. For example, this is what part the current RSS2 feed looks like: <code> &lt;category&gt;&lt;![CDATA[blog]]&gt;&lt;/category&gt; &lt;category&gt;&lt;![CDATA[test]]&gt;&lt;/category&gt; &lt;category&gt;&lt;![CDATA[testing]]&gt;&lt;/category&gt; &lt;category&gt;&lt;![CDATA[yeah!]]&gt;&lt;/category&gt; </code> "blog" is a Wordpress Category, while "test", "testing", and "yeah!" are Wordpress Tags. What I want is to exclude the entry <code> &lt;category&gt;&lt;![CDATA[blog]]&gt;&lt;/category&gt; </code> entirely from the feed. The same should apply to Atom feeds and any others.
Tricky. It lumps categories and tags together pretty good. Had couple of approaches here is least messy: <code> add_filter('the_category_rss', 'remove_rss_categories'); function remove_rss_categories( $the_list ) { $categories = get_the_category(); foreach ($categories as $category) $the_list = str_replace("&lt;category&gt;&lt;![CDATA[{$category-&gt;name}]]&gt;&lt;/category&gt;", '', $the_list); return $the_list; } </code>
How to not treat categories as tags in feeds
wordpress
I have a need to customize some posts from the loop. Here's the deal: My site is set to 10 posts per page. On post #2,#5, #7 (on every page), I want to display specific background. What's the best solution for this kind of problem?
This should do it: <code> $real_current_post = $wp_query-&gt;current_post + 1; switch( $real_current_post ){ case 2: // Do something for 2 break; case 5: // Do something for 5 break; case 7: // Do something for 7 break; } </code> You may need to globalize $wp_query, but as long as you're using the normal template hierarchy, it should already be in scope. If you do use <code> global $wp_query; </code> , use it before the loop starts.
How to track post number on the_loop
wordpress
Which function can be used to get the user's object using the username? I've tried get_userdatabylogin() but the function seemed to throw an error: Parse error, unexpected T_STRING on line xx The function was called like so: get_userdatabylogin($username);
That function should do what you want. Are you sure the error is not elsewhere? You can also try using the <code> get_user_by() </code> ( source ) function: <code> $user = get_user_by('login', 'MaryJane'); </code> This is the same as <code> get_userdatabylogin('MaryJane'); </code>
Function Get User Object By Username?
wordpress
I am trying to manually upgrade my wordpress to the latest version (3.0.3)-- after autoupgrade fails. After the upgrade everything works fine except for one little nagging message at the top of my admin area: An automated WordPress update has failed to complete - please attempt the update again now I search the Internet and everyone is saying that it is because of a <code> .maintenance </code> file located in the Wordpress root folder, a relic of a failed auto-upgrade or a manual upgrade. In the second case one would just have to delete that file and everything would be fine. But I search my wordpress installed directory, there is no such file. Any idea what contributes to this problem?
I think what Rarst means is that it is a .file (or hidden file) much like the .htaccess file. If you are browsing your files, there is an option to show hidden files. Once that option is chosen, you will most likely also see the .maintenance file
"An automated WordPress update has failed to complete - please attempt the update again now"-- But there is no .maintenance file
wordpress
I don't need to search for pages in my site and only want to search posts, is there a way to do it? Thanks
The below should make the page post type no longer search-able. <code> function remove_pages_from_search() { global $wp_post_types; $wp_post_types['page']-&gt;exclude_from_search = true; } add_action('init', 'remove_pages_from_search'); </code>
How do I remove Pages from search?
wordpress
I'm attempting to use the 'feature image' feature of Wordpress to make a full screen background, that resizes to fit the browser window using jQuery The bit I'm stuck on is adding a custom id (#bgimg) to the code generated by this: <code> &lt;div class="background"&gt;&lt;?php the_post_thumbnail (array(1024,768));?&gt;&lt;/div&gt; </code> The image generated needs to have specific id tag in it, eg... <code> &lt;img id="bgimg" src="wordpress/generated/etc.jpg"&gt; </code> So that the jQuery plugin, can hook on to it, and scale it to fit the browser window. I know the jQuery works (as I've used it in other projects) Any suggestions? Alex
Use get_the_post_thumbnail() instead. It allows you to pass in an array of attributes for the image tag that gets returned. For example: <code> $attr = array( 'id' =&gt; 'YOUR-UNIQUE-ID', ); echo get_the_post_thumbnail( $id, 'thumbnail', $attr ); </code> EDIT: I'm dumb. the_post_thumbnail() also lets you do that. Try passing the same args array I outlined as the second param.
adding an id to the_post_thumbnail
wordpress
My goal is to only show posts with opening hours after business hours, for a given day. So, e.g. I have a (custom) post with following meta_key and meta_value: meta_key = 'monday, meta_value = '14:00 - 22:00' The business hours are fixed: '08:00 - 18:00' I'd like to add a filter to my custom wp_query. Only, I am getting stuck at defining a function. My logic input (definitely not correct &amp; complete) for the function: <code> $from_std = strtotime("08:00"); $to_std = strtotime("18:00"); $open = $my_meta['monday']; list($from, $hyphen, $to) = explode(' ', $open); $from_bus = strtotime($from); $to_bus = strtotime($to); if ($from_bus &lt; $from_std) { $show = 1; } // before standard starting time - so SHOW else {if ($to_bus &gt; $to_std) { $show = 1; }} // after standard closing time - so SHOW if (empty($from_bus)) { show = 0; } // $var is either 0, empty, or not set at all - so do NOT show </code> Help on a function is very much appreciated.
You can use the WP query_posts to filter about your custom values; ean example: <code> query_posts('meta_key=my_type&amp;meta_compare=&lt;=&amp;my_value=20&amp;orderby=my_value'); if (have_posts()) : while ( have_posts() ) : the_post(); </code> But, i think you must replace the time-values for readable string, maybe woth strotime, that you have the same format for the query.
Custom wp_query time filter on meta_value
wordpress
I'm using a custom post type for a portfolio. I have a few option in there, bring saved by <code> update_post_meta() </code> , it seems to work fine, but then out of the blue (within the hour), the data deletes its self. I have looked in the DB and all custom metadata values are empty. I'm a little stumped really. Here's the code that's saving one of the options. <code> function update_colour_palette(){ global $post; $color = get_post_custom($post-&gt;ID); $palette = $color["palette"][0]; update_post_meta($post-&gt;ID, "palette", $_POST["palette"], $palette); } </code> Any help, tips &amp; tricks would be useful.
I've been using this for a while to solve exactly your issue, I think I got it from the codex somewhere. But it works. <code> // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything if ( defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE ) return $post_id; </code>
Post metadata deletes itself
wordpress
I'm wondering why I only get one result in my search. My search query is this: http://www.norwegianfashion.no/?s=oslo+fashion+week If I search google, you'll see I got plenty of hits: http://www.google.no/search?hl=en&amp;client=opera&amp;hs=GTw&amp;rls=en-GB&amp;q=oslo+fashion+week+site%3Awww.norwegianfashion.no&amp;aq=f&amp;aqi=&amp;aql=&amp;oq=&amp;gs_rfai= On my local computer I looked in the query log and I see this: <code> 29 Query SELECT option_name, option_value FROM nfwp_options WHERE autoload = 'yes' 29 Query SELECT option_value FROM nfwp_options WHERE option_name = 'akismet_comment_nonce' LIMIT 1 29 Query SELECT * FROM nfwp_users WHERE user_login = 'admin' 29 Query SELECT user_id, meta_key, meta_value FROM nfwp_usermeta WHERE user_id IN (1) 29 Query SELECT SQL_CALC_FOUND_ROWS nfwp_posts.* FROM nfwp_posts WHERE 1=1 AND (((nfwp_posts.post_title LIKE '%oslo%') OR (nfwp_posts.post_content LIKE '%oslo%')) AND ((nfwp_posts.post_title LIKE '%fashion%') OR (nfwp_posts.post_content LIKE '%fashion%')) AND ((nfwp_posts.post_title LIKE '%week%') OR (nfwp_posts.post_content LIKE '%week%')) OR (nfwp_posts.post_title LIKE '%oslo fashion week%') OR (nfwp_posts.post_content LIKE '%oslo fashion week%')) AND nfwp_posts.post_type IN ('post', 'page', 'attachment') AND (nfwp_posts.post_status = 'publish' OR nfwp_posts.post_author = 1 AND nfwp_posts.post_status = 'private') ORDER BY nfwp_posts.post_date DESC LIMIT 0, 10 29 Query SELECT FOUND_ROWS() 29 Query SELECT post_id, meta_key, meta_value FROM nfwp_postmeta WHERE post_id IN (4139,4135,4130,4129,3831,4126,3750,2564,3667,3573) 29 Query SELECT t.*, tt.* FROM nfwp_terms AS t INNER JOIN nfwp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN nfwp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('post_tag') AND tr.object_id IN (4139) ORDER BY t.name ASC 29 Query SELECT t.*, tt.* FROM nfwp_terms AS t INNER JOIN nfwp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'nav_menu' AND t.term_id = '0' LIMIT 1 29 Query SELECT t.*, tt.* FROM nfwp_terms AS t INNER JOIN nfwp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'nav_menu' AND t.slug = 'quick-menu' LIMIT 1 29 Query SELECT tr.object_id FROM nfwp_term_relationships AS tr INNER JOIN nfwp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('nav_menu') AND tt.term_id IN ('997') ORDER BY tr.object_id ASC 29 Query SELECT nfwp_posts.* FROM nfwp_posts WHERE 1=1 AND nfwp_posts.ID IN (4309) AND nfwp_posts.post_type = 'nav_menu_item' AND (nfwp_posts.post_status = 'publish') ORDER BY menu_order ASC 29 Query SELECT post_id, meta_key, meta_value FROM nfwp_postmeta WHERE post_id IN (4309) 29 Query SELECT nfwp_posts.* FROM nfwp_posts WHERE 1=1 AND nfwp_posts.ID IN (2) AND nfwp_posts.post_type = 'page' AND (nfwp_posts.post_status = 'publish') ORDER BY nfwp_posts.post_date DESC 29 Query SELECT post_id, meta_key, meta_value FROM nfwp_postmeta WHERE post_id IN (2) 29 Query SELECT SQL_CALC_FOUND_ROWS nfwp_posts.* FROM nfwp_posts WHERE 1=1 AND (((nfwp_posts.post_title LIKE '%oslo%20fashion%20week%') OR (nfwp_posts.post_content LIKE '%oslo%20fashion%20week%'))) AND nfwp_posts.post_type IN ('post', 'page', 'attachment') AND (nfwp_posts.post_status = 'publish' OR nfwp_posts.post_author = 1 AND nfwp_posts.post_status = 'private') ORDER BY nfwp_posts.post_date DESC LIMIT 0, 10 29 Query SELECT FOUND_ROWS() 29 Query SELECT t.*, tt.* FROM nfwp_terms AS t INNER JOIN nfwp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'nav_menu' AND t.term_id = '0' LIMIT 1 29 Query SELECT t.*, tt.* FROM nfwp_terms AS t INNER JOIN nfwp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'nav_menu' AND t.slug = 'main-menu' LIMIT 1 29 Query SELECT tr.object_id FROM nfwp_term_relationships AS tr INNER JOIN nfwp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('nav_menu') AND tt.term_id IN ('939') ORDER BY tr.object_id ASC 29 Query SELECT nfwp_posts.* FROM nfwp_posts WHERE 1=1 AND nfwp_posts.ID IN (3729,3731,3732,3733,3734,3735) AND nfwp_posts.post_type = 'nav_menu_item' AND (nfwp_posts.post_status = 'publish') ORDER BY menu_order ASC 29 Query SELECT post_id, meta_key, meta_value FROM nfwp_postmeta WHERE post_id IN (3729,3734,3733,3732,3731,3735) 29 Query SELECT nfwp_posts.* FROM nfwp_posts WHERE 1=1 AND nfwp_posts.ID IN (30,31,786,3365,7) AND nfwp_posts.post_type = 'page' AND (nfwp_posts.post_status = 'publish') ORDER BY nfwp_posts.post_date DESC 29 Query SELECT post_id, meta_key, meta_value FROM nfwp_postmeta WHERE post_id IN (3365,786,31,30,7) 29 Query SELECT t.*, tt.* FROM nfwp_terms AS t INNER JOIN nfwp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN nfwp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (4139) ORDER BY t.name ASC 29 Query SELECT SQL_CALC_FOUND_ROWS nfwp_posts.* FROM nfwp_posts WHERE 1=1 AND nfwp_posts.post_type = 'post' AND (nfwp_posts.post_status = 'publish') ORDER BY nfwp_posts.post_date DESC LIMIT 0, 5 29 Query SELECT FOUND_ROWS() 29 Query SELECT t.*, tt.*, tr.object_id FROM nfwp_terms AS t INNER JOIN nfwp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN nfwp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category', 'post_tag') AND tr.object_id IN (4329, 4318, 4313, 4303, 4277) ORDER BY t.name ASC 29 Query SELECT post_id, meta_key, meta_value FROM nfwp_postmeta WHERE post_id IN (4329,4318,4313,4303,4277) 29 Query SELECT t.*, tt.* FROM nfwp_terms AS t INNER JOIN nfwp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'category' AND t.term_id = '998' LIMIT 1 29 Query SELECT * FROM nfwp_users WHERE ID = 31 LIMIT 1 29 Query SELECT user_id, meta_key, meta_value FROM nfwp_usermeta WHERE user_id IN (31) 29 Query SELECT * FROM nfwp_comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 5 29 Query SELECT * FROM nfwp_posts WHERE ID = 1154 LIMIT 1 29 Query SELECT t.*, tt.* FROM nfwp_terms AS t INNER JOIN nfwp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN nfwp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (1154) ORDER BY t.name ASC 29 Query SELECT * FROM nfwp_posts WHERE ID = 1684 LIMIT 1 29 Query SELECT t.*, tt.* FROM nfwp_terms AS t INNER JOIN nfwp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN nfwp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (1684) ORDER BY t.name ASC 29 Query SELECT * FROM nfwp_posts WHERE ID = 3432 LIMIT 1 29 Query SELECT t.*, tt.* FROM nfwp_terms AS t INNER JOIN nfwp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN nfwp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (3432) ORDER BY t.name ASC 29 Query SELECT * FROM nfwp_posts WHERE ID = 4138 LIMIT 1 29 Query SELECT t.*, tt.* FROM nfwp_terms AS t INNER JOIN nfwp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN nfwp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (4138) ORDER BY t.name ASC </code> You can see that it finds several articles <code> (3729,3731,3732,3733,3734,3735) </code> . I also see a lot of <code> LIMIT 1 </code> in these queries. IS that correct? Any ideas why I'm only getting one result?
What template does search page use? It is either generic <code> index.php </code> or specialized <code> search.php </code> . What does Loop in that template look like? I suspect this might be Loop issue that is set to only dislpay single post, instead of iterating all of them.
Any reason why search result lists only one entry?
wordpress
I have a little bug on my WordPress... When I added a custom field, I have no ajax, I need to saved the draft or publish to see the update. And after I saved my post, the custom field display twice. <code> name : Steffi name : Steffi </code> Help, please ! Thanks Update : Console with Firebug <code> _ajax_nonce 0 _ajax_nonce-add-meta 53208ba18d action add-meta metakeyinput metakeyselect titre metavalue e post_id 1151 </code>
Hey guys, I found THE solution. Problems : Custom field display twice. No Ajax/jQuery visual feedback. If you've been working on the file <code> function.php </code> , make sure you remove extra line breaks. Particularly at the top and <code> the bottom of your file </code> ... If you have some line breaks, your xml got an error : <code> XML or text declaration not at start of entity </code>
Wordpress: custom field display twice
wordpress
I want to migrate a group's site from Joomla to WordPress. The group has a library for members and lends books for certain periods of time, etc. (Regular library functionality). Although the site doesn't have a library functionality in it now, it would be something cool to add. And there's probably some plugin to add this to a page or something for WordPress. Are you aware of something like this? EDIT : The functionality would be: Tracking who borrowed or reserved a book for certain date. Which books are in stock, etc.
just come across this which looks like it might be what you're looking for Web Librarian by Deepsoft. http://www.deepsoft.com/home/products/web-librarian/ appears to be free, and released under a GNU license etc
Library plugin for WordPress
wordpress
this code works fine. the problem i have is that when i submit it only checks the parent category not the subcategory even though i specified both a parent and a subcategory. please. what am i doing wrong. ohh if you look in the html chunk, the <code> 7 </code> is parent cat and the numbers after the comma are the subcategories. <code> &lt;?php if(isset($_POST['new_post']) == '1') { $post_title = $_POST['post_title']; $post_category = $_POST['cat']; $post_content = $_POST['post_content']; $new_post = array( 'ID' =&gt; '', 'post_author' =&gt; $user-&gt;ID, 'post_content' =&gt; $post_content, 'post_title' =&gt; $post_title, 'post_status' =&gt; 'publish', 'post_category' =&gt; array($post_category) ); $post_id = wp_insert_post($new_post); // This will redirect you to the newly created post $post = get_post($post_id); wp_redirect($post-&gt;guid); } ?&gt; </code> this is the <code> html </code> <code> &lt;form method="post" action="" name="" onsubmit="return checkformf(this);"&gt; &lt;input type="text" name="post_title" size="45" id="input-title"/&gt; &lt;textarea rows="5" name="post_content" cols="66" id="text-desc"&gt;&lt;/textarea&gt;&lt;/br&gt; &lt;ul&gt;&lt;select name='cat' id='cat' class='postform' &gt; &lt;option class="level-0" value="7,95"&gt;child cat1&lt;/option&gt; &lt;option class="level-0" value="7,100"&gt;child cat2&lt;/option&gt; &lt;option class="level-0" value="7,101"&gt;child cat3&lt;/option&gt; &lt;option class="level-0" value="7,94"&gt;child cat4&lt;/option&gt; &lt;/select&gt; &lt;/ul&gt; &lt;input type="hidden" name="new_post" value="1"/&gt; &lt;input class="subput" type="submit" name="submitpost" value="Post"/&gt; &lt;/form&gt; </code> please let me know if you need more information. thanks in advance
The problem is, you can't make an array like that in PHP. Trying to cast a string that contains a comma separated list as an array just produces an array with a single value--your comma separated string. You want to use php's explode function to create the array. It takes a string an splits it into a bona fide array based on an arbitrary delimiter (in your case, we'll use a comma). Try something like this: <code> if(isset($_POST['new_post']) == '1') { $post_title = $_POST['post_title']; $arr_post_category = explode(',',$_POST['cat']); // EXPLODE! $post_content = $_POST['post_content']; $new_post = array( 'ID' =&gt; '', 'post_author' =&gt; $user-&gt;ID, 'post_content' =&gt; $post_content, 'post_title' =&gt; $post_title, 'post_status' =&gt; 'publish', 'post_category' =&gt; $arr_post_category // NOW IT'S ALREADY AN ARRAY ); $post_id = wp_insert_post($new_post); // This will redirect you to the newly created post $post = get_post($post_id); wp_redirect($post-&gt;guid); } </code>
post to subcategory and parent in wp_insert_post
wordpress
I'm trying to add the post content in the header but for some reason it doesn't show anything. However it does retrieve the post content. I wrote this: <code> &lt;div &lt;?php post_class() ?&gt; id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;?php the_title(); ?&gt; &lt;?php the_content(); ?&gt; </code> I tried and and none showed anything... Is there any way I can archive this? I really need it for the site's navigation. Thanks
The simplest solution is to call the_post() to setup the post data before calling the template functions. <code> &lt;?php if(have_posts()) : the_post(); ?&gt; //your header code here &lt;?php rewind_posts(); //to set the post pointer back to the beginning ?&gt; &lt;?php else : ?&gt; //alternative header code here &lt;?php endif; ?&gt; </code>
How do I show current post content in the header?
wordpress
As above Background info Main problem: users pay to post an ad on the website Solution: they sign up as contributors and I publish their posts once the payment is received, after that they can make any edit to their posts
There is a capability in WordPress called "edit_published_posts". Contributors do not have this capability by default (refer to the Roles and Capabilities Codex page to see the out-of-box role configurations). You can add this capability to the contributor role with code like this: <code> // get the "contributor" role object $obj_existing_role = get_role( 'contributor' ); // add the "organize_gallery" capability $obj_existing_role-&gt;add_cap( 'edit_published_posts' ); </code> This code should only need to be run once--perhaps on activation of a plugin. If you're not comfortable with code, you can use the Role Scoper plugin (or something like it) to add this capability to the contributor role.
How do I let contributors edit their posts after being approved once?
wordpress
SOLUTION I've gone with Update 3 and have got it working. What I had misunderstood, was that I believed that a rewrite rule would change <code> designers/?designer=some-designer&amp;bid=9 </code> to <code> /designers/some-designer </code> . But it is of course the other way around. I've been doing some research, but I don't quite get how to use add_rewrite_rule(). stackexchange-url ("This post") is pretty close to what I need, but do I really need that much code? My current link is this: http://www.norwegianfashion.no/designers/?designer=Batlak-og-Selvig&amp;bid=9 What I want is this http://www.norwegianfashion.no/designers/Batlak-og-Selvig/ How do I use <code> add_rewrite_rule() </code> ? I need to pass the designer ID (bid). How can I do that when using re.write rules with out it showing in the URL? Update 1 I found this which is a bit more explainatory. But it's not working: <code> function add_rewrite_rules( $wp_rewrite ) { $new_rules = array( '('.$template_page_name.')/designers/(.*?)/?([0-9]{1,})/?$' =&gt; 'designers.php?designer='. $wp_rewrite-&gt;preg_index(1).'&amp;bid='. $wp_rewrite-&gt;preg_index(2) ); // Always add your rules to the top, to make sure your rules have priority $wp_rewrite-&gt;rules = $new_rules + $wp_rewrite-&gt;rules; } add_action('generate_rewrite_rules', 'add_rewrite_rules'); function query_vars($public_query_vars) { $public_query_vars[] = "designer"; $public_query_vars[] = "bid"; return $public_query_vars; } add_filter('query_vars', 'query_vars') </code> Update 2 Here is another solution I've tried, that stackexchange-url ("Jan Fabry suggesten") in another thread. I put this in my functions.php, but it has no effect. <code> add_action('generate_rewrite_rules', 'add_rewrite_rules'); add_filter('query_vars', 'query_vars'); /* Custom re-write rules for desigenrs ------------------------------------------------------------------------------*/ function add_rewrite_rules( $wp_rewrite ) { add_rewrite_rule('^designers/([^/]*)/([^/]*)$ /designers/?designer=$1&amp;bid=$2 [L]', 'top'); flush_rewrite_rules(false); } function query_vars($public_query_vars) { $public_query_vars[] = "designer"; $public_query_vars[] = "bid"; return $public_query_vars; } </code> Update 3 I found a few examples here as well. But this is not working either :( <code> add_filter('rewrite_rules_array','wp_insertMyRewriteRules'); add_filter('query_vars','wp_insertMyRewriteQueryVars'); add_filter('init','flushRules'); // Remember to flush_rules() when adding rules function flushRules(){ global $wp_rewrite; $wp_rewrite-&gt;flush_rules(); } // Adding a new rule function wp_insertMyRewriteRules($rules) { $newrules = array(); $newrules['(designers)/(\d*)$'] = 'index.php?pagename=designers&amp;designer=$matches[1]'; return $newrules + $rules; } // Adding the bid var so that WP recognizes it function wp_insertMyRewriteQueryVars($vars) { array_push($vars, 'designer'); return $vars; } </code> Update 4 I also tried this solution, but still no sucess. <code> add_filter('search_rewrite_rules', 'designers_createRewriteRules'); function designers_createRewriteRules($rewrite) { global $wp_rewrite; // add rewrite tokens $designer_token = '%designers%'; $wp_rewrite-&gt;add_rewrite_tag($designer_token, '(.+)', 'designers='); $bid_token = '%bid%'; $wp_rewrite-&gt;add_rewrite_tag($bid_token, '(.+)', 'bid='); $keywords_structure = $wp_rewrite-&gt;root . "designers/$designer_token/$bid_token"; $keywords_rewrite = $wp_rewrite-&gt;generate_rewrite_rules($keywords_structure); return ( $rewrite + $keywords_rewrite ); </code> } Update 5 It seems that my rewrite rules are not added. Executing the follwoing afte radding new rules: <code> print_r($wp_rewrite) </code> , does not include my new rewrite rules. Update 6 I tested Jan's solution. But URL does not change :( <code> /* Initiation script for NF template ------------------------------------------------------------------------------*/ add_action('after_setup_theme','norwegianfashion_setup'); if ( ! function_exists( 'norwegianfashion_setup' ) ): function norwegianfashion_setup() { /* Here I do a lot of stuff */ // SEO friendly URL for desigenrs add_action( 'init', 'wpa5413_init' ); add_filter( 'query_vars', 'wpa5413_query_vars' ); } endif; /* Custom re-write rules for desigenrs ------------------------------------------------------------------------------*/ function wpa5413_init() { // Remember to flush the rules once manually after you added this code! add_rewrite_rule( 'designers/([^/]+)/?', 'index.php?pagename=designers&amp;designer=$matches[1]', 'top' ); } function wpa5413_query_vars( $query_vars ) { $query_vars[] = 'designer'; return $query_vars; } </code> I would really appreciate it if someone were able to help me solve this issue.
Some background on rewrite rules The WP Rewrite system looks complicated, but in fact it's not that hard to understand how it works. It is used to parse pretty URLs ( <code> /designers/ </code> ) as if they were non-pretty ( <code> /index.php?pagename=designers </code> ). The basic idea is that you have a list of rewrite rules , regular expressions that can match the incoming URLs, and rewrite them into other URLs, mostly in the form of <code> index.php </code> with some query variables. These variables are set to parts of the regular expression that matched the URL. The rules are evaluated top to bottom, so if two rules might match, the first one "wins". These rewrite rules are stored in the database by calling <code> flush_rewrite_rules() </code> , but because generating and writing these rules is an expensive operation, you should not do it on every <code> init </code> . Instead, you only do it when you change the rules: probably on plugin activation (using <code> register_activation_hook() </code> ), or manually by visiting the Permalinks settings page (stackexchange-url ("because it's hard to do this automatically on theme activation")). If you don't flush the rules, calling <code> add_rewrite_rule() </code> has no effect. It is no problem to call <code> add_rewrite_rule() </code> on every <code> init </code> , even after you flushed the rules. There are many ways to add your rewrite rules, and if you only want to add one rule, you can do this with <code> add_rewrite_rule() </code> . Because the rules for posts, pages, taxonomies, ... result in multiple rules, they are created with high level functions like <code> add_rewrite_tag() </code> , <code> add_permastruct() </code> , ... But these are not needed for the simple case we have here. There are also some filters, so you can also add your rules using the <code> generate_rewrite_rules </code> or <code> generate_rewrite_rules_array </code> hooks. These give you very detailed control over the complete rules, but again, <code> add_rewrite_rule() </code> is enough if you just want to add one rule. I created stackexchange-url ("a little plugin that allows you to analyze the current rewrite rules"), and (of course) I recommend you use it when you try to change anything. Getting your extra info from the URL Let's build on the example you gave. You have the designer brand <code> Batlak og Selvig </code> , with the numberic ID ( <code> bid </code> ) <code> 9 </code> . You don't want this ID in the URL, but only the name. We call the URL-friendly version of the name (without spaces or special characters) the slug: <code> Batlak-og-Selvig </code> . In general, the URL should contain all info to identify the content you want to show on the page. You can use cookies or POST requests to store the actual designer ID you want to display, but this will break down if anyone shares the link, by sending it via mail, Facebook, Twitter, or just reading it out loud over the phone. If you don't want to use the numeric ID in your URL, you should make sure the slug is unique: then you first do a lookup of the ID based on the slug, and continue as you did before. So what we have learned now is that we want to add a rewrite rule for the pattern " <code> /designers/ </code> followed by anything up to the next <code> / </code> " , and save that "anything" in the <code> designer_slug </code> query variable. In your case I believe you also want to use the page with the slug <code> designers </code> as the general page content, so we'll tell WordPress that too. <code> add_action( 'init', 'wpa5413_init' ); function wpa5413_init() { // Remember to flush the rules once manually after you added this code! add_rewrite_rule( // The regex to match the incoming URL 'designers/([^/]+)/?', // The resulting internal URL: `index.php` because we still use WordPress // `pagename` because we use this WordPress page // `designer_slug` because we assign the first captured regex part to this variable 'index.php?pagename=designers&amp;designer_slug=$matches[1]', // This is a rather specific URL, so we add it to the top of the list // Otherwise, the "catch-all" rules at the bottom (for pages and attachments) will "win" 'top' ); } </code> The only thing left to do is to tell WordPress to also keep the <code> designer_slug </code> in the query variables, so you can access it later. WordPress uses a whitelist of allowed query variables, to prevent people from modifying every parameter of the posts query via the URL. Everything not on this list is ignored. Just hook into the <code> query_vars </code> hook and add your extra variable: <code> add_filter( 'query_vars', 'wpa5413_query_vars' ); function wpa5413_query_vars( $query_vars ) { $query_vars[] = 'designer_slug'; return $query_vars; } </code> As you can see, this answer is basically the same as stackexchange-url ("my previous answer"), but without the rule flushing in the code (so you can use it in your theme's <code> functions.php </code> instead of a plugin), and with a bit more certainty and explanation because I learned a lot about rewrite rules since (and because of) answering your first question. Chat room discussion We cleared up final issues for this question stackexchange-url ("in the chat room"). In the end, Steven used the <code> generate_rewrite_rules </code> hook, because the <code> add_rewrite_rule() </code> function did not seem to work for him.
Need help with add_rewrite_rule
wordpress
I want to create a plugin that will place a few elements on the post edit page. How do I do this? Is there an action that is run after before the post_edit page is loaded?
Here's a nice tutorial on how to create custom meta boxes in the dashboard: http://www.deluxeblogtips.com/2010/04/how-to-create-meta-box-wordpress-post.html
Extend the Admin Post/Edit page
wordpress
My theme creates several widget areas for the end user. However, I've got a slight problem in that, if multiple widgets are dropped onto any sidebar container, the resulting code in "view source" is not wrapped in a single container div. For example, here's what it looks like Start of a single widget container: <code> &lt;div class="name-of-my-widget"&gt; &lt;h4&gt;Widget title&lt;/h4&gt; &lt;div class="textwidget"&gt; contents of widget 1 &lt;/div&gt; &lt;/div&gt; &lt;div class="name-of-my-widget"&gt; &lt;h4&gt;Widget title&lt;/h4&gt; &lt;div class="textwidget"&gt; contents of widget 2 &lt;/div&gt; &lt;/div&gt; </code> What do I need to do to the way I'm creating this widget so that a single wrapper div encloses all of the widgets added to the container? <code> if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' =&gt; 'Inside Header Area', 'id' =&gt; 'inside-header-widget', 'before_widget' =&gt; '&lt;div class="test-sidebar %2$s"&gt;', 'after_widget' =&gt; '&lt;/div&gt;', 'before_title' =&gt; '&lt;h4&gt;', 'after_title' =&gt; '&lt;/h4&gt;', )); </code>
Sidebar functionality doesn't handle wrapping container, you need to add that on template level. Here is example markup of <code> sidebar-primary.php </code> template (taken from Hybrid theme and simplified a bit): <code> if ( is_active_sidebar( 'primary' ) ) : ?&gt; &lt;div id="primary" class="sidebar aside"&gt; &lt;?php dynamic_sidebar( 'primary' ); ?&gt; &lt;/div&gt;&lt;!-- #primary .aside --&gt; &lt;?php endif; ?&gt; </code> Also I highly recommend Justin's Sidebars in WordPress tutorial.
How do you force a sidebar widget to have a container div around all child widgets?
wordpress
I'm creating a separate (simple) directory that does not use any internal WP permalinks or pretty link structure. I've been studying how to make my own custom SEF URLs for this part of my site, and almost have it (or thought so). I have a separate table with records like this: <code> id | section | category | co_name 1 | Consulting | Innovation | Innocentive.com 2 | Tasks | Employment | Microtask.com .... </code> The directory shows a page of all the sections &amp; categories from the database at this URL: dailycrowdsource.com/companies/ (I did this with a companies.php file &amp; created a 'page' with the slug 'companies') I want this URL to display all the 'employment' category listings: dailycrowdsource.com/companies/tasks/employment/ I can handle the php &amp; mySQL, but I don't know how to make the links pretty. This works http://dailycrowdsource.com/companies/?category=poll This helped using an extra parameter in an URL , &amp; I think I got it working, but I couldn't figure out how to convert the &lt; a href=.... into the SEF link. I prefer to do this in my functions.php file, as I haven't written a plugin yet. I've done this in Joomla with the router.php file. In my research ( stackexchange-url ("Need help with friendly URL's in Wordpress"), stackexchange-url ("Custom Post Type Rewrite Rule for Author &amp; Paging?"), Rewrite API ), I'm seeing a lot of the same tags &amp; buzzwords, but no one explains how to change the actual link. Does WP do it automatically? (In Joomla you have to do: JRoute::_('index.php?var1=great&amp;var2=more'); for the conversion to take place.) I realize the first answers will tell me to use some built in taxonomy of WP, but I need this to be updated easily. And by adding a record to the database with a brand new section or category, my directory needs to be instantly updated (that's why I've chosen this method - no administration). I would appreciate someone showing me how to add in hooks/filters/etc to make a custom SEF URL. (All URLs will start with dailycrowdsource.com/companies/ ). (I'm hoping Mike Schinkel reads this - as I got a lot of help from his responses to similar posts) Thank You -David
Modifying the URL structure always consists of two parts: one two modify the URLs you generate with your code, and one to handle the incoming URLs of the new structure. The latter part is done by modifying the rewrite rules. I have just written a detailed explanation of the relevant rewrite functionality in stackexchange-url ("a response to a similar question"), so here is just the code for your situation: <code> add_action( 'init', 'wpa5444_init' ); function wpa5444_init() { // Remember to flush the rules once manually after you added this code! add_rewrite_rule( // The regex to match the incoming URL 'companies/tasks/([^/]+)/?', // The resulting internal URL: `index.php` because we still use WordPress // `pagename` because we use this WordPress page // `category_slug` because we assign the first captured regex part to this variable 'index.php?pagename=companies&amp;category_slug=$matches[1]', // This is a rather specific URL, so we add it to the top of the list // Otherwise, the "catch-all" rules at the bottom (for pages and attachments) will "win" 'top' ); } add_filter( 'query_vars', 'wpa5444_query_vars' ); function wpa5444_query_vars( $query_vars ) { $query_vars[] = 'company_slug'; return $query_vars; } </code> The first part, writing your URLs to match this new pretty structure, is not bundled in one place but spread over all the functions that generate URLs. You will need to write a function to handle your case yourself, since you generate a page URL and add the category part to it. It could look like this: <code> function wpse5444_company_link( $category_slug = '' ) { $company_page_id = 42; // Somehow convert the page slug to page ID $link = get_page_link( $company_page_id ); if ( $category_slug ) { // trailingslashit() makes sure $link ends with a '/' $link = trailingslashit( $link ) . 'tasks/' . $category_slug; // user_trailingslashit() adds a final '/' if the settings require this, // otherwise it is removed $link = user_trailingslashit( $link ); } return $link; } </code>
How do I display a friendly URL link in the frontend?
wordpress
I'd like to be able to choose an object from another custom post type I've created when adding a second type. Similar to the way you can choose an author for a post. So when creating a post of type B there would be a dropdown of all the post As that the current author has created. Is there a way to do this? Thanks for any suggestions or direction.
The simplest way is probably this plugin: Posts 2 Posts http://wordpress.org/extend/plugins/posts-to-posts/
Is there a way to relate custom post types?
wordpress
Has anyone used any of the Wordpress Weather Plugins? Any recommendations? Anyone tried out more than one? Hoping to get pointed in the right direction before I dive in.
What do you actually need plugin to do? Interconnect IT folks had recently released pretty cool Weather Widget .
Weather Plugin Recommendation
wordpress
This plugin is a simple demo test to see if I can dynamically populate a pre-existing widget area with text. In this case, my theme has created the widget area "home-header-widget" and I'm trying to populate it with the contents of 'text' below. I'm stuck at the line... <code> $sidebars_widgets[$sidebar_id] = "widget_text-".$id; </code> In that I'm not certain how to obtain a reference to the dynamically created text widget object in order to preset its contents and place it inside my 'home-header-widget'... <code> &lt;?php /* Plugin Name: Widget Test */ function cb_activate_widgettest(){ $sidebar_id = 'home-header-widget'; $sidebars_widgets = get_option('sidebars_widgets'); $id = count($opts)+1; $sidebars_widgets[$sidebar_id] = array("text-".$id); $ops = get_option('widget_text'); // find an $id that works... $ops[$id] = array( 'title' =&gt; 'foo hoo', 'text' =&gt; 'bar mitz', // content? ); update_option('widget_text', $ops); update_option('sidebars_widgets', $sidebars_widgets); } register_activation_hook(__FILE__, 'cb_activate_widgettest'); ?&gt; </code>
There are a few mistakes in your code: You need to specify the instance ID manually, for eg. 2. If you want to append a text widget, and not overwrite the sidebar's contents, then try using <code> $id = count($opts)+1 </code> , or you could just generate a random ID. Use the widget_ID_base-instance_ID in <code> $sidebars_widgets[$sidebar_id] = "widget_text-".$id; </code> , and put that inside a array: <code> $sidebars_widgets[$sidebar_id] = array("text-".$id); </code>
Possible to preset a widget's contents via a plugin script?
wordpress
I just installed WP 3.1 Beta 2 on my test server. I noticed that it ships with a new <code> l10n.js </code> file that gets automatically inserted into the header. I did a bit of digging and it has something to do with localization. I'm guessing that many people don't use this, so I'm wondering how I could remove it? If it's important not to remove it, please let me know as well.
It contains the <code> convertEntities() </code> function that (as the name says) converts HTML entities to their actual value. It is mostly used for scripts that send over localization data from PHP to the JS side using <code> wp_localize_script() </code> . Just search for <code> l10n_print_after </code> in the code base and you see it a lot. The data you add in <code> wp_localize_script() </code> is added before the script it translates (it must be, because it is referenced there). However, if you use a script concatenator (so you only have one request that returns all used JS files), this one file would also be called after all localized data - but now <code> convertEntities() </code> is not defined when we need it. For this reason this function is split off the general <code> utils.js </code> file and added with a high priority at the top. For this reason you should not remove it: all scripts that use translatable strings use it (even if they are still in English), and you might break places that still have entities.
What does l10n.js do in WordPress 3.1? And how do I remove it?
wordpress
Is there a plug-in that can incorporate a StackExchange-like flag system on a WordPress blog? Then registered users can flag an article/post so that the admin or moderator can review the post later and decide whether the post should be published or not.
I still dint found any separate plugin for the same. However i did the same by doing some modifications in My Favorite plugin
StackExchange-like flag system for WordPress
wordpress
Is it possible to bring intellisense (autocomplete) in the search box of the website????
So you want more general autocomplete, rather than something specific (like blog tags for example)? If you use (or will consider using) Google Custom Search (which is very popular option to replace native WP search), they made it quite easy to enable native autocomplete with it. See: Autocompletion of queries in Custom Search Control over your Autocompletions
intellisense in wp search
wordpress
I would very much like to know if there is a widget that exists that would let me show the current page's associated taxonomy terms (preferably hierarchically) in a widget. For example, if the current post has a Taxonomy term "Tom Hanks" in the Taxonomy of "Actor", the widget would list "Actor" then "Tom Hanks". Even though there are many other actors in the taxonomy of "Actors", only the ones from the current page, are listed.
This is a simple conversion of the Taxonomy terms list plugin to a widget: <code> class WPSE_5394_Widget extends WP_Widget { public function __construct() { parent::__construct( 'wpse5394_widget', 'Taxonomy Terms List' ); } public function widget( $sidebar_args, $widget_options ) { if ( ! is_single() ) { // I don't think we can display anything sensible on a page with multiple posts return; } $output = $sidebar_args['before_widget']; // If we want to use this we should provide a way to set the title if ( ! empty( $widget_options['title'] ) ) { $output = $sidebar_args['before_title'] . $widget_options['title'] . $sidebar_args['after_title']; } // This is the meat of the function: get the taxonomies we want to display, and get the terms for each taxonomy $taxonomy_names = apply_filters( 'wpse5394_taxonomies', array_fill_keys( get_taxonomies(), true ) ); $taxonomy_terms = ''; foreach ( $taxonomy_names as $taxonomy_name =&gt; $dummy ) { $taxonomy = get_taxonomy( $taxonomy_name ); $before = apply_filters( 'wpse5394_taxonomy_before', '&lt;p&gt;' . $taxonomy-&gt;label . ': ', $taxonomy ); $sep = apply_filters( 'wpse5394_taxonomy_sep', ', ' ); $after = apply_filters( 'wpse5394_taxonomy_after', '&lt;/p&gt;' ); $terms = get_the_term_list( 0, $taxonomy_name, $before, $sep, $after ); if ( $terms ) { $taxonomy_terms .= $terms; } } if ( ! $taxonomy_terms ) { // No taxonomy terms will be displayed - don't display the widget return; } $output .= $taxonomy_terms; $output .= $sidebar_args['after_widget']; echo $output; } } add_action( 'widgets_init', 'wpse5394_widgets_init' ); function wpse5394_widgets_init() { register_widget( 'WPSE_5394_Widget' ); } </code> Most options can be set via filters, like the taxonomies you want to display: <code> add_filter( 'wpse5394_taxonomies', 'wpse5394_taxonomies' ); function wpse5394_taxonomies( $taxonomies ) { unset( $taxonomies['category'] ); return $taxonomies; } </code>
List a current posts' taxonomy terms in a widget in Wordpress
wordpress
Hey all, i'm using the plugin wp-Lifestream in its 0.99.9.6 version (the 0.99.9.8-BETAdoesnt work for me) and i was wondering if it was possible to associate a fb page feed rather than a profile feed. So far i didnt find any answer to that. Thanks in advance.
If you're talking about subscribing to a page's wall (not notifications feed), then yes, you can do that. To find the feed for the wall, the easiest thing is to visit the target Facebook page in Firefox. Click the RSS icon in the address bar and choose "Subscribe to THE PAGE NAME". This will bring you to the actual feed. Copy the URL of the feed, and set it up as a new Facebook feed in your Lifestream settings (Lifestream > Feeds > Add a Feed > Facebook). And you're done. The reason you can't subscribe to a page's notifications feed is that there is no such thing. Pages are connected to user accounts, and as such they don't have notifications feeds of their own. If you do see a notifications feed while you're administering a Facebook page, it's the feed of the administering user, not of the page itself.
How to grab facebook page feed?
wordpress
I was wondering what you guys are doing to dress up your blogs ? any plugins that add some cool effects like snow flakes, maybe greeting popup, footer, music, header rotation, list of new years resolution, wishlist widget display .... I was wondering what you doing to dress up your blog around holidays, maybe we can compile a nice list together - but god forbid - do them all together in one blog :P thanks for suggestions.
Themes The Free Themes Directory at WordPress.org just updated its list of featured themes, and now includes two different Christmas-related themes: Red Christmas This Christmas Plug-ins The most commonly used holiday/Winter plug-in is the snow plug-in featured on WordPress.com: Snow Storm There are also 35 different plug-ins in the repository that match a search for " Christmas ." I tried looking for anything freely available for other holidays, but I have yet to find anything ... so if you want to write a plug-in to celebrate Hanukkah, I think it would be very welcome! :-)
Suggestions for Dressing up blog for the holidays
wordpress
i have a piece of code which is helped to display the description of custom taxonomies but i want to put <code> &lt;h1&gt; </code> tag for the title of description, but that description box doesn't takes html tags, so how can i implement html tags to my description here is my code <code> &lt;div class="featured post"&gt; &lt;p&gt;&lt;?php if ( is_tax( 'location' ) ) { echo term_description(); } elseif (is_tax('mba_courses')){ echo term_description(); } elseif (is_tax('duration')){ echo term_description(); } ?&gt;&lt;/p&gt; &lt;/div&gt; </code>
H1 tags around the descriptions? <code> echo '&lt;h1&gt;' . term_description() . '&lt;/h1&gt;'; </code> UPDATE: Add link to plugin to allow HTML in term descriptions. WordPress Plugins - Allow HTML in Category Descriptions This will work with custom taxonomies to. http://wordpress.org/extend/plugins/allow-html-in-category-descriptions/ Copy of the appropriate code For those of you that want to simply see how it's done. <code> $filters = array('pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description'); foreach ( $filters as $filter ) { remove_filter($filter, 'wp_filter_kses'); } foreach ( array( 'term_description' ) as $filter ) { remove_filter( $filter, 'wp_kses_data' ); } </code>
term_description help
wordpress
Just a quick question that might help a tad bit with security. I noticed that the readme.html file has the version number listed. It reappears after each upgrade and so do the licence.txt, and wp-config-sample.php. Is there a easy way to have WordPress auto remove these files after an upgrade? I already block the version number from showing in the meta tags, rss feeds, atom, etc. I know this type of security isn't exactly that much helpful, but just thought it might be a tiny start. I heard that people can simply check the version of jQuery that is included in WP-includes and cross reference which version of WP shipped it.
You don't really need to remove these files. It's much easier to just block access to them. If you are using pretty URL's you already have an .htaccess file. Using .htaccess to block the files is secure and you only have to add a directive once. Blocking files is done by adding a directive to .htaccess like this: <code> &lt;files filename.file-extension&gt; order allow,deny deny from all &lt;/files&gt; </code> So, to block readme.html you do this: <code> &lt;files readme.html&gt; order allow,deny deny from all &lt;/files&gt; </code> Do the same with the license file or any other file you want to prevent anyone from accessing. Just open .htaccess in Notepad or any other basic text editor, add the directives and save, making sure that the text editor keeps the file name exactly - without any .txt on the end.
Prevent access or auto-delete readme.html, license.txt, wp-config-sample.php
wordpress
I'm testing a script to create a database insert. Is this the correct syntax for the insert or do I need to obtain a reference to global $wpdb and use that? <code> &lt;?php /* Plugin Name: Test Database Insert */ function test_db_insert() { INSERT wp_terms(term_id, 'name', slug) VALUES (1, 'test', 'test'); INSERT wp_term_taxonomy(term_taxonomy_id, term_id, taxonomy, parent) VALUES (1, 1, 'category', 0); INSERT wp_term_relationships(object_id, term_taxonomy_id, term_order) VALUES (1, 1, 0); } register_activation_hook(__FILE__, 'test_db_insert'); </code>
This seems like raw SQL that won't make sense to PHP at all. You can run this queries, as raw queries using <code> $wpdb-&gt;query() </code> but it's more proper to use its <code> $wpdb-&gt;insert() </code> method. See wpdb Class > INSERT rows in Codex.
Correct syntax for database inserts from plugin?
wordpress
i have a function in my plugin <code> append_the_content($content) </code> this is used to display my function inside the post, but it is coming before the post, i want to make it after the post, for this i tried this code, but then too its not coming <code> function parse_twitter_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix) { $feed = str_replace("&amp;lt;", "&lt;", $feed); $feed = str_replace("&amp;gt;", "&gt;", $feed); $clean = explode("&lt;content type=\"html\"&gt;", $feed); $amount = count($clean) - 1; echo $prefix; for ($i = 1; $i &lt;= $amount; $i++) { $cleaner = explode("&lt;/content&gt;", $clean[$i]); echo $tweetprefix; echo $cleaner[0]; echo $tweetsuffix; } echo $suffix; } function the_twitter_feed($username) { // $username = "Mba_"; // Your twitter username. $limit = "5"; // Number of tweets to fetch. /* These prefixes and suffixes will display before and after the entire block of tweets. */ $prefix = ""; // Prefix - some text you want displayed before all your tweets. $suffix = ""; // Suffix - some text you want displayed after all your tweets. $tweetprefix = "&lt;b&gt;".$username.": &lt;/b&gt; "; // Tweet Prefix - some text you want displayed before each tweet. $tweetsuffix = "&lt;br&gt;"; // Tweet Suffix - some text you want displayed after each tweet. $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&amp;rpp=" . $limit; $twitterFeed = get_transient($feed); if (!$twitterFeed) { $twitterFeed = wp_remote_fopen($feed); set_transient($feed, $twitterFeed, 3600); // cache for an hour } if ($twitterFeed) parse_twitter_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix); } function append_the_content($content) { if(get_option('tweetID')!=null){ $content .= "&lt;div class='post'&gt;&lt;p&gt;".the_twitter_feed(get_option('tweetID'))."&lt;/p&gt;&lt;/div&gt;"; echo $content; } else{ return $content; } } add_filter('the_content', 'append_the_content'); add_action('admin_menu','tweet_fetch'); function tweet_fetch(){ add_options_page('Tweet','Tweet', 8, 'tweet', 'tweet_fetcher'); } function tweet_fetcher(){ ?&gt; &lt;h2&gt;Tweet Fetcher options&lt;/h2&gt; &lt;table&gt; &lt;form method='post' action='options.php' style='margin:0 20px;'&gt; &lt;?php wp_nonce_field('update-options'); ?&gt; &lt;tr&gt;&lt;td&gt;Twitter UserID:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="tweetID" value="&lt;?php echo get_option('tweetID'); ?&gt;" &lt;?php echo get_option('tweetID'); ?&gt; /&gt; &lt;/td&gt;&lt;/tr&gt; &lt;input type='hidden' name='action' value='update'/&gt; &lt;input type='hidden' name='page_options' value='tweetID'/&gt; &lt;tr&gt;&lt;td&gt;&lt;p class='submit'&gt; &lt;input type='submit' name='Submit' value='Update Options &amp;raquo;'/&gt; &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;?php } </code> how can i make it after the post???
Edited, try this <code> &lt;?php function parse_twitter_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix) { $feed = str_replace("&amp;lt;", "&lt;", $feed); $feed = str_replace("&amp;gt;", "&gt;", $feed); $clean = explode("&lt;content type=\"html\"&gt;", $feed); $amount = count($clean) - 1; $output = $prefix; for ($i = 1; $i &lt;= $amount; $i++) { $cleaner = explode("&lt;/content&gt;", $clean[$i]); $output .= $tweetprefix; $output .= $cleaner[0]; $output .= $tweetsuffix; } $output .= $suffix; return $output; } function the_twitter_feed($username) { // $username = "Mba_"; // Your twitter username. $limit = "5"; // Number of tweets to fetch. /* These prefixes and suffixes will display before and after the entire block of tweets. */ $prefix = ""; // Prefix - some text you want displayed before all your tweets. $suffix = ""; // Suffix - some text you want displayed after all your tweets. $tweetprefix = "&lt;b&gt;" . $username . ": &lt;/b&gt; "; // Tweet Prefix - some text you want displayed before each tweet. $tweetsuffix = "&lt;br&gt;"; // Tweet Suffix - some text you want displayed after each tweet. $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&amp;rpp=" . $limit; $twitterFeed = get_transient($feed); if (!$twitterFeed) { $twitterFeed = wp_remote_fopen($feed); set_transient($feed, $twitterFeed, 3600); // cache for an hour } if ($twitterFeed) return parse_twitter_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix); } function append_the_content($content) { if (get_option('tweetID') != null) { $content .= "&lt;div class='post'&gt;&lt;p&gt;" . the_twitter_feed(get_option('tweetID')) . "&lt;/p&gt;&lt;/div&gt;"; return $content; } else { return $content; } } add_filter('the_content', 'append_the_content'); add_action('admin_menu', 'tweet_fetch'); function tweet_fetch() { add_options_page('Tweet', 'Tweet', 8, 'tweet', 'tweet_fetcher'); } function tweet_fetcher() { ?&gt; &lt;h2&gt;Tweet Fetcher options&lt;/h2&gt; &lt;table&gt; &lt;form method='post' action='options.php' style='margin:0 20px;'&gt; &lt;?php wp_nonce_field('update-options'); ?&gt; &lt;tr&gt;&lt;td&gt;Twitter UserID:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="tweetID" value="&lt;?php echo get_option('tweetID'); ?&gt;" &lt;?php echo get_option('tweetID'); ?&gt; /&gt; &lt;/td&gt;&lt;/tr&gt; &lt;input type='hidden' name='action' value='update'/&gt; &lt;input type='hidden' name='page_options' value='tweetID'/&gt; &lt;tr&gt;&lt;td&gt;&lt;p class='submit'&gt; &lt;input type='submit' name='Submit' value='Update Options &amp;raquo;'/&gt; &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;?php } ?&gt; </code>
append_content help
wordpress
can anyone tell me what's the best way to redirect a general category page to a specific one? for example: <code> categoryName1 -&gt; subcategoryName1 -&gt; subCategoryName2 -&gt; subCategoryName3 categoryName2 -&gt; subCategoryName4 </code> and when i click in the menu "categoryName1" (but not on "categoryName2") i'm redirect automatically into "subcategoryName2". thanks a lot!
If you are looking for some simple redirect solution, in a stackexchange-url ("previous answer") the following two were suggested: Redirection (Wordpress Plugin) Simple 301 Redirects (Wordpress Plugin) With those or a comparable plugin it should be possible that you can add the redirects you need to your site.
redirecting from a general category page to another specific one
wordpress
Basically I want to develop the ability to search comments on my site. A form with input field where the visitor can enter a search string, which tells WP to display only comments that contain that search phrase. I think the best way to do this is by making a custom comments_template() function, then filtering out comments that don't contain <code> $_GET['search_phrase'] </code> . Any pointers/suggestions, especially on the SQL part are welcome :)
You create your own <code> comments_template </code> , it can be a duplicate function of the default one, the only changes are the database queries anyway. But you need your own function as WP doesn't help you with filters here. SO, name it <code> my_comments_template() </code> : <code> $filter = mysql_real_escape_string($_POST['comment-filter']); if(!empty($filter)) $filter = "AND (comment_content LIKE '%%{$filter}%%' OR comment_author LIKE '%%{$filter}%%')"; if($user_ID) $comments = $wpdb-&gt;get_results($wpdb-&gt;prepare("SELECT * FROM $wpdb-&gt;comments WHERE (comment_post_ID = %d) {$filter} AND (comment_approved = '1' OR (user_id = %d AND comment_approved = '0')) ORDER BY comment_date_gmt", $post-&gt;ID, $user_ID)); elseif(empty($comment_author)) $comments = $wpdb-&gt;get_results($wpdb-&gt;prepare("SELECT * FROM $wpdb-&gt;comments WHERE (comment_post_ID = %d) {$filter} AND (comment_approved = '1') ORDER BY comment_date_gmt", $post-&gt;ID)); else $comments = $wpdb-&gt;get_results($wpdb-&gt;prepare("SELECT * FROM $wpdb-&gt;comments WHERE (comment_post_ID = %d) {$filter} AND (comment_approved = '1' OR (comment_author = %s AND comment_author_email = %s AND comment_approved = '0')) ORDER BY comment_date_gmt", $post-&gt;ID, wp_specialchars_decode($comment_author, ENT_QUOTES), $comment_author_email)); </code> then add a simple form in the comments template file: <code> &lt;form action="&lt;?php echo get_permalink(); ?&gt;" method="post" id="comment-filter"&gt; &lt;input type="text" name="comment-filter" rel="&lt;?php _e("Search in comments"); ?&gt;" value="&lt;?php echo esc_attr($_POST['comment-filter']); ?&gt;" size="20" /&gt; &lt;/form&gt; </code> and of course replace all <code> comments_template() </code> function calls with <code> my_comments_template() </code> I'm implementing this code into a theme I'm working on. My code is a little bigger as I've added ajax &amp; query highlighting... If you want to see it all wait for the 1.3 release of my Atom theme. One thing I didn't figure out yet is how to keep $_POST['comment-filter'] when navigating trough comment pages. For eg. if you search for something inside 5000 comments and you get 1000 comments containing that text and broken up in pages, when you switch the page the comment filter query is lost and you get 2000 comments displayed again... This function is really useful on Tech related WordPress sites that have hundreds of comments on posts...
Comment filtering (search)
wordpress
I am developing a site that will need to have a slider with 4-8 images, but only on certain page-types. These pages must be editable and the sliders must be able to be updated whenever I'd like. I can easily do the slider and the page theme, it's just the dynamic slider area that is getting me. I've been theming wordpress for a long time but have never run into this situation, it's kicking my butt. Any help would be appreciate, thank you for your time and effort. Update I have the individual templates for the pages. And have looked into the conditional tags which will help for sure. I'm building this for a client who is new to Wordpress so I want to make the process very easy for them. They need to be able to post these slides themselves.
Well your options are to hook the slider into the page/post media gallery using something like get_children or get_posts attachments. Another option is to use a custom "image" field for the slider images and query them using query_posts.
Custom Slider Per Page created
wordpress
I have a site that I'm having so much trouble to try to sort the order of a list of Pages based on their tag. I've build this site over a year ago, with wordpress at the time there isn't any tag support for Page, so I used the plugin called tags4page. And I believe they still don't have tag support for pages ? Anyhow, my problem is if you go this page http://www.patentable.com/index.php/lawyers/ the list of Lawyers are in the right order. I can do this with wordpress build in order by giving each page a different weight. However the problem is if you try to sort the list of Lawyers by selecting the drop down manual it will return a list of lawyers that are belong to this tag that you have selected. PROBLEM is the order are in reversed order for the lawyers. Is there any way to fix this ? Right now my code is simple, basically is the following: <code> &lt;?php if (have_posts()) : ?&gt; &lt;?php /* If this is a tag archive */ if( is_tag() ) { ?&gt; &lt;h2&gt;Lawyers in &lt;i&gt;&lt;?php single_tag_title(); ?&gt;&lt;/i&gt; Practice Area:&lt;/h2&gt; &lt;?php } ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;li&gt; &lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="&lt;?php the_title(); ?&gt;"&gt; &lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php endwhile; /* rewind or continue if all posts have been fetched */ ?&gt; </code>
You could merge order parameters into the query when it's a tag page.. Replace the following lines. <code> &lt;?php /* If this is a tag archive */ if( is_tag() ) { ?&gt; &lt;h2&gt;Lawyers in &lt;i&gt;&lt;?php single_tag_title(); ?&gt;&lt;/i&gt; Practice Area:&lt;/h2&gt; &lt;?php } ?&gt; </code> with.. <code> &lt;?php if( is_tag() ) { $args = array_merge( array( 'order' =&gt; 'asc', 'orderby' =&gt; 'title' ), $wp_query-&gt;query ); query_posts( $args ); ?&gt; &lt;h2&gt;Lawyers in &lt;em&gt;&lt;?php single_tag_title(); ?&gt;&lt;/em&gt; Practice Area:&lt;/h2&gt; &lt;?php } ?&gt; </code>
Sort list of Wordpress Page under tag when is_tag() called
wordpress
My girlfriend has a very popular blog, but we are growing beyond current bandwidth limit (1TB). Adsense doesn't pay enough for an expensive CDN. What recommendations can you make about image hosting. Preferably a plugin, or something that can easily be implemented.
Its not recommended often enough, but Flickr is an excellent image host for blogs as well. Their pro account costs only $25/year. You get unlimited image, video uploads and no bandwidth limit. If you don't want your blog image uploads populating your personal photostream, you can easily create a separate account for it. You can easily streamline your uploading and insertion process by using plugins like Flickr Photo Album for Wordpress , Flickrpress , Alternative WordPress Image Uploader Using Flickr . Or you can do it the old-fashioned manual way .
Best image hosting service
wordpress
I've found a widget that I need to add to more than one sidebar widget area. However, apparently its been coded so that once you drag it from "available widgets" over to a sidebar widget, it disappears from the "available widgets" listing. I'd like to use it in more than one sidebar. What determines this in the widget code?
Sounds like your widget written in the old (pre 2.8) style rather than using the widget class. If that's the case, you need to add code in a few different places to handle multiple instances (it's not a simple option you can turn on or off). Check out this page in the Codex, and this article about creating a multiple instance widget linked from it. Depending on the complexity of the widget, it might be easier to just rewrite it using the Widgets class (examples are provided in that Codex article). It handles multiple instances automagically.
How to add multiple copies of a widget from "available widgets"
wordpress
I would like to upload a PDF file with spaces in it, and I want to do this using the uploader in the rich text editor (really, I want other, less savvy people to be able to do it, so convoluted workarounds are not really an option). Trouble is, Wordpress (3.0.3) insists on replacing spaces with hyphens and lowercasing everything (despite the fact that it's just not necessary ). Can I stop this? Turn it off? Or is there an extension to thwart this behaviour? Even a manual edit to the PHP might be okay, if there's no alternative.
"despite the fact that it's just not necessary" I think you'd be surprised by how unnecessary looking stuff has a tendency of becoming absolutely necessary on some poorly configured servers. Else yes, it can be overridden using filters. You're looking into overriding the stuff in <code> sanitize_file_name() </code> , which is located in wp-includes/formatting.php.
Prevent renaming of uploaded media
wordpress
I want to create a Groupon.com clone. Do you think WordPress is the right system? If not, do you have any other recommendations? Any tips/tricks you have? What are the recommended plug-ins? If anyone has any better CMS option, I'd love a recommendation...
You can build a clone of just about any website using WordPress. The question, though, is how much work are you willing to put into it? Since you're already asking for tips/tricks and plug-ins, I'm guessing you want to make a quick clone that requires little to no additional development time. That said, here are the basic features of Groupon that you'll need to reproduce: Different listings for different regions/cities You can do this several different ways, but the easiest would be with a custom taxonomy for your site. Each city or region would be a taxonomy term, which you can use to separate and categorize the posted deals. Displaying deals for different regions would require you only to add a region-specific filter to your query. Coupon Purchase The core of Groupon is the ability to actually purchase the posted coupons. You could set this up with just about any of the e-commerce or shopping cart plug-ins available in the repository. Deal Timeout Every Groupon deal expires after a certain period of time. You can achieve the same kind of functionality with the Post Expirator plug-in. Social Networking There's no real value in Groupon if people can't share it with others. I'd recommend a Facebook Like button or a Tweet This widget somewhere so people can broadcast deals as they're found.
WordPress as a Groupon clone
wordpress
I have a PHP script that I need to run as a cron job. However this script needs access to the WP API ( <code> get_pages() </code> , <code> get_post_meta() </code> and <code> get_permalink() </code> specifically). I've followed the instructions at http://codex.wordpress.org/Integrating_WordPress_with_Your_Website, but to no avail. Code: <code> require_once('../../../wp-blog-header.php'); $args = array( 'child_of' =&gt; 2083 ); $pages = get_pages($args); </code> However when I run <code> php -q this_file.php </code> from the command-line I get the following output: <code> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Database Error&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Error establishing a database connection&lt;/h1&gt; &lt;/body&gt; &lt;/html&gt; </code> Anyone have any thoughts/suggestions?
WordPress expects the $_SERVER variables to be setup as if it were a normal web request. Also, I would suggest loading wp-load.php instead of wp-blog-header.php since you probably don't need the WP class or the template loader to run. Here is how I normally start any scripts I need to interact with WP from command line: <code> define('DOING_AJAX', true); define('WP_USE_THEMES', false); $_SERVER = array( "HTTP_HOST" =&gt; "mysite.com", "SERVER_NAME" =&gt; "mysite.com", "REQUEST_URI" =&gt; "/", "REQUEST_METHOD" =&gt; "GET" ); require_once('current/wp-load.php'); </code>
Access WordPress API Outside of WordPress (command-line PHP)
wordpress
The dashboard conveniently tells me how many posts, pages, and comments I have. I would like it to tell me how many articles, videos and cartoons I have too (three custom post types registered with my theme). How would I go about including these into the "Right Now" panel on the dashboard?
Yes, there are several actions within that widget, including <code> right_now_content_table_end </code> . Example: <code> function my_right_now() { $num_widgets = wp_count_posts( 'widget' ); $num = number_format_i18n( $num_widgets-&gt;publish ); $text = _n( 'Widget', 'Widgets', $num_widgets-&gt;publish ); if ( current_user_can( 'edit_pages' ) ) { $num = "&lt;a href='edit.php?post_type=widget'&gt;$num&lt;/a&gt;"; $text = "&lt;a href='edit.php?post_type=widget'&gt;$text&lt;/a&gt;"; } echo '&lt;tr&gt;'; echo '&lt;td class="first b b_pages"&gt;' . $num . '&lt;/td&gt;'; echo '&lt;td class="t pages"&gt;' . $text . '&lt;/td&gt;'; echo '&lt;/tr&gt;'; } add_action( 'right_now_content_table_end', 'my_right_now' ); </code>
Adding Custom Post Type Counts to the Dashboard
wordpress
I have a custom role, "Ministry Representative", which is able to log in and create and manage their own "Opportunities" and "Events", which is each a custom post type. On the front end of the site, you can filter opportunities or events by "Ministry", which is a custom taxonomy associated with both the "Opportunities" and "Events" custom post type. On the backend, I create an account for a "Ministry Representative" to manage what appears on their profile as well as within the filtered results on the "Opportunities" and "Events" index pages. The Challenge When a "Ministry Representative" goes to create a new "Event", they enter the details, and, from the custom taxonomy, they have to choose: Location (a hierarchal custom taxonomy) Presenter (a non-hierarchal custom taxonomy) Ministry (a non-hierarchal custom taxonomy) So, in essence, they have to choose themselves. John Doe, who is a "Ministry Representative" for "Ministry A", has to choose his own ministry from a dropdown (a custom meta box via WP Alchemy). The Ideal Solution Ideally, when a new "Event" or "Opportunity" is created by John Doe of "Ministry A", the association is made without any input required on the interface level by the end-user. So, what I think I'm looking for is a way to associate a user account with a specific term within a custom taxonomy. Does that make sense? Is there, perhaps, another way to look at the problem? As I'm imagining, I could see other applications which could make this useful. An account is created and when X user contributes a given type of content, pre-selected terms are automatically associated to their contributed content. Any thoughts or ideas are greatly appreciated. Thank you!
I was able to come up with a work around! First, I used Role Scoper to limit a user account to a specific term - in this case, a Ministry Representative is limited to the name of their Ministry in the "ministries" taxonomy. Then, I used the WPAlchemy class to create a custom metabox that would list the terms and, since it only returned one (theirs), I would have it already selected. Next, I hid it via an admin stylesheet. The effect is that, when a Ministry Representative creates a new Event or Opportunity, their ministry name is already selected (though they don't see it) and the association is made on save. It requires a bit of work on the part of the admins to setup the term and I would still like a cleaner way of doing the same if it exists. If anyone would like further details on my work-around, let me know.
Associating an "author" with a custom taxonomy
wordpress
I am looking for a way that I could add some code to my wordpress template to display the time of a post in relative terms. So if, for example, I posted something 5 minutes ago it would say something along the lines of Posted 6 minutes ago or 2 days ago, or 1 week ago. You get the idea. Could anyone give me some guidance on how I could go about doing this?
WordPress actually has an obscure and little known function called <code> human_time_diff() </code> that does this. It takes two arguments; the first is the earlier timestamp, and the second is the later timestamp. Both should be Unix timestamps. The first argument is required, but the second is optional, and will use <code> time() </code> if left empty. So, for example, in the loop, you could do this: <code> &lt;p&gt;Posted &lt;?php echo human_time_diff( get_the_time( 'U' ) ); ?&gt; ago.&lt;/p&gt; </code> The function will only do minutes, hours, and days, though. If you need to get weeks, for example, you could do something like this: <code> $diff = explode( ' ', human_time_diff( get_the_time( 'U' ) ) ); if( $diff[1] == 'days' &amp;&amp; 7 &lt;= $diff[0] ){ $diff[1] = 'week'; $diff[0] = round( (int)$diff[0] / 7 ); if( $diff[0] &gt; 1 ) $diff[1] .= 's'; $diff = implode( ' ', $diff ); } </code> That would give you <code> N week(s) </code> as a string.
Relative Time On Posts
wordpress
I'm using wordpress for a large non-profit with many sites. I'd like to decrease the amount of installation steps for the people setting up their sites. Is it possible to make a WP install that automatically activates the plugins, themes and default content I choose?
Sure. <code> wp_install_defaults() </code> is a pluggable function. (As are wp_new_blog_notification() and wp_upgrade(), in case you ever need to override those too.) <code> # in wp-config.php if ( defined('WP_INSTALLING') &amp;&amp; WP_INSTALLING ) { include_once dirname(__FILE__) . '/wp-content/install.php'; } # in wp-content/install.php function wp_install_defaults($user_id) { global $wpdb, $wp_rewrite, $current_site, $table_prefix; // do whatever you want here... } </code>
Automatically enable custom theme, plugins and default content on installation?
wordpress
this code is working perfect for me, but just want to know, how can i bring this after my post, currently all my tweets are coming before the post, how can i make it before the post?? <code> function parse_twitter_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix) { $feed = str_replace("&amp;lt;", "&lt;", $feed); $feed = str_replace("&amp;gt;", "&gt;", $feed); $clean = explode("&lt;content type=\"html\"&gt;", $feed); $amount = count($clean) - 1; echo $prefix; for ($i = 1; $i &lt;= $amount; $i++) { $cleaner = explode("&lt;/content&gt;", $clean[$i]); echo $tweetprefix; echo $cleaner[0]; echo $tweetsuffix; } echo $suffix; } function the_twitter_feed($username) { // $username = "Mba_"; // Your twitter username. $limit = "5"; // Number of tweets to pull in. /* These prefixes and suffixes will display before and after the entire block of tweets. */ $prefix = ""; // Prefix - some text you want displayed before all your tweets. $suffix = ""; // Suffix - some text you want displayed after all your tweets. $tweetprefix = ""; // Tweet Prefix - some text you want displayed before each tweet. $tweetsuffix = "&lt;br&gt;"; // Tweet Suffix - some text you want displayed after each tweet. $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&amp;rpp=" . $limit; $twitterFeed = get_transient($feed); if (!$twitterFeed) { $twitterFeed = wp_remote_fopen($feed); set_transient($feed, $twitterFeed, 3600); // cache for an hour } if ($twitterFeed) parse_twitter_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix); } function append_the_content($content) { $content .= the_twitter_feed(get_option('tweetID')); return $content; } add_filter('the_content', 'append_the_content'); add_action('admin_menu','tweet_fetch'); function tweet_fetch(){ add_options_page('Tweet','Tweet', 8, 'tweet', 'tweet_fetcher'); } function tweet_fetcher(){ ?&gt; &lt;h2&gt;Tweet Fetcher options&lt;/h2&gt; &lt;form method='post' action='options.php' style='margin:0 20px;'&gt; &lt;?php wp_nonce_field('update-options'); ?&gt; &lt;p&gt;Twitter UserID:&lt;input type="text" name="tweetID" value="&lt;?php echo get_option('tweetID'); ?&gt;" &lt;?php echo get_option('tweetID'); ?&gt; /&gt; &lt;/p&gt; &lt;input type='hidden' name='action' value='update'/&gt; &lt;input type='hidden' name='page_options' value='tweetID'/&gt; &lt;p class='submit'&gt; &lt;input type='submit' name='Submit' value='Update Options &amp;raquo;'/&gt; &lt;/p&gt; &lt;/form&gt; &lt;?php } </code>
I'm not completely sure what you want, but I noticed with position that echo not always give the right position try to build up a large string and then echo the complete results or just return the results. like this: $output .= echo $prefix; $output .= echo $tweetprefix; $output .= echo $cleaner[0]; $output .= echo $tweetsuffix; $output .= echo $suffix; return $output if you want to do it with echo use comma's to seperate the strings like this: echo $string1, $string2, $string3, etc.
plugin backend help
wordpress
How can I create a form that allows people to submit questions / ideas that once submitted creates a post in wordpress?
The excellent Gravity Forms plugin makes this extremely easy. It's not free (starts at $39), but I highly recommend it. I am not affiliated with the Gravity Forms team in any way - I'm just a satisfied customer!
Form that creates posts
wordpress
I have the following foreach witch gets all the content in several groups. I am using Magic Fields. <code> &lt;?php $omtaleseksjoner = get_group('Seksjoner'); foreach($omtaleseksjoner as $seksjoner){ echo "&lt;h3&gt;" . $seksjoner['sectiontitle'][1] . "&lt;/h3&gt;"; echo $seksjoner['sectioncontent'][1]; } ?&gt; </code> I have usually 5 groups in this foreach, and I want to break it off in two places. Is it possible to insert other content e.g. after group 2 and 4 ? Thanks
You can keep tracks of number of cycles and run extras when counter matches. Something like this: <code> $array = array(1,2,3,4,5); $i = 0; foreach($array as $set) { if(2 == $i) echo 'after 2'; if(4 == $i) echo 'after 4'; echo $set; $i++; } </code> I must note that this is more of PHP basics and really has nothing to do with WordPress. I highly recommend PHP documentation as first stop for such.
Add content in between of foreach
wordpress
i'm using this plugin to show an exapandable/collapsible widget-menu in my sidebar. http://wordpress.org/extend/plugins/folding-category-widget it works very well! the question, not directly connected with this plugin, is: how can i also show in the list, all posts related to a category (title + a href)? for example: <code> category A post1 post2 category B post3 post4 category C post5 </code> thanks a lot in advance.
Well the simplest way I can think of is something like this... <code> &lt;ul class="categories"&gt; &lt;?php $categories = get_categories(); //can add parameters here to swtich the order, etc; if(!empty(categories)): foreach($categories as $i =&gt; $category): ?&gt; &lt;li class="category"&gt; &lt;span&gt;&lt;?php echo $category-&gt;name ?&gt;&lt;/span&gt; &lt;?php query_posts('posts_per_page=-1&amp;cat=' . $category-&gt;term_id); if ( have_posts() ) : ?&gt; &lt;ul class="posts"&gt; &lt;?php while ( have_posts() ) : the_post(); //we make a loop for each category, ?&gt; &lt;li class="post"&gt; &lt;a href="&lt;?php the_permalink();&gt;"&gt;&lt;?php the_title();?&gt;&lt;/a&gt; &lt;/li&gt; &lt;?php endwhile; ?&gt; &lt;/ul&gt; &lt;?php endif; ?&gt; &lt;?php wp_reset_query(); ?&gt; &lt;/li&gt; &lt;?php endforeach; endif; ?&gt; &lt;/ul&gt; </code> Warning: this is untested code, but it should work just fine. (Just add it to your sidebar.php file or wherever you generate yuor sidebar.)
show posts names and links in the sidebar list as categories child
wordpress
I have a custom page template that loops through all custom posts with the post_type of "product_listing" AND the custom taxonomy "product_cat" of "shirts" and returns 4 posts per page (as seen below:) <code> &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'product_listing', 'product_cat' =&gt; 'shirts', 'posts_per_page' =&gt; 4 ) ); ?&gt; </code> It is the client's responsibility to manage those categories. I'd like to assign a variable to display in place of "shirts" so that I don't have to modify the template each time the client adds a new product category (such as shoes, pants, etc.). I am not a programmer by any means. Does anybody have a snippet of code that would work for this? Or perhaps an article I could read more about assigning dynamic variables in the loop? Thanks!
Apparently I needed to loop the function to set the variable: <code> &lt;!-- BEGIN CODE FOR PRODUCT AREA --&gt; &lt;?php $prod_cats = get_terms('product_cat'); foreach ($prod_cats as $prod_cat) { $cat_name = $prod_cat-&gt;name; ?&gt; &lt;div id="products"&gt; &lt;!-- post begin --&gt; &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'product_listing', 'posts_per_page' =&gt; 4, 'product_cat' =&gt; $cat_name ) ); ?&gt; &lt;?php while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); ?&gt; &lt;div class="product-tease" id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;div class="upper"&gt; &lt;h3&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt; &lt;p align="center"&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;&lt;img src="&lt;?php echo catch_that_image() ?&gt;" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;?php the_excerpt('Read the rest of this entry &amp;raquo;'); ?&gt; &lt;/div&gt; &lt;span class="btn-readon"&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title(); ?&gt;"&gt;Read On&lt;/a&gt;&lt;/span&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;br clear="all" /&gt; &lt;!-- post end --&gt; &lt;br clear="all" /&gt; &lt;?php wp_reset_query(); ?&gt; &lt;?php rewind_posts(); ?&gt; &lt;/div&gt; &lt;?php } // End foreach $prod_cats ?&gt; </code>
Dynamic variable for custom taxonomy in loop?
wordpress
I just installed a friends blog on my LAMP stack, which has mod_rewrite enabled (I'm using it for clean URLs on my Drupal installs on the same server). For some reason, WordPress (3.0.3) isn't recognizing that mod_rewrite is enabled. In the Permalinks menu it's displaying options for PATHINFO permalinks (with index.php preceding the url string). My fix for now was to just use the Custom Structure field and input what I wanted less the index.php part WordPress seems intent on inserting, which works but I'd like to get an actual fix for this in place. Is this a 3.0.3 anomaly? I haven't had much time to investigate my server configuration, but any guidance would be much appreciated.
The output of $_SERVER['SERVER_SOFTWARE'] is WebServerX That looks like your problem - check out this line in <code> wp-includes/vars.php </code> : <code> /** * Whether the server software is Apache or something else * @global bool $is_apache */ $is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false); </code> I think you'll need to override this variable manually, either in a plugin or your theme's <code> functions.php </code> : <code> global $is_apache; $is_apache = true; </code> Props to @John P Bloch: The only time it'll automatically add 'index.php' to a permalink is if $is_apache returns false.
mod_rewrite enabled but Permalinks show index.php
wordpress
What is the "best" setup for <code> robots.txt </code> ? I'm using the following permalink structure <code> /%category%/%postname%/ </code> . My <code> robots.txt </code> currently looks like this (copied from somewhere a long time ago): <code> User-agent: * Disallow: /cgi-bin Disallow: /wp-admin Disallow: /wp-includes Disallow: /wp-content/plugins Disallow: /wp-content/cache Disallow: /wp-content/themes Disallow: /trackback Disallow: /comments Disallow: /category/*/* Disallow: */trackback Disallow: */comments </code> I want my comments to be indext. So I can remove this Do I want to disallow indexing categories because of my permalinkstructure? An article can have several tags and be in multiple categories. This may cause duplicates in google. How should I work around this? Would you change anything else here?
FWIW, trackback URLs issue redirects and have no content, so they won't get indexed. And at the risk of not answering the question, RE your points 2 and 3: http://googlewebmastercentral.blogspot.com/2008/09/demystifying-duplicate-content-penalty.html Put otherwise, I think you're wasting your time worrying about dup content, and your robots.txt should be limited to: <code> User-agent: * Disallow: /cgi-bin Disallow: /wp-admin Disallow: /wp-includes Disallow: /wp-content/plugins Disallow: /wp-content/cache Disallow: /wp-content/themes </code>
What is a good robots.txt?
wordpress
How can I show 'Read more' links in rss feed instead of showing excerpt? The settings in reading only allow to choose between full content and excerpt.
You can, but you shouldn't. RSS feeds are built in XML. Not in HTML. Links in XML don't have meaning because they're HTML elements. However, because XML can be read by most HTML parsers (i.e. web browsers), you can easily mistake an XML document for an HTML one (the prevalence of XHTML helps to blur this line even further). In reality, though, no one actually reads a raw XML feed. They open the feed in a web browser and let the browser parse it into something intelligible. Firefox and Safari are very good at this actually. Or they open it in an eternal feed aggregator like Google Reader. All of these other applications will parse the content permalink (your post's url) and use it as a contextual reference for the post. In some cases, they'll add the "read more" link for you. In others, they'll convert the title to a click-able link in the display. In either case, you're relying on the reader to generate the link, not on the rendered content of your post. For example, here is the feed for my blog - http://mindsharestrategy.com/feed - rendered by Safari. The browser has both turned the title into a link and automatically added a "Read More ..." link to the bottom of each post. The key thing to remember is that this feed is a raw XML document that was parsed automatically by the browser. I did not specify any of the styling, colors, or even the Read More link ... Safari did that all on its own. Firefox actually only displays an excerpt for each post rather than the full post content (each followed by an auto-generated "Read More" link). Google Reader does something very similar, as will most other feed aggregators.
Show 'Read more' in rss feed
wordpress
This is driving me nuts and I'm sure it's simple but nothing I search for comes up with a simple structure (everything is very complex). I have a custom post type "product_listing" and a custom taxonomy of "product_cat" (which is hierarchical and should be have like categories). I simply want my URLs to look like this: <code> mysite.com/products/category1/product-name1 mysite.com/products/category2/product-name2 </code> But for the life of me, no matter what I do, I'm getting the dreaded 404 issue. Pages work okay, and Posts work okay, but my custom posts don't work correctly. They're showing up as: <code> mysite.com/products/product-name1 mysite.com/products/product-name2 </code> Which actually works ! It's just that I want to see my custom taxonomy in there, PLUS, I want to be able to access the taxonomy.php template I have setup by going to: <code> mysite.com/products/category1/ mysite.com/products/category2/ </code> None of my slugs are the same, nor do I want them to be. Here is the post type and taxonomy part of my functions.php file: <code> ///// CUSTOM POST TYPES ///// // register the new post type register_post_type( 'product_listing', array( 'labels' =&gt; array( 'name' =&gt; __( 'Products' ), 'singular_name' =&gt; __( 'Product' ), 'add_new' =&gt; __( 'Add New' ), 'add_new_item' =&gt; __( 'Create New Product' ), 'edit' =&gt; __( 'Edit' ), 'edit_item' =&gt; __( 'Edit Product' ), 'new_item' =&gt; __( 'New Product' ), 'view' =&gt; __( 'View Products' ), 'view_item' =&gt; __( 'View Product' ), 'search_items' =&gt; __( 'Search Products' ), 'not_found' =&gt; __( 'No products found' ), 'not_found_in_trash' =&gt; __( 'No products found in trash' ), 'parent' =&gt; __( 'Parent Product' ), ), 'description' =&gt; __( 'This is where you can create new products on your site.' ), 'public' =&gt; true, 'show_ui' =&gt; true, 'capability_type' =&gt; 'post', 'publicly_queryable' =&gt; true, 'exclude_from_search' =&gt; false, 'menu_position' =&gt; 2, 'menu_icon' =&gt; get_stylesheet_directory_uri() . '/images/tag_orange.png', 'hierarchical' =&gt; true, '_builtin' =&gt; false, // It's a custom post type, not built in! 'rewrite' =&gt; array( 'slug' =&gt; 'products', 'with_front' =&gt; true ), 'query_var' =&gt; true, 'supports' =&gt; array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions' ), ) ); //hook into the init action and call create_book_taxonomies when it fires add_action( 'init', 'create_product_taxonomies', 0 ); //add_action('admin_init', 'flush_rewrite_rules'); //create two taxonomies, genres and writers for the post type "book" function create_product_taxonomies() { // Add new taxonomy, make it hierarchical (like categories) $labels = array( 'name' =&gt; _x( 'Categories', 'taxonomy general name' ), 'singular_name' =&gt; _x( 'Category', 'taxonomy singular name' ), 'search_items' =&gt; __( 'Search Categories' ), 'all_items' =&gt; __( 'All Categories' ), 'parent_item' =&gt; __( 'Parent Categories' ), 'parent_item_colon' =&gt; __( 'Parent Categories:' ), 'edit_item' =&gt; __( 'Edit Category' ), 'update_item' =&gt; __( 'Update Category' ), 'add_new_item' =&gt; __( 'Add New Category' ), 'new_item_name' =&gt; __( 'New Category Name' ), 'menu_name' =&gt; __( 'Category' ), ); register_taxonomy('product_cat',array('product_listing'), array( 'hierarchical' =&gt; true, 'labels' =&gt; $labels, 'show_ui' =&gt; true, 'query_var' =&gt; true, //'rewrite' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; '%category%', 'with_front' =&gt; true ), )); // Add new taxonomy, NOT hierarchical (like tags) $labels = array( 'name' =&gt; _x( 'Scents', 'taxonomy general name' ), 'singular_name' =&gt; _x( 'Scent', 'taxonomy singular name' ), 'search_items' =&gt; __( 'Search Scents' ), 'popular_items' =&gt; __( 'Popular Scents' ), 'all_items' =&gt; __( 'All Scents' ), 'parent_item' =&gt; null, 'parent_item_colon' =&gt; null, 'edit_item' =&gt; __( 'Edit Scent' ), 'update_item' =&gt; __( 'Update Scent' ), 'add_new_item' =&gt; __( 'Add New Scent' ), 'new_item_name' =&gt; __( 'New Scent Name' ), 'separate_items_with_commas' =&gt; __( 'Separate scents with commas' ), 'add_or_remove_items' =&gt; __( 'Add or remove scents' ), 'choose_from_most_used' =&gt; __( 'Choose from the most used scents' ), 'menu_name' =&gt; __( 'Scents' ), ); register_taxonomy('scent','product_listing',array( 'hierarchical' =&gt; false, 'labels' =&gt; $labels, 'show_ui' =&gt; true, 'query_var' =&gt; true, //'rewrite' =&gt; array( 'slug' =&gt; 'scents' ), )); } </code> I also have another custom taxonomy of "scents" that I'd ideally like to have some kind of friendly url but I'm more open on this. I'd like to maybe access a list of all scents by going to mysite.com/products/scents but they don't have to be category specific. Can anybody help me? I've been going crosseyed for hours. Thanks!
Change <code> slug </code> in your post type arguments to <code> products/%product_cat% </code> , and <code> slug </code> in your taxonomy arguments to just <code> products </code> , then flush your rewrite rules. WordPress should now handle <code> /products/my-product-cat/post-name/ </code> ! Now finally, we need to help WordPress a little with generating permalinks (out of the box, it won't recognise the permastruct tag <code> %product_cat% </code> ): <code> function filter_post_type_link($link, $post) { if ($post-&gt;post_type != 'product_listing') return $link; if ($cats = get_the_terms($post-&gt;ID, 'product_cat')) $link = str_replace('%product_cat%', array_pop($cats)-&gt;slug, $link); return $link; } add_filter('post_type_link', 'filter_post_type_link', 10, 2); </code> One thing to note, this will just grab the first product category for the post ordered by name . If you're assigning multiple categories to a single product, I can easily change how it determines which one to use in the permalink. Lemme know how you get on with this, and we can tackle the other issues!
Custom post types, taxonomies, and permalinks
wordpress