Php 如何在wordpress的子主题中编辑父主题的变量值
我想更改主题Writee(Wordpress)的变量值。“content post header.php”中有一个名为“$date_format”的变量,其值硬编码为“l,F j,Y”(此变量不在函数中)。它是内容:Php 如何在wordpress的子主题中编辑父主题的变量值,php,wordpress,wordpress-theming,overriding,child-theming,Php,Wordpress,Wordpress Theming,Overriding,Child Theming,我想更改主题Writee(Wordpress)的变量值。“content post header.php”中有一个名为“$date_format”的变量,其值硬编码为“l,F j,Y”(此变量不在函数中)。它是内容: <?php /****************************************/ ## Blog post header content. /***************************************/ global $post; $
<?php
/****************************************/
## Blog post header content.
/***************************************/
global $post;
$date_format = 'l, F j, Y';
?>
<div class="entry-header">
<div class="entry-meta">
<span class="entry-cat"><?php the_category(' ')?></span>
</div>
<?php
if (! is_single()) :
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '">', '</a></h2>' );
else:
the_title( '<h1 class="entry-title">', '</h1>' );
endif;
?>
<div class="entry-meta">
<span class="entry-author"><?php echo __('By', 'writee'); ?> <?php the_author_posts_link(); ?> </span>
<span class="entry-date"><?php echo __('on', 'writee'); ?> <a href="<?php echo get_month_link(get_the_time('Y'), get_the_time('m')); ?>"><?php the_time($date_format); ?></a></span>
</div>
</div>
当然,我不知道代码的作用是什么,但这是我通过谷歌搜索发现的最相关的东西。那么,我如何更改这个变量值呢?您需要在子主题中创建一个与父主题中的文件同名的文件。并将该新文件放在与父主题中的文件相同的文件夹结构中。然后在新文件夹中文件,您可以更改代码
<?php
/****************************************/
## Blog post header content.
/***************************************/
global $post;
$date_format = 'what you want';
?>
<div class="entry-header">
<div class="entry-meta">
<span class="entry-cat"><?php the_category(' ')?></span>
</div>
<?php
if (! is_single()) :
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '">', '</a></h2>' );
else:
the_title( '<h1 class="entry-title">', '</h1>' );
endif;
?>
<div class="entry-meta">
<span class="entry-author"><?php echo __('By', 'writee'); ?> <?php the_author_posts_link(); ?> </span>
<span class="entry-date"><?php echo __('on', 'writee'); ?> <a href="<?php echo get_month_link(get_the_time('Y'), get_the_time('m')); ?>"><?php the_time($date_format); ?></a></span>
</div>
</div>
您需要在子主题中创建一个与父主题中的文件同名的文件。并将该新文件放在与父主题中的文件相同的文件夹结构中。在新文件中,您可以更改代码
<?php
/****************************************/
## Blog post header content.
/***************************************/
global $post;
$date_format = 'what you want';
?>
<div class="entry-header">
<div class="entry-meta">
<span class="entry-cat"><?php the_category(' ')?></span>
</div>
<?php
if (! is_single()) :
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '">', '</a></h2>' );
else:
the_title( '<h1 class="entry-title">', '</h1>' );
endif;
?>
<div class="entry-meta">
<span class="entry-author"><?php echo __('By', 'writee'); ?> <?php the_author_posts_link(); ?> </span>
<span class="entry-date"><?php echo __('on', 'writee'); ?> <a href="<?php echo get_month_link(get_the_time('Y'), get_the_time('m')); ?>"><?php the_time($date_format); ?></a></span>
</div>
</div>