In this article, we will show you how to retrieve wordpress posts within specific time frame and display all months wordpress post. code snippet with detail.
how to display all months wordpress posts on homepage
how to display all months wordpress posts on homepage
WordPress is providing as full proof wordpress api so we can achieve the this using wordpress api only.
You can use the query_posts() function for fetching the wordpress posts. Open your index.php from your wordpress template folder. Before loop just use the following code for in index.php file.
Another good example for fetching the 30 days latest post from wordpress
<!--?php
//based on Austin Matzko's code from wp-hackers email list
function filter_where($where = '') {
//posts in the last 30 days
$where .= " AND post_date --> '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);
?>
Using above code you can display all months wordpress posts.
We need to get the div height and width when these properties not defined. Here in this article, get div height using javascript when div height is auto. Many times we need to get the div or any DOM elements height and width when these properties not defined.
get div height using javascript when div height is auto
Lets say I kept div height auto and width as 200px fix and data is dynamic for eash user. So how we can get the div height.
take div height from javascript
We can use two javascript functions for fetching the div height.
1. offsetHeight – this will return the value which are specified in your CSS
2. clientHeight – this function will return real inner height of element that does not matter about CSS.
I recomend to use this function.
Exmaple code as follows:
[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]
<style>
#wordpressapidiv{ width:200px; height:auto;border:#ccc 1px solid}
</style>
wordpressapidiv">
This is dummy content. This is dummy content. This is dummy content. This is dummy content. This is dummy content. This is dummy content.
This is dummy content. This is dummy content. This is dummy content. This is dummy content. This is dummy content. This is dummy content. This is dummy content.
This is dummy content. This is dummy content. This is dummy content. This is dummy content. This is dummy content. This is dummy content.
This is dummy content. This is dummy content.
</div>
<script>
function getDivHeight(divID){
gd = document.getElementById(divID).clientHeight;
alert(gd);
}
function getDivWidth(divID){
gw = document.getElementById(divID).clientWidth;
alert(gw);
}
</script>
<input name="test" type="button" onclick="getDivHeight('wordpressapidiv')" >
[/viral-lock]
Function above code you can fetch the div height and width using the javascript.
Many times we normally face problems while reading a file using url. Due to wrong PHP configuration we are facing fopen and fread not working with url issue.
fopen and fread not working with url
Using following solution we can easily fix this PHP issue.
For e.g :
$url = ‘http://somesite.com/somefile.txt’;
$fp = fopen($url,”r”);
To allow the fopen to get the contents of the file through url, do the following settings in php.ini file :
allow_url_include = On
By setting above 2 directives to ‘On’, fopen will be able to read the contents from url.
If you are using wamp than we can change this setting by on clicking on wamp icon and than go to PHP and click on setting > and allow_url_fopen option setting.
For linux users, you need to change /etc/php.ini file and do not forget to restart to apache server.
Many times we need to run the linux commands using PHP language. We are going to give you code to, execute linux commands using php. This is my favorite question about PHP when I take an interview of new PHP developer.
execute linux commands using php
In this article I will show you how to execute the linux command using PHP language syntax or script.
You can executelinuxcommands within a php script – all you have to do is put the command line in backticks (”) ,exec() , and shell_exec().
Many new PHP developer looking for how to easily read the xml file. In this tutorial I will show you how to read the xml file using PHP language. Here I given the sample code for parsing the XML using PHP.
How to read xml using php
This is my xml file format and file name is readxml.xml file
<?xml version="1.0"?>
<!-- our XML-document describes a purchase order -->
<purchase-order>
<date>2005-10-31</date>
<number>12345</number>
<purchased-by>
<name>My name</name>
<address>My address</address>
</purchased-by>
<!-- a collection element, contains a set of items -->
<order-items>
<item>
<code>687</code>
<type>CD</type>
<label>Some music</label>
</item>
<item>
<code>129851</code>
<type>DVD</type>
<label>Some video</label>
</item>
</order-items>
</purchase-order>
This is one php file called test.php and code as follows
Many times this issue is happened with me I tried the kill command to stop the process. Solved, Kill command is not working on linux.
But that is really not responding. For Example, following command executed but not worked.
I specially like the kill -9 processid command. Using kill -9 on a process is like just hitting the power button on your running PC. You already know that powering off a running PC can damage your filesystem because of run-time inconsistent data, why would you do the same thing to your applications? You risk the _exact same_ data corruption.
How to set up Firefox Profile Manager on Fedora or Linux
Firefox has new functionality called Profile manager which will allow you to switch with multiple Users.
You can create many user profiles in Firefox and save that as per your choice.
setup Firefox Profile Manager on Fedora
Many times on same Firefox some user don’t want some addons or theme. That time we got some difficulties.
For avoiding this issue we can create the firefox profile in firefox.
In windows creating Firefox profile is very easy. Just open windows run window and type “firefox -P”. That sit!
You will see following screens.
Using this you can create the firefox profiles.
Now I am going to show you how to create the firefox profile in Fedora.
In single.php file we have function to add comments functionality. Here in this article I will give the code for customize the comments template.
From wordpress 2.7 version we got the functionality of changing or customizing the comments template as per your theme. As we all know in single.php file we called following function to add comments functionality. wordpress comments is very important functionality. Here in this article I will give the code for customize the comment template.
customize the comments template
<?php comments_template(); ?>
This function basically calls the comments.php file and add the data from wordpress database.
If we check the comments.php file. Usually we are having following content in comments.php file
[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]
<?php
// Do not delete these lines
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not load this page directly. Thanks!');
if ( post_password_required() ) { ?>
<p>This post is password protected. Enter the password to view comments.</p>
<?php
return;
}
?>
<!-- You can start editing here. -->
<div id="comment">
<?php if ( have_comments() ) : ?>
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
<div>
<div><?php paginate_comments_links(); ?></div>
</div>
<ol>
<?php wp_list_comments('callback=wordpressapi_comments'); ?>
</ol>
<div>
<div><?php paginate_comments_links(); ?></div>
</div>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p>Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
<?php if ('open' == $post->comment_status) : ?>
<div id="respond">
<h3><?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?></h3>
<div>
<small><?php cancel_comment_reply_link(); ?></small>
</div>
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p>
<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<?php if ( $user_ID ) : ?>
<p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out »</a></p>
<?php else : ?>
<p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="author"><small>Name <?php if ($req) echo "(required)"; ?></small></label></p>
<p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="email"><small>Mail (will not be published) <?php if ($req) echo "(required)"; ?></small></label></p>
<p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
<label for="url"><small>Website</small></label></p>
<?php endif; ?>
<!--<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>-->
<p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>
<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
<?php comment_id_fields(); ?>
</p>
<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; // If registration required and not logged in ?>
</div>
<?php endif; // if you delete this the sky will fall on your head ?>
</div>
In the comments loop for showing the comments we used the wp_list_comments() function. Use this for customize the comments template.
We can customize this function as per our requirement. We can pass the following parameters to this function. use following for customize the comments template.
[/viral-lock]
For customize the comments template following parameter is important.
callback (string) The name of a custom function to use to display each comment. Defaults to null. Using this will make your custom function get called to display each comment, bypassing all internal WordPress functionality in this respect. Use to customize comments display for extreme changes to the HTML layout. Not recommended.
In my theme I used that in following way. I changed and passed parameter in comments.php file.
Many times some people add the full URL of website in the name parameter. That time showing author name of comment writer is looks so ugly. So I used following trick in this function. Using this line of code we can show only 20 characters of author.
Ruby is very powerful object-oriented language. new Ruby performance improvement. Working with pure Ruby is really fun and interesting to me. I am the real fan of Ruby language.
Ruby performance improvement
I am working Ruby on Rails for around last four years. There is always I am thinking and all ROR developers are thinking about performance of application.
We always compare Ruby on Rails with PHP, Java, Python, dot net. We came to know that where we are lacking in ROR. Just one issue performance and memory issue.
When we got news about Ruby 1.9 is comming with performance improvement of 63%. Yes, It is not a joke. This is really great news for every ROR developers. Ruby 1.9 and Rails 3.0 is the future of internet.
Now I will talk about Ruby Software engineer who developed and worked on the Ruby 1.9.
Masahiro Kanai, who improved the performance of several methods in Ruby 1.9. He is the age of high school, just 17.
This year, Ruby 1.9 by the Fibonacci sequence of operations (multiple-precision addition) is,
Ruby 1.8 is slower than I realized Mr. Kanai is a challenge to freedom of choice camp Ruby faster.
In front of all the participants had a similar problem occurring, Ruby of type String, Array types (structures that may have an embedded data structure type object itself) and some of the faster method, attention collection. Oden’s is known to be well-covered tongue teachers. Ruby continued even after the camp’s efforts to speed up to approximately some methods to remove the macro in a constant loop of 63 percent to about 8 percent of success in speeding. This patch has been adopted by the community of developers Ruby, Ruby has been incorporated into the trunk (October 5, 2009).
many professional engineers and developers, with patience to hold out that the problem is resolved, probably as a programmer in one or two talents.
Ketai that builds skills and career tips for the professional engineer. Interviewers are already familiar with this series, the Mr. Ikuo Takeuchi, Professor Department of Creative Informatics, Graduate School of Information Science and Engineering, University of Tokyo. This time, who undertook the voluntary and discover if training for a talented programmer.
His mentor was Koichi Sasada (ko1). The performances of the methods he worked have been bumped up 63% in maximum, 8% in average. His patches were applied to Ruby trunk in Oct. 5 this year.
What he did for Ruby Performance tuning?
He took unnecessary macro references out from a loop. Masahiro spotted macros below in array.c, string.c, and struct.c were referred every time Ruby checked whether data was hold in a structure or not. Even though data were constants, Ruby saw the macros to judge data’s presence in every loop.
What I say now more… I am really happy and I can say this is the biggest news of 2010 in IT world.
One thing I want to mention here about Ruby on Rails. This thing is in mind of all ROR developers.
“Thank God, No need to look Jruby”
He took unnecessary macro references out from a loop. Masahiro spotted macros below in array.c, string.c, and struct.c were referred every time Ruby checked whether data was hold in a structure or not. Even though data were constants, Ruby saw the macros to judge data’s presence in every loop.