我們的 WordPress 網站上的作者頁面之類的頁面缺少標簽。由于頁面是由默認模板 index.php 呈現的,因此我正在尋找一種在其中添加標簽的方法。下面是 index.php。像 echo $thumb 這樣的測驗代碼。$替代文本;似乎不起作用,不是因為變數不包含任何值,而是代碼本身不起作用。
<?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 >
%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();
uj5u.com熱心網友回復:
我會盡量在我的回答中更準確一點,評論允許我:)
當您想要自定義模板或創建自定義模板時,在 Wordpress 中,您有 3 種可能性:
1 - 錯誤的方式
您可以直接在主題中編輯模板檔案。
為什么這是錯誤的?因為模板和插件一樣會定期更新,所以如果您直接編輯模板的檔案,您可能會在更新時失去所有自定義設定。
為避免這種情況,您可以在 Wordpress 中創建我們稱為“子主題”的內容。
2 - 創建一個兒童主題
簡單地說,這是一個很好的解決方案,可以避免第 1 點遇到的問題;)
子主題繼承父主題的功能,并允許您對其進行一些自定義/添加而不會丟失它(因為當您更新父主題時,子主題不會被觸及)。
這里有一個完整的原理教程: https ://developer.wordpress.org/themes/advanced-topics/child-themes/
注意:這需要一定程度的 PHP 知識,因為錯誤的更改可能會破壞您的網站。
3 - 使用主題生成器
這是您的情況:在您的站點上安裝了主題 DIVI,它允許您自定義主題并創建自定義模板,而無需(或至少很少)開發技能。
這就是為什么它被稱為“主題構建器”。僅舉幾例:Divi,Elementor,...
同樣在這種情況下,您可以直接使用主主題或創建子主題(強烈推薦)。
話雖這么說(寫),回到你的情況,你發現你需要編輯的檔案是“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/
希望能幫助到你。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/531480.html
上一篇:讓一個類成為函式族的朋友
