简体   繁体   English

如何在Wordpress中按页面ID设置页面标题

[英]How to set page title by page id in wordpress

I am trying to set the page title in wordpress. 我正在尝试在wordpress中设置页面标题。

Suppose in a blog centered site, whenever we click a tag, a new page is opened with all the posts of that tag. 假设在以博客为中心的站点中,每当我们单击标签时,都会打开一个新页面,其中包含该标签的所有帖子。 I cannot set page title for these pages. 我无法为这些页面设置页面标题。

There should be a solution to that problem, that is like adding filter to set page title by page ids. 应该有解决该问题的方法,例如添加过滤器以按页面ID设置页面标题。 I mean whenever pages with specific ids open, it should show custom title. 我的意思是,每当打开具有特定ID的页面时,它都应显示自定义标题。 How can I do this? 我怎样才能做到这一点?

I've encounterer the same problem i made this : 我遇到了同样的问题,我做了这个:

 <?php $tag_name = get_tags(array('slug'=>get_query_var('tag'))); ?>

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



                    <div <?php post_class(array('pin-article')); ?> >



                        <article class="article category">

                             <p><?php _e( 'Tag','wip'); ?> : <strong> <?php echo $tag_name[0]->name;  ?> </strong> </p>

                    </article>



                    </div>

             <?php if ( $wp_query->post_count > 1 ) : ?>



                          <div class="filter" data-filter="all"><?php _e( 'Show all','wip' ); ?></div>

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

                          <?php $mixitTags = get_the_tags();?>  

                                <?php foreach($mixitTags as $k => $tag):

                                          if($tag->name != $tag_name[0]->name):

                                             $tagFilter[] = $tag->name;



                                          endif;

                                 endforeach;?>

                          <?php endwhile;?>

                          <?php 

                          $tagFilter = array_unique($tagFilter);



                          foreach ($tagFilter as $filter) :

                            echo '<div class="filter" data-filter=".'.sanitize_title($filter).'">'.$filter.'</div>';

                          endforeach ?>

              <?php endif; ?><!-- Fin de vérification si post > 1 -->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM