为什么我的帖子标题取代了我的页面标题

时间:2013-12-12 12:26:13

标签: php wordpress

大家好我之前发过一个问题,关于我的博文如何在wordpress中替换我的网页标题 https://stackoverflow.com/questions/20541544/why-do-my-recent-post-titles-replace-the-page-title-i-am-posting-on/20542610?noredirect=1#20542610 但我不明白我的问题得到解答的方式,因为我没有PHP的经验,所以我认为id在这里发布我的代码,所以如果有人能指点在wordpress代码它有错吗? 这是其标题“最新消息”被替换的页面的代码

    <?php
/**
 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the wordpress construct of pages
 * and that other 'pages' on your wordpress site will use a
 * different template.
 *
 */
?>
<?php get_header(); ?>
<div class="page-heading">
    <h1 class="page-title"><?php the_title(); ?></h1>
    <div class="clear"></div>
</div>
<!--Start Page Content -->
<div class="page-content-container">
    <div class="page-content">
        <div class="grid_16 alpha">
            <div class="content-bar">           
                <?php if (have_posts()) : the_post(); ?>
                    <?php the_content(); ?>
                    <div class="clear"></div>
                    <?php wp_link_pages(array('before' => '<div class="page-link"><span>' . __('Pages:', 'black-bird') . '</span>', 'after' => '</div>')); ?>
                <?php endif; ?>

                <!--Start Comment box-->
                <?php comments_template(); ?>
                <!--End Comment box-->

            </div>
        </div>
        <div class="grid_8 omega">
            <!--Start Sidebar-->
            <?php get_sidebar(); ?>
            <!--End Sidebar-->
        </div> 
    </div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>

这是每个新帖子标题替换页面标题

的帖子的代码
    <?php
/**
 * The Template for displaying all single posts.
 * 
 */
?>
<?php get_header(); ?>

<!--Start Page Heading-->
<!--Start Page Content -->
<div class="page-content-container">
    <div class="page-content single">
        <div class="grid_16 alpha">
            <div class="content-bar">
                <!-- Start the Loop. -->
                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>  
                        <!--post start-->
                        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

                                        <div class="post_content">
                                            <?php the_content(); ?>
                                            <div class="clear"></div>
   <h1 class="post_title single"  ><span><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(esc_attr__('Permalink to %s', 'black-bird'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a><span></h1>
                                            <?php wp_link_pages(array('before' => '<div class="page-link"><span>' . __('Pages:', 'black-bird') . '</span>', 'after' => '</div>')); ?>
                                            <?php if (has_tag()) { ?>
                                                <div class="tag">
                                                    <?php the_tags(__('Post Tagged with ', ', ', '')); ?>
                                                </div>
                                            <?php } ?>
                                        </div>                              
                                        <ul class="post_meta clearfix">
                                            <li class="posted_by"><span><?php _e('Posted by', 'black-bird'); ?></span>&nbsp;&nbsp;<img src="<?php echo get_template_directory_uri(); ?>/images/admin.png" /><?php the_author_posts_link(); ?></li>
                                            <li class="post_category"><span><?php _e('Posted in', 'black-bird'); ?></span>&nbsp;&nbsp;<?php the_category(', '); ?></li>
                                            <li class="post_date"><img src="<?php echo get_template_directory_uri(); ?>/images/date.png" />&nbsp;&nbsp; <?php echo get_the_time('M, d, Y') ?></li>
                                            <li class="post_comment"><img src="<?php echo get_template_directory_uri(); ?>/images/comment.png" />&nbsp;&nbsp;<span><?php comments_popup_link('No Comments.', '1 Comment.', '% Comments.'); ?></span></li>
                                        </ul>
                                        </div>
                                        <!--End Post-->
                                        <?php
                                    endwhile;
                                else:
                                    ?>
                                    <div class="post">
                                        <p>
                                            <?php _e('Sorry, no posts matched your criteria.', 'black-bird'); ?>
                                        </p>
                                    </div>
                                <?php endif; ?>
                                <!--End Loop-->
                                <nav id="nav-single"> <span class="nav-previous">
                                        <?php previous_post_link('%link', __('<span class="meta-nav">&larr;</span> Previous Post ', 'black-bird')); ?>
                                    </span> <span class="nav-next">
                                        <?php next_post_link('%link', __('Next Post <span class="meta-nav">&rarr;</span>', 'black-bird')); ?>
                                    </span> </nav>
                                <!--Start Comment box-->
                                <?php comments_template(); ?>
                                <!--End Comment box--> 
                                </div>
                                </div>
                                <div class="grid_8 omega">
                                    <!--Start sidebar-->
                                    <?php get_sidebar(); ?>
                                    <!--End sidebar-->
                                </div>
                                </div>
                                </div>
                                </div>
                                </div>
                                </div>
                                <?php get_footer(); ?> 

这也是头文件的代码

 <?php
/**
 * The Header for our theme.
 *
 * Displays all of the <head> section and everything up till <div id="main">
 *
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html <?php language_attributes(); ?>>
    <head>
        <meta charset="<?php bloginfo('charset'); ?>" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
  <title><?php wp_title(''); ?></title>
        <link rel="profile" href="http://gmpg.org/xfn/11" />
        <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
        <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('stylesheet_url'); ?>" />
        <?php wp_head(); ?> 
    </head>             
    <body <?php body_class(); ?> style="<?php if (blackbird_get_option('blackbird_bodybg') != '') { ?>background: fixed url(<?php echo blackbird_get_option('blackbird_bodybg'); ?>);<?php } else {
            ?> background: fixed url(<?php echo get_template_directory_uri(); ?>/images/bg.jpg); <?php } ?>" >
        <div class="main-container">
            <div class="container_24">
                <div class="grid_24">
                    <div class="header">
                        <div class="grid_16 alpha">
                            <div class="logo"> <a href="<?php echo home_url(); ?>"><img src="<?php if (blackbird_get_option('blackbird_logo') != '') { ?><?php echo blackbird_get_option('blackbird_logo'); ?><?php } else { ?><?php echo get_template_directory_uri(); ?>/images/logo.png<?php } ?>" alt="<?php bloginfo('name'); ?>" /></a></div>
                        </div>
                        <div class="grid_8 omega">
                            <div class="header-info">
                                <?php if (blackbird_get_option('blackbird_topright_cell') != '') { ?>
                                    <p class="cell"><img src="<?php echo get_template_directory_uri(); ?>/images/call-us.png"  class="call-us" />&nbsp; <?php echo stripslashes(blackbird_get_option('blackbird_topright_cell')); ?></p>
                                <?php } else { ?>
                                    <p class="cell"><img src="<?php echo get_template_directory_uri(); ?>/images/call-us.png"  class="call-us" />&nbsp;Call Us (111) 234 - 5678</p>
                                <?php } ?>
                                <?php if (blackbird_get_option('blackbird_topright_text') != '') { ?>
                                    <p><?php echo stripslashes(blackbird_get_option('blackbird_topright_text')); ?></p>
                                <?php } else { ?>
                                    <p><?php _e('21/B, London Campus, British Road, Birmingham, UK','black-bird'); ?></p>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                    <div class="clear"></div>
                    <!--start Menu wrapper-->
                    <div class="menu_wrapper">
                        <div class="grid_18 alpha">
                            <div id="MainNav">
                                <a href="#" class="mobile_nav closed"><?php _e('Pages Navigation Menu','black-bird'); ?><span></span></a>
                                <?php blackbird_nav(); ?> 
                            </div></div>
                        <div class="grid_6 omega">
                            <div class="top-search">

                                <?php get_search_form(); ?>
                            </div>
                        </div>
                    </div>
                    <!--End Menu wrapper-->
                    <div class="clear"></div>

那么伙计们我需要改变什么才能让每个帖子标题停止替换页面标题?

1 个答案:

答案 0 :(得分:0)

这段代码:

<h1 class="post_title single"

将打印帖子标题的内容。你可以尝试用

替换它
<h1><?php wp_title(''); ?></h1>

获取页面标题,或使用

$parent_title = get_the_title($post->post_parent);
echo '<h1>' . $parent_title . '</h1>';

获取父页面标题