dongtui6347 2013-12-12 12:26
浏览 43

为什么我的帖子标题取代我的页面标题[重复]

This question is an exact duplicate of:

Hi guys i posted a question earlier about how my blog posts kept replacing my page titles in wordpress https://stackoverflow.com/questions/20541544/why-do-my-recent-post-titles-replace-the-page-title-i-am-posting-on/20542610?noredirect=1#20542610 but i did not understand the way my questions were answered as i have no php experience so i thought id post my code here so if anyone could pin point were in the wordpress code it has a fault ? this is the code for the page in which its title "Latest News" is being replaced

    <?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(); ?>

and this is the code for the posts of which each new post title replaces the page title

    <?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(); ?> 

also this is the code for the header file

 <?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>

so guys what do I need to alter and were in order for each post title to stop replacing the page title?

</div>
  • 写回答

1条回答 默认 最新

  • douji3623 2013-12-12 13:30
    关注

    This bit of code:

    <h1 class="post_title single"
    

    Will print whatever the post title is. YOu can try replacing it with

    <h1><?php wp_title(''); ?></h1>
    

    To get the page title, or with

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

    To get the parent page title

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探