您好,专业编码员。 抱歉我的英语不好,我对代码一无所知。
我想在blog-layout.php文件中为每个帖子项添加permlink。 它与类别页面有关。
我在那里找到了post loop,并想知道如何添加永久链接。
参考网站:http://blog.lgchem.com/category/company-story/
由于我不是开发人员,所以一步一步的说明将真正受到赞赏。
// Start the main loop
while ( have_posts() ): the_post();
// Set the time stamps for timeline month/year check
$alignment_class = '';
if( $blog_layout == 'timeline' ) {
$post_timestamp = get_the_time( 'U' );
$post_month = date( 'n', $post_timestamp );
$post_year = get_the_date( 'o' );
$current_date = get_the_date( 'o-n' );
// Set the correct column class for every post
if( $post_count % 2 ) {
$alignment_class = 'fusion-left-column';
} else {
$alignment_class = 'fusion-right-column';
}
// Set the timeline month label
if ( $prev_post_month != $post_month ||
$prev_post_year != $post_year
) {
if( $post_count > 1 ) {
echo '</div>';
}
echo sprintf( '<h3 class="fusion-timeline-date">%s</h3>', get_the_date( Avada()->settings->get( 'timeline_date_format' ) ) );
echo '<div class="fusion-collapse-month">';
}
}
// Set the has-post-thumbnail if a video is used. This is needed if no featured image is present.
$thumb_class = '';
if ( get_post_meta( get_the_ID(), 'pyre_video', true ) ) {
$thumb_class = ' has-post-thumbnail';
}
$post_classes = sprintf( '%s %s %s post fusion-clearfix', $post_class, $alignment_class, $thumb_class );
ob_start();
post_class( $post_classes );
$post_classes = ob_get_clean();
//发布项目
echo sprintf( '<div id="post-%s" %s>', get_the_ID(), $post_classes);
// Add an additional wrapper for grid layout border
if ( $blog_layout == 'grid' ) {
echo '<div class="fusion-post-wrapper">';
}
// Get featured images for all but large-alternate layout
if ( Avada()->settings->get( 'featured_images' ) &&
$blog_layout == 'large-alternate'
) {
get_template_part( 'new-slideshow' );
}
// Get the post date and format box for alternate layouts
if ( $blog_layout == 'large-alternate' ||
$blog_layout == 'medium-alternate'
) {
echo '<div class="fusion-date-and-formats">';
/**
* avada_blog_post_date_adn_format hook
*
* @hooked avada_render_blog_post_date - 10 (outputs the HTML for the date box)
* @hooked avada_render_blog_post_format - 15 (outputs the HTML for the post format box)
*/
do_action( 'avada_blog_post_date_and_format' );
echo '</div>';
}
// Get featured images for all but large-alternate layout
if ( Avada()->settings->get( 'featured_images' ) &&
$blog_layout != 'large-alternate'
) {
get_template_part( 'new-slideshow' );
}
// post-content-wrapper only needed for grid and timeline
if ( $blog_layout == 'grid' ||
$blog_layout == 'timeline'
) {
echo '<div class="fusion-post-content-wrapper">';
}
// Add the circles for timeline layout
if ( $blog_layout == 'timeline' ) {
echo '<div class="fusion-timeline-circle"></div>';
echo '<div class="fusion-timeline-arrow"></div>';
}
echo '<div class="fusion-post-content">';
// Render the post title
echo avada_render_post_title( get_the_ID() );
// Render post meta for grid and timeline layouts
if ( $blog_layout == 'grid' ||
$blog_layout == 'timeline'
) {
echo avada_render_post_metadata( 'grid_timeline' );
if ( ( Avada()->settings->get( 'post_meta' ) && ( ! Avada()->settings->get( 'post_meta_author' ) || ! Avada()->settings->get( 'post_meta_date' ) || ! Avada()->settings->get( 'post_meta_cats' ) || ! Avada()->settings->get( 'post_meta_tags' ) || ! Avada()->settings->get( 'post_meta_comments' ) || ! Avada()->settings->get( 'post_meta_read' ) ) ) &&
Avada()->settings->get( 'excerpt_length_blog' ) > 0
) {
echo '<div class="fusion-content-sep"></div>';
}
// Render post meta for alternate layouts
} elseif( $blog_layout == 'large-alternate' ||
$blog_layout == 'medium-alternate'
) {
echo avada_render_post_metadata( 'alternate' );
}
echo '<div class="fusion-post-content-container">';
/**
* avada_blog_post_content hook
*
* @hooked avada_render_blog_post_content - 10 (outputs the post content wrapped with a container)
*/
do_action( 'avada_blog_post_content' );
do_action( 'avada_blog_post_date_and_format' );
echo '</div>';
echo '</div>'; // end post-content
if( $blog_layout == 'medium' ||
$blog_layout == 'medium-alternate'
) {
echo '<div class="fusion-clearfix"></div>';
}
// Render post meta data according to layout
if ( ( Avada()->settings->get( 'post_meta' ) && ( ! Avada()->settings->get( 'post_meta_author' ) || ! Avada()->settings->get( 'post_meta_date' ) || ! Avada()->settings->get( 'post_meta_cats' ) || ! Avada()->settings->get( 'post_meta_tags' ) || ! Avada()->settings->get( 'post_meta_comments' ) || ! Avada()->settings->get( 'post_meta_read' ) ) ) ) {
echo '<div class="fusion-meta-info">';
if ( $blog_layout == 'grid' ||
$blog_layout == 'timeline'
) {
// Render read more for grid/timeline layouts
echo '<div class="fusion-alignleft">';
if ( ! Avada()->settings->get( 'post_meta_read' ) ) {
$link_target = '';
if( fusion_get_page_option( 'link_icon_target', get_the_ID() ) == 'yes' ||
fusion_get_page_option( 'post_links_target', get_the_ID() ) == 'yes' ) {
$link_target = ' target="_blank"';
}
echo sprintf( '<a href="%s" class="fusion-read-more"%s>%s</a>', get_permalink(), $link_target, apply_filters( 'avada_blog_read_more_link', __( 'Read More', 'Avada' ) ) );
}
echo '</div>';
// Render comments for grid/timeline layouts
echo '<div class="fusion-alignright">';
if ( ! Avada()->settings->get( 'post_meta_comments' ) ) {
if( ! post_password_required( get_the_ID() ) ) {
comments_popup_link('<i class="fusion-icon-bubbles"></i> ' . __( '0', 'Avada' ), '<i class="fusion-icon-bubbles"></i> ' . __( '1', 'Avada' ), '<i class="fusion-icon-bubbles"></i> ' . '%' );
} else {
echo sprintf( '<i class="fusion-icon-bubbles"></i> %s', __( 'Protected', 'Avada' ) );
}
}
echo '</div>';
} else {
// Render all meta data for medium and large layouts
if ( $blog_layout == 'large' || $blog_layout == 'medium' ) {
echo avada_render_post_metadata( 'standard' );
}
// Render read more for medium/large and medium/large alternate layouts
echo '<div class="fusion-alignright">';
if ( ! Avada()->settings->get( 'post_meta_read' ) ) {
$link_target = '';
if( fusion_get_page_option( 'link_icon_target', get_the_ID() ) == 'yes' ||
fusion_get_page_option( 'post_links_target', get_the_ID() ) == 'yes' ) {
$link_target = ' target="_blank"';
}
echo sprintf( '<a href="%s" class="fusion-read-more"%s>%s</a>', get_permalink(), $link_target, __( 'Read More', 'Avada' ) );
}
echo '</div>';
}
echo '</div>'; // end meta-info
}
if ( $blog_layout == 'grid' ||
$blog_layout == 'timeline'
) {
echo '</div>' ;
// end post-content-wrapper
}
if ( $blog_layout == 'grid' ) {
echo '</div>'; // end post-wrapper
}
echo '</div>'; // end post
// post item
// Adjust the timestamp settings for next loop
if ( $blog_layout == 'timeline' ) {
$prev_post_timestamp = $post_timestamp;
$prev_post_month = $post_month;
$prev_post_year = $post_year;
$post_count++;
}
endwhile; // end have_posts()
if ( $blog_layout == 'timeline' &&
$post_count > 1
) {
echo '</div>';
}
echo '</div>'; // end posts-container
答案 0 :(得分:0)
你可以采取几种方法。
您可以将其链接到Wordpress CMS后端中您喜欢的任何内容。
如果要修改所有项目的源代码,可以将div包装成以下内容:
<a href="<?php the_permalink(); ?>">
如果您要更改源代码,我建议您使用子主题,在这种情况下,当您的主题(Avada)更新时,您的更改不会消失。
详细了解Wordpress文档的永久链接: https://codex.wordpress.org/Function_Reference/the_permalink https://codex.wordpress.org/Using_Permalinks