How to create wordpress theme from scratch, lesson -12-: split the code part 2

July 1
H

ere we come again with part 2 of splitting the code. Today I will talk about archives.php, single.php, page.php and search.php. let’s start….

 

Step *1: create a new php file using any editor, name it achieve.php and save.

Copy everything in your index.php and paste it in archieves.php and save.

 

Now, open the archives.php and replace <?php the_content(); ?>with <?php the_excerpt(); ?> and save.

 

Why did I do that?

Because this way the archieves.php will be different from index.php, you won’t have a duplicate contents in your site, it is better for google and other search engines. And  by using the_excerpt() function we will get only the excerpts of the posts not the full posts.

 

Step *2: create another php file, name it search.php and copy everything from archives.php and paste it in search.php and save.

In this step, I made all the search results to show up as excerpt not like the index, I mean full posts.

 

Step *3: create a new php file, name it page.php, copy everything from index.php and paste it in page.php and save.

Now type this code under <?php the_content(); ?> and save.


<?php link_pages(’<p><strong>Pages:</strong> ‘, ‘</p>’, ‘number’); ?>

<?php edit_post_link(’Edit’, ‘<p>’, ‘</p>’); ?>

This code <?php link_pages(’<p><strong>Pages:</strong> ‘, ‘</p>’, ‘number’); ?> for adding links in sub pages.

And this code <?php edit_post_link(’Edit’, ‘<p>’, ‘</p>’); ?> used for allowing the administrator edit the post.

 

Step *4: in page.php, remove the postmeta , and here is what you will get:


<div class="entry">

<?php the_content(); ?>

<?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>

<?php edit_post_link('Edit', '<p>', '</p>'); ?>

</div>

Step *5: in page.php, remove the following navigation code and save.


<div class="navigation">

<?php posts_nav_link(); ?>

</div>

Step *6: create another php file, name it single.php, copy everything from index.php and paste it in single.php and save.

type this code under <?php the_content() ?> and save.


<?php link_pages(’<p><strong>Pages:</strong> ‘, ‘</p>’, ‘number’); ?>

Step *7: in single.php, Remove this code <?php comments_popup_link(); ?> and the <br /> tag before it. now you will have something like this:


<p class="postmetadata">

<?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>

</p>

Step *8: in single.php, replace this code <?php posts_nav_link(); ?> with the following code, and save.


<?php previous_post_link(’&laquo; %link’) ?> <?php next_post_link(’ %link &raquo;’) ?>

That’s all for splitting the code, now the only thing left to finish this tutorial is adding the comments to the post, seeya next week.

 


StumbleUpon.com Add us to your digg favorites Add us to your delicious favorites add us to your facebook favorites follow us on twitter Add us to your technorati favorites Add us to your wordpress favorites Add us to your reddit favorites Add us to livejournal favorites

Leave a Reply