在 WordPress 的回声中包含一个,但它不起作用(PHP),php,html,wordpress"/>

首页 > 解决方案 > 试图在 WordPress 的回声中包含一个,但它不起作用(PHP)

问题描述

PHP 不是我最好的,所以我一直很难在 php 滑块上包含一个。为了更容易理解我在说什么,请查看我的网站:

https://sooretamaemfoco.com.br/

您可以注意到,在标题中,左侧有一个大滑块,右侧有 4 个迷你滑块。当我们点击图片时,我的主页中唯一没有指向帖子的超链接的地方是那些大的。

看截图

当您单击图片时,它没有href。href 就在下面的标题上。我尝试了多种方法在代码中包含 aa href,但它不起作用。

请看一下代码的摘录:

} elseif ($magbook_slider_design_layout=='small-slider'){
    echo '<div class="small-slider">';
    } else {
        echo  '<div class="multi-slider">';
    }
    echo  '<ul class="slides">';
    while ($query->have_posts()):$query->the_post();
        $attachment_id = get_post_thumbnail_id();
        $image_attributes = wp_get_attachment_image_src($attachment_id,'magbook_slider_image');
        $excerpt = get_the_excerpt();
            echo '<li>';
            if ($image_attributes) {
                echo  '<div class="image-slider" title="'.the_title_attribute('echo=0').'"' .' style="background-image:url(' ."'" .esc_url($image_attributes[0])."'" .')">';
            }else{
                echo  '<div class="image-slider">';
            }
            echo  '<article class="slider-content">';
            if ($image_attributes != '' || $excerpt != '') {
                echo  '<div class="slider-text-content">';

                if($entry_format_meta_blog != 'hide-meta' ){
                    echo  '<div class="entry-meta">';
                        do_action('magbook_post_categories_list_id');
                    echo '</div> <!-- end .entry-meta -->';
                }

                $remove_link = $magbook_settings['magbook_slider_link'];
                    if($remove_link == 0){

                            echo '<h2 class="slider-title"><a href="'.esc_url(get_permalink()).'" title="'.the_title_attribute('echo=0').'" rel="bookmark">'.get_the_title().'</a></h2><!-- .slider-title -->';

                    }else{
                        echo '<h2 class="slider-title">'.get_the_title().'</h2><!-- .slider-title -->';
                    }

                    if ($excerpt != '') {
                        echo '<p class="slider-text">'.wp_strip_all_tags( get_the_excerpt(), true ).'</p><!-- end .slider-text -->';
                    }
                if($entry_format_meta_blog != 'hide-meta' ){
                    echo  '<div class="entry-meta">';
                    echo '<span class="author vcard"><a href="'.get_author_posts_url( get_the_author_meta( 'ID' ) ).'" title="'.the_title_attribute('echo=0').'"><i class="fa fa-user-o"></i> ' .esc_attr(get_the_author()).'</a></span>';
                    printf( '<span class="posted-on"><a href="%1$s" title="%2$s"><i class="fa fa-calendar-o"></i> %3$s</a></span>',
                                        esc_url(get_the_permalink()),
                                        esc_attr( get_the_time(get_option( 'date_format' )) ),
                                        esc_attr( get_the_time(get_option( 'date_format' )) )
                                    );

                    if ( comments_open()) { ?>
                            <span class="comments">
                            <?php comments_popup_link( __( '<i class="fa fa-comment-o"></i> No Comments', 'magbook' ), __( '<i class="fa fa-comment-o"></i> 1 Comment', 'magbook' ), __( '<i class="fa fa-comment-o"></i> % Comments', 'magbook' ), '', __( 'Comments Off', 'magbook' ) ); ?> </span>
                    <?php }
                    echo  '</div> <!-- end .entry-meta -->';
                }
                echo  '</div><!-- end .slider-text-content -->';
            }
            if( $magbook_settings['magbook_slider_button'] == 0 && $magbook_tag_text !='' ){
                echo '<div class="slider-buttons">';
                echo  '<a title='.'"'.the_title_attribute('echo=0'). '"'. ' '.'href="'.esc_url(get_permalink()).'"'.' class="btn-default">'.esc_attr($magbook_tag_text).'</a>';

                echo  '</div><!-- end .slider-buttons -->';
            }
            echo '</article><!-- end .slider-content --> ';
            echo '</div><!-- end .image-slider -->
            </li>';

我一直试图改变的部分是这个:echo '<div class="image-slider" title="'.the_title_attribute('echo=0').'"' .' style="background-image:url(' ."'" .esc_url($image_attributes[0])."'" .')">';

有人可以帮我处理一下吗?这是高度赞赏。提前致谢!


编辑:

我在以下链接中发布了整个代码: https ://pastebin.com/QFMSMdZy

标签: phphtmlwordpress

解决方案


尝试这个:

} elseif ($magbook_slider_design_layout=='small-slider'){
    echo '<div class="small-slider">';
    } else {
        echo  '<div class="multi-slider">';
    }
    echo  '<ul class="slides">';
    while ($query->have_posts()):$query->the_post();
        $attachment_id = get_post_thumbnail_id();
        $image_attributes = wp_get_attachment_image_src($attachment_id,'magbook_slider_image');
        $excerpt = get_the_excerpt();
            echo '<li>';
            if ($image_attributes) {
                echo  '<a href=" ' . get_the_permalink() . ' "><div class="image-slider" title="'.the_title_attribute('echo=0').'"' .' style="background-image:url(' ."'" .esc_url($image_attributes[0])."'" .')"> ';
            }else{
                echo  '<a href=" ' . get_the_permalink() . ' "><div class="image-slider">';
            }
            echo  '<article class="slider-content">';
            if ($image_attributes != '' || $excerpt != '') {
                echo  '<div class="slider-text-content">';

                if($entry_format_meta_blog != 'hide-meta' ){
                    echo  '<div class="entry-meta">';
                        do_action('magbook_post_categories_list_id');
                    echo '</div> <!-- end .entry-meta -->';
                }

                $remove_link = $magbook_settings['magbook_slider_link'];
                    if($remove_link == 0){

                            echo '<h2 class="slider-title"><a href="'.esc_url(get_permalink()).'" title="'.the_title_attribute('echo=0').'" rel="bookmark">'.get_the_title().'</a></h2><!-- .slider-title -->';

                    }else{
                        echo '<h2 class="slider-title">'.get_the_title().'</h2><!-- .slider-title -->';
                    }

                    if ($excerpt != '') {
                        echo '<p class="slider-text">'.wp_strip_all_tags( get_the_excerpt(), true ).'</p><!-- end .slider-text -->';
                    }
                if($entry_format_meta_blog != 'hide-meta' ){
                    echo  '<div class="entry-meta">';
                    echo '<span class="author vcard"><a href="'.get_author_posts_url( get_the_author_meta( 'ID' ) ).'" title="'.the_title_attribute('echo=0').'"><i class="fa fa-user-o"></i> ' .esc_attr(get_the_author()).'</a></span>';
                    printf( '<span class="posted-on"><a href="%1$s" title="%2$s"><i class="fa fa-calendar-o"></i> %3$s</a></span>',
                                        esc_url(get_the_permalink()),
                                        esc_attr( get_the_time(get_option( 'date_format' )) ),
                                        esc_attr( get_the_time(get_option( 'date_format' )) )
                                    );

                    if ( comments_open()) { ?>
                            <span class="comments">
                            <?php comments_popup_link( __( '<i class="fa fa-comment-o"></i> No Comments', 'magbook' ), __( '<i class="fa fa-comment-o"></i> 1 Comment', 'magbook' ), __( '<i class="fa fa-comment-o"></i> % Comments', 'magbook' ), '', __( 'Comments Off', 'magbook' ) ); ?> </span>
                    <?php }
                    echo  '</div> <!-- end .entry-meta -->';
                }
                echo  '</div><!-- end .slider-text-content -->';
            }
            if( $magbook_settings['magbook_slider_button'] == 0 && $magbook_tag_text !='' ){
                echo '<div class="slider-buttons">';
                echo  '<a title='.'"'.the_title_attribute('echo=0'). '"'. ' '.'href="'.esc_url(get_permalink()).'"'.' class="btn-default">'.esc_attr($magbook_tag_text).'</a>';

                echo  '</div><!-- end .slider-buttons -->';
            }
            echo '</article><!-- end .slider-content --> ';
            echo '</div></a><!-- end .image-slider -->
            </li>';

推荐阅读