如何正确地为WordPress创建博客模板?

时间:2012-02-13 作者:user385917

我想这很容易做到:只需把索引中的所有内容都取下来。php。添加

<?php
/*
Template Name: Blog
*/
?>
在顶端,你们都准备好了,但在我的情况下,它不起作用。我复制了索引中的所有内容。php,创建模板博客。php并通过新页面添加为“new”。这是我得到的结果:http://bellated.us.lt/new/ (测试页)

看起来博客的循环正在开始,但它并没有像应该的那样通过。任何帮助都将不胜感激。谢谢

<?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 个回复
SO网友:Chip Bennett

记住:自定义页面模板仍然是static Pages, 因此,自定义页面模板的默认循环将是分配模板的静态页面的发布内容。

你需要add a custom query 以查询除默认查询以外的任何内容。

请参阅Codex文档以创建a custom template for a Page of Posts.

结束

相关推荐

Querying both pages and posts

我正在为一个客户构建一个“降临日历”,他们希望以特定的顺序将特定页面和出现在首页的自定义帖子组合在一起。需要检索的内容包括标题、摘录(或内容最多)、永久链接、特色图像和自定义字段。。。从数据库中检索这些内容的最佳方法是什么?自定义SQL查询?某种步行者?复杂的菜单?