0

I imagined that it is pretty easy to do: just take everything what is in index.php. Add

<?php
/*
Template Name: Blog
*/
?>

at the top and you all set, but in my case it is not working. I copied everything what was in my index.php, created template-blog.php and added through new page as "new". And this is the result I get: http://bellated.us.lt/new/ (testing page)

It's seems like the blog loop is starting, but it do not go through as it should. Any help will be appreciated. Thanks!

<?php
/*
Template Name: Blog
*/
?>

<?php get_header(); ?>


            <!-- BEGIN #content-wrap -->
            <div id="content-wrap" class="clearfix">

                <div id="content-top">&nbsp;</div>

                <!--BEGIN #primary .hfeed-->
                <div id="primary" class="hfeed">

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

                    <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
                    <?php /* If this is a category archive */ if (is_category()) { ?>
                        <h1 class="page-title"><?php printf(__('Visi &#303;ra&#353;ai i&#353; %s', 'framework'), single_cat_title('',false)); ?></h1>
                    <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
                        <h1 class="page-title"><?php printf(__('&#302;ra&#353;&#371; &#279;ym&#278;s %s', 'framework'), single_tag_title('',false)); ?></h1>
                    <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
                        <h1 class="page-title"><?php _e('Archyvas', 'framework') ?> <?php the_time('F jS, Y'); ?></h1>
                     <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
                        <h1 class="page-title"><?php _e('Archyvas', 'framework') ?> <?php the_time('F, Y'); ?></h1>
                    <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
                        <h1 class="page-title"><?php _e('Archyvas', 'framework') ?> <?php the_time('Y'); ?></h1>
                    <?php /* If this is an author archive */ } elseif (is_author()) { ?>
                        <h1 class="page-title"><?php _e('Visi &#303;ra&#353;ai pagal', 'framework') ?> <?php echo $curauth->display_name; ?></h1>
                    <?php /* If this is a category archive */} elseif (is_search()) { ?>
                        <h1 class="page-title"><?php _e('Paie&#353;kos rezultatai: ', 'framework'); echo '"'.$_GET['s'].'"'; ?></h1>
                     <?php } ?>

                    <?php while (have_posts()) : the_post(); ?>

                        <!--BEGIN .hentry -->
                        <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">               
                            <h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'framework'), get_the_title()); ?>"> <?php the_title(); ?></a></h2>

                            <!--BEGIN .entry-meta .entry-header-->
                            <div class="entry-meta entry-header">
                                <span><?php _e('pagal', 'framework') ?></span> <?php the_author(); ?> <span><?php _e('&middot;', 'framework') ?></span> <?php the_time('Y/m/j  H:i'); ?> <span><?php _e('&middot;', 'framework') ?></span> <?php the_category(', ') ?> <span><?php _e('&middot;', 'framework') ?></span> <?php comments_popup_link(__('Komentar&#371; n&#279;ra', 'framework'), __('1 Komentaras', 'framework'), __('% Komentarai', 'framework')); ?> <?php edit_post_link( __('', 'framework'), '<span class="edit-post">[', ']</span>' ); ?><a href="http://twitter.com/share" class="twitter-share-button" data-url="<?php the_permalink(); ?>" data-text="<?php bloginfo('name'); ?>: <?php the_title(); ?>," data-count="horizontal">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>


                            </div>

                            <?php /* if the post has a WP 2.9+ Thumbnail */
                            if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) : ?>
                            <div class="post-thumb post-lead">
                                <a title="<?php printf(__('Permanent Link to %s', 'framework'), get_the_title()); ?>" href="<?php the_permalink(); ?>"><?php the_post_thumbnail('archive-thumb'); /* post thumbnail settings configured in functions.php */ ?></a>
                            </div>
                            <?php endif; ?>

                            <!--BEGIN .entry-content -->
                            <div class="entry-content">
                                <?php the_content(__('Skaityti toliau &rarr;', 'framework')); ?>
                            <!--END .entry-content -->
                            </div>

                        <!--END .hentry-->  
                        </div>

                        <?php endwhile; ?>

                    <!--BEGIN .navigation .page-navigation -->
                    <div class="navigation page-navigation clearfix">
                        <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
                        <div class="nav-next"><?php next_posts_link(__('&larr; Senesni &#303;ra&#353;ai', 'framework')) ?></div>
                        <div class="nav-previous"><?php previous_posts_link(__('Naujesni &#303;ra&#353;ai &rarr;', 'framework')) ?></div>
                        <?php } ?>
                    <!--END .navigation ,page-navigation -->
                    </div>

                    <?php else : ?>

                    <!--BEGIN #post-0-->
                    <div id="post-0" <?php post_class(); ?>>

                        <h2 class="entry-title"><?php _e('Ups, puslapis nerastas', 'framework') ?></h2>

                        <!--BEGIN .entry-content-->
                        <div class="entry-content">
                            <p><?php _e("Atsipra&#353;ome, bet puslapis, kurio ie&#353;kote nerastas.", "framework") ?></p>
                            <?php get_search_form(); ?>
                        <!--END .entry-content-->
                        </div>

                    <!--END #post-0-->
                    </div>

                    <?php endif; ?>

                <!--END #primary .hfeed-->
                </div>

                <div id="content-btm">&nbsp;</div>

            <!-- END #content-wrap -->
            </div>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

1 Answer 1

1

Remember: custom page templates are still static Pages, so the default Loop for a custom page template will be the post content of the static page to which the template is assigned.

You need to add a custom query to the template, in order to query anything other than the default query.

Refer to the Codex documentation for creating a custom template for a Page of Posts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.