.

.

HOW TO ADD OR GET MEDIA IMAGES IN WP.




u add media and featured image in post and u can get media image if media image add.
.firstly add this function in functions.php

function catch_that_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches[1][0];

  if(empty($first_img)) {
    $first_img = bloginfo(template_directory)."/images/download.jpg";  // this image used when                        //no image found
  }
  return $first_img;
}

Now this used where u want to add image .
if ( get_the_post_thumbnail($post_id) != '' ) {

 $large_image_url=wp_get_attachment_image_src(get_post_thumbnail_id(),'large');
  echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
  echo '<img src="';
 echo $large_image_url[0];
 echo '" alt=""  style="width:281px;height:154px;"/>';
 echo '</a>';

} else {

 echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';


 echo '<img src="';
 echo catch_that_image();
 echo '" alt=""  style="width:281px;height:154px;"/>';
 echo '</a>';

}
OR

if ( get_the_post_thumbnail($post_id) != '' ) {

  echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
   the_post_thumbnail();
  echo '</a>';

} else {

 echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
 echo '<img src="';
 echo catch_that_image();
 echo '" alt="" />';
 echo '</a>';


}

HOW TO FIND LATEST POST IN WP.


<?php $args = array(
    'numberposts' => 10,
    'offset' => 0,
    'category' => 0,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'include' => ,
    'exclude' => ,
    'meta_key' => ,
    'meta_value' =>,
    'post_type' => 'post',
    'post_status' => 'draft, publish, future, pending, private',
    'suppress_filters' => true );

    $recent_posts = wp_get_recent_posts( $args, ARRAY_A );
?>
Example of recent post:

<h2>Recent Posts</h2>
<ul>
<?php
 $args = array( 'numberposts' => '5' );
 $recent_posts = wp_get_recent_posts( $args );
 foreach( $recent_posts as $recent ){
  echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a> </li> ';
 }
?>

</ul>

HOW TO GET POPULAR POST IN WP.






//popular post is the post who have been opened maximum number of times..

<?php
 query_posts('meta_key=post_views_count&orderby=meta_value_num&order=DESC');
 if (have_posts()) : while (have_posts()) : the_post(); ?>
 <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
 <?php
 endwhile; endif;
 wp_reset_query();

?>

HOW To ADD WORDPRESS PAGINATION IN ANY POSTS OR CATEGORY OR ANYWHERE IN WP.




UThe default WordPress pagination only comes with the “Older posts” and “Newer posts” links at the bottom of the page when you want to navigate to the older entries.Thankfully, there are many available WordPress pagination plugins that do just that. Among these, Lester Chan’s WP-PageNavi is possibly the most popular one.
But if you prefer to keep plugin overhead to a minimum, here’s a function you can use to add WordPress pagination without a plugin.
The code is provided by Kriesi and you can get his code and instructions. The pagination looks like this:



We would like to provide an enhanced version of the pagination by introducing more useful information such asPage X of Y and make the arrows more intuitive, like this:
Page 1 of 2012345Next ›Last »



You can see a working example over at Sparklette.

Here’s our sauce for the enhanced pagination, modified from Kriesi’s code.
1.                  Add the following function to your functions.php file:
2.                     function pagination($pages = '', $range = 4)
3.                     
4.                          $showitems = ($range * 2)+1;  
5.                      
6.                          global $paged;
7.                          if(empty($paged)) $paged = 1;
8.                      
9.                          if($pages == '')
10.                      {
11.                          global $wp_query;
12.                          $pages = $wp_query->max_num_pages;
13.                          if(!$pages)
14.                          {
15.                              $pages = 1;
16.                          }
17.                      }   
18.                  
19.                      if(1 != $pages)
20.                      {
21.                          echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
22.                          if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
23.                          if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";
24.                  
25.                          for ($i=1; $i <= $pages; $i++)
26.                          {
27.                              if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
28.                              {
29.                                  echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
30.                              }
31.                          }
32.                  
33.                          if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";  
34.                          if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
35.                          echo "</div>\n";
36.                      }
}
37.               To style it, add the following to your stylesheet (typically style.css).
38.                 .pagination {
39.                 clear:both;
40.                 padding:20px 0;
41.                 position:relative;
42.                 font-size:11px;
43.                 line-height:13px;
44.                 }
45.                  
46.                 .pagination span, .pagination a {
47.                 display:block;
48.                 float:left;
49.                 margin: 2px 2px 2px 0;
50.                 padding:6px 9px 5px 9px;
51.                 text-decoration:none;
52.                 width:auto;
53.                 color:#fff;
54.                 background: #555;
55.                 }
56.                  
57.                 .pagination a:hover{
58.                 color:#fff;
59.                 background: #3279BB;
60.                 }
61.                  
62.                 .pagination .current{
63.                 padding:6px 9px 5px 9px;
64.                 background: #3279BB;
65.                 color:#fff;
}
66.               Finally, call the function in your theme (typically near the bottom of index.php or loop.php where it says "Older posts" or "Older entries"):
67.                 <?php if (function_exists("pagination")) {
68.                     pagination($additional_loop->max_num_pages);

} ?>

HOW TO MAKE MENU IN WORDPRESS









<?php wp_nav_menu( array( 'menu' => 'home', 'container_class' => 'my_extra_menu_class' ,'link_before' => '<span>', 'link_after' => '</span>','sub_menu' => true ) ); ?>

OR

<?php //wp_nav_menu( array( 'menu' => 'home','sub_menu' => true) );
$str = strtolower(get_the_title());
 ?>
<ul>
        <li><a href="<?php echo home_url();?>">
        <?php
   if($str == 'hello world!')
   {
    ?>
                 <img src="<?php bloginfo(template_directory);?>/image/webheader_r3_c2.gif" height="47">
                <?php
   }
   else
   {
    echo 'ABOUT';
   }
  ?>
      
        </a></li>
        <li><a href="<?php echo home_url('portfolio');?>">
        <?php
   if($str == 'portfolio')
   {
    ?>
                 <img src="<?php bloginfo(template_directory);?>/image/portbutt.gif" height="47">
                <?php
   }
   else
   {
    echo 'PORTFOLIO';
   }
  ?>
      
        </a></li>
      
       <span style="float:left; padding:0 20px;"><a href="<?php echo home_url();?>"><img src="<?php bloginfo(template_directory);?>/image/logo.gif"></a></span>
        <li><a href="<?php echo home_url('blog');?>">BLOG</a></li>
        <li><a href="<?php echo home_url('contactus');?>">CONTACT</a></li>

      </ul>

JOIN QUERY IN WORDPRESS







<?php
global $wpdb;
$table_name1 = $wpdb->prefix . 's2p_member_questions';
$table_name = $wpdb->prefix . 's2p_member_uploads';
$table_name12 = $wpdb->prefix . 's2p_scheduling';

$rows2 = $wpdb->get_results( $wpdb->prepare( "SELECT  * from $table_name1
inner join $table_name12 on $table_name12.schid =  $table_name1.m_id
inner join $table_name on $table_name.mid =  $table_name1.m_id
where  mediatype = %s order by mop_rating desc limit $lim
","video"), ARRAY_A );
//check print_r($rows2)
Foreach($rows2 as $value)
{echo $value[‘’];
}?> 

CREATE ADMIN PAGE OR MENU IN DASHBOARD IN WORDPRESS




<?php

add_action('admin_menu', 's2p_plugin_settings');
function s2p_plugin_settings() {
            add_menu_page('S2P Register Settings', 'S2P Register Settings', 'administrator', 's2p_settings', 's2p_display_settings');

}
function s2p_display_settings() {
           
}

?>

ADDING CSS AND JS STYLES IN PLUGIN







<?php
add_action('wp_enqueue_scripts', 's2p_range_slider_styles');
function s2p_range_slider_styles() {
            wp_register_style('s2prangecss', plugins_url('css/simple-slider.css', __FILE__));
            wp_enqueue_style('s2prangecss');

}

?>

<?php
add_action('wp_enqueue_scripts', 's2p_range_slider_js');

function s2p_range_slider_js()
{
            wp_enqueue_script('jquery');
            wp_register_script('s2p_range_slider_core', plugins_url('js/simple-slider.js', __FILE__),array("jquery"));
  wp_enqueue_script('s2p_range_slider_core');
}
  ?>

CREATE PLUGIN USING SHORTCODE




function s2p_map_activation() {
}
register_activation_hook(__FILE__, 's2p_map_activation');

function s2p_map_deactivation() {
}
register_deactivation_hook(__FILE__, 's2p_map_deactivation');

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

add_shortcode("S2P_Gmap", "s2p_display_map");

function s2p_display_map($content) {

}

ADVANCE SEARCH IN JOOMLA


public function getFindLoved($data)
{
$str = array();

if($data['fname'])

{

$str[] = 'f_name = "'. $data['fname'].'"';

}

if($data['lname'])

{

$str[] = 'l_name = "'. $data['lname'].'"';

}

if($data['city'])

{

$str[] = 'city = "'. $data['city'].'"';

}

if($data['state'])

{

$str[] = 'state = "'. $data['state'].'"';

}

if($data['dob'])

{

$str[] = 'dob = "'. $data['dob'].'"';

}

if($data['dod'])

{

$str[] = 'dod = "'. $data['dod'].'"';

}

if($data['cemetry'])

{

$str[] = 'cemetryid = "'. $data['cemetry'].'"';

}



$wherestr = implode(" AND ",$str);



$db = JFactory::getDBO();

$query = $db->getQuery(true);

$query = 'SELECT * FROM #__listloved WHERE '.$wherestr ;

$db->setQuery($query);

$db->query();

$num_rows = $db->getNumRows();

return $rows = $db->loadObjectList();

}










Selecting Records from Multiple Tables





/ Get a db connection.
$db = JFactory::getDbo();
 
// Create a new query object.
$query = $db->getQuery(true);
 
// Select all articles for users who have a username which starts with 'a'.
// Order it by the created date.
// Note by putting 'a' as a second parameter will generate `#__content` AS `a`
$query
    ->select($db->quoteName(array('a.*', 'b.username', 'b.name')))
    ->from($db->quoteName('#__content', 'a'))
    ->join('INNER', $db->quoteName('#__users', 'b') . ' ON (' . $db->quoteName('a.created_by') . ' = ' . $db->quoteName('b.id') . ')')
    ->where($db->quoteName('b.username') . ' LIKE \'a%\'')
    ->order($db->quoteName('a.created') . ' DESC');
 
// Reset the query using our newly populated query object.
$db->setQuery($query);
 
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadObjectList();
 
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for joins:
·           innerJoin()
·           leftJoin()
·           rightJoin()
·           outerJoin()
We can use multiple joins to query across more than two tables:
$query
    ->select($db->quoteName(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*')))
    ->from($db->quoteName('#__content', 'a'))
    ->join('INNER', $db->quoteName('#__users', 'b') . ' ON (' . $db->quoteName('a.created_by') . ' = ' . $db->quoteName('b.id') . ')')
    ->join('LEFT', $db->quoteName('#__user_profiles', 'c') . ' ON (' . $db->quoteName('b.id') . ' = ' . $db->quoteName('c.user_id') . ')')
    ->join('RIGHT', $db->quoteName('#__categories', 'd') . ' ON (' . $db->quoteName('a.catid') . ' = ' . $db->quoteName('d.id') . ')')
    ->where($db->quoteName('b.username') . ' LIKE \'a%\'')
    ->order($db->quoteName('a.created') . ' DESC');
Notice how chaining makes the source code much more readable for these longer queries.
In some cases, you will also need to use the AS clause when selecting items to avoid column name conflicts. In this case, multiple select statements can be chained in conjunction with using the second parameter of $db->quoteName.
$query
    ->select($db->quoteName('a.*'))
    ->select($db->quoteName('b.username', 'username'))
    ->select($db->quoteName('b.name', 'name'))
    ->from($db->quoteName('#__content', 'a'))
    ->join('INNER', $db->quoteName('#__users', 'b') . ' ON (' . $db->quoteName('a.created_by') . ' = ' . $db->quoteName('b.id') . ')')
    ->where($db->quoteName('b.username') . ' LIKE \'a%\'')
    ->order($db->quoteName('a.created') . ' DESC');
A second array can also be used as the second parameter of the select statement to populate the values of the AS clause. Remember to include nulls in the second array to correspond to columns in the first array that you don't want to use the AS clause for:
$query
    ->select($db->quoteName(array('a.*', 'b.username', 'b.name'), array('', 'username', 'name'))
    ->from($db->quoteName('#__content', 'a'))
    ->join('INNER', $db->quoteName('#__users', 'b') . ' ON (' . $db->quoteName('a.created_by') . ' = ' . $db->quoteName('b.id') . ')')
    ->where($db->quoteName('b.username') . ' LIKE \'a%\'')
    ->order($db->quoteName('a.created') . ' DESC');