Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - abhimanyu

Pages: [1]
1
C# / How to find font is available in computer using c# application
« on: October 22, 2013, 04:38:54 PM »
Code: [Select]
var fontsCollection = new InstalledFontCollection();
            foreach (var fontFamiliy in fontsCollection.Families)
            {
                if (fontFamiliy.Name == "Font Name")
                {
                      messagebox.show("Available");
                }
                else
                {
                      messagebox.show("Not Available");
                }
             }

2
PHP / 10 Useful Hacks & Tips to take your WordPress blog to next level
« on: August 08, 2013, 04:15:54 PM »
1. Automatically Set the Featured Image in WordPress

This code will automatically set the first image as Featured Image in WordPress. Add the following code in functions.php file.

function autoset_featured() {
          global $post;
          $already_has_thumb = has_post_thumbnail($post->ID);
              if (!$already_has_thumb)  {
              $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
                          if ($attached_image) {
                                foreach ($attached_image as $attachment_id => $attachment) {
                                set_post_thumbnail($post->ID, $attachment_id);
                                }
                           }
                        }
      }  //end function
add_action('the_post', 'autoset_featured');
add_action('save_post', 'autoset_featured');
add_action('draft_to_publish', 'autoset_featured');
add_action('new_to_publish', 'autoset_featured');
add_action('pending_to_publish', 'autoset_featured');
add_action('future_to_publish', 'autoset_featured');


2. How to load jQuery in Footer
Add jquery or any other script to footer. Add this in function.php file:

<?php
/**
 * Prints jQuery in footer on front-end.
 */
function ds_print_jquery_in_footer( &$scripts) {
    if ( ! is_admin() )
        $scripts->add_data( 'jquery', 'group', 1 );
}
add_action( 'wp_default_scripts', 'ds_print_jquery_in_footer' );
 
?>

3. Get the first link from the blog posts
Sometimes you may need the link to display in roundup or sidebar. This simple code lets you copy the first link from the blog posts.
Add this code in functions.php file

function get_content_link( $content = false, $echo = false )
{
    if ( $content === false )
        $content = get_the_content();
 
    $content = preg_match_all( '/hrefs*=s*["']([^"']+)/', $content, $links );
    $content = $links[1][0];
 
    if ( empty($content) ) {
        $content = false;
    }
 
    return $content;
}


Usage:

<h2><a href="<?php echo get_content_link( get_the_content() ); ?>"><?php the_title(); ?></a></h2>
<p><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>">Comment »</a>

4. Add Author Box
Author box plays a big role in building engagement and generating leads. These days, every WordPress theme comes with an author box but there are still a few themes that doesn’t come with an author box.
Add this code in the single.php file, after the content() tag.

<div id="author-info">
                    <div id="author-avatar">
            <?php echo get_avatar( get_the_author_meta('user_email'), '80', '' ); ?>
            </div>
            <div id="author-description"><h3><?php the_author_link(); ?></h3>
            <?php the_author_meta('description'); ?>
                        </div>
</div>

Add the css in style.css of your theme

#author-info { float: left; padding: 20px;background-color: #f0f0f0; margin-bottom:10px; -moz-border-radius: 5px;border-radius: 5px;}
#author-info .avatar { position: relative; top: 0; left: 0; float: left; }
#author-description { margin-left: 100px; }
#author-description h3 { margin-top:0px;margin-bottom:10px;}

5. Activate Link Manager in WordPress 3.5
In the latest version (WordPress 3.5), they have disabled the link manager in the admin area. The link manager can be easily added back by adding this code snippet in your theme functions file.

<?php
 
    //Activate the Link Manager built in to the WordPress admin
    add_filter( 'pre_option_link_manager_enabled', '__return_true' );
 
?>


6. Add Custom Post Type & Taxonomies

Not everyone is good at building websites or adding a new functionality. That being said, WordPress is used to build different type of sites and one of the requirement is using custom post type & taxonomies feature.

7. Display Related Posts with Thumbnails in WordPress

Show Related posts with thumbnails with the nRelate plugin.
Installing this plugin is as simple as activating it, and you can leave the rest to nrelate. Once activated, the nrelate servers will immediately begin analyzing your website content and associating similar articles.
Download the plugin


8. Get the first image from the post automatically and display it


Fetch the first image from the blog posts and display it in the loop. You can use it, for displaying thumbnails in sidebar, footer, related posts, etc.


Paste this code in your functions.php file.

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]
  • ;

  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}


Next, paste this code in the loop to fetch the first image from the blog posts

<?php echo catch_that_image() ?>

9. Delete Post Revisions to Improve your blog speed


WordPress by default creates revisions of your posts automatically. Whenever you save a page or post, the older version is retained so that you can revert it back at any time.

To delete all previous revisions, you will need to visit PHPMyAdmin and run the following SQL query.

DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
WHERE a.post_type = 'revision';

10. Remove All HTML tags in comments


To disable the HTML tags in comments, paste the following code in functions.php file.

add_filter('comment_text', 'wp_filter_nohtml_kses');
add_filter('comment_text_rss', 'wp_filter_nohtml_kses');
add_filter('comment_excerpt', 'wp_filter_nohtml_kses');

3
SQL Server / Top 10 performance tuning tips for relational databases
« on: August 07, 2013, 04:53:49 PM »


Top 10 performance tuning tips for relational databases

http://web.synametrics.com/top10performancetips.htm

5
SQL Server / PowerPivot with Excel 2013
« on: February 04, 2013, 01:04:12 PM »

6
ASP.NET / Re: For Vs Foreach
« on: February 01, 2013, 11:35:24 AM »
Hi bhushan,
            This is nice link. This is help me lot.
Thank You.
 :D

7
ASP.NET / Updating URL of ASP.NET hyperlink at runtime using jquery
« on: October 19, 2012, 07:44:04 PM »
Just Add one .js File in header Tag in .aspx page(jquery-1.4.1.min.js)
Code: [Select]
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
Than Write one script
Code: [Select]
<script type="text/javascript">
        $(document).ready(function () {
            $("input[type=radio]").bind("change", function () {
                $("a").attr("href", $(this).val());
            });
        });
    </script>

Add an ASP.NET hyperlink control on the page. Also add a RadioButtonList to the form as follows:

Code: [Select]
<form id="form1" runat="server">
    <div align="left">
        <fieldset style="width: 300px; height: 200px;">
            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td width="10px">
                    </td>
                    <td>
                        <p>
                            Get your news updates here:</p>
                        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                            <asp:ListItem Text="Learn Extreme-Advice" Value="http://learn.extreme-advice.com"></asp:ListItem>
                            <asp:ListItem Text="Ritesh Blog" Value="http://blog.extreme-advice.com/"></asp:ListItem>
                        </asp:RadioButtonList>
                        <br />
                        <asp:HyperLink ID="HyperLink1" runat="server">Click here!</asp:HyperLink>
                    </td>
                </tr>
            </table>
        </fieldset>
    </div>
    </form>

 :) Happy Coding

Thanks
Abhimanyu Rawat

8
ASP.NET / Disallowing cut copy paste using jquery in asp.net
« on: October 19, 2012, 07:17:19 PM »
First Add .js file
If .js file is not available than download from internet

Code: [Select]
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>than add one java script block
Code: [Select]
<script type="text/javascript">
        $(document).ready(function () {
            $('#<%=txtNewPwd.ClientID%>').bind('cut copy paste', function (e) {
                e.preventDefault();
                alert("Cut / Copy / Paste disabled in this textbox");
            });
            $('#<%=txtConfirmNewPwd.ClientID%>').bind('cut copy paste', function (e) {
                e.preventDefault();
                alert("Cut / Copy / Paste disabled in this textbox too!");
            });
        });
    </script>
Design in aspx page
Code: [Select]
    <form id="form1" runat="server">
    <div align="center">
        <fieldset style="width: 400px; height: 180px;">
            <table cellpadding="3" cellspacing="3" border="0">
                <tr>
                    <td colspan="2" class="header">
                        CHANGE PASSWORD
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblCurrentPwd" Text="Current Password: " runat="server" />
                    </td>
                    <td>
                        <asp:TextBox ID="txtCurrentPwd" Width="200px" runat="server" TextMode="Password"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblNewPwd" Text="New Password:" runat="server" />
                    </td>
                    <td>
                        <asp:TextBox ID="txtNewPwd" Width="200px" runat="server" TextMode="Password"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label id="lblConfirmNewPwd" runat="server">
                            Confirm New Password:</label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtConfirmNewPwd" Width="200px" runat="server" TextMode="Password"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <asp:Button ID="btnSubmit" runat="server" Text="SUBMIT" />
                        <asp:Button ID="btnReset" runat="server" Text="RESET" />
                    </td>
                </tr>
            </table>
        </fieldset>
    </div>
    </form>

9
ASP.NET / what is the diff between persistent vs non persistent cookies
« on: September 21, 2012, 09:50:11 AM »
Code: [Select]
Persistent cookies are stored in a text file on the clients computer.

  Non-Persistent cookies are stored in RAM on the client and are destroyed when the browser is closed.

10
ASP.NET / Multiple file upload user control in C#.net
« on: September 17, 2012, 07:17:50 PM »
find attachment for muliple file upload user control code in C#.net

Pages: [1]