Copyright © ashik rahman's Blog
Showing posts with label wordpress. Show all posts
Showing posts with label wordpress. Show all posts

Thursday, September 20, 2012

All about Wordpress Post

@ You know the category name want to know the category ID :
<?php
$cat_id=get_cat_ID("style");
echo $cat_id;
?>
@ You know the category name of category ID want to post Name, post ID,  featured image, post content: 
<?php
$posts_array = get_posts( $args );
?>
Here is the definition of the $arg:
<?php
$args = array(
    'numberposts'     => 5,
    'offset'          => 0,
    'category'        => ,
    'orderby'         => 'post_date',
    'order'           => 'DESC',
    'include'         => ,
    'exclude'         => ,
    'meta_key'        => ,
    'meta_value'      => ,
    'post_type'       => 'post',
    'post_mime_type'  => ,
    'post_parent'     => ,
    'post_status'     => 'publish',
    'suppress_filters' => true ); 
?>
I think it will be better to see an Example:
global $post;
    <?php $cat_id=get_cat_ID("style"); // get the category Id echo $cat_id; // print the category Id $args = array( 'numberposts' => 9,'order'=> 'ASC','category' => $cat_id ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); echo $post->ID; // print the Post ID ?>
  • <?php the_title(); ?>
  • <?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );// get the Featured image echo ""; // Print the image endforeach; ?>

EXCLUDING PAGE NAME FROM NAVIGATION BAR IN WORDPRESS


Some-time we have to hide the page name from navigation bar. Let see how can we hide the page name. it's very simple if you get help from a plugin "Exclude Pages".
1. Go to you admin area > Plugins > Add new
  • make a search with this plugins "Exclude Pages"
  • click in install now then okay
  • click on "Activate Plugin"
2. Now Create a new page
  • Pages > Add new
3. in this Page you can find the "Exclude Pages" div with a check box "Include this page in lists of pages"
  • if you unchecked the check Box this Page is not visible in the front-end.


Get Log in Form in wordpress

simply render the log in from in wordpress is so simple:

&lt?php
wp_login_form( $args );
?&gt
Here is $args  definition   :
&lt?php
$args = array(
        'echo' => true,
        'redirect' => site_url( $_SERVER['REQUEST_URI'] ), 
        'form_id' => 'loginform',
        'label_username' => __( 'Username' ),
        'label_password' => __( 'Password' ),
        'label_remember' => __( 'Remember Me' ),
        'label_log_in' => __( 'Log In' ),
        'id_username' => 'user_login',
        'id_password' => 'user_pass',
        'id_remember' => 'rememberme',
        'id_submit' => 'wp-submit',
        'remember' => true,
        'value_username' => NULL,
        'value_remember' => false );
?&gt

Wednesday, September 19, 2012

Showing Current Loged in User information

To determine the current user info:
<?php
$current_user =wp_get_current_user();
echo "Welcome".$current_user->user_login;
echo 'User email: ' . $current_user->user_email;
echo 'User first name: ' . $current_user->user_firstname;
echo 'User last name: ' . $current_user->user_lastname;
echo 'User display name: ' . $current_user->display_name;
echo 'User ID: ' . $current_user->ID ;
?>

Loged in Or Not User check in wp

Display different output depending on whether the user is logged in or not.
<?php
if (is_user_logged_in()){
    echo "Welcome, registered user!";
}
else {
    echo "Welcome, visitor!";
};
?>

Changing the default input type of gravity from

This example changes the default input type to use the button element with an included span, popular for implementing the Sliding Door CSS technique.

This code should be placed in the functions.php file of your active theme.
<?php
// filter the Gravity Forms button type
add_filter("gform_submit_button", "form_submit_button", 10, 2);
function form_submit_button($button, $form){
    return "";
}
?>

Short Code of Gravity From

@ Using Shortcode Builder :
Clicking on the Form icon will activate the insert form modal window (left of the Visual/HTML tabs in the body text editor of Upload/Insert toolbar)


Using the shortcode builder you will first want to select a form from the Select a Formdropdown. then give choose from check Box. And click in the insert Button. Just add the Short code in the Editor


Shortcode Manually :


Just add the Short code in the Editor: [gravityform id=1 title=false description=false]

Function Call For PHP coding:



Wednesday, September 12, 2012

Redirect partent page to the first child page in wordpress.

if you want to redirect a Parent page to his first child page then follow the post.
01. take a php file "redirect.php" in this path folder : "wp-content/themes/[your theme folder].
02. put the code below:
<?php
/* Template Name: Redirect To First Child */
  if (have_posts()) {
    while (have_posts()) {
       the_post();
       $pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
       $firstchild = $pagekids[0];
       wp_redirect(get_permalink($firstchild->ID));
    }
  } 
?>
03. go to you dashboard and Pages >> Add New you can see the option in template of Page Attributes section. Select the template to Redirect the page.

Internal Or External page redirect page in wordpress

if you want to redirect you wp-page to a internal and external url then you should take a PHP file in theme folder.
01. take a php file "redirect.php" in this path folder : "wp-content/themes/[your theme folder].
02. put the code below:
<?php
/*
Template Name: Redirect page.
*/
 wp_redirect('your url'); exit;
?> 
03. if you redirect in internal page then url should be like this: wp_redirect(home_url().'/your page path');
otherwish you can direct put the url in between single citation.

04. go to you dashboard and Pages >> Add New you can see the option in template of Page Attributes section. Select the template to Redirect the page.

Thursday, August 9, 2012

Enable and Disable Comments in Wordpress


  • Go to the Posts -> All Posts screen in your blog dashboard.
  • Select the posts you would like to modify or check the box next to “Title” column at the top to select all posts on that page.
  • Select Edit from the Bulk Actions drop down menu.
  • See in the top of your screen you can find Like this:


    •  Expand the Screen Option and Check the Discussion check box. You can find a option blow the Content writing body.

    •  Uncheck the Both check boxes if you don't want to give option to comment. that's it. than just
    • Click the Update button.
    •  You also can easily remove the comment optio from you page easily By this way.
    For More Detail. Visit this page.