WordPress子主题的模板文件没有<h1>标签



像我们的WordPress网站的作者页面这样的页面缺少标签。由于页面是由默认模板index.php呈现的,因此我正在寻找在其中添加标记的方法。下面是index.php。测试类似echo $thumb的代码。alttext美元;似乎不起作用,不是因为变量没有保存任何值,而是代码本身不起作用。

<?php get_header(); ?>
<div id="main-content">
<div class="container">
<div id="content-area" class="clearfix">
<div id="left-area">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$post_format = et_pb_post_format(); echo $post_format; ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post' ); ?>>
<?php
$thumb = '';
$width = (int) apply_filters( 'et_pb_index_blog_image_width', 1080 );
$height    = (int) apply_filters( 'et_pb_index_blog_image_height', 675 );
$classtext = 'et_pb_post_main_image';
$titletext = get_the_title();
$alttext   = get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true );
$thumbnail = get_thumbnail( $width, $height, $classtext, $alttext, $titletext, false, 'Blogimage' );
$thumb     = $thumbnail["thumb"];
echo $thumb . $alttext;
et_divi_post_format_content();
if ( ! in_array( $post_format, array( 'link', 'audio', 'quote' ) ) ) {
if ( 'video' === $post_format && false !== ( $first_video = et_get_first_video() ) ) :
printf(
'<div class="et_main_video_container">
%1$s
</div>',
et_core_esc_previously( $first_video )
);
elseif ( ! in_array( $post_format, array( 'gallery' ) ) && 'on' === et_get_option( 'divi_thumbnails_index', 'on' ) && '' !== $thumb ) : ?>
<a class="entry-featured-image-url" href="<?php the_permalink(); ?>">
<?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
</a>
<?php
elseif ( 'gallery' === $post_format ) :
et_pb_gallery_images();
endif;
} ?>
<?php if ( ! in_array( $post_format, array( 'link', 'audio', 'quote' ) ) ) : ?>
<?php if ( ! in_array( $post_format, array( 'link', 'audio' ) ) ) : ?>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php endif; ?>
<?php
et_divi_post_meta();
if ( 'on' !== et_get_option( 'divi_blog_style', 'false' ) || ( is_search() && ( 'on' === get_post_meta( get_the_ID(), '_et_pb_use_builder', true ) ) ) ) {
truncate_post( 270 );
} else {
the_content();
}
?>
<?php endif; ?>
</article>
<?php
endwhile;
if ( function_exists( 'wp_pagenavi' ) )
wp_pagenavi();
else
get_template_part( 'includes/navigation', 'index' );
else :
get_template_part( 'includes/no-results', 'index' );
endif;
?>
</div>
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php
get_footer();

我会尽量在评论允许的范围内给出更具体的回答:)

当你想自定义模板或创建自定义模板时,在Wordpress中,你有三种可能性:

1 -错误的方式

您可以直接编辑主题中的模板文件。

为什么这是错误的?因为模板,就像插件一样,是定期更新的,所以如果你直接编辑你的模板文件,当你更新它的时候,你就有可能失去你所有的自定义。

为了避免这种情况,你可以创建一个"子主题"。在Wordpress。2 -创建子主题

简单地说,这是一个很好的解决方案,可以避免在第1点遇到的问题;)

子主题继承父主题的函数,并允许您对其进行一些自定义/添加,而不会有丢失它的风险(因为当您更新父主题时,子主题不会被触及)。

这是一个完整的原理教程:https://developer.wordpress.org/themes/advanced-topics/child-themes/

注意:这需要一定程度的PHP知识,因为一个错误的更改可能会破坏你的网站。

3 -使用主题构建器

这是您的情况:在您的网站上安装了主题DIVI,它允许您自定义主题并创建自定义模板,而无需(或至少很少)开发所需的技能。

这就是为什么它被称为"主题构建器"。举几个例子:Divi, element,…

同样,在这种情况下,您可以直接使用主主题或创建子主题(强烈建议)。

说(写),回到你的情况,你发现你需要编辑的文件是"index.php"。我对此表示怀疑,因为它似乎是一个作者页面,所以更有可能是"author.php">

为什么?

因为事实上,所有的页面都是由"index.php"文件,因为它是中心模板文件,但如果与内容类型对应的模板存在于您的主题中,它将被使用(index.php只是一个备用方案,以防您的主题不包含任何特定情况下的自定义文件)。

有关模板层次结构的更多信息,请参阅本文:https://developer.wordpress.org/themes/basics/template-hierarchy/

但是,由于您使用了主题构建器,因此不需要编辑这些文件。

当你在使用Divi时,我建议你看一些关于主题构建器在实践中如何工作的教程。

简而言之,在Divi的模板生成器界面中,您可以创建模板,您可以影响到任何类型的内容。

这个视频应该会指引你正确的方向:https://www.elegantthemes.com/documentation/divi/the-divi-theme-builder/

希望有帮助。

相关内容

最新更新