Query:
INSERT INTO upsert_table(id, name, value) VALUES(4,"Check_Upsert",888) ON DUPLICATE KEY UPDATE name = VALUES(name), value = VALUES(value);
If id=4 already there in table it will update values else write the new record in table
Query:
INSERT INTO upsert_table(id, name, value) VALUES(4,"Check_Upsert",888) ON DUPLICATE KEY UPDATE name = VALUES(name), value = VALUES(value);
If id=4 already there in table it will update values else write the new record in table
Use this snippet in your theme’s functions.php file to disable the editor for a specific page template.
add_action( 'admin_init', 'hide_editor' );
function hide_editor() {
// Get the Post ID.
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
if( !isset( $post_id ) ) return;
// Get the name of the Page Template file.
$template_file = get_post_meta($post_id, '_wp_page_template', true);
if($template_file == 'contact.php'){ // edit the template name
remove_post_type_support('page', 'editor');
}
}
Date picker required doesn’t work in Contact Form 7
You need to edit core plugin files before that you need to save contact-form-7-datepicker folder for backup
You go to wp-content/plugins/contact-form-7-datepicker/modules/date.php
Normal Code (Line Number :124)
if ('datetime*' == $type && empty($value)) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_required');
}
if (! empty($value) && ! self::is_valid_date($value)) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_datetime');
}
Change to below code
if ('date*' == $type && empty($value)) { $result['valid'] = false; $result['reason'] = array($name => wpcf7_get_message('invalid_required')); } if (! empty($value) && ! self::is_valid_date($value)) { $result['valid'] = false; $result['reason'] = array($name => wpcf7_get_message('invalid_datetime')); }
Then I changed also time.php (from line 119) and datetime.php (from line 119) files in that similar way.
I hope this helps to you
<p>
tags from images in WordPressPlease add below code in function.php
function img_unautop($pee) {
$pee = preg_replace('/<p>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s', '<div class="figure">$1</div>', $pee);
return $pee;
}
add_filter( 'the_content', 'img_unautop', 30 );
<?php $args = array( 'post_type' => 'nav_menu_item', 'orderby' => 'menu_order', 'order' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'nav_menu', 'field' => 'slug', 'terms' => 'my' ) ) ); query_posts($args); while( have_posts()):the_post(); echo $post->ID; endwhile; wp_reset_query();?>
Getting a Post’s Featured Image URL By Post ID
<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?> <img src="<?php echo $feat_image; ?>" width="80" height="100" />
If Featured Image else your default image:
check below code:
<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?> <?php if($feat_image) {?> <img src="<?php echo $feat_image; ?>" width="80" height="100" /> <?php } else {?> <img src="default.jpg" width="80" height="100" /> <?php } ?>
Display all child and sub child pages using parent ID
This way the page that you are on will show in a post type the child pages of that page
<?php
$pages = get_pages('child_of=7&sort_column=post_date&sort_order=desc'); //Replace your parent id with 7
$count = 0;
foreach($pages as $page)
{
$content = $page->post_content;
?>
<h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
<p><?php echo $content ?></p>
<?php
}
?>
Insert Featured Image In Style Background :
<section class="banner inner-banner" style="background:url(<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); if(!empty($feat_image)){echo $feat_image;}else { echo bloginfo('template_url')."/images/inner-baner.jpg";} ?>) no-repeat top center; height:395px;">
HTML wise all we need to do is add a “back to top” link at the bottom of the blog post
Below Jquery code add in your header file:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
jQuery(document).ready(function() {
$(".top").hide();
var offset = 820;
var duration = 700;
jQuery(window).scroll(function() {
if (jQuery(this).scrollTop() > offset) {
jQuery('.top').fadeIn(duration);
} else {
jQuery('.top').fadeOut(duration);
}
});
jQuery('.top').click(function(event) {
event.preventDefault();
jQuery('html, body').animate({scrollTop: 0}, duration);
return false;
})
});
</script>
Below code add in footer file means end of page:
<a href="#" title="Back to Top" >Back to top</a>
Flexslider jquery conflict with contact form 7 ?
Sol: Remove the old flexslider code replace with below code
<script type="text/javascript">
(function($) {
$(window).load(function(){
$('.flexslider').flexslider({
animation: "slide",
start: function(slider){
$('body').removeClass('loading');
}
});
});
})(jQuery);
</script>
After really simple captcha, if entered captcha correctly when click on submit button it’s take very long time to submit your details, because some of permission reason it is not creat captcha image in temp folder . Add below change in really simple captcha file.
Open really simple captcha folder from plugin folder -wp-content/plugin/really-simple-captcha/really-simple-captcha.php
really-simple-captcha.php:
old:
/* Image type. 'png', 'gif' or 'jpeg' */ $this->img_type = 'png'; /* Mode of temporary image files */ $this->file_mode = 0444; /* Mode of temporary answer text files */ $this->answer_file_mode = 0440;
Change to:
/* Image type. 'png', 'gif' or 'jpeg' */ $this->img_type = 'png'; /* Mode of temporary image files */ $this->file_mode = 0777; /* Mode of temporary answer text files */ $this->answer_file_mode = 0770;
If ajax validation not woking in your theme, add below code into header.php above close head [</head>]
<script type='text/javascript' src='/wp-content/plugins/contact-form-7/includes/js/jquery.form.min.js?ver=3.40.0-2013.08.13'></script> <script type='text/javascript'> /* <![CDATA[ */ var _wpcf7 = {"loaderUrl":"\/wp-content\/plugins\/contact-form-7\/images\/ajax-loader.gif","sending":"Sending ..."}; /* ]]> */ </script> <script type='text/javascript' src='/wp-content/plugins/contact-form-7/includes/js/scripts.js?ver=3.5.2'></script>
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
function set_html_content_type() {
return 'text/html';
}
Simply paste above code in to your function.php file
Simply paste the following snippet into your functions.php file
Don’t forget to put the desired FROM NAME on return
add_filter( 'wp_mail_from_name', 'my_mail_from_name' ); function my_mail_from_name( $name ) { return 'VENU'; }
WordPress is a very flexible blogging platform, but by default, you can’t modify the FROM email adress. If you want to be able to easily change it,
Simply paste the following snippet code into your functions.php file
add_filter( 'wp_mail_from', 'my_mail_from' ); function my_mail_from( $email ) { return 'examplemail@mail.com'; }
Default the login logo url points to WordPress.org. If you have a custom WordPress login logo, or a completely custom WordPress login page design, then you should probably change the login logo url to your main site or anything that you think is more relevant.
All you have to do is simply paste the codes below in your theme’s functions.php file:
<?php add_filter( 'login_headerurl', 'custom_logo_url' ); function custom_logo_url($url) { return 'http://example.com'; } ?>
<?php if ( is_object_in_taxonomy( get_post_type(), 'category' ) ) : // Hide category text when not supported ?> <?php /* translators: used between list items, there is a space after the comma */ $categories_list = get_the_category_list( __( ', ', 'theme' ) ); if ( $categories_list ): ?> <h4> <?php printf( __( '%2$s', 'theme' ), 'entry-utility-prep entry-utility-prep-cat-links', $categories_list); ?> </h4> <?php endif; // End if categories ?> <?php endif; // End if is_object_in_taxonomy( get_post_type(), 'category' ) ?>
Using the below code get the category name
<?php echo get_cat_name(category ID here) ?>
Example:
<?php query_posts("cat=3");?>
<?php echo get_cat_name(3);?>
<?php while(have_posts()): the_post();?>
<?php the_content();?>
<?php endwhile;?>
Problem : Page navigation problem with custom query ?
Solution : Find below
wp_Pagenavi in query posts:
<?php query_posts('showposts=6'.'&paged='.get_query_var('paged') ;?> <?php while ( have_posts() ) : the_post(); ?> <?php the_content();?> <?php endwhile; // end of the loop. ?> <?php wp_pagenavi() //call pagenavi?>
How To Limit Words and Characters in content WordPress
1. Words Length:
Remove the <?php the_content();?> insert the below code
2. Character Length :
Remove the <?php the_content();?> insert the below code
<?php echo substr(strip_tags($post->post_content), 0, 46);?> //(Change the 46 to your desire string length)
<?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'Your-Custom-Field', true); wp_reset_query(); ?>
Example:
<?php
global $wp_query;
$postid = $wp_query->post->ID;
$img = get_post_meta($postid, 'sidebar_image', true);
if($img)
{
echo "<img src ='$img'>";
}
else{
?>
<img src="<?php bloginfo("template_url")?>/images/care.jpg" />
<?php
}
wp_reset_query();
?>
Get the current page Id
<?php $pid = $post->ID;?> <?php echo $pid ?>
How to Get the Dyanmic Categories:
Here small snippet code is avialble for get categories related posts
1. You have to give the page name and category name should be same
2. Add below code where you want..and than refresh page . you will get the post related categories.
<?php query_posts('category_name='.get_permalink().'&post_status=publish,future');?>
The content_url template tag retrieves the url to the content area for the current site with the appropriate protocol, ‘https’ if is_ssl() and ‘http’ otherwise.
WordPress Directories: | ||
home_url() | Home URL | http://www.example.com |
site_url() | Site directory URL | http://www.example.com or http://www.example.com/wordpress |
admin_url() | Admin directory URL | http://www.example.com/wp-admin |
includes_url() | Includes directory URL | http://www.example.com/wp-includes |
content_url() | Content directory URL | http://www.example.com/wp-content |
plugins_url() | Plugins directory URL | http://www.example.com/wp-content/plugins |
theme_url() | Themes directory URL |
http://www.example.com/wp-content/themes |
wp_upload_dir() | Upload directory URL |
http://www.example.com/wp-content/uploads |
query_posts() is the easiest, but not preferred or most efficient, way to alter the default query that WordPress uses to display posts. Use query_posts() to display different posts than those that would normally show up at a specific URL. (The preferred way is hooking into ‘pre get posts’ and altering the main query that way using is main query)
For example, on the homepage, you would normally see the latest 10 posts. If you want to show only 5 posts (and don’t care about pagination), you can use query_posts() like so: query_posts( 'posts_per_page=5' );
Examples:
query_posts( 'cat=1&tag=apples' );
Placing this code in index.php file will cause the home page to display posts from all categories except category ID 3.
<?php if ( is_home() ) { query_posts( 'cat=-3' ); } ?>
You can also add some more categories to the exclude-list (tested with WP 3.3.1):
<?php if ( is_home() ) { query_posts( 'cat=-1,-2,-3' ); } ?>
To retrieve a particular post, you could use the following:
query_posts( 'p=5' );
Note: If the particular post is an attachment, you have to use attachment_id instead of p:
query_posts( 'attachment_id=5' );
If you want to use the Read More functionality with this query, you will need to set the global $more variable to 0.
<?php // retrieve one post with an ID of 5 query_posts( 'p=5' ); // set $more to 0 in order to only get the first part of the post global $more; $more = 0; // the Loop while (have_posts()) : the_post(); the_content( 'Read the full post »' ); endwhile; ?>
Display content based on post and page parameters.
Show Post/Page by ID
Display post by ID:
$query = new WP_Query( 'p=7' );
Display page by ID:
$query = new WP_Query( 'page_id=7' );
Show Post/Page by Slug
Display post by slug:
$query = new WP_Query( 'name=about-my-life' );
Display page by slug:
$query = new WP_Query( 'pagename=contact' );
Show Child Posts/Pages
Display child page using the slug of the parent and the child page, separated by a slash (e.g. ‘parent_slug/child_slug’):
$query = new WP_Query( 'pagename=contact_us/canada' );
Display child pages using parent page ID:
$query = new WP_Query( 'post_parent=93' );
Display only top-level pages, exclude all child pages:
$query = new WP_Query( 'post_parent=0' );
Multiple Posts/Pages Handling
Display only the specific posts:
$query = new WP_Query( array( 'post_type' => 'page', 'post__in' => array( 2, 5, 12, 14, 20 ) ) );
Display all posts but NOT the specified ones:
$query = new WP_Query( array( 'post_type' => 'post', 'post__not_in' => array( 2, 5, 12, 14, 20 ) ) );
Note: you cannot combine ‘post__in’ and ‘post__not_in’ in the same query.
Show Posts for One Category:
Display posts that have this category (and any children of that category), using category id:
$query = new WP_Query( 'cat=4' );
Display posts that have this category (and any children of that category), using category slug:
$query = new WP_Query( 'category_name=staff' );
Display posts that have this category (not children of that category), using category id:
$query = new WP_Query( 'category__in=4' );
Show Posts From Several Categories
Display posts that have these categories, using category id:
$query = new WP_Query( 'cat=2,6,17,38' );
Display posts that have these categories, using category slug:
$query = new WP_Query( 'category_name=staff,news' );
Exclude Posts Belonging to Category
Display all posts except those from a category by prefixing its id with a ‘-‘ (minus) sign.
$query = new WP_Query( 'cat=-12,-34,-56' );
Multiple Category Handling
Display posts that are in multiple categories. This shows posts that are in both categories 2 and 6:
$query = new WP_Query( array( 'category__and' => array( 2, 6 ) ) );
To display posts from either category 2 OR 6, you could use cat as mentioned above, or by using category__in (note this does not show posts from any children of these categories):
$query = new WP_Query( array( 'category__in' => array( 2, 6 ) ) );
You can also exclude multiple categories this way:
$query = new WP_Query( array( 'category__not_in' => array( 2, 6 ) ) );
Show Posts for one Author
Display posts by author, using author id:
$query = new WP_Query( 'author=123' );
Display posts by author, using author ‘user_nicename’:
$query = new WP_Query( 'author_name=rami' );
Show Posts From Several Authors
Display posts from several specific authors:
$query = new WP_Query( 'author=2,6,17,38' );
Exclude Posts Belonging to an Author
Display all posts except those from an author(singular) by prefixing its id with a ‘-‘ (minus) sign:
$query = new WP_Query( 'author=-12' );
Making WordPress Speak Your Language
Everything Around WordPress Themes
PHP - Wordpress - Joomla - Developer
Create cool applications that integrate with WordPress.com
The latest news on WordPress.com and the WordPress community.