Wordpress

<link href="<?php bloginfo('template_directory'); ?>/css/bootstrap.css" rel="stylesheet">
<link href="<?php bloginfo('template_directory'); ?>/css/bootstrap-responsive.css" rel="stylesheet">

===============================================
PAGE PATH
<?php echo get_permalink( 2 ); ?>
================================================

Wordpress Sitepath:

<?php echo get_template_directory_uri(); ?>/
==================================================
Wordpress  Top Menu Code

<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
=====================================================
Search Form:

get_search_form();
========================================================
Index.php(Home Path)

<?php echo esc_url( home_url( '/' ) ); ?>
==========================================================
The The Slider Code

<?php if (function_exists('get_thethe_image_slider')) { print get_thethe_image_slider('slider1'); } ?>


Create New Function
======================================================
wpcontent->theme->open function.php

register_sidebar( array(
'name' => __( 'Footer Menu', 'twentyeleven' ),
'id' => 'footermenu',
'description' => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );

Copy and Past then change it name and id

==========================================================
Remove toolbar on top

wp-admin->users->allusers->admin and then remove click toolbar checkbox
=======================================================

Page is Home Or Not(Check Condition)?

<?php
if ( is_home() || is_front_page() ) { ?>
//content
<?php } else { ?>
// else content
<?php } ?>
=================================================

Remove comment From page

wp-admin->pages->click quick edit link->then uncheck on "Allow comment" button
=======================================================
get Side bar

<?php get_sidebar(); ?>
=====================================================
Show the post by category

<?php
$homecontent = get_posts('numberposts=3&category=1&order=ASC');
foreach( $homecontent as $home) {
?>
<li><a href="<?php echo $home->guid; ?>"><?php echo $home->post_title; ?></a></li>
<?php } ?>

==========================================================

Fetch Particular Page Content
<?php
$welcome_id='page_id';
$welcome_post=get_post($welcome_id);
$content=$welcome_post->post_content;
$title=$welcome_post->post_title;?>
==================================================================
Read More Code
<?php
add above code with this

 $limit=300;
 if (strlen($content) > $limit)
 $content = substr($content, 0, strrpos(substr($content, 0, $limit), ' ')) . '...';
 ?>
<div class="readmore"><a href="<?php echo esc_url( home_url( '/' ) ); ?>?page_id=67">Read More...</a></div>

Display Post by url(url?postid=1)

==============================================================
<?php if( have_posts() ):?>
<?php $request_id=$_REQUEST['postid'];;

$object=get_post($request_id);

echo '<div class="post_title">'.$post_title=$object->post_title.'</div>';
echo '<div class="post_content">'.$post_content=$object->post_content.'</div>';
?>
<?php endif; ?>

===========================================================
Get the Featured image
<? get_post_thumbnail_id($post->ID)) ?>
=============================================================

GET THE PAGE FETURED IMAGE
if (has_post_thumbnail( $post->ID ))
{
the_post_thumbnail( 'single-post-thumbnail', array('class' => 'bann_img') );
}

==========================================================

 Plug in  >>Page Excerpt                                    
 FRONT CODE
 $imd = '24';
 $mark = get_post($imd);                              
 echo $content = $mark->post_excerpt;



========================================================

PAGE CONTENT specific

<?php if ( is_home() || is_front_page() ) {
                $welcome_id='5';
                $welcome_post=get_post($welcome_id);
                echo $content=$welcome_post->post_content;
                $title=$welcome_post->post_title;
                 } ?>  
============================================================
PAGE CONTENT

<h1><?php the_title(); ?></h1>
<?php
  if (have_posts()): while (have_posts()): the_post();
  the_content();
  endwhile; endif;
?>
============================================================
<?php echo get_permalink( 2 ); ?>
==============================================================
MENU WITH CSS CLASS

<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav' ) ); ?>

===========================================
page featured image
 echo get_the_post_thumbnail( 4, 'full' );
====================================
LOGO AND HOME PAGE
<?php echo site_url(); ?>
=================================================
REMOVE IMG FROM CONTENT
add_filter('the_content', 'strip_images',2);
function strip_images($content){
   return preg_replace('/<img[^>]+./','',$content);
}
==================================
preg_replace('/<img[^>]+./','',$content);
===================================

<?php get_site_url(); ?>

===================================================
Featured image path
==================================================
$image1=kd_mfi_get_featured_image_url( 'featured-image-1', 'post', 'full' );
===================================================
ADD LIMI TO EXCERT FILE
ADD IN FUNCTION.PHP
function string_limit_words($string, $word_limit) {
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(' ', $words);
}

add code in page or sinlg .php

<?php echo string_limit_words(get_the_excerpt(), 20); ?>
======================================================
CUSTOM FIELD VALUE
$color=get_post_meta($ID, 'color', true);
======================================================

activation link
.menu4 ul li:hover a,
.menu4 ul li a:hover,
.current-menu-item a{
color: #fff; /*background-color:#742129;*/ background:url(../images/hover_bg.jpg) repeat-x;
text-decoration:none;

}
======================================================
FETCH POST FROM CATEGORY

<?php
query_posts( 'cat=6' );  
while (have_posts()) : the_post();
$content_post = get_post($post->ID);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
//echo var_dump($content);  
$str = substr($content, 0, 50);
echo "<div class='abt'>".$str."...</div>";  
endwhile;
?>
=============================================================
ADD SPLASH CODE IN INDEX PAGE
<?php

if( (strpos($_SERVER['HTTP_REFERER'], get_bloginfo('home')) === false) && !$_SERVER['QUERY_STRING']) :
{
   plase code
}
else
{
index code
}
?>

=========================================================================================================
DYNAMIC MEGA MENU WITH CATEGORY

<?php wp_nav_menu( array( 'container_class' => 'menu4', 'theme_location' => 'primary','menu' => 'Header Menu'  ) ); ?>
    </div>
        <?php
           $items = wp_get_nav_menu_items( 6, $args );        
          foreach ( $items as $key => $menu_item ) {
          //print_r($menu_item);
          ?>
          <div id="div_<?php echo $menu_item->ID ?>" class="dropdown_4columns" style="display:none;" >
           
               <div class="col_1">
              <ul>
                  <?php
                $deptID = $menu_item->object_id;
                $childCatID = $wpdb->get_col("SELECT term_id FROM $wpdb->term_taxonomy WHERE parent=$deptID");
                if ($childCatID){
                $i = 0;
                foreach ($childCatID as $kid)
                {
                //print_r($kid);
                $childCatName = $wpdb->get_row("SELECT name, term_id, slug FROM $wpdb->terms WHERE term_id=$kid");
                echo '<li><a href="'.get_category_link( $childCatName->term_id ).'">'.$childCatName->name.'</a></li>';
                //echo '<li><a href="/'.$childCatName->slug.'">'.$childCatName->name.'</a></li>';             
                        if($i == 7)
                        {
                            echo '</ul></div><div class="col_2"><ul>';
                        }
                        if($i == 15)
                        {
                            echo '</ul></div><div class="col_3"><ul>';
                        }
                        if($i == 23)
                        {
                            echo '</ul></div><div class="col_4"><ul>';
                        }
                $i++;
                }
                }
                  //$give = get_categories( array( 'child_of' => $menu_item->object_id, 'sort_column' => 'post_date', 'sort_order' => 'asc' ,'parent'=>$menu_item->object_id ) );
                  //print_r($give);
                ?>
==============================
ADD PHP CODE IN WIDGET
ADD THIS IN TO FUNCTION

add_filter('widget_text','execute_php',100);
function execute_php($html){
     if(strpos($html,"<"."?php")!==false){
          ob_start();
          eval("?".">".$html);
          $html=ob_get_contents();
          ob_end_clean();
     }
     return $html;
}
=============================================

CREATE CUSTOM POST TYPE
http://themergency.com/generators/cpt-code-output/?id=76954
============================================


global $wpdb;
  $wpdb->query(
  "
  UPDATE $wpdb->wp_frm_items
  SET alerts = 1
  WHERE id = $entry_id   
  "
  );

$myrows = $wpdb->get_results( "SELECT id, name FROM mytable" );
$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10");
<?php
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
echo "<p>User count is {$user_count}</p>";
?>


http://wp.smashingmagazine.com/2012/06/05/front-end-author-listing-user-search-wordpress/
===============================================

Custom Post Type UI

Admin UI for creating custom post types and custom taxonomies in WordPress 
 code
    <?php $loop = new WP_Query( array( 'post_type' => 'testimonials', 'posts_per_page' => 4 ) );

 

Admin UI for creating custom post types and custom taxonomies in WordPress

 

1 comment: