iCyborg
iCyborg

Reputation: 4728

How to show only post title on front page in twentyweleve theme?

I am using twentytwelve theme and wants to show only title on home page. This is what I have in index.php loop, I am not able to understand what should I edit to get only titles

  <?php if ( have_posts() ) : ?>

     <?php /* Start the Loop */ ?>

     <?php while ( have_posts() ) : the_post(); ?>
        <?php get_template_part( 'content', get_post_format() ); ?>
     <?php endwhile; ?>

     <?php twentytwelve_content_nav( 'nav-below' ); ?>

  <?php else : ?>

EDIT - I am able to get the title printed using get_title();but this only prints title and no links to the post.

Upvotes: 1

Views: 5529

Answers (2)

PUSTAKAKORAN.COM
PUSTAKAKORAN.COM

Reputation: 477

Use this theme: Theme Name: Twenty Twelve Theme URI: https://wordpress.org/themes/twentytwelve/ Author: the WordPress team

Install this plugin: Prime Strategy Page Navi (https://wordpress.org/plugins/prime-strategy-page-navi/) ---> for page navigation Auto Numbering Post (https://wordpress.org/plugins/auto-numbering-post/) ---> for add numbering front title

1. Open file: /wp-content/themes/twentytwelve/index.php

Find this code (line 25):

<?php get_template_part( 'content', get_post_format() ); ?>

Replace with this code:

<?php if ( function_exists( 'page_navi' ) ) page_navi( 'items=7&prev_label=Prev&next_label=Next&first_label=First&last_label=Last&show_num=1&num_position=after' ); ?>
            <?php /* Start the Loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>
                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <div class="entry-title">
                <a href="<?php echo get_permalink($recent->ID); ?>">
                <?php the_title(); ?>
                </a>
                </div>
                </div><!-- #post -->
            <?php endwhile; ?>
<?php if ( function_exists( 'page_navi' ) ) page_navi( 'items=7&prev_label=Prev&next_label=Next&first_label=First&last_label=Last&show_num=1&num_position=after' ); ?>

Save file and close.

2. Open file: /wp-content/themes/twentytwelve/style.css

In bottom, paste this code:

/* =Style for Page Navigasi
----------------------------------------------- */
.page_navi {
    text-align: center;
}

.page_navi li {
    display: inline;
    list-style: none;
}

.page_navi li.current span {
    color: #000;
    font-weight: bold;
    display: inline-block;
    padding: 3px 7px;
    background: #fee;
    border: solid 1px #fcc;
}

.page_navi li a {
    color: #333;
    padding: 3px 7px;
    background: #eee;
    display: inline-block;
    border: solid 1px #999;
    text-decoration: none;
}

.page_navi li a:hover {
    color: #f00;
}

.page_navi li.page_nums span {
    color: #fff;
    padding: 3px 7px;
    background: #666;
    display: inline-block;
    border: solid 1px #333;
}

Save file and close.

3. This Result:

enter image description here

Be happy theme for list or directory article.

Upvotes: 0

Gopal S Rathore
Gopal S Rathore

Reputation: 9995

replace this:

<?php while ( have_posts() ) : the_post(); ?>
  <?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>

with this:

<?php $recent_posts = get_posts('numberposts=10');
if($recent_posts) { ?>
    <ul>
        <?php foreach( $recent_posts as $recent ) { ?>
        <li>
        <a href="<?php echo get_permalink($recent->ID); ?>"><?php echo $recent->post_title; ?></a>
        </li>
        <?php } ?>
    </ul>
<?php } ?>

Upvotes: 2

Related Questions