tag:blogger.com,1999:blog-54717769267809894482024-03-05T14:21:25.069+05:30Learn PHP - PHP Tutorials - PHP Interview Questions and Answers - PHP, MySQL Tutorials -WordpressLearn PHP, PHP Tutorial, PHP Code, PHP, MySQL, MySQL Database, SQL, SQL Code, HTML, Javascript, JQuery, Ajax, WordpressAnonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.comBlogger187125tag:blogger.com,1999:blog-5471776926780989448.post-70526101536831236912013-07-31T07:21:00.004+05:302013-07-31T07:22:05.857+05:30WordPress function to check if the current post is a custom post type<div dir="ltr" style="text-align: left;" trbidi="on">
<b>WordPress function to check if the current post is a custom post type</b><br /><br /><br />Just paste this code into your functions.php file:<br /><br /><br />function is_custom_post_type() {<br /> global $wp_query;<br /> <br /> $post_types = get_post_types(array('public' => true,'_builtin' => false),'names','and');<br /> <br /> foreach ($post_types as $post_type ) {<br /> if (get_post_type($post_type->ID) == get_post_type($wp_query->post->ID)) {<br /> return true;<br /> } else {<br /> return false;<br /> }<br /> }<br />}<br /><br />Once complete, we can use the function as display below. <br /><br />P.S. : function can be used outside the loop:<br /><br />if (is_custom_post_type()) {<br /> //Current post is a custom post type<br />}<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-80798240040458218982013-06-01T10:09:00.000+05:302013-06-01T10:09:51.313+05:30How to automatically insert a list of related articles below the post<div dir="ltr" style="text-align: left;" trbidi="on">
In wordpress When a reader finished reading one of your blog posts, you can suggesting him to read other article that he might like as well? Here is a quick solution to automatically display related posts (based on category) below the current post<br />
<br />
First, you have to paste the code below into the functions.php file from your theme.<br />
<br />
<pre>// "More from This Category" list by Barış Ünver @ Wptuts+
function wptuts_more_from_cat( $title = "More From This Category:" ) {
global $post;
// We should get the first category of the post
$categories = get_the_category( $post->ID );
$first_cat = $categories[0]->cat_ID;
// Let's start the $output by displaying the title and opening the <ul>
$output = '<div id="more-from-cat"><h3>' . $title . '</h3>';
// The arguments of the post list!
$args = array(
// It should be in the first category of our post:
'category__in' => array( $first_cat ),
// Our post should NOT be in the list:
'post__not_in' => array( $post->ID ),
// ...And it should fetch 5 posts - you can change this number if you like:
'posts_per_page' => 5
);
// The get_posts() function
$posts = get_posts( $args );
if( $posts ) {
$output .= '<ul>';
// Let's start the loop!
foreach( $posts as $post ) {
setup_postdata( $post );
$post_title = get_the_title();
$permalink = get_permalink();
$output .= '<li><a href="' . $permalink . '" title="' . esc_attr( $post_title ) . '">' . $post_title . '</a></li>';
}
$output .= '</ul>';
} else {
// If there are no posts, we should return something, too!
$output .= '<p>Sorry, this category has just one post and you just read it!</p>';
}
// Let's close the <div> and return the $output:
$output .= '</div>';
return $output;
}</pre>
<pre> </pre>
<pre> </pre>
<pre> </pre>
<pre>Now open your single.php file in theme folder and call the function as describe below, where you'd like to display the related posts:
<?php echo wptuts_more_from_cat( 'More From This Category:' ); ?>
</pre>
</div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-27955444474116471532013-04-26T16:50:00.004+05:302013-04-26T16:51:16.826+05:30Exclude certain categories from being displayed in Wordpress<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Exclude certain categories from being displayed in Wordpress</b><br />
<br />
Thre are two ways to hide posts from certain categories to be displayed on the wordpress blog. You can either put this code inside the loop <br /><br /> <?php <br /> if ( have_posts() ) : query_posts($query_string .'&cat=-1,-2'); while ( have_posts() ) : the_post(); <br /> ?> <br /> <br /><br />or you van use the plugin "Advanced Category Excluder" from wordpress plugin directory.<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-27948029521670982152013-04-26T16:38:00.000+05:302013-04-26T16:38:46.115+05:30Add SVG upload support to WordPress blog<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to add SVG upload support to your WordPress blog</b> <br />
<br />
The WordPress uploader generally do not support the SVG format by default. But this file format is becoming quite popular nowadays, Thee simple example can guide you to add SVG upload to your WordPress install. <br /><br />You have to simply just add the code below to your functions.php file. After that SVG upload will be supported autometically once the file is saved.<br /><br />add_filter('upload_mimes', 'my_upload_mimes');<br /><br />function my_upload_mimes($mimes = array()) {<br /> $mimes['svg'] = 'image/svg+xml';<br /> return $mimes;<br />}<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-21177712366748813762013-04-10T12:55:00.000+05:302013-04-10T12:55:24.130+05:30Redirect to post if search results only returns one post<div dir="ltr" style="text-align: left;" trbidi="on">
In Wordpress when a visitor search your website using WordPress built-in search engine function, the search results are displayed as a list. The following functionality can improve the search engine by automatically redirecting the visitor to the post if there is only one post is found by WordPress search engine.<br /><br /><br />You need to just paste the following code into the functions.php file:<br /><br />add_action('template_redirect', 'redirect_single_post');<br />function redirect_single_post() {<br /> if (is_search()) {<br /> global $wp_query;<br /> if ($wp_query->post_count == 1) {<br /> wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );<br /> }<br /> }<br />}<br /></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-66560435286304025082013-04-05T10:09:00.001+05:302013-04-05T10:09:18.581+05:30How to add hook in PrestaShop 1.5<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to add hook in PrestaShop 1.5</b><br />
<br />
Sometimes we need to add custom hook in prestashop<br />The process of Hook adding in FrontController.php in PrestaShop 1.5 is different from the other previous version of prestashop like PreataShop 1.4 but for database and installing module parts are still the same way as it before.<br /><br />1. Open “FrontController.php” from /override/classes/controller/<br />Default file is looks like this<br />
<br />
<div class="container">
<div class="line number1 index0 alt2">
<code class="php plain"><?php</code></div>
<div class="line number2 index1 alt1">
</div>
<div class="line number3 index2 alt2">
<code class="php keyword">class</code> <code class="php plain">FrontController </code><code class="php keyword">extends</code> <code class="php plain">FrontControllerCore</code></div>
<div class="line number4 index3 alt1">
<code class="php plain">{</code></div>
<div class="line number5 index4 alt2">
</div>
<div class="line number6 index5 alt1">
<code class="php plain">}</code></div>
<div class="line number6 index5 alt1">
<code class="php plain"> </code></div>
<div class="line number6 index5 alt1">
<code class="php plain">2. Then, add this following code from main FrontController.php</code></div>
<div class="line number6 index5 alt1">
<code class="php plain"> </code></div>
<div class="line number6 index5 alt1">
<div class="container">
<div class="line number1 index0 alt2">
<code class="php plain"><?php</code></div>
<div class="line number2 index1 alt1">
</div>
<div class="line number3 index2 alt2">
<code class="php keyword">class</code> <code class="php plain">FrontController </code><code class="php keyword">extends</code> <code class="php plain">FrontControllerCore</code></div>
<div class="line number4 index3 alt1">
<code class="php plain">{</code></div>
<div class="line number5 index4 alt2">
<code class="php spaces"> </code><code class="php keyword">public</code> <code class="php keyword">function</code> <code class="php plain">initContent()</code></div>
<div class="line number6 index5 alt1">
<code class="php spaces"> </code><code class="php plain">{</code></div>
<div class="line number7 index6 alt2">
<code class="php spaces"> </code><code class="php variable">$this</code><code class="php plain">->process();</code></div>
<div class="line number8 index7 alt1">
<code class="php spaces"> </code><code class="php keyword">if</code> <code class="php plain">(!isset(</code><code class="php variable">$this</code><code class="php plain">->context->cart))</code></div>
<div class="line number9 index8 alt2">
<code class="php spaces"> </code><code class="php variable">$this</code><code class="php plain">->context->cart = </code><code class="php keyword">new</code> <code class="php plain">Cart();</code></div>
<div class="line number10 index9 alt1">
<code class="php spaces"> </code><code class="php keyword">if</code> <code class="php plain">(</code><code class="php variable">$this</code><code class="php plain">->context->getMobileDevice() == false) {</code></div>
<div class="line number11 index10 alt2">
<code class="php spaces"> </code><code class="php comments">// These hooks aren't used for the mobile theme.</code></div>
<div class="line number12 index11 alt1">
<code class="php spaces"> </code><code class="php comments">// Needed hooks are called in the tpl files.</code></div>
<div class="line number13 index12 alt2">
<code class="php spaces"> </code><code class="php keyword">if</code> <code class="php plain">(!isset(</code><code class="php variable">$this</code><code class="php plain">->context->cart))</code></div>
<div class="line number14 index13 alt1">
<code class="php spaces"> </code><code class="php variable">$this</code><code class="php plain">->context->cart = </code><code class="php keyword">new</code> <code class="php plain">Cart();</code></div>
<div class="line number15 index14 alt2">
<code class="php spaces"> </code><code class="php variable">$this</code><code class="php plain">->context->smarty->assign(</code><code class="php keyword">array</code><code class="php plain">(</code></div>
<div class="line number16 index15 alt1">
<code class="php spaces"> </code><code class="php comments">/* === START: DO NOT TOUCH IT */</code></div>
<div class="line number17 index16 alt2">
<code class="php spaces"> </code><code class="php string">'HOOK_HEADER'</code> <code class="php plain">=> Hook::</code><code class="php functions">exec</code><code class="php plain">(</code><code class="php string">'displayHeader'</code><code class="php plain">),</code></div>
<div class="line number18 index17 alt1">
<code class="php spaces"> </code><code class="php string">'HOOK_TOP'</code> <code class="php plain">=> Hook::</code><code class="php functions">exec</code><code class="php plain">(</code><code class="php string">'displayTop'</code><code class="php plain">),</code></div>
<div class="line number19 index18 alt2">
<code class="php spaces"> </code><code class="php string">'HOOK_LEFT_COLUMN'</code> <code class="php plain">=> (</code><code class="php variable">$this</code><code class="php plain">->display_column_left ? Hook::</code><code class="php functions">exec</code><code class="php plain">(</code><code class="php string">'displayLeftColumn'</code><code class="php plain">) : </code><code class="php string">''</code><code class="php plain">),</code></div>
<div class="line number20 index19 alt1">
<code class="php spaces"> </code><code class="php string">'HOOK_RIGHT_COLUMN'</code> <code class="php plain">=> (</code><code class="php variable">$this</code><code class="php plain">->display_column_right ? Hook::</code><code class="php functions">exec</code><code class="php plain">(</code><code class="php string">'displayRightColumn'</code><code class="php plain">, </code><code class="php keyword">array</code><code class="php plain">(</code><code class="php string">'cart'</code> <code class="php plain">=> </code><code class="php variable">$this</code><code class="php plain">->context->cart)) : </code><code class="php string">''</code><code class="php plain">),</code></div>
<div class="line number21 index20 alt2">
<code class="php spaces"> </code><code class="php comments">/* === END: DO NOT TOUCH IT */</code></div>
<div class="line number22 index21 alt1">
<code class="php spaces"> </code> </div>
<div class="line number23 index22 alt2">
<code class="php spaces"> </code><code class="php comments">/* === START: ADD HOOK | EXAMPLE */</code></div>
<div class="line number24 index23 alt1">
<code class="php spaces"> </code><code class="php string">'HOOK_MY_USER'</code> <code class="php plain">=> Module::hookExec(</code><code class="php string">'myUser'</code><code class="php plain">),</code></div>
<div class="line number25 index24 alt2">
<code class="php spaces"> </code><code class="php string">'HOOK_MY_CATEGORIES'</code> <code class="php plain">=> Module::hookExec(</code><code class="php string">'myCategories'</code><code class="php plain">),</code></div>
<div class="line number26 index25 alt1">
<code class="php spaces"> </code><code class="php string">'HOOK_SEARCH'</code> <code class="php plain">=> Module::hookExec(</code><code class="php string">'mySearch'</code><code class="php plain">)</code></div>
<div class="line number27 index26 alt2">
<code class="php spaces"> </code><code class="php comments">/* === END: ADD HOOK | EXAMPLE */</code></div>
<div class="line number28 index27 alt1">
<code class="php spaces"> </code><code class="php plain">));</code></div>
<div class="line number29 index28 alt2">
<code class="php spaces"> </code><code class="php plain">} </code><code class="php keyword">else</code> <code class="php plain">{</code></div>
<div class="line number30 index29 alt1">
<code class="php spaces"> </code><code class="php variable">$this</code><code class="php plain">->context->smarty->assign(</code><code class="php keyword">array</code><code class="php plain">(</code></div>
<div class="line number31 index30 alt2">
<code class="php spaces"> </code><code class="php string">'HOOK_MOBILE_HEADER'</code> <code class="php plain">=> Hook::</code><code class="php functions">exec</code><code class="php plain">(</code><code class="php string">'displayMobileHeader'</code><code class="php plain">),</code></div>
<div class="line number32 index31 alt1">
<code class="php spaces"> </code><code class="php plain">));</code></div>
<div class="line number33 index32 alt2">
<code class="php spaces"> </code><code class="php plain">}</code></div>
<div class="line number34 index33 alt1">
<code class="php spaces"> </code><code class="php plain">}</code></div>
<div class="line number35 index34 alt2">
<code class="php plain">}</code></div>
<div class="line number35 index34 alt2">
<code class="php plain"> </code></div>
<div class="line number35 index34 alt2">
<code class="php plain">Now save he file and its done.. </code></div>
<div class="line number35 index34 alt2">
<code class="php plain"><br /></code></div>
<div class="line number35 index34 alt2">
<code class="php plain"><br /></code></div>
<div class="line number35 index34 alt2">
<code class="php plain"><br /></code></div>
</div>
<code class="php plain"> </code></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-60300610413476901092013-04-05T10:04:00.003+05:302013-04-05T10:05:02.785+05:30How to change mail color in PrestaShop 1.5<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to change mail color in PrestaShop 1.5</b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvO5bE5ZhqJ0idlCXNlOLbYj9WPOquoVrAfGcxXB1r9ww_0mRcSR8x7iQWSCF_yM74chab_ngYfLMgtaIvQhw7z6v1tW_FB9f3riesUxGavW6jns4j8tvm4Bt8KApDGUDoDvEZwpWNo3g/s1600/php-mysql-guide.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="62" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvO5bE5ZhqJ0idlCXNlOLbYj9WPOquoVrAfGcxXB1r9ww_0mRcSR8x7iQWSCF_yM74chab_ngYfLMgtaIvQhw7z6v1tW_FB9f3riesUxGavW6jns4j8tvm4Bt8KApDGUDoDvEZwpWNo3g/s320/php-mysql-guide.png" width="320" /></a></div>
<br />
Just follow the simple steps<br />Go to<br />1. Preferences -> Themes<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQoZNukcyMqxogNXCLKIItJdwJD3W82EH8TuAnmqt-PeabI_SILam64mHRfrSEtD8LDM-6T-r8e8YwO62ggYuO7mRjTMrHc8Iyd_JTNjzJSIRWYt-nSlvferENlxvEO-j9kdug-BR6o4g/s1600/php_mysql-guide.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="193" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQoZNukcyMqxogNXCLKIItJdwJD3W82EH8TuAnmqt-PeabI_SILam64mHRfrSEtD8LDM-6T-r8e8YwO62ggYuO7mRjTMrHc8Iyd_JTNjzJSIRWYt-nSlvferENlxvEO-j9kdug-BR6o4g/s320/php_mysql-guide.png" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
Thenge change in the manner of the following way<br /><br />Now<br />2. Save and Done!<br />
<br />
<br />
</div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-8109599579706403182013-04-02T10:07:00.003+05:302013-04-02T10:07:35.626+05:30How to activate link manager on WordPress 3.5 (and newer)<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to activate link manager on WordPress 3.5 (and newer)</b><br />
<br />
The new WordPress version like 3.5 (and newer) , wordpress have left out the Link Manager facility from the admin area. In the following way we can bring it back!<br /><br /><br />You can just paste this code into your functions.php file and it will works<br /><br /><?php<br /><br /> //Activate the Link Manager built in to the WordPress admin<br /> add_filter( 'pre_option_link_manager_enabled', '__return_true' );<br /><br />?><br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-51805729768411498062013-04-02T10:02:00.000+05:302013-04-02T10:02:23.941+05:30How to directly include Typekit fonts on your WordPress theme<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to directly include Typekit fonts on your WordPress theme</b><br />
<br />
How to directly include Typekit fonts on your WordPress theme<br /><br />Typekit is a very useful service which allow us to use countless different fonts on our website or blog. Typekit provide a WordPress plugin by using this we can easily add their fonts to our WordPress site, but there are no built-in solution by which we can integrating Typekit fonts directly to your theme. Please following tricks can do so.<br /><br />Edit the code below and update the .js file path on line 2. Then, simple paste it on your functions.php file. Save the file, and you're done!<br /><br />function theme_typekit() {<br /> wp_enqueue_script( 'theme_typekit', '//use.typekit.net/xxxxxxx.js');<br />}<br />add_action( 'wp_enqueue_scripts', 'theme_typekit' );<br /><br />function light_typekit_inline() {<br /> if ( wp_script_is( 'theme_typekit', 'done' ) ) { ?><br /> <script type="text/javascript">try{Typekit.load();}catch(e){}</script><br /><?php }<br />}<br />add_action( 'wp_head', 'theme_typekit_inline' );<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-9401280084046465302013-03-25T20:06:00.002+05:302013-03-25T20:06:20.850+05:30How To Add HTML Links To Standard Prestashop E-Mail Messages<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How To Add HTML Links To Standard Prestashop E-Mail Messages</b><br /><br /><br />Standard Prestashop order messages section settings do not allow us creating messages which would contain HTML links with clickable anchor texts. But if you want that feature there is still a workaround which you can use to add HTML links to your e-mail messages.<br /><br />To do this it is necessary to override the method AdminOrderController.php PostProcess as follows:<br />$customer_message->message = htmlentities(Tools::getValue('message'), ENT_COMPAT, 'UTF-8');<br /><br /><br />Change to<br />$customer_message->message = Tools::getValue('message');</div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-57612901320755571502013-03-25T20:02:00.000+05:302013-03-25T20:04:40.093+05:30How To Put Prestashop Category List In Alphabetical Order<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How To Put Prestashop Category List In Alphabetical Order</b><br />
<br />
In prestashop when new categories are added to the multi-level navigation blocks, they are placed at the end position of the list which makes it look quite messy. So to sort all the categories in alphabetical order we need to do the following:<br />
<br />
In the file modules/blocklayered/blocklayered.php change this line:<br />
GROUP BY c.id_category ORDER BY c.nleft, c.position';<br />
<br />
To this one:<br />
GROUP BY c.id_category ORDER BY cl.name ASC, c.nleft, c.position';<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-63482051206991227912013-03-21T10:16:00.003+05:302013-03-21T10:16:55.371+05:30Dynamic Copyright Date in WordPress Footer<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Dynamic Copyright Date in WordPress Footer</b><br /><br />Sometimes you will will see various websites with outdated copyright dates. Some of the websites show the current year as their copyright date. This is not a very good sign for a website.To give your users a little background information about your website, you should display the copyright date like: © 2010 – 2012. You can do this by just pasting the following code:<br /><br /><br />function updated_copyright() {<br />global $wpdb;<br />$copyright_dates = $wpdb->get_results("<br />SELECT<br />YEAR(min(post_date_gmt)) AS firstdate,<br />YEAR(max(post_date_gmt)) AS lastdate<br />FROM<br />$wpdb->posts<br />WHERE<br />post_status = 'publish'<br />");<br />$output = '';<br />if($copyright_dates) {<br />$copyright = "&copy; " . $copyright_dates[0]->firstdate;<br />if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {<br />$copyright .= '-' . $copyright_dates[0]->lastdate;<br />}<br />$output = $copyright;<br />}<br />return $output;<br />}<br /><br /><br /><br /><br />Once you haveadd this function, now open your footer.php file in theme folder add the following code in the footer or wherever you want to display the dynamic copyright date:<br /> <?php echo updated_copyright(); ?><br /><br />This function looks for the date of your first post, and the date of your last post. It then echos the years wherever you call the function.<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-12929391670630704202013-03-21T10:06:00.001+05:302013-03-21T10:06:32.984+05:30Change the Footer in WordPress Admin Panel<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Change the Footer in WordPress Admin Panel</b> <br />
<br />
In the following way ,you can change the footer of your wordPress themes by adding the following guideline. You need to just paste the following code:<br /><br />function remove_footer_admin () {<br />echo 'Powered by <a href="http://www.sandipdas.in" target="_blank">Sandip Das</a> | Designed by <a href="http://php-mysql-guide.blogspot.com/" target="_blank">PHP MYSQL GUIDE</a></p>';<br />}<br /><br />add_filter('admin_footer_text', 'remove_footer_admin');<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT2zBXfrPQcsueizHumvK_4UaUsN-dQWQ9cpuhOHhOX_mTE9s29u7kWyfdpZWkHKdIcz0FvUpEyh7XfMf9s7qdoMqMLm_8ov_50YoVSGCPDQFA0wtbsqiOFwhEoSNsjwN95M2TjD3TGaY/s1600/sandipdas.in.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="21" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT2zBXfrPQcsueizHumvK_4UaUsN-dQWQ9cpuhOHhOX_mTE9s29u7kWyfdpZWkHKdIcz0FvUpEyh7XfMf9s7qdoMqMLm_8ov_50YoVSGCPDQFA0wtbsqiOFwhEoSNsjwN95M2TjD3TGaY/s320/sandipdas.in.png" width="320" /></a></div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-46747794174085696932013-03-20T12:59:00.001+05:302013-03-20T12:59:39.769+05:30How to redirect users to a random post<div dir="ltr" style="text-align: left;" trbidi="on">
How to redirect users to a random post<br /><br /><br />To do this follow the instruction below<br />Create a new file and name it page-random.php and just paste the code below in it:<br /><br />// set arguments for get_posts()<br />$args = array(<br /> 'numberposts' => 1,<br /> 'orderby' => 'rand'<br />);<br /><br />// get a random post from the database<br />$my_random_post = get_posts ( $args );<br /><br />// process the database request through a foreach loop<br />foreach ( $my_random_post as $post ) {<br /> // redirect the user to the random post<br /> wp_redirect ( get_permalink ( $post->ID ) );<br /> exit;<br />}<br /><br />Now, upload the page-random.php file to your wordpress theme directory. After upload login to your WP dashboard and create a new page, called "random" [If you dont call it random, otherwise, the standard page layout will apply, you can check Wordpress Codex for more details about page hierarchy].<br /><br />Now after you published the random page, if any user visit the http://www.website.com/random page, he will be automatically redirected to a random post.<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-43490015266032137332013-03-20T12:53:00.000+05:302013-03-20T12:54:08.819+05:30How to only display the author posts in the admin post list<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to only display the author posts in the admin post list</b><br />
<br />
In a multi-author blog, the code is very useful to allow each author to only see his own posts in the wordpress admin post list. The following is a simple code snippet to do it.<br /><br />So you have to paste the code below into the theme functions.php file. Now saved the file, and then authors will only see only their own posts in the admin post list.<br /><br /><?php<br /><br />function mypo_parse_query_adminonly( $wp_query ) {<br /> if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {<br /> if ( !current_user_can( 'level_10' ) ) {<br /> global $current_user;<br /> $wp_query->set( 'author', $current_user->id );<br /> }<br /> }<br />}<br /><br />add_filter('parse_query', 'mypo_parse_query_adminonly' );<br /><br />?><br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-13201167209112569092013-03-14T10:31:00.000+05:302013-03-14T10:31:25.388+05:30How to run the loop outside of WordPress<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to run the loop outside of WordPress</b><br />
<br />
If you need to access your WordPress content and need to run a loop OUTSIDE of your WORDPRESS install? The following code snippet can allow you to run a WordPress loop on any PHP file, or even outside of your WordPress install.<br /><br /><br /><br />So just paste the following code on any PHP file where you want to run your WordPress loop for accessing data. So for this you need to modify the following:<br /><br />line 4: Please specify the path to your WordPress wp-blog-header.php file.<br />line 5: Query posts using the query_posts() function.<br /><br /><?php<br /> // Include WordPress<br /> define('WP_USE_THEMES', false);<br /> require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php');<br /> query_posts('posts_per_page=1');<br />?><br /><br /><?php while (have_posts()): the_post(); ?><br /> <h2><?php the_title(); ?></h2><br /> <?php the_excerpt(); ?><br /> <p><a href="<?php the_permalink(); ?>" class="red">Read more...</a></p><br /><?php endwhile; ?><br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-84820565745817880092013-03-12T17:13:00.004+05:302013-03-12T17:14:16.200+05:30How to save bandwidth and reduce server load<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to save bandwidth and reduce server load</b><br />
<br />
1. Use CSS instead of images<br />
2. Always make sure that your images are optimized<br />
3. Use a cache on your website<br />
4. Prevent bandwidth stealing and hotlinking<br />
5. Use Minify to compress CSS and JavaScript files<br />
6. Use hosting websites to host big files<br />
7. Use GZip compression on your PHP files<br />
8. Use a reliable web hosting</div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-37759970675227949952013-03-12T16:53:00.000+05:302013-03-12T16:53:40.056+05:30Image resizing using jQuery<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Image resizing using jQuery</b><br />
<br />
Example<b> </b>of jquery fixed image resize<br />
<br />
<br />
<pre>$(window).bind("load", function() {
// IMAGE RESIZE
$('#product_cat_list img').each(function() {
var maxWidth = 120;
var maxHeight = 120;
var ratio = 0;
var width = $(this).width();
var height = $(this).height();
if(width > maxWidth){
ratio = maxWidth / width;
$(this).css("width", maxWidth);
$(this).css("height", height * ratio);
height = height * ratio;
}
var width = $(this).width();
var height = $(this).height();
if(height > maxHeight){
ratio = maxHeight / height;
$(this).css("height", maxHeight);
$(this).css("width", width * ratio);
width = width * ratio;
}
});
//$("#contentpage img").show();
// IMAGE RESIZE
});</pre>
<pre> </pre>
<pre> </pre>
<pre>Source: http://snipplr.com/view/62552/mage-resize/ </pre>
<br />
<b><br /></b></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-42522139137807220722013-03-11T19:13:00.001+05:302013-03-11T19:14:17.112+05:30How to make WordPress images responsive<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to make WordPress images responsive</b><br />
<br />
The responsive images can be big on wide screens but automatically adapt to smaller screens such as iphone,iPad. Very easily you can make images responsive. Just follow the simple steps on your blog.<br /><br /><br />First you have to create the shortcode. Open your functions.php file and paste the following php code in it:<br /><br />function responsive_images($atts, $content = null) {<br /> return '<div class="image-resized">' . $content .'</div>';<br />}<br /><br />add_shortcode('responsive', 'responsive_images');<br /><br />Now after that open your style.css file and add those CSS rules:<br /><br />@media only screen and (max-width:767px) {<br /> .image-resized img {<br /> width:100%;<br /> height:auto;<br /> }<br />}<br /><br />So now you can use the [responsive] shortcode to insert responsive images in your wordpress blog:<br /><br />[responsive]<img src="image_url" alt="alt" title="title" />[/responsive]</div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-54724144967186797752013-03-11T19:01:00.001+05:302013-03-11T19:02:04.988+05:30Sql query to delete orphaned post meta from WordPress database<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Sql query to delete orphaned post meta from WordPress database</b><br />
<br />
WordPress blog contain thousands of rows of useless meta data. The following simple SQL query can delete orphaned post meta on our database.<br /><br /><br />You have to just run the following sql query on the WordPress database which delete orphaned post meta. <br />Before you start, create a backup of your database!<br /><br />DELETE pm<br />FROM wp_postmeta pm<br />LEFT JOIN wp_posts wp ON wp.ID = pm.post_id<br />WHERE wp.ID IS NULL</div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-55588619413259283272013-02-24T10:53:00.004+05:302013-02-24T10:53:41.722+05:30Disable automatic paragraphs in WordPress editor<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to disable automatic paragraphs in WordPress editor</b><br />
<br />
WordPress by default automatically creates paragraphs on the post content. Sometimes this is very useful, but sometimes we might want to change this type of behavior which can fit our specific needs. The following recipe explains how we can disable automatic paragraphs in wordpress.<br />
<br />
<br />
<br />
JUst paste the following line into the theme functions.php file:<br />
<br />
remove_filter('the_content', 'wpautop');<br />
<br />
Now Once you saved the file then the WordPress will never create automatic paragraphs on the wordpress post or page content.</div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-26640253748263478292013-01-22T22:24:00.000+05:302013-01-22T22:24:17.230+05:30Shortcode to display external files on Wordpress post<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Shortcode to display external files on Wordpress post</b><br />
<b><br /></b>
While blogging on wordpress, sometimes we may need to include an external file on our post, like text or image etc, into our wordpress posts. Checkout the following a very useful shortcode which embed and display any external files in our wordpress blog posts.<b></b><br />
<b><br /></b>
<br />
<pre>function show_file_func( $atts ) {
extract( shortcode_atts( array(
'file' => ''
), $atts ) );
if ($file!='')
return @file_get_contents($file);
}
add_shortcode( 'show_file', 'show_file_func' );</pre>
<pre> </pre>
<pre> </pre>
<pre>Now use the shortcode like the following example
[show_file file="http://www.thesandip.com/test.html"] </pre>
</div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-38595416721677095562012-12-10T15:49:00.004+05:302012-12-10T15:50:07.741+05:30Important Methods for On Page Optimization<div dir="ltr" style="text-align: left;" trbidi="on">
<b>The following process need to do for on page optimization in SEO.</b><br /><br /> Keyword Research and Analysis<br /> Keyword Density<br /> Title Tag (Page Title Optimization)<br /> Page Specific Meta Tag Creation<br /> Anchor Text Optimization<br /> Alt Tag Optimization<br /> Submission of XML Sitemap<br /> Content Placement <br /> Implementation of Google Analytic<br /> Search Engine Verification from Google, Yahoo and MSN<br /> Creation and Submission of ROR.xml<br /> Creation of Proper Link Structure<br /> Implementation of 301 Permanent Redirect<br /> Optimization of Search Engine Essential Files (robots.txt, urllist.txt, sitemap.xml)<br /> Creating micro-formats like hcard integration, hrview integration, vCard integration.</div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-49038945944792964262012-12-06T23:45:00.001+05:302012-12-06T23:45:32.056+05:30How to get the first link in wordpress posts<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to get the first link in wordpress posts</b><br />
<br />
Please follow the code structure to get the first link from a post.<br /><br /><br />To make this happen just paste this code into your functions.php file.<br /><br />function get_content_link( $content = false, $echo = false ){<br /> if ( $content === false )<br /> $content = get_the_content(); <br /><br /> $content = preg_match_all( '/hrefs*=s*["']([^"']+)/', $content, $links );<br /> $content = $links[1][0];<br /><br /> if ( empty($content) ) {<br /> $content = false;<br /> }<br /><br /> return $content;<br />}<br /><br />The above function finds the first link in the post and returns that link to you. So In this following way, we can link the title(or whatever) to this place, as describe below:<br /><br /><h2><a href="<?php echo get_content_link( get_the_content() ); ?>"><?php the_title(); ?></a></h2></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0tag:blogger.com,1999:blog-5471776926780989448.post-20780775157163461252012-11-27T21:59:00.001+05:302012-11-27T21:59:28.523+05:30How to create a Pinterest "pin it" button for your WordPress blog<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to create a Pinterest "pin it" button for your WordPress blog</b><br />
<br />
Just paste the following code where you like the "Pin It" button to be displayed. But remeber that this code must be inserted within the loop.<br /><br /><a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' ); echo $thumb['0']; ?>&description=<?php the_title(); ?>" class="pin-it-button" count-layout="horizontal">Pin It</a><br /><br />Now footer.php file and add the pinterest JavaScript code:<br /><br /><script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script><script src="http://assets.pinterest.com/js/pinit.js" type="text/javascript"></script></div>
Anonymoushttp://www.blogger.com/profile/02074393398011459300noreply@blogger.com0