WordPress Themes Development Question:
Download Job Interview Questions and Answers PDF
Explain me how can I have a static front page and posts display on a page called Blog?
Answer:
If using WordPress as a CMS, you might want to present readers with a static front page, and then display your posts on another page called Blog. To accomplish that follow these instructions:
Create a Page and use “My Front Page” for the Page Title. Of course, in the content for that Page, you can enter the information you want presented on your site’s front page (see example below if you want to display a post).
Create a Page and call it Blog. Nothing needs to be entered in the content field of this Page.
In Administration > Settings > Reading set the Front page displays to A static page, and select My Front Page for Front page:, and select Blog for the Posts page:.
If you want to further customize your front page, you can create a Template, and fit it to meet your needs:
With the help of the Template Hierarchy article, determine what Template is normally used to display your Pages (e.g. page.php or index.php).
Copy that template to myfrontEnd.php. If you were using the WordPress Default theme you would copy wp-content/themes/default/page.php to wp-content/themes/default/myfrontEnd.php.
In Administration > Appearance > Editor, edit the myfrontEnd.php and change the beginning of the file from:
<?php
/**
* @package WordPress
* @subpackage Default_Theme
*/
to:
<?php
/*
Template Name: MyFrontEnd
*/
?>
Then access the Page called Front in Administration > Page > Edit and set the Template to MyFrontEnd.
Once that’s all working, begin changing myfrontEnd.php to make it look like what you want.
That’s it. You are done.
Use this example for the ‘MyFrontEnd’ Page Template if you want to display one post, instead of the Page content, on your ‘static front page’:
<?php
/*
Template Name: MyFrontEnd
*/
?>
<?php get_header(); ?>
<div id=”content”>
<?php
query_posts(‘p=1′); //set p=x where x is post id of post you want to see or use query_posts(‘cat=1&posts_per_page=1); to show one post from Category 1
if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id=”post-<?php the_ID(); ?>”>
<h2><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></h2>
<small><?php the_time(‘F jS, Y’) ?> <!– by <?php the_author() ?> –></small>
<div class=”entry”>
<?php the_content(‘Read the rest of this entry »’); ?>
</div>
<p class=”postmetadata”><?php the_tags(‘Tags: ‘, ‘, ‘, ‘
’); ?> Posted in <?php the_category(‘, ‘) ?> | <?php edit_post_link(‘Edit’, ”, ‘ | ‘); ?> <?php comments_popup_link(‘No Comments »’, ’1 Comment »’, ‘% Comments »’); ?></p>
</div>
<?php endwhile; ?>
<div class=”navigation”>
<div class=”alignleft”><?php next_posts_link(‘« Older Entries’) ?></div>
<div class=”alignright”><?php previous_posts_link(‘Newer Entries »’) ?></div>
</div>
<?php else : ?>
<h2 class=”center”>Not Found</h2>
<p class=”center”>Sorry, but you are looking for something that isn’t here.</p>
<?php get_search_form(); ?>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Create a Page and use “My Front Page” for the Page Title. Of course, in the content for that Page, you can enter the information you want presented on your site’s front page (see example below if you want to display a post).
Create a Page and call it Blog. Nothing needs to be entered in the content field of this Page.
In Administration > Settings > Reading set the Front page displays to A static page, and select My Front Page for Front page:, and select Blog for the Posts page:.
If you want to further customize your front page, you can create a Template, and fit it to meet your needs:
With the help of the Template Hierarchy article, determine what Template is normally used to display your Pages (e.g. page.php or index.php).
Copy that template to myfrontEnd.php. If you were using the WordPress Default theme you would copy wp-content/themes/default/page.php to wp-content/themes/default/myfrontEnd.php.
In Administration > Appearance > Editor, edit the myfrontEnd.php and change the beginning of the file from:
<?php
/**
* @package WordPress
* @subpackage Default_Theme
*/
to:
<?php
/*
Template Name: MyFrontEnd
*/
?>
Then access the Page called Front in Administration > Page > Edit and set the Template to MyFrontEnd.
Once that’s all working, begin changing myfrontEnd.php to make it look like what you want.
That’s it. You are done.
Use this example for the ‘MyFrontEnd’ Page Template if you want to display one post, instead of the Page content, on your ‘static front page’:
<?php
/*
Template Name: MyFrontEnd
*/
?>
<?php get_header(); ?>
<div id=”content”>
<?php
query_posts(‘p=1′); //set p=x where x is post id of post you want to see or use query_posts(‘cat=1&posts_per_page=1); to show one post from Category 1
if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id=”post-<?php the_ID(); ?>”>
<h2><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></h2>
<small><?php the_time(‘F jS, Y’) ?> <!– by <?php the_author() ?> –></small>
<div class=”entry”>
<?php the_content(‘Read the rest of this entry »’); ?>
</div>
<p class=”postmetadata”><?php the_tags(‘Tags: ‘, ‘, ‘, ‘
’); ?> Posted in <?php the_category(‘, ‘) ?> | <?php edit_post_link(‘Edit’, ”, ‘ | ‘); ?> <?php comments_popup_link(‘No Comments »’, ’1 Comment »’, ‘% Comments »’); ?></p>
</div>
<?php endwhile; ?>
<div class=”navigation”>
<div class=”alignleft”><?php next_posts_link(‘« Older Entries’) ?></div>
<div class=”alignright”><?php previous_posts_link(‘Newer Entries »’) ?></div>
</div>
<?php else : ?>
<h2 class=”center”>Not Found</h2>
<p class=”center”>Sorry, but you are looking for something that isn’t here.</p>
<?php get_search_form(); ?>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Download WordPress Theme Development Interview Questions And Answers
PDF
Previous Question | Next Question |
Tell me how to Change Your Default WordPress Post Category & Post Type? | Explain me does de-activated plugins slow down a WordPress site? |