INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Child theme functions.php do I use php open and close tags? I setup a child theme which works fine. It's importing the main style.css and has custom css styles along with custom header.php and footer.php files When using functions.php in a child theme it's going to append the child themes functions.php to the main theme. Do I need to wrap my functions in opening and closing php tags or can I just add the following without php tags `add_image_size( 'related-thumbnail', 130, 130, true );`
Opening tags are required, closing tags are only needed if you have other code (HTML, CSS) after them in the same file. See PHP manual. A closing tag with nothing after it may lead to problems with included files if they contain a BOM. That’s one of the reasons why all optional closing tags were removed for WordPress 3.4 in core files. Follow this style. It’s useful. Here is an example from Automattic’s _s theme’s `functions.php`.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 5, "tags": "functions, child theme" }
How to remove Tags: text from the_tags? The function `the_tags();` gives output as: `Tags: tag1, tag2`. But I want to get the tags only without the text `Tags:`. How can I use the function so that it does not out the text`? Thanks.
Use something like `<?php the_tags('', ', ', '<br />'); ?>` From Wordpress codex for the_tags(): <?php the_tags( $before, $sep, $after ); ?> > **Parameters** > > **$before** (string) Text to display before the actual tags are displayed. Defaults to Tags: > > **$sep** (string) Text or character to display between each tag link. The default is a comma (,) between each tag. > > **$after** (string) Text to display after the last tag. The default is to display nothing.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "tags" }
How to display subcategory articles in the category view? I have the wordpress category widget installed on my website that lists all categories/subcategories on my site and their hierachy: Watch Accessories (1) - Straps (1) Watch Glossary (5) Watch Guides (1) - Maintenance (1) Watch News (2) - New Releases (2) Watch Reviews (7) - Christopher Ward (1) - Hamilton (1) - Seiko (2) - Tissot (2) - Vostok (1) I am using the following permalink structure: /%category%/%postname%/ When I click on the parent categories > > > it shows the category view and lists all articles in that category. But when I click on a subcategory > > > it doesn't show the category view, it doesn't list all the articles in the subcategory. Instead it redirects to the first article in the sub category. How can I get Wordpress to display all articles in a subcategory?
This is a matter of your template. To display the subcategories in a list view as well you would have to customize the template. I do not know what kind of template you use and how the file is named which displays the subcategories, but you could change it so that it displays the articles of the current category. Therefore you will have to take a look at the wp loop. Another option would be to look for a theme that does so. And there are plugins to display Articles on posts, but therefore you would have to implement the category pages manually.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, categories, permalinks" }
Fetching ten ten records from JSON API in word press I am using `JSON API` for getting web services.. I have 80 records in my `wp_posts` table . I need to display 10 , 10 records so that my mobile app will be faster. I used the following method in this here i get 84 records, if i specify my count to 10 , only ten records will be displayed but later on i need to fetch next ten records. I searched json api documentation but dint find solution What method should i use to do so.. please help
First, there's the debug query arg: `?dev=1`, which you can simply append to the URl. AFAIK, the plugin relies on `get_posts()`, so you should be save to use `&offset=10`. _Disclaimer: Not tested, as I ain't got a setup with the plugin in use.`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin json api, json, web services" }
Youtube parameters within WordPress embed code? Ok, so I want to embed youtube videos but also remove the annoying annotations. The following code works great from to embed the video [embed width="599" height="360"]youtube.com/watch?v=mNf0v2WkV0U [/embed] But whatever I seem to do, I cannot add the following parameter: > > iv_load_policy=3 > Im not sure if its even possible to to add this within the wordpress embed code? I then found something intresting: $('object').each(function(){ var $param = $(this).children(':first-child'); var newUrl = $param.attr('value') + '&iv_load_policy=3'; $param.attr('value', newUrl); }); The above code is meant to set all youtube videos globally (`iv_load_policy=3`) but i think Im doing it wrong. Thanks in advance.
Managed to do it, <iframe frameBorder="0" probably_logged_in="0" width="599" height="360" src="youtube.com/embed/…; frameBorder="0"> (the B in border must be caps) `probably_logged_in=0` (removes the watch later button, as long as the user isnt logged in) `modestbranding=1` (removes youtube logo) `rel=0` (removes related videos at the end of your video) `&vq=hd720` (this one forces hd, unlike `hd=1` which goes by iframe height)
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "embed, youtube" }
Show recent posts from one category on a non-WP site I'm trying to move back to WP for our blog, after struggling with a clunky CMS for a few years, but we'll be sticking with that CMS for the rest of the site. Is there a plugin (or code) that I can use to pull the recent posts in a particular category from my WP blog to the sidebar of my non-WP site? Assume full permissions on both the WP blog and the external site.
The easy way is to just use a PHP based reader and parse/output the results. Maybe your CMS already has one but if not and it's based on PHP you can use, * MagpieRSS * SimplePie * Simplexml Then you simple point it to your categories /feed, like --> `www.example.com/your_category/feed` You can easily customize a feed to show whatever you want < That way you can have a feed that only shows recent posts from one category using WP Query, you just have to point your reader to it. Alternatives you can try via a plugin that allow for external HTTP requests: Hookpress JSON API
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "categories, get posts" }
Changing the username character limit from four to less characters I want to create a user account on my multi-site installation of Wordpress with a username less than 4 characters. But since Wordpress has a limit of usernames at least being 4 characters, this error message is shown: > Username must be at least 4 characters. I found a solution involving a mu-plugins folder in the wp-content folder, but it doesn't work. Is there any possible way that would allow me to create a user account with a username less than 4 characters?
You can filter `'wpmu_validate_user_signup'` and check if the error code matches the 4 character warning. Then just unset the error code. Sample plugin: <?php # -*- coding: utf-8 -*- /* Plugin Name: Allow short user names for multi site. */ add_filter( 'wpmu_validate_user_signup', 'wpse_59760_short_user_names' ); /** * Allow very short user names. * * @wp-hook wpmu_validate_user_signup * @param array $result * @return array */ function wpse_59760_short_user_names( $result ) { $error_name = $result[ 'errors' ]->get_error_message( 'user_name' ); if ( empty ( $error_name ) or $error_name !== __( 'Username must be at least 4 characters.' ) ) { return $result; } unset ( $result[ 'errors' ]->errors[ 'user_name' ] ); return $result; }
stackexchange-wordpress
{ "answer_score": 10, "question_score": 7, "tags": "limit, username" }
Stop editor from removing <p> tags and replacing them with nbsp When I enter content in posts/pages' WYSIWYG editor, I do not get `<p>` when ending paragraphs, just `&nbsp`s. If I manually place `<p></p>` in the HTML mode, they are stripped as soon as I switch to 'visual' mode. This is repeated in several sites (I thought it was the theme but it isn't). I have read dozens of topics and answers, but none solve my problem. I tried `add/remove wpautop` in my functions.php file but nothing helps. I do not want to use a tinymce plugin.
I have done extended research and found the answer - I am now using a hook on 'tiny_mce_before_init'. Based on other answers (special thanks to answer #2 @Chip Bennett), I have used the following code in my functions.php to secure the paragraph breaks (in the editor HTML mode they show as **& nbsp** but become paragraphs on the front-end): function tinymce_config_59772( $init ) { // Don't remove line breaks $init['remove_linebreaks'] = false; // Convert newline characters to BR tags $init['convert_newlines_to_brs'] = true; // Do not remove redundant BR tags $init['remove_redundant_brs'] = false; // Pass $init back to WordPress return $init; } add_filter('tiny_mce_before_init', 'tinymce_config_59772'); You can find on the tinyMCE site the different possible configurations.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 6, "tags": "tinymce, wp autop, line breaks" }
Using "/blog" as a site with Wordpress Multi-Site I have Wordpress installed in the root directory, and plan to use the `domain.tld` as a portfolio and `domain.tld/blog` as personal blog site. Since the `blog` keyword is reserved in Wordpress and can't be used for creating any child site, I tried changing the reserved words defined with `subdirectory_reserved_names` in `/wp-admin/network/site-new.php`. I was successful in creating /blog site. But the problem is, when I try to visit the `domain.tld/blog`, the error below is shown: > This is somewhat embarrassing, isn’t it? > > It seems we can’t find what you’re looking for. Perhaps searching, or one of the links below, can help. This only happens when I try to visit the child site's homepage, but the pages and posts are fine. For example, I can visit the `domain.tld/blog/about/` page, but can't do the same with `domain.tld/blog` What is the problem here? And how can I solve it?
the main problem is that you should never alter core files ... the next time WordPress does an update it might overwrite the file you just changed. you should not have needed to use a multisite for your scenario - you can have a portfolio and blog in the same setup using plugins or a great theme (even without using something called custom post types). I'm not certain of a fix but have a look at this and contact @Ipstenu or @AndreaR on the Multisite forum for why you shouldn't do this <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "multisite, blog" }
Does WordPress have an Browser Agent? I want to block a directory to everyone but WordPress's internal upgrade feature (I am trying to get WordPress to do auto-updates of my premium plugin). I have it updating, but I really would like to block the directory for everyone but WordPress. Anyone know what WP's internal User Agent is?
The WordPress user agent is set in the class `WP_Http` as 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) You can set it to a (secret) fixed value per filter: add_filter( 'http_headers_useragent', 'wpse_59788_user_agent' ); function wpse_59788_user_agent() { // to remove this filter immediately uncomment the following line // remove_filter( current_filter(), __FUNCTION__ ); return 'alfgjlkgjlkgjsldkjhrkjh'; } To change the user agent for a plugin upgrade only try something like this (not tested): add_filter( 'upgrader_pre_install', 'wpse_59788_register' ); function wpse_59788_register( $dummy ) { add_filter( 'http_headers_useragent', 'wpse_59788_user_agent' ); return $dummy; } And uncomment the self deactivation line in the first function.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "plugin development" }
Permalink for regular posts "/blog/" I'm trying to figure out how to accomplish the following: ` I'm using the `/%postname%/` for my permalink structure, but this eliminates the "/blog/" from all posts that are technically blog only. Is there a way to ensure that "/blog/" is within the URL structure for regular Posts? * * * In addition, is there a way to REMOVE the post type slug from the URL for a Custom Post Type?
I've come to accept that this is just not possible with WordPress. You MUST have a slug for a custom post type.
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "custom post types, permalinks, blog page" }
Use Ajax To filter posts? Right now I'm submitting a drop-down form to it's own page (action="") to filter posts displayed. I'd like to not have to refresh the page, which resets the forms. Is there a way to query posts/filter them using ajax?
I'd go with @Vinicius' answer with the following changes: 1. Change `type: 'GET'` to `type: 'POST'` 2. Change `ajax: 1` to `action: 'filter_posts'` 3. Replace `add_action('init', 'check_ajax');` with: add_action('wp_ajax_filter_posts', 'check_ajax'); add_action('wp_ajax_nopriv_filter_posts', 'check_ajax'); 4. Remove: if (!isset($_POST['ajax'])) return false;
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp query, ajax" }
How to disable tinyMCE button added by a plugin? I know how to disable `TinyMCE` default buttons with `add_filter('tiny_mce_before_init')` using `theme_advanced_disable` parameter, but a button added by a 3rd party plugin seems impossible to hide with `tiny_mce_before_init` The available array with `add_filter('mce_buttons')` returns only the default tinyMCE buttons. How to disable this tinyMCE button?
I've found that you can manual set availability button by this attribute `theme_advanced_buttons1` (for button in row 1) Example : function disable_mce_buttons( $opt ) { //set button that will be show in row 1 $opt['theme_advanced_buttons1'] = 'bold,italic,strikethrough,|,bullist,numlist,blockquote,|,justifyleft,justifycenter,justifyright,|,link,unlink,wp_more,|,spellchecker,wp_fullscreen,wp_adv,separator'; return $opt; } add_filter('tiny_mce_before_init', 'disable_mce_buttons');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, tinymce" }
How to get all events from 'All in one Events calender' plugin in JSON format? I am using `All in one Events Calendar` plugin to add the events. It works fine in CMS. I would like to display the events data in mobile version. for this i used `JSON-API` for obtaining web-services in json format. To obtain all events , I dint find any plugin which will full-fill my requirement. so i started writing php code and uploaded the `getevents.php` to `www/.../services/getevents.php` When i execute the file it is redirected to Calendar page in my cms. But i am expecting a json formatted output of all the events. Please suggest a solution... Thanks
I had to do the same thing. I used the JSON API plugin and had to create a new controller for JSON API that read the specific data out of the tables that All-in-One created. Unfortunately there really were not the right calls in the calendar plugin to access all the data (or at least on the older version I used this for) so I had to write the whole controller to do it. It took only a few hours to do and was pretty trivial once you look at the database structure, so this would be my recommended method to do this.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugins, php, plugin json api, json" }
Post Quote with image on header for news site I'm working on a news website. (wordpress.org) I want to add a quote on the header with an image. Please have a look at this !image For this I want to add a check box on the post publish section (post.php) like this !image Please guide me on how to do this, should I use custom field or what? should i try custom metaboxes... or custom post type ?
I think using CPT may not be necessary as we already have post formats. Trun on "Quote" post format and their you can add the quote, the image as featured image. And on the header section just query for the post format and show the latest one or use jquery if you like to have multiple on a slider. You can use a post meta box/or excerpt for quote source/author/name, title for the quote preview title.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, metabox" }
blank white page in admin, white space hunting? Upon logging into the dashboard, I am presented with a blank white page, tho the front end of the site works fine. I am pretty sure its due to a white space oposed to a plugin issue, but not sure where the white space could be hiding, I have checked wp-config and functions to no avail, any way to sniff them out? Thanks!
What your seeing is probably a PHP fatal error, however your server will be configured to log them to the error log rather than present it on the frontend. To find out what the error is, check your error log, or alternatively, if you don't have access to the error log or enabling the error log is not an option, you could enable printing the errors to the frontend. This will give you a blank page but now there will be a PHP error message. You will not want to do this in a production environment, and you won't want to enable this for very long if you're forced into that situation. One way of doing this is by enabling WP_DEBUG in wp-config.php. How you would enable error logging to the screen is a subject for another question
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "admin, errors, fatal error" }
WordPress.org how to force expire Cached Banner-772x250 from my Plugin page I created and added a banner to my plugin page < but there was a spelling mistake so I deleted & committed a new verison. After I added the new image back in the SVN - it's still showing the old one. So I know that the CDN has cached the image for a very long time. I checked via anonymouse.org just now and the correct banner is showing. **EDIT** It's been three days so far since I uploaded the image and for me I'm still seeing the same broken banner. I guess the CDN is serving out the old cached image to my IP :( So my questions ... * is there a way for _developers_ to expire the old image? or force it from the cache? * does anyone know how long these banner images are cached for? and ... * Let me know if you are not seeing this image as I've got an update ready but not going to change /trunk until the correct banner is showing for everyone. (!enter image description here
This was discussed on the WP Hackers mailing list. > On Tue, Jul 31, 2012 at 7:15 PM, Dion Hulse (dd32) wrote: > >> s-plugins.wordpress.org is a Externally hosted CDN - Edgecast to be specific. >> >> Right now, the only way is to wait for it to update, the Edgecast CDN has a long cache expiry time, so WordPress.org needs to be updated to add a Cache busting version/revision parameter by the look of it. > > The cache-busting parameter has been implemented now. It will take effect on the next plugin update. > > So touch the plugin's readme.txt file or perform some other update of your choice, and the cache will get busted for your banner image. It will then get busted again when you change something in the assets directory going forward. > > -Otto
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, svn, plugin repository" }
Approve comment hook? I'm looking to send out emails to subscribers when a comment has been approved. The two actions in the Codex are: **1.** add_action('comment_post', 'callback', $priority, $accepted_args); Where the arguments are `comment_ID` and `approval status` (0 or 1). **2.** add_action('edit_comment', 'callback', $priority, $accepted_args); With argument `comment_ID` By default comments are not approved when they are posted so I think I would be editing them when I approve them but it's unclear in the Codex. Which option should I use when I approve a comment?
Just like posts, a comment can have an array of different statuses, so instead of naming a hook with each status, they have transition hooks, which tell you what status it had before and what's the new status. In your case, this might do the trick: add_action('transition_comment_status', 'my_approve_comment_callback', 10, 3); function my_approve_comment_callback($new_status, $old_status, $comment) { if($old_status != $new_status) { if($new_status == 'approved') { // Your code here } } } Let us know how it goes?
stackexchange-wordpress
{ "answer_score": 18, "question_score": 10, "tags": "comments" }
Force hide custom field metaboxes How can I completely remove the custom fields and the collapse button in the Edit Post/Edit Page custom screen, but without removing the capability to add custom fields with a PHP function?
< function remove_custom_meta_form() { remove_meta_box( 'postcustom', 'post', 'normal' ); remove_meta_box( 'postcustom', 'page', 'normal' ); } add_action( 'admin_menu' , 'remove_custom_meta_form' ); HTH
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "custom field, metabox, filters" }
Media Library not showing images but still acknowledges existence I have no idea why this is happening. I've read A LOT about it and there don't seem to be any solutions. I once read that it was expected behaviour because of some plug-ins and that the Hotfix plugin would fix it but that wasn't the case. !media library However, if I go to the actual media gallery through the sidebar, I can see all my images. I've tried searching and filtering the page in the image but still no images show. **Any one familiar with this problem and know of a fix?**
This is a little known error caused by creating a custom taxonomy called 'type'. To solve just need to change the taxonomy's name.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "media, media library" }
Options Theme - Wordpress Searching about options page, I found a lot of themes that uses a options theme page like this one: !enter image description here There is an pre-built option? What framework do you advise? Thanks
Don't forget the Option Framework Theme and Plugin. They are killer solutions IMO.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme options, framework" }
Aviary + Wordpress Media has anyone tried to implement Aviary API and wordpress successfully? I am looking for a tutorial or guide of some sort.
I just Finished a part of my theme framework which Integrates aviary editor to WordPress media library and since i was asked, I released it in a plugin form Aviary Editor !enter image description here !enter image description here
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images, media" }
How to edit pages after installing WP I'm really new to Wordpress. I just installed it following the instructions here and I'm wondering what to do next. I already have an account and a website set up, and how do I edit that website now on my computer? any input would be really appreciated.
from your description, its time to visit your localhost/wordpress/wp-admin/ and login
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "customization" }
How to check if this is the nth instance of a given shortcode in a post Suppose I have a shortcode called `[item]`, which I have used 20 times in a particular post. Is it possible, from within the shortcode handler function, to know what the numerical index of the given `[item]` is? Like, whether this is the 1st `[item]` in the post, or the 16th? I know that I would be able to achieve the same result by manually adding an attribute, such as `[item order="1"]` and `[item order="16"]`, but I want to make things as easy as possible when adding and rearranging content. Items are often added, deleted and rearranged in the editing process, and it would be tedious and prone to error for the author and editor to re-number them with every change. Is there a good way to do this? Would it require global variables? Is that bad?
If you're using a class, it would be class MyShortcode { static $instance = 0; function __construct($args = array()) { add_action( 'init', array(&$this, 'init') ); } function init() { add_shortcode('myshortcode', array(&$this, 'shortcode')); } static function shortcode($atts) { //this is the code of your shortcode // you can increment your counter self::$instance++; } }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "shortcode, the content, globals" }
What is allowed as an id argument in register_sidebar( $args ) I want to register a sidebar but I am a little confused about the uses of the `id` argument in `register_sidebar` function. > Codex says: id - Sidebar id - Must be all in lowercase, with no spaces (default is a numeric auto-incremented ID). Of what use is the `id` argument and must it always be in numeric form?.
The sidebar ID is used to uniquely identify this specific sidebar. If you don't set it and something creates another, you could find that your sidebar moves somewhere unexpected! It doesn't need to be numeric - you can use strings, too.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 13, "tags": "register sidebar" }
How to detect single.php (but not single-portfolio.php)? When I'm using `is_single();` in my `<head>` section to add some style to website navigation it executes correctly on blog posts but it also executes on single "portfolio" post type posts (so single-portfolio.php and single.php). How do I make it execute only on single.php?
You can use the following instead, if (is_singular('post')) { //your code here... } Where by `is_singular` is the WordPress API conditional function for testing for the existence of a post type. You can also pass an array of post types if you wish. <
stackexchange-wordpress
{ "answer_score": 28, "question_score": 14, "tags": "posts, functions, single" }
Add a Page without header and menus? Is it possible to add a Page in WordPress, so that none of the header or the menus of the site appears on that page? And also so that the stuff in sidebars that's on the rest of the site doesn't appear. And the stuff at the bottom of the page (there's a 'Leave a reply' form on the other pages.) So on this site: < don't want any of the header handwriting or the 'hey there' / 'portfolio' / 'need copywriting' / 'etc' menu items to appear on one particular page, nor the side-bar sign-up box, nor the 'leave a reply' form. But I want all that stuff to appear on all other pages.
Create a custom Page Template, leave out the get_header(), get_footer(), and get_sidebar() calls in it, and put in your own html header/footer code in the Page template instead. <
stackexchange-wordpress
{ "answer_score": 10, "question_score": 5, "tags": "pages" }
How can I stop WordPress from catching URL's for static pages that I save on my server I posted a question about whether it's possible to add a Page in WordPress without headers and footers. Here's that question: Add a Page without header and menus? So how can I create a static page with none of the WordPress stuff that appears on all the other pages of my WordPress site, and add html at that url? How would I do that?
Richard To be honest I think you are asking `How can I stop WordPress from responding to URL's for static pages that I save in other directories on my server` Basically its in 2 files * your VHOST (which maps mydomain.com to www/some_folder/ ) * your .htaccess file which manages redirects So you can do 2 things ... 1\. get a new VHOST for subdomain so something-mydomain.com maps to another a folder on your server - or - 2\. update your .htaccess file to include redirect urls your .htaccess file will pick up any requests for urls BEFORE WordPress gets involved. so you can have `mydomain.com` and WordPress will manage all requests and then create a rule that says `mydomain.com/this_page.html` is in `www/some_folder/this_page.html` here is an example of code for a redirect to a static page that you can add to your .htaccess file: #static page redirects here redirectMatch 301 ^/this_page(.*)$ /this_folder/this_page.htm'
stackexchange-wordpress
{ "answer_score": 1, "question_score": -2, "tags": "htaccess, html, customization" }
How to check for images before echo I have the following code in attempt to check for an image before an echo. The reason for doing so is if there is no image it won't echo anything and there won't be a missing image link put in a post that has no image. However this code does not work and when no image exists a missing image icon is added. Is there another way to solve this. <?php $image = wp_get_attachment_image_src(get_field('post_image1'), 'thumbnail'); ?> <img src="<?php if($image !=false) echo $image[0]; ?>" alt="<?php get_the_title(get_field('post_image1')) ?>" /> <?php $image = wp_get_attachment_image_src(get_field('post_image2'), 'thumbnail'); ?> <img src="<?php if($image !=false) echo $image[0]; ?>" alt="<?php get_the_title(get_field('post_image2')) ?>" />
wrap the html output in the conditional like this: <?php $image = wp_get_attachment_image_src(get_field('post_image1'), 'thumbnail'); if( $image !=false ) { ?> <img src="<?php echo $image[0]; ?>" alt="<?php get_the_title(get_field('post_image1')) ?>" /> <?php } $image = wp_get_attachment_image_src(get_field('post_image2'), 'thumbnail'); if( $image !=false ) { ?> <img src="<?php echo $image[0]; ?>" alt="<?php get_the_title(get_field('post_image2')) ?>" /> <?php } ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "images, customization" }
Custom Fields on User Dashboard? I was thinking about either getting a plugin or shortcode to create custom field that shows on user and allows admin to change them and edit the information, not users. For example, if we have wp site where 5 members are registered under admin and there are tasks that admin wants to show in their profile page. so there has to be non editable text area. so that member can view the task if they are logged in. It could show either on dashboard page or any other specific non editable widget. Is it possible? any pointers for this particular task? links?
I just found this plugin which allows you to create custom options < You can then place the php code to display the value of the option inside your dashboard for members who are logged in but not administrators. You can display the value as text wrapped in a div tag and style as you need. Using the plugin I have linked to you can create two options one called 'members' another called 'guests', now that you have control of these variable values through your dashboard as the administrator the code below should display these messages accordingly to your members if they are logged in or not logged in. An example php function may look like this <?php if ( is_user_logged_in() ) { echo get_custom('members'); } else { echo get_custom('guests'); }; ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "plugins, dashboard" }
How to add "time" data this? I am using this simple snippets to get post view count for a long time I was wondering if we can add a "time" data ? Because I would like to show the view of yesterday/ 2 days ago / 2 days ago etc... ? we can display in sidebar like MOST POPULAR POSTS OF THE **DAY** , **MONTH** or **HOURS** (if possible) here is my sidebar code <?php query_posts('meta_key=post_views_count&orderby=meta_value_num&posts_per_page=4&order=DESC'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php echo getPostViews(get_the_ID()); ?> <a class="tab_caption" href="<?php the_permalink(); ?>" title="<?php echo $post_title; ?>"><?php echo get_the_title($post->ID);?></a> <?php endwhile; ?> <?php endif; ?> <?php wp_reset_query(); ?>
Well, the code you are using to count views does store the count data as a `custom_field` value. If I want the functionality you mentioned in question, I'd rather use a custom plugin to create a separate table in database to store view count and respective dates. So doing some queries you can display popular posts by date/month etc.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "loop, post meta, views" }
Changing wp-content to other name? Multisite set up Is there an easy way to change the words `wp-content` that show in the source code to `xyz-content` without breaking my site? I want to do it for branding purposes. I tried: 1. Url rewriting but the original `wp-content` still shows in the source code. 2. Doing a site download, find and replace and then re-upload but it takes over 24 hours with my server. 3. The plugin Real-Time Find and Replace changes the words from `wp-content` to `xyz-content` quickly, but the css etc does not load. Is there another way to do this?
You can move the wp-content directory to a different location, which essentially renames it. First, in your wp-config.php file, add this: `define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/folder/path/to/new/dir' );` And second, also in wp-config.php, add this: `define( 'WP_CONTENT_URL', ' You can read more about changing the wp-content dir on the Codex.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "multisite" }
Where to put snarfer.php? I followed these instructions: < My understanding of those instructions was that the file snarfer.php needed to be in the folder 'themes', so it appears in the same list as the following folders and file: twentyeleven (folder) twentyeleven-child (folder) twentyten (folder) index.php …but when I put it there, and went to create a Page, the new template didn't appear as an option in the list Default Template / Showcase Template / Sidebar Template. So I tried putting snarfer.php in the folder 'twentyeleven-child' -- which is the active theme. And the new template now appears in the Template list when I create a Page. Do I have snarfer.php in the right place?
Yes, templates files belong to a theme and therefore into the theme directory. The Codex text is a bit vague currently. You should edit that until it is easy to understand. :)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php" }
Comments deactivated I can't write comments to new articles (no `add comment` link available). I use Wordpress 3.4. I checked the discussion properties and they are set to * allow guests to comment articles * none of the other (relevant) options are checked I have the feeling that comments aren't available since I installed some plugins. But I tried deactivating some with no success in activating comments again. Suggestions?
Comments might have been closed once. If you change this option later globally it doesn’t affect existing posts when comments were turned off per post. To test if comments really work create a new post and enable the _discussion_ meta box on that screen: !enter image description here If you can comment while all plugins are disabled and the theme is TwentyEleven (default) – then everything works as expected.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "comments, activation" }
How to make text show up - new page template I created a Page Template following these instructions: < When I create some text in a test page and apply the template I created using the instructions at that link, the text I create doesn't show up when I go 'view page'. What code do I need to add to the template so that text shows up?
Your template must have the `the_content()` function called within the Wordpress loop to show up the text you've entered while creating new post. You might have missed the `the_content()` function in your custom template, that function retrieves and show the content of your page. ### Here is sample usage <?php get_header(); ?> <div> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php the_title(); ?> <?php the_content(); /*This code prints the content*/ ?> <?php endwhile; endif; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "page template" }
Custom Post Type to Upload Images I'm wanting to create a custom post type that can upload 2 images to display on the home page of a website. How would I attempt this? The images needs to be displayed underneath each other. Thanks!
Use this plugin < Add two custom fields to upload image. Assign this custom fields to custom post. Use short code to display it. Other simple solution is to use custom fields for images.And display them where you want.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, uploads" }
Custom headers for the WordPress plugin directory I just have submitted one of my simple WP Widget to the Wordpress Directory. < I want to add Plugin Title Image as like in < How can I add that? From readme.txt file? How?
Very simple, All you need to create a image of size exactly `772×250` pixel and name it as `banner-772x250.jpg`. You have to save this image in `/assets/` folder in your plugins SVN directory. * Make sure the image is of either `.png` or `.jpg` type. * The `.gif` images are not allowed. * It may take upto 15 minitues to appear on your plugin page. * Another note - WordPress adds title to lower left corner of image. Here is the example directory location and image name `assets/banner-772x250.jpg)` OR `assets/banner-772x250.png` Link to official update by matt (cofounder of wordpress ) Also, from the Codex: > For development and testing, you can add a URL parameter to your plugin's URL of "?banner_url=A_LINK_TO_YOUR_IMAGE" to preview what the page will look like with your own image. This will only work with your own plugins, you can not use this parameter on anybody else's plugins.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "plugins, plugin development, readme" }
WordPress multi-site: How do I create the home page, the root URL? I have a WordPress installation running since ages ago at mydomain.com. It's mostly administered by someone else, so I haven't really had to understand the inner workings of WordPress—I can create and edit content, but I don't mess around in the code. Today I created a new site using the multi-site features, located at mydomain.com/project/. Everything went well—the site was created, I could set up the theme etc, but when I try to create the home page (i.e. simply mydomain.com/project), I can't get the URL right. No matter how I try, I'm not allowed to create a page with an empty slug, so all pages I create get something like mydomain.com/project/some-slug instead. How do I create a page with the URL mydomain.com/project in this site?
You can set your homepage in Wordpress by creating your page (the slug doesn't matter) and then going into `Settings` > `Reading` and selecting the page in `Front page displays` > `Front Page` setting.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "multisite" }
Images inside post title Is there a way to insert images into a post title? It would also need to display the alt text in the `<title>` tag, permalinks, etc. The reason I need to do this is I have a client who want their logo used in page titles instead of plain text. Therefore, the image could be anywhere in the title, so I can't just append/prepend the image. The only solution I can think of would be to do a find and replace using javascript, but this doesn't seem like a great solution...
A search and replace solution does sound viable. I wouldn’t do it via JavaScript, though. add_filter('the_title', 'wpse60174_logo_in_title', 10, 2); function wpse60174_logo_in_title($title, $post_id) { // Add a <span> around the company name return preg_replace('~\bCompany\s+Name\b~i', '<span class="company">$0</span>', $title); } With the extra span in place it is just a matter of applying some custom styles to it. You can provide different styles depending on where the title is shown. You may even decide to not replace the company name with a logo image in some place. It’s a flexible setup with clean HTML. /* A demo CSS rule */ h1 > .company { display:inline-block; background:url(logo.png); width:100px; height:20px; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "posts, title" }
Add simple Nivo Slider to wordpress site I have a wordpress website, on the front page i have an area below the main menu which takes a post and displays it along with an image, what i would like to do is swap this box for the nivo slider. The problem is, this area of the website isn't controlled through the admin area and although i have the simple-nivo-slider plugin installed, i don't know if it is possible to place it in place of the current post area and if so how i would do that. Thanks Lee
If you want to add Simple Nivo Slider to a post you can use this shortcode `[snivo]` \-- this is from the instructions at < If you want to place it on your homepage ... you can edit your theme files (probably content-single.php) and this code `<?php if (function_exists('simple_nivo_slider')) simple_nivo_slider(); ?>` The simplest ... is create a Page (WordPress Admin > Add New Page) and add the `[snivo]` then go to Wordpress Admin > Settings > General and Choose your new page see also: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins" }
What does wp-list.js do? Pretty straightforward question! What does wp-list.js do? It's listed in the wp_enqueue_script codex page as one of the WP included javascript libraries. Thanks!
This file is for list manipulations with jQuery: add, delete or dim list items. It was introduced in Ticket #4805 to replace some prototype code. Attached to the ticket is a sample plugin which holds the actual documentation. It doesn’t work really good … line 461 should be: $id = isset ( $_POST['id'] ) ? (int) $_POST['id'] : 0; But at least you can test what the code really does in a reduced example. !enter image description here The readable code for the file is in `wp-includes/js/wp-lists.dev.js`.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 5, "tags": "javascript, wp enqueue script" }
wp_query() get_col error I'm trying to create an auto search jQuery function by using AJAX to send data to the database and back to the search field. In my wordpress theme, I create a folder called "include" and in there I created a file called "autoSearch.php" In that file I have my PHP code like so: global $wpdb; $searchQuery = mysql_escape_string($_POST['value']); $mypostids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_title LIKE '$searchQuery' LIMIT 5"); $args = array('post__in='.$mypostids); $res = new WP_Query($arg); $titles =""; while ( $res->have_posts() ) : $res->the_post(); $titles .= get_the_title().'<br />'; endwhile; echo json_encode(array("everything"=>$titles)); wp_reset_postdata(); However, I get the error: Fatal error: Call to a member function get_col() on a non-object. I have no idea why that's happening. Thanks for the help in advance.
UPDATE, Correct Answer: The core WordPress functions are inaccessible at time when using AJAX calls. The proper way to handle this is covered in "AJAX in Plugins" on the Codex. * * * Original answer that didn't solve the issue but might be interesting for others some day. Here's an alternate way that avoids having to directly query the DB. You'd replace all of your code up to and including the `$res = ...` line: // get search term $search_query = mysql_escape_string($_POST['value']); // args for get_posts $my_post_args = array( 's' => $search_query, 'fields' => 'ids' ); // get array of post IDs (see "fields" argument above) $my_post_ids = get_posts( $my_post_args ); // now WP_Query args $res_args = array( 'post__in=' . $my_post_ids ); // make sure that the args parameter matches (it doesn't in your code snippet) $res = new WP_Query( $res_args ); // etc...
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "wp query" }
Lightbox Effect Not Working I followed the steps to create a lightbox gallery. The gallery is created, but does not open with the lightbox. It just opens as a post. Does anybody know the step I've missed? Here is the site in progress. (I also must mention that pretty much nothing in this theme I bought seems to work) < Any insight would be greatly appreciated. I'm relatively new to wordpress
It seams like you forgot to set the Gallery Settings > Link thumbnails to: Image File! Go to edit page/post click on edit gallery inside of your editor and at the bottom you'll find the Gallery Settings. Hope that helps.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "gallery" }
the_excerpt not showing posts I'm using the following code to show the single most recent post on my landing page: <?php if (have_posts()) : ?> <?php if (($wp_query->post_count) > 1) : ?> <?php while (have_posts()) : the_post(); ?> <?php the_excerpt() ?> <?php endwhile; ?> <?php else : ?> <?php while (have_posts()) : the_post(); ?> <?php the_excerpt() ?> <?php endwhile; ?> <?php endif; ?> <?php else : ?> <p>Nothing to see here.</p> <?php endif; ?> My problem is the code doesn't seem to be producing an excerpt. What could be the problem?
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php the_excerpt() ?> <?php endwhile; else: ?> <p>Nothing to see here.</p> <?php endif; ?> This is the right syntax to show title and the excerpt on home page.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "loop, excerpt, recent posts" }
How to call images from your plugins image folder? I've done a lot of research and learned a lot about WP constants and function usage for getting image paths etc. but still my original problem persists. <img src="<?PHP echo WP_PLUGIN_DIR . 'vertical-social-buttons/images/facebook.png'?>"> <img src="<?PHP echo WP_PLUGIN_DIR . 'vertical-social-buttons/images/facebook.png'?>"> <img src="<?PHP echo plugins_url('vertical-social-buttons/images/facebook.png', __FILE__);?>"> All give me broken images. Am I missing something obvious?
Use `plugin_dir_url()` to get the public URI for the directory where the calling PHP file is. <img src="<?php echo plugin_dir_url( __FILE__ ) . 'images/facebook.png'; ?>"> If the PHP file is in a sub directory of your plugin you have to go up: <img src="<?php echo plugin_dir_url( dirname( __FILE__ ) ) . 'images/facebook.png'; ?>">
stackexchange-wordpress
{ "answer_score": 30, "question_score": 15, "tags": "plugin development, urls, plugins url" }
add_rewrite_rule behaving strangely I'm customizing another plugin by changing the rewrite rule, from: add_rewrite_rule('^api/auth/([0-9]+)?/?','index.php?__api=1&uid=$matches[1]','top'); to: add_rewrite_rule('^api/auth/','index.php?__api=1','top'); After making the change (and **not forgetting to refresh the permalinks** ) my endpoint fails to work. When I attempt something like: file_get_contents(" ...instead of the json object that should be returned, I get the user login form. !enter image description here What's even weirder is that when I add an integer to the end like this: file_get_contents(" ...I get the json object that I expect! What's going on here?
So I've solved this problem, but I'm still scratching my head about the "solution": add_rewrite_rule('api/autho/?$','index.php?__api=1','top'); **This** version of the rewrite rule works for some reason. I'm guessing that there's some sort of namespace conflict that I accidentally stumbled across. Maybe `/auth/` is used somewhere else?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugin development, permalinks, url rewriting, rewrite rules" }
How can we hide the parent's theme url at the child themes details on a multisite? I hope the title makes sense. But anyway, to clear things up, here is a screen shoot of what I mean: !enter image description here To be honest I really don't see how site admins benefit from this piece of information since they cannot edit the files. I have tried using: div.themedetaildiv p { display:none !important; } but it hides everything and NOT just the second paragraph. Any ideas? Thanks.
I finally managed to work it out myself, after reading a similar question over at the **Stackoverflow Site** : div.themedetaildiv > p:nth-child(n+3) { display:none; } Which means: we go to the theme details and hide all paragraphs after the second one. The first one being the version number of the theme (Version: 1.4.2). Hope it helps someone else.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "themes, admin, child theme" }
is_page conditional question I am using `is_page` in my `functions.php` file to display some code and I wanted only to display the code in the header if the contact page is being shown. I made a template called contact.php and in the top did the template name: contact. The templates shows just fine but when I went into the functions file and did `is_page('contact')` or `is_page('contact.php')` the code stopped working. Is the function based on the permalinks settings? right now I have wordpress setup for default so instead of showing `contact.php` in the address bar, it shows ?`page_id=94`. If I do `is_page(94)` then my test code works
If the page slug is 'contact' then is_page('contact') should work. You can check out the optional parameters for page in the codex here . Using post ID, e.g. 94 in your example will work regardless of permalink settings. If you want it to display for a specific template you can use is_page_template('contact.php').
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "conditional tags" }
Looks like this if condition is not working I want a query to be executed IF the following condition is true... but looks like the query is executed anyways. ` if($post->post_parent = '302'){ // Query goes here }` Is this query fine?? I want to executed the query if the parent page of current page is 302. Thanks
The following solution worked `$query2= mysql_query("SELECT * FROM wp_posts WHERE ID='$post->ID' AND post_parent=302"); $numrows2 = mysql_num_rows($query2); if($numrows2 != 0) { // query goes here }`
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "conditional content" }
How to Create a Frontend Html-list Editable in the Backend? I would like to add a feature to a page to display a short list of people, like the one seen here. I have done this on other sites by styling lists with css. This time however, it's for a client and I can't trust them to copy and paste a `<li>`, editing the name, job title and img name without messing it up. What is the best way to go about creating this so that it can be easily reduced/added to in the dashboard? Basically, so that the user simply clicks "add person" then fills in some fields before updating the page. Here is the architecture of what I've used in the past (to be styled with css)- <ul class="people"> <li> <img src=" alt="a person" /> Jakie <span> her job</span> </li> </ul>
This can be solved using a Custom Post Type and Custom Fields. Although it can be created manually, a plugin can do it in a breeze. Using Custom Content Type Manager, I just did this in a couple of minutes: !Custom Content Type Manager resulting interface Well, I did it fast because I'm used to the plugin. It has a bunch of options that can be overwhelming at first, but once they're understood it's all very easy. So, it's better to install it first in a testing environment before applying to the live site. And it's very well documented.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, custom field, images, list" }
Find out if logged in user is not subscriber Is there a conditional tag that will allow me to display certain content only if the user is NOT a subscriber?
<?php $current_user = wp_get_current_user(); if ( ! user_can( $current_user, "subscriber" ) ) // Check user object has not got subscriber role echo 'User is a not Subscriber'; else echo 'User is a Subscriber'; ?>
stackexchange-wordpress
{ "answer_score": 11, "question_score": 13, "tags": "users, user roles" }
Sort posts by popularity/page views How can I sort posts by popularity or page views in my template file? I guess I need to count page views first, is there any good plugin to integrate with to sort posts by views or what is the best practice of doing it.
The WP Postviews plugin is one of the most used to record post views. Then you can sort by amount by; <?php if (function_exists('get_most_viewed')): ?> <ul> <?php get_most_viewed(); ?> </ul> <?php endif; ?> Or pass in the variables to the URL: > > > Or even run a custom query that sorts by the post_meta value.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "posts, order" }
$wp_query->queried_object->ID throws warning: Undefined property <?php $current_term = $wp_query->queried_object->name; $current_term_id = $wp_query->queried_object->ID; ?> <hgroup class="section-heading wrapper"> <h1><?php echo $current_term; ?></h1> <h3><?php echo category_description( $current_term_id ); ?></h3> </hgroup> This works fine but the `$current_term_id` variable throws a warning … Notice: Undefined property: stdClass::$ID in /Users/my/htdocs/wr/wp-content/themes/wr/taxonomy-event_type.php on line 12 Any ideas what I'm doing wrong here or what's the real property for the ID of the current term?
I faced the exact same problem for days and then found this! Use the function `$wp_query->get_queried_object_id()`. Check this for more details.
stackexchange-wordpress
{ "answer_score": 9, "question_score": 5, "tags": "custom post types, custom taxonomy, wp query" }
Joining confirmation email When a super admin adds a network user to a blog via wp-admin/user-new.php where does that confirmation email come from? How do I change? It says incorrectly comes from > [email protected] Thanks
Not sure how to close this post. I used WP better emails plugin < on the subsites and it removed the wordpress email address. (I was only using it on the main site before so it didn't work.) Thanks.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "email, wp mail" }
Help with a query not working with custom taxonomy The query below is always returning the latest "news" post, not the latest "news" post with the taxonomy "sotm". I have verified the details of my custom taxonomy, name is "postCat" attached to post type "news", and there is a term "sotm" applied to the post I want to display. Can anyone point out what might be wrong? <?php $sotmArticle_query = new WP_Query(array( 'post_type' => 'news', 'postCat' => 'sotm', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => 1 )); if($sotmArticle_query->have_posts()){ while($sotmArticle_query->have_posts()){ $sotmArticle_query->the_post(); ?>
Try something like this: $sotmArticle_query = new WP_Query( array( 'post_type' => 'news', 'tax_query' => array( array( 'taxonomy' => 'postCat', 'field' => 'slug', 'terms' => 'sotm' ) ), 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => 1 ) ); if($sotmArticle_query->have_posts()){ while($sotmArticle_query->have_posts()){ $sotmArticle_query->the_post(); ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom taxonomy, wp query" }
Fatal error: Call to undefined function wpsc_cart_item_count() \-- I've just done a fresh install of Wordpress 3.4 \-- I've downloaded and uploaded this new free eCommerce wordpress theme suggested by smashing magazine. { < } \-- And I get this giant error on the homepage: Fatal error: Call to undefined function wpsc_cart_item_count() in /home/content/97/8209697/html/websitename/wp/wp-content/themes/balita/header.php on line 78 Line 78 reads: <div class="totalItem totalitems"><?php printf( _n('%d item', '%d items', wpsc_cart_item_count(), 'tokokoo'), wpsc_cart_item_count() ); ?></div> _Live Site at ( **Any pointers?**
If you followed the install instructions with that theme, one of the steps was to add the WP e-Commerce plugin and activate it. `wpsc_cart_item_count` is a function of that plugin, so it is likely not currently activated.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "php, themes, errors" }
Is it possible to host a WordPress site entirely on Cloudfront? I love the Cloudfront approach described here: < I wonder if this is possible to do with caching plugins that create static html files?
It depends what you mean, **entirely on Cloudfront**. Cloudfront is a CDN only. It can't run any server side scripting environments (PHP or MySQL), it therefore isn't possible to host a wordpress site entirely with Cloudfront. You could alternatively use Cloudfront to host your images to improve speed. The closest way to host a wordpress site _entirely_ on Cloudfront is to use ‘ **Origin Pull** ’. It is relatively easy to setup (see this article), but still requires a backend server (therefore not offer a saving on cost).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "cdn" }
New Template -- copy existing template and change code? > **Possible Duplicate:** > Correct process for a new Page Template? I created a page template following these instructions: < I'm having difficulty figuring out how to apply margins, fonts, and font sizes to the new page template. So I'm thinking perhaps there's another way to do it: if I can make the new template so it displays Pages exactly the same as my active template (twentyeleven-child), I can then remove things and change things -- I might find it easier this way to locate the things to remove and change rather than figure out how to build the Page Template from scratch. Is this a sensible approach? If it is, would I copy all the text in content.php to my new page template file, and then edit things both in the new page template file and in style.css ?
For custom templates, I tend to use the default `page.php`, make any changes to the HTML (if need be), and enqueue an overriding stylesheet before `get_header()`: /** * Template Name: My Page Template */ wp_enqueue_style( 'my-page-template', get_template_directory_uri() . '/css/page-template.css' ); get_header(); Everything'll function like a normal page, except now you have a stylesheet for declaring any unique rules for this particular template.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "templates" }
Using WPDB to output raw XML fails because of wp-blog-header.php I'm coding a plugin. One particular file of this plugin is supposed to pull data from the plugin's custom DB table, and output it with minimal processing as raw XML. The problem is, to get the WPDB class to work when the file was opened directly, I had to add a require to wp-blog-header.php. This worked great BUT it turns out that including the file outputs the tags < html>, < head>, and < body>, which kinda screws up certain parts of the XML. Is there any way I can [A] Suppress the tag-spitting behavior of wp-blog-header.php? [B] Get WPDB working in some other way? Or should I just not use WPDB for DB access in this file in the plugin? EDIT: False alarm. Firefox was adding the tags at the user's end, not Wordpress. Sorry for raising a big stink.
Include `wp-load.php`, **_not_** `wp-blog-header.php`. Better yet, hook onto the execution of a standard WordPress request and die early. isset( $_GET['my_conditional_check'] ) && add_action( 'plugins_loaded', 'my_xml_output' ); function my_xml_output() { // do my stuff exit; } This'll run WordPress, then `my_xml_output()`, then die before the request is actually parsed & the template is loaded/rendered:
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugin development, database, wpdb, xml, wp blog header.php" }
Gravatar always shows default image When I call the following code: echo get_avatar( get_the_author_meta('user_email'), '70', get_bloginfo('template_directory')."/images/default.png" ); It generates the following: > > [ > It is adding to the end of the default URL: %3Fs%3D70 This prevents it from working and always returns the default image. If you remove the extra data from the URL it works.
I worked out I needed to add quotes around the parameter. echo get_avatar(get_the_author_meta('user_email'), '70', "'" . get_bloginfo('template_directory')."/images/default.png'");
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "gravatar" }
Custom post types with categories in template I´d like to do something like this: Pages: 1\. Sport 2\. Business 3\. Normal Custom Category "Car-Types": 1\. Audi 2\. BMW 3\. VW My custom post type will called "Cars" I´d like to show the cars by using a custom category like "Car-Type". How can I filter the content from the custom categories, too and show it? E. G.: On Page "Sport" should just show the content from "BMW". <?php $args = array( 'post_type' => 'cars' ); // How can I add a category-filter to this? $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); echo '<li>'; the_title('<h3>', '</h3>'); the_content(); echo '</li>'; endwhile; ?> Thanks
<?php $args = array( 'post_type' => 'cars' ); // How can I add a category-filter to this? $args = array( 'tax_query' => array( array( 'taxonomy' => 'Car-Types', 'field' => 'slug', 'terms' => 'Audi' ) ) ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); echo '<li>'; the_title('<h3>', '</h3>'); the_content(); echo '</li>'; endwhile; ?> <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, categories, templates" }
Get the attachment URL on single.php i've been trying to get the attachment URL on single.php, so far this code gets the DIRECT LINK to the image; <?php if ( $attachments = get_children( array( 'post_type' => 'attachment', 'post_mime_type'=>'image', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post->ID ))); foreach ($attachments as $attachment) { echo '<a target="_blank" href="' . wp_get_attachment_url( $attachment->ID ) . '">Download Full Size</a>'; } ?> but instead i want the attachment URL, PLEASE HELP!
The `the_attachment_link` returns an HTML link, so use this code: if ( $attachments = get_children( array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post->ID ) ) ); foreach ( $attachments as $attachment ) { echo wp_get_attachment_link( $attachment->ID, '' , true, false, 'Link to image attachment' ); } Here I'm passing 5 parameters to function `wp_get_attachment_link()` * First parameter is `$attachment->ID` to get attachment ID * Second parameter `''` says not to print image * Third parameter `true` links to attachment page * Fourth `false` parameter tells not to print media parameter * The last one is the text you'd like to appear as a link
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "attachments, media library" }
how to create several url aliases for a page on the root page of a WordPress site we have a custom page template, that also handles some forms and dynamically changes part of the content. Something like this: <form action="" method="post"> ... <input type="hidden" name="action" id="action" value="do_this" /> </form> and then in the page template we check for $_POST['action']=="do_this". Works perfectly. Now we would like that when these forms are posted to have the url change (action="/do_this"). For that to work, we need /do_this to deliver the root page, but the url to not change. we have tried this in .htaccess RewriteRule ^do_this(.*)$ index.php?p=12 [L] but it changes the browser url. It must have something with WordPress, since if we use another file RewriteRule ^do_this(.*)$ test.html [L] it works: the url is not changed and the test.html is being delivered. Thanks.
a colleague fixed it using parse_request. similar to this one: <
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "permalinks, url rewriting, mod rewrite" }
How do I retrieve an image's width and height using Advanced Custom Fields? Using a get_field('sampleImage'), how would I go about in order to get the image's width and height using the ACF plug-in? I need to be able to print out the img tag with width and height attributes because of a script.
You can get the ID for the attachment with `$attachment_id = get_field('field_name');`. When you have the ID you can use `wp_get_attachment_metadata()` to get the info associated with the image in an array. The images width and height are stored in cells named `width` and `height`. $attachment_id = get_field('field_name'); $metadata = wp_get_attachment_metadata($attachment_id); $width = $metadata['width']; $height = $metadata['height'];
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "images, advanced custom fields" }
How to access .html file that's located in the theme folder from the browser? By default you cannot access a file inside the theme folder directly from the browser, what changes should I make to make an exception?
> By default you cannot access a file inside the theme folder directly from the browser But that's just not true.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "templates, rewrite rules" }
Exclude images uploaded via meta boxes from Wordpress gallery I am using the following simple get attachment code to display all images attached to a certain post but I want to be able to exclude the images uploaded via a couple of custom meta boxes that are also attached to the post. For example, how could I exclude an image uploaded with a meta key of sample_image_1 from this code? <?php $args = array ( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID, ); $attachments = get_posts($args); if ($attachments) { foreach ( $attachments as $attachment ) { the_attachment_link( $attachment->ID , 'screenshot' ); }} ?>
Get all of the attachment IDs from your meta fields, put them in an array, and pass that as `exclude` parameter of `get_posts`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom field, images" }
SEO module to change tag title for different listing page I need to have different tag titles for each category of my website. I've tried all in one SEO but it looks like i cannot change it individually. Thanks in advance
Would you mind using the "description" field for tags as the SEO title? If so: add_filter( 'single_term_title', 'wpse_60464_title_from_description' ); function wpse_60464_title_from_description( $title ) { if ( ( $obj = get_queried_object() ) && ! empty( $obj->description ) ) $title = $obj->description; return $title }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "title, seo" }
Bidding site plugin I have to make the bidding site like odesk, freelancer type. Is there any helpful plugin for job, contractor, user, project and payment management in wordpress as these are the main tasks of this project? Secondly, building it in wordpress will be good or in a custom way?
It's not a plugin but a commercial theme, but you might want to check it out. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "plugins" }
Add number of members to “Right Now” dashboard widget ## Problem I have this code in functions.php but it does not output the total number of members (something is wrong with it it breaks the site) in my "Right Now" dashboard. Is there a way to fix it? function dashboard_wps_user_count() { global $wpdb; $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); ?> <table> <tbody> <tr class="first"> <td class="first b b_pages"><a href="users.php"><? echo $users; ?></a></td> <td class="t pages"><a href="users.php">Members</a></td> </tr> </tbody> </table> <?} add_action( 'right_now_content_table_end', 'dashboard_wps_user_count'); ## Additional feature Also is there a way to show how many authors are registered and how many subscribers are registered also in the "Right now " dashboard?
So here is the small snippet to show total number of users and all roles with user count. This code should go in the themes `functions.php` file. The code uses `count_user` function to fetch the array and show it up on Right Now dashboard screen. function wpse_60487_custom_right_now() { $users = count_users(); echo '<table><tbody>'; echo '<tr><td class="first b b_pages">'.$users['total_users'].'</td><td class="t pages"> total users</td></tr>'; foreach($users['avail_roles'] as $role => $count) echo '<tr><td class="first b b_pages">'.$count.'</td><td class="t pages">'.$role.'</td></tr>'; echo '</tbody></table>'; } add_action( 'wpse_60487_custom_right_now', 'dashboard_wps_user_count');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "users, dashboard, members" }
wp_query a single custom post type? How does one get a custom post by id? FYI: I am passing a particular post id through a form and it's performing an ajax call. I'd like to retrieve just one post and grab the title: <?php // E.g. $loc = 700 $args = array('post_id'=>$loc, 'post_type'=>'seminars', 'limit'=> '1'); $loop = new WP_Query($args); // Start loop for seminar posts $loop->the_post(); echo the_title(); // returns just one post and it's not the right custom post
`'post_id'` is not a valid page/post parameter for `WP_Query()`. Try using `p` or `post__in` instead: array( 'p' => 700 ) or array( 'post__in' => array( 700 ) )
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "wp query" }
Display most recent post on homepage? Is there any plugin that allows me to customize my blog homepage to show only most recent post? Problem is that on my home page, it displays too much posts, my blog is here, < Thanks
In the admin panel, Go to `Settings > Reading` and set _Blog pages show at most_ to `1` post.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "posts, recent posts" }
Send email when a new post is published I'm looking for a method, or plugin, that will allow me to do the following: 1. User can signup to a 'notifications' email list 2. When a new post is published on the site, users on this list are automatically emailed a notification This is for site visitors as opposed to administrators or registered users. Any suggestions much appreciated.
I haven't used it yet, but you can accomplish this with Jetpack, which is made (at least partially) by the founders of WordPress. The advantage is that it uses the Wordpress.com servers to handle the outgoing mail. This is a big plus because shared servers have throttling limits that only allow you to send a certain amount of e-mails in a given time frame (usually an hour). You don't have to worry about the IP of your own servers ending up blacklisted if anyone marks the e-mails as spam instead of unsubscribing. Check it out, there are other features to it as well.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 5, "tags": "plugins, plugin recommendation, email, notifications" }
Multiple Single Installs of Wordpress with a central user base Im sorry that I am asking this but I have been searching for ages and for some reaseon the suggested custom user table dosn't work, it just gives me a username error. This is the code I am taking about: define('CUSTOM_USER_TABLE','new_user_table'); define('CUSTOM_USER_META_TABLE', 'new_usermeta_table'); So I have a main Single install of Wordpress, Lets say I have another on a subdomain (Subdomain A) and a different WordPress site which IS a Sub Directory MU Install on Sub Domain B. I only want people to create an account at the top, main site however they can log in on any of the domains. I would use MU but one of the sub sites is using MU so I cant. Single Sign on is not important but if possible then that would also be really good. Any Ideas would be appreciated! Cheers, Joe
OK Guys. There is a way to do this without editing the core files! 1) Open up your WP-config.php file and add to the file the following code. This will change where WordPress gets it's users from. define('CUSTOM_USER_TABLE','wp_users'); define('CUSTOM_USER_META_TABLE', 'wp_usermeta'); Remember to replace the wp_ prefix with the prefix of your main site. 2) So no download and install the WordPress Plugin WP-Orphanage Extended (< This will allow you to sync the user privileges across all of the sites. 3) Go to Settings > WP-Orphanage Extended and set the default role (Subscriber is probably the best choice. Now add two prefix's, one being the original/master sites prefix and the other being the sub sites prefix. That is all there is to it now. Sorry for the inconvenience with the previous way of editing core files. Non of that is needed now.
stackexchange-wordpress
{ "answer_score": -2, "question_score": 2, "tags": "users, single, subdomains" }
404 Error for Custom Post type I have a function on my theme ("dancefloor" by "Gorilla Themes") that allows me to make a post in a section in my dashboard called Events _(Custom post Type)_. If you schedule the date to anytime in the future it will show up in the Events widget or on the Events Page. That all work fine and Dandy. > But when you click on the link or excerpt, it give a `404` error. Anyone know why this might be happening? Live Example here.
Opps I take that back ... you must be changing stuff at the same time as i was writing this .. so this answer may not be any help at first it seemed the URL's were wrong the title url is linking to `events` the read more is linking to `event` eg .. < and <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "404 error" }
Shortcode Not displayed at the Right Place > **Possible Duplicate:** > Shortcode always displaying at the top of the page I am using custom shortcode to show some message at the end of the post. I am finding it hard to do so because it shows up at the top of the post. Here is my code. I am placing the shortcode at the end of the post but the message appears at the top of the post. What should I do to fix this? function hello_kitty(){ if ( is_single() ){ echo 'This is hello Kitty message'; } } add_shortcode('hellokitty',hello_kitty);
Shortcodes are supposed to return your html, not echo it. Make sure you check the documentation on the Shortcodes API <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "posts, shortcode" }
Share Bar over laps left column on my posts page i have a share thing in the side bar, however the side bar over laps the main content even though there is plenty of room on the right, i have tried changing single right column and single left column but nothing makes any difference, any advice would be appreciated. Thanks Lee
Your `#primary` container is only `620px` wide: #primary { float: left; width: 620px; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins" }
Basics: adding template tag to display custom fields in the post _I've just started learning so this might be a noob question_. > Displaying Custom Fields > > With a Custom Field added to the post, it's time to display your books and mood to the world. To display the Custom Fields for each post, use the the_meta() template tag. The tag must be put within The Loop in order to work. **Many people add the_meta() template tag to the end of their post** or in their Post Meta Data Section. \- Custom Fields on Codex I think I'm misinterpreting the bold part but I tried to add the tag `<?php the_meta(); ?>` in my post and it's not showing up. Screenshot here.
you should add `<?php the_meta(); ?>` in your `single.php` or in other relevant file. reference how to edit your theme files
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom field" }
array_pop() expects array, boolean given for $event_type_term ->slug I have the following function I wrote … add_filter('post_type_link', 'events_permalink_structure', 10, 4); function events_permalink_structure($post_link, $post, $leavename, $sample) { if ( false !== strpos( $post_link, '%event_type%' ) ) { $event_type_term = get_the_terms( $post->ID, 'event_type' ); $post_link = str_replace( '%event_type%', array_pop( $event_type_term )->slug, $post_link ); } return $post_link; } When creating a new post I get the following Warnings in the backend … > Warning: array_pop() expects parameter 1 to be array, boolean given in /Users/my/htdocs/wr/wp-content/themes/wr/functions.php on line 168 > > Notice: Trying to get property of non-object in /Users/my/htdocs/wr/wp-content/themes/wr/functions.php on line 168 Any ideas what I'm doing wrong here? Thank you in advance!
get_the_terms() is probably returning false. Do a print_r($event_type_term) to see what you have in it. From: < > Array of term objects on success. False if no terms are found in the given taxonomy and a wp_error object if an invalid taxonomy is entered.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "custom post types, custom taxonomy, permalinks, terms, array" }
Download WordPress.com theme: how? I like this theme. But I don't want it to use with a wordpress.com blog but download it to use with my WordPress site at my own domain. But I can't find a download link. Is it possible?
For custom installation you should search for the theme on wordpress.org site. > ~~The Wordpress.com hosts themes that are available for use only on wordpress.com blogs and they do not provide download link there.~~ > \- See @markratledge's answer below. Here's the link to download that theme - <
stackexchange-wordpress
{ "answer_score": -1, "question_score": 1, "tags": "themes" }
How to manually activate user in dashboard only by admin I'm looking for a function that allows admins (only) to activate new users. When a user registers he have to be approved by the admin before he gets access to log in. Does anyone know how I can do this?
We are using this wordpress plug in - New User Approve Provides functionality to approve/deny new user registrations.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 4, "tags": "functions, users, dashboard, user access, activation" }
Easy way to inject js in tinymce iframe? I was wondering if there is any direct hook to inject some javascript into tinymce iframe?
WordPress injects its own external script files in the TinyMCE editor `iframe`, see for example the `wp-includes/js/tinymce/plugins/wpembed/plugin.js` file: (function ( tinymce ) { 'use strict'; tinymce.PluginManager.add( 'wpembed', function ( editor, url ) { editor.on( 'init', function () { var scriptId = editor.dom.uniqueId(); var scriptElm = editor.dom.create( 'script', { id: scriptId, type: 'text/javascript', src: url + '/../../../wp-embed.js' } ); editor.getDoc().getElementsByTagName( 'head' )[ 0 ].appendChild( scriptElm ); } ); } ); })( window.tinymce ); The `plugin.js` file is loaded in TinyMCE using the `tiny_mce_plugins` filter.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "tinymce, iframe" }
Limit access to posts/pages by user roles I'm looking for a way to protect content by user roles. Example: you have to be registered to view posts (frontend). If a user is a subscriber he can read post 1, 2 and 3, but if the user is a contributor he can view post 1,2,3 and 4,5,6... does anyone know how I can do this?
Although I haven't used this personally you are probably looking at a plugin like this Seems to provide all the functionality you have requested above.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 5, "tags": "plugins, posts, functions, user roles, user access" }
How to add a second custom menu in my sidebar when theme only supports one? I simply want a second menu in my sidebar to show on all pages. My theme only supports one custom menu though. I am using the first custom menu for the top level nav, and I wanted my 2nd custom menu in the sidebar. I created a second menu and tried adding it using the custom menu widget, however this just adds my first menu, I'm guessing because the theme only supports one menu.
Search for the code give here in your themes `functions.php` file. and register second nave menu as show here. register_nav_menus( array( 'primary-nav' => "Primary Menu", // file may have this with different name 'sidebar-nav' => "Sidebar Menu" //add this line ) ); Use custom menu widget to show it up in sidebar. OR If you want to edit the theme template, then put following code where you want the second menu to appear put follwoing code <?php wp_nav_menu( array( 'theme_location' => 'sidebar-nav' ) ); ?> Now you can got to `Menu Appearance Screen` to assign items to it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "menus" }
Hide tag and category boxes from the post editor I want to hide the tag and category boxes from the post editor, the theme I've just developed doesn't need them, thus I want to hide them. I am aware they could be hidden using the 'screen options' menu, however I'd prefer to do this with a bit of code. Is this possible?
Using `remove metabox` function you can do this. Simply put this inside your themes `functions.php` file at very end. _NOTE - unwrap`<?php` `?>` if necessary._ <?php function wpse60590_remove_metaboxes() { remove_meta_box( 'categorydiv' , 'post' , 'normal' ); remove_meta_box( 'tagsdiv-post_tag' , 'post' , 'normal' ); } add_action( 'admin_menu' , 'wpse60590_remove_metaboxes' ); ?>
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "categories, tags, post editor" }
Theme using masonry layout script rendering overlaped images in Google Chrome I have a WordPress theme built with Masonry script , I added a new template file for list gallery, is working ok in FF and IE but in Google Chrome gallery images (inside containers) are overlapped. Seems like the content is loading faster than images but they don't adjust afterwards.
I can't find any reference about it but it seems Google Chrome (v 21.0.1180.60) do need specified image sizes, in image tag or passing this in css (either class or local): style="display:block;width:333px;height:333px" Or: container.img { display:block;width:333px;height:333px } Maybe this issue has something to do with this question, but I'm not sure. They say images need width and height info in image tag, but some themes/plugins around aren't even informing `alt` tag.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "images, jquery, css, browser compatibility, google chrome" }
Can I get the ID of an inserted / linked image? I am using this code to get the url of first inserted image in a post. Is there any way I can get the ID of that image. global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=\'"[\'"].*>/i', $post->post_content, $matches); $first_image = $matches [1] [0];
No, an image placed inside a post/page content don't reference in your database other than inside your content only. That's why an image attached is better: you have full control over your images since they are in your server and referenced in your database. An attachment is a child post, once you attach an file to a post/page you can use get_children for retrieve file description, title etc.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "theme development, images, uploads, id" }
How should I structure my post types? For the site I am making, I have a few post types: News, Events, Projects, Placements. Each one of these post types will need its own archive page, accessible through the navigation. I am able to create these post types using the Types plugin, but my question is how do I create a archive page for them? I can't figure out what the URL will be. `/projects` for the post type with slug `projects` gives me nothing. I think I understand how the templates for custom post types work (`archive-{post-slug}.php`), but I don't know how to make these pages accessible.
When a post type is registered, you need to at least set `has_archive` to true. This will use the post type name as the slug for archive. You can also specify a string representing the slug for `has_archive`: 'has_archive' => 'projects' This should be accessible under Type's advanced settings, according to their documentation.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, custom post type archives" }
Determine page content based on page parent How can I display a gallery shortcode for pages who are children of the page with an ID of 9, and the regular content for pages who aren't? This is what I've tried so far, but it's not working: <?php global $wp_query; if( (9 == $ $wp_query->post->post_parent ) :?> <?php echo do_shortcode('[gallery link="file" columns="1" size="large"]'); ?> <?php else (); ?> <?php the_content(); ?>
$thispageid = get_the_ID(); $thispageparent = get_ancestors($thispageid); if( in_array( 9, $thispageparent ) ) echo do_shortcode('[gallery link="file" columns="1" size="large"]'); else the_content(); reference get_ancestors()
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "pages, page template, conditional content, hierarchical" }
Calling a div and content in php? Is there a code that i can place in the header that will call a certain div and the content i place inside it for every custom post type i have, Somthething like this. <?php if (is_post_type('pretty-little-liars') ) {echo '<div id="headerimg"><img src=" } ?> I know that the code above doesn't work, but is there a way that i can call something like that for each post type i have, i will be placing this code in the header. Also if anyone does have the solution could you please tell me where do i add a second line to the code that repeats the first line but with a different post type name?
I think that will only work in the loop, but what you can do outside of the loop is use <?php if (get_post_type() == 'pretty-little-liars') { echo '<div id="headerimg"><img src=" } ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, templates" }
Contact Management Plugin suggestions, or tutorials/resources recommendations I will soon be building a site for a local Non-Profit Art Community, and they would like a to have a powerful **contact/member management system** that can do these key things: 1. Store User Contact info (Address, Phone, Email, Website, regdate, etc.) 2. Synchronize with a newsletter mailing service, their preference is Emma. (Alternatively, the desired plugin could handle the newsletters internally) 3. Tag users with multiple tags, example would be Artist, Volunteer, Member. 4. Track membership and expiry, as well as payment history for Members. 5. Hopefully use the built-in Wordpress User area of the admin. My question is, can anyone recommend a plugin that can get me all the way, or part of the way there?
Buddypress will probably help you too. I guess you'll want your community members to interact? Also just search the wordpress.org plugins repository, for "membership" or "members" plugins to compare with. The plugin "s2member", for example, is very popular.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin recommendation, users, newsletter, management" }
Buddypress shortcode for tabs I want to add some more tabs like photos, videos on the user profiles of my buddypress site. Is there any shortcodes or functions to add the tabs?
Use the following code, function custom_add_activity_tab() { ?> <li id="custom-tab"> <a href="<?php echo site_url( BP_ACTIVITY_SLUG . '/' ) ?>" title="<?php _e( 'Tab.', 'buddypress' ) ?>"> <?php printf( __( 'tab' , 'buddypress' ) ); ?> </a> </li> <?php } add_action( 'bp_activity_type_tabs', 'custom_add_activity_tab' ); Check it, Will work better
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "shortcode, buddypress" }
How to rate a post from Admin Side / Manually? I am working on a Mini Job Site. i want to give rating to posts manually from admin / editor side Best rated people will be on top. so visitor'll get better choice. visitor are not allowed to rate posts like this !please have a look how to do this ? {1} Meta-box uses {2} Custom Field help me please
Here's something I'd use if I want to do that without using plugins Create a custom field as `rating` and provide the value while doing post. Suppose I gave a rating of 6, Now wordpress save it into the database as. * `meta_key` => rating * `meta_value` => 6 Now to show the rating on post I'll use this code into `single.php` or `index.php` but make sure to put it within `Wordpress loop` \- <?php //grab the rating value $rating = get_post_meta($post->ID, 'rating', true); //prints star image for ($i=1; $i<=$rating; $i++){ echo '<img src="LINK-TO-STAR-ICON"/>'; } //prints unstar image for ($i=$rating; $i<10; $i++){ echo '<img src="LINK-TO-UNSTAR-ICON"/>'; } ?> The above code will result like this - !enter image description here
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "posts, custom field, rating" }
Display "a generated one [avatar] based on their e-mail address" I was looking at the discussion settings in WordPress and near the "Default Avatar" option I saw that it said the following: > For users without a custom avatar of their own, you can either display a generic logo or a **generated one based on their e-mail address.** (I bolded the second part.) I'm just curious as to how these avatars are "generated" based on email addresses.
The way gravatar works is that it creates an MD5 of the email address and passes that to gravatar.com. If an avatar exists for that hashed email address, then it gets returned. If not, then it generates a random one based on the data in the hash. Essentially, it's arbitrary. There's code in there that basically says "if character 3 is A, use this color" and so forth. This means that the same email generates the same avatar every time, but still makes it randomish. More info and examples: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "email, avatar, customization" }
How do you keep your live and and testing server? I have a live site and a testing server (XAMPP) that I built the site on originally before publishing it. Obviously, there are a number of things you need to do to migrate a site from one place to another. I was hoping to tap into collective experience to find out the best way of doing this, keeping fuss to a minimum. The obvious answer (to me, at least) is to keep a folder of files to merge into the XAMPP files for when it's built on the testing site and a folder of the same files but with production server info to apply when the site is uploaded. This is a bit messy and leads to mistakes. Is there a program out there that I've never come across or better way of doing this? (I've been auto-warned about the subjectivity of this question, I do hope it passes the community test!)
there are quite a few threads on here about this topic ... just look at these examples: Database synchronization between dev/staging and production I would also recommend you read Mark Jaquith's post on Local and Dev Tip's.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "production, xampp, customization" }
Where do hackers usually run their hacking script? So in my quest to solve this mystery, I actually found some script that might be similar to one used to deface our sites: < Now my question is where do they usually run this? Do they run it inside the hacked server or their own PCs?
They run it on your server, just like any other script runs (including WordPress). In the log you provided, it looks like the hacker knew your password. Perhaps you are using the same password on other sites, and he somehow gained access to one of them? Always set different and complex passwords; combine a large character range; include special characters and so on...
stackexchange-wordpress
{ "answer_score": 3, "question_score": -1, "tags": "hacked" }
Any plugins that upload, resize, and display images? Here is an ideal workflow for my situation: 1. Upload a folder full of images 2. Resize images according to a specified size 3. Have the ability to organize these images into folders (collection1, collection2, etc) 4. Display the images within these folders in a non-flash gallery (collection1 on page 1, collection2 on page 2, etc) Is there any plugin that will help this process from start to finish, or set of plugins that play nicely together? It's important that these galleries work on non-flash-supported devices, as mobile and tablet traffic will be significant. Paid is fine for a good quality plugin.
i've been using nextgen gallery and i believe it fits your needs: _1\. Upload a folder full of images_ : **yes** _2\. Resize images according to a specified size_ : **yes** , on the gallery option you can set the standard size. _3\. Have the ability to organize these images into folders (collection1, collection2, etc)_ : **yes** , they're called albums and galleries. Albums contain Galleries, and each Gallery can a set of images. _4\. Display the images within these folders in a non-flash gallery (collection1 on page 1, collection2 on page 2, etc)_ : **yes** use the shortcode `[nggallery id="x"]` there's also many plugins that extend it's funcionaly, like extra slideshows and lightbox effects.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, images, gallery, plugin recommendation" }
Customize Activity Stream - Buddypress Where would I begin if I wanted to rename a string in the buddypress activity stream? Instead of it saying "so and so wrote a new post", I would like it to say "so and so wrote a new **article** " (or whatever word I choose) Thanx.
Got it add_filter('bp_blogs_activity_new_post_action', 'record_cpt_activity_action', 1, 3); function record_cpt_activity_action( $activity_action, $post, $post_permalink ) { global $bp; if( $post->post_type == 'post' ) { if ( is_multisite() ) $activity_action = sprintf( __( '%1$s wrote a new article, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' ); else $activity_action = sprintf( __( '%1$s wrote a new article, %2$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ); } return $activity_action; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "buddypress" }
Make wordpress comments work with include templatepath How can I make the wordpress comments work with: include(TEMPLATEPATH."/comments.php"); instead of: comments_template( '', true ); Ay ideas? Ty
Short answer: you _can't_. Longer answer: You can _include_ `comments.php` as a _template-part_ file inside another template, via: get_template_part( 'comments.php' ) ...but that won't actually make comments _work_ , because the `comments_template()` template tag does far more than merely include the `comments.php` template-part file. In order to make comments actually _work_ when using `get_template_part()` as opposed to `comments_template()`, you'd need to duplicate all of the functions performed by `comments_template()`. And if you need to duplicate all of that code in order to make comments _work_ , you might as well just use the function itself.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "comments" }
How to create directory using username within theme I have the following code to save the uploaded file to a static directory. <?php //set the image size in mb $max_upload_size='10'; $MAXIMUM_FILESIZE = $max_upload_size * 1024 * 1024; $uploaddir = './uploads/file/'; $file = $uploaddir . basename($_FILES['uploadfile']['name']); if ($_FILES['uploadfile']['size']<$MAXIMUM_FILESIZE) { if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { echo "success"; } else { echo "error"; } }else{ echo"size_error"; } ?> But what I want is to create a username directory under "/uploads/file/". For example if the username is "john", then it should create a folder like "/uploads/file/john/" and saved the file under that folder.
Note - User needs to be logged in to work global $current_user; get_currentuserinfo(); $uploaddir = './uploads/file/'.$current_user->user_login.'/'; wp_mkdir_p( $uploaddir ); **Reference -** `wp_mkdir_p()` \-
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "directory" }
Does code run faster in functions.php than in different theme templates? For example I have this code which gets the post title: function baracuda_sinlge_post_title(){ // Single Post Title $post_title = single_post_title('','0'); return $post_title; } Where do you think it would run faster, in functions.php or direcly in the template I need it to be like this: $post_title = single_post_title('','0');
It doesn't matter. I know you think it matters, but it doesn't. The reason it doesn't matter has nothing to do with which one is actually faster. The speed of your website will NEVER be influenced by the placement of this function. Theoretically, sure, but in practice you'll never see it. The only two places to spend time are the front end bandwidth and back end DB calls. That's it. The front end will be too heavy, have too many http requests, errors, and a plethora of other front end issues. And the database is typically the biggest bottleneck on a website. If you're not spending time in these two areas, you're wasting time.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "functions" }