您好我是wordpress的新手,我正在尝试为网站创建自己的自定义主题,我理解我所做的一些但我必须承认有些东西看起来仍然很奇怪 对我来说。我现在的问题是当我添加新页面并添加内容时 当我访问该网站但页眉和页脚显示正常时,该页面内容不显示,我检查了源 代码,并注意到内容不会生成。
这些是我的custom themefile的代码文件:
[header.php文件]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/menu.css" type="text/css" />
<title><?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> » Blog Archive <?php } ?> <?php wp_title(); ?></title>
</head>
<body>
<div id="header">
<div class="content">
<div id="logo-with-contact">
<img src="<?php bloginfo('template_url') ?>/images/Amissah, Amissah - Logo.png" alt="Amissah, Amissah & Co" id="header-image" />
<div class="clear"></div>
</div>
</div>
<nav id="top-menu-nav">
<ul>
<li><a href="<?php echo get_option('home') ?>">Home</a></li>
<?php echo wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?>
</ul>
</nav>
</div>
<div class="clear"></div>
[Footer.php]
<div id="footer">
<div class="content">
<div class="block" style="margin-left: 0px">
<h3>Quick Links</h3>
<br />
<ul>
<li><a href="our-firm.html">Our Firm</a></li>
<li><a href="our-practices.html">Our Practices</a></li>
<li><a href="resources.html">Resources</a></li>
</ul>
</div>
<div class="block">
<h3>About Us</h3>
<br />
<ul>
<!--<li><a href="corporate-info.html">Corporate Info</a></li>-->
<li><a href="staff.html">Staff</a></li>
<li><a href="testimonials.html">Testimonials</a></li>
</ul>
</div>
<div class="block">
<h3>Stay Connected</h3>
<br />
<ul>
<li><a href="#" title="facebook"><img src="<?php bloginfo('template_url') ?>/images/facebook-icon.png" alt="facebook" /> Join us on facebook</a></li>
<li><a href="#" title="twitter"><img src="<?php bloginfo('template_url') ?>/images/twitter-icon.png" alt="twitter" /> Follow us on twitter</a></li>
<li><a href="https://login.secureserver.net/index.php?app=wbe" title="mail"><img src="<?php bloginfo('template_url') ?>/images/E-Mail.png" alt="staff mail" /> Staff Email</a></li>
</ul>
</div>
<div class="block" style="width:220px; line-height: 18px;">
<h3>Contact Us</h3>
<br />
Email: info@example.com<br />
Location: xxxxx-xxxxx Memorial Court,<br />
F xxx/5, xth xxxxx Street,<br />
xxxx xxxx Avenue, xxxx,<br />
Adjacent the xxxx xxxxxx Embassy,<br />
Accra<br />
Telephone: xxxx xxx xxx </div>
<div class="clear"><br /><br /></div>
<div class="horizontal-divider"></div>
</div>
</div>
</body>
</html
[的index.php]
<?php get_header(); ?>
<div id="main" class="site-main">
<div class="content">
</div>
</div>
<?php get_footer(); ?>
答案 0 :(得分:2)
看起来你错过了循环,这就是wordpress用来遍历传递给模板并呈现内容的任何帖子/页面。
尝试将此添加到内容div中的index.php
<?php if(have_posts()) : ?>
<?php while ( have_posts() ) : the_post() ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
您可以在此处阅读所有相关内容 - http://codex.wordpress.org/The_Loop
答案 1 :(得分:0)
按照WordPress,
循环是WordPress用于显示帖子的PHP代码。使用The Loop,WordPress会处理每个帖子以显示在当前页面上,并根据它与The Loop标签中指定条件的匹配方式对其进行格式化。循环中的任何HTML或PHP代码都将在每个帖子上处理。
可在此处找到,http://codex.wordpress.org/The_Loop
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here the_content();
//
} // end while
} // end if
?>
基本上,“循环”是WordPress的动态部分,它会吐出页面,帖子和其他内容。
答案 2 :(得分:0)
将以下COde放在
之后的index.php中<div id="primary" class="site-content">
<div id="content" role="main">
<?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 : ?>
<article id="post-0" class="post no-results not-found">
<?php if ( current_user_can( 'edit_posts' ) ) :
// Show a different message to a logged-in user who can add posts.
?>
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'No posts to display', 'twentytwelve' ); ?></h1>
</header>
<div class="entry-content">
<p><?php printf( __( 'Ready to publish your first post? <a href="%s">Get started here</a>.', 'twentytwelve' ), admin_url( 'post-new.php' ) ); ?></p>
</div><!-- .entry-content -->
<?php else :
// Show the default message to everyone else.
?>
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
</header>
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
<?php endif; // end current_user_can() check ?>
</article><!-- #post-0 -->
<?php endif; // end have_posts() check ?>
</div><!-- #content -->
</div><!-- #primary -->