简体   繁体   中英

Trying to include a <a href> on an echo on WordPress, but it doesn't work (PHP)

PHP is not my best, so I've been having a hard time trying to include a on a php slider. To make easier to understand what I'm talking about, please take a look at my website:

https://sooretamaemfoco.com.br/

You can notice that in the header there are a big slider on the left, and 4 mini sliders on the right. The ONLY place in my home page that doesn't have a hiperlink to the post when we click in the image is those big ones.

See screenshot

When you click on the picture, it doesn't have a href. The href is just on the title below. I've tried multiple ways to include aa href on the code, however it doesn't work.

Please take a look at the excerpt of code:

 } 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>';

The part that I've been trying to change is this one: echo '<div class="image-slider" title="'.the_title_attribute('echo=0').'"'.' style="background-image:url('."'".esc_url($image_attributes[0])."'".')">'; echo '<div class="image-slider" title="'.the_title_attribute('echo=0').'"'.' style="background-image:url('."'".esc_url($image_attributes[0])."'".')">';

Can somebody please give me a handle on this? It's highly appreciated. Thanks in advance!


EDIT:

I've posted the whole code in the following link: https://pastebin.com/QFMSMdZy

Try this:

} 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>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM