I have a post loop on wordpress where I want an anchor to be wrapped around the main project posts container so they can click and open the link on the whole element and for ipads it works better as a click.

In my loop I have a function that gets categories for that post and outputs them into the container but for some reason when I try and wrap the around the div it closes it at the top like so:

Here is how I have setup the inner loop for the listed posts:

<article id="post-<?php the_ID(); ?>" class="global-post text-center col-1-3 <?php _mbbasetheme_get_classes(); ?> <?php _mbbasetheme_get_categories(); ?>">
        <!-- the anchor wrap -->
        <a class="link-wrap" href="<?php echo get_permalink(); ?>">
            <div class="post-inner" style="background-image:url(<?php _mbbasetheme_post_thumbnail_helper(); ?>);">
                <div class="post-meta-info">
                    <div class="categories">
                        <?php
                        _mbbasetheme_get_category_loop();    
                        ?>
                    </div>
                    <h2><?php the_title(); ?></h2>
                    <?php if ( in_category( '4' ) ) { ?>
                        <p><?php echo wp_trim_words( get_the_content(), 40, '...' ); ?></p>
                        <div class="share">
                            <a class="sharer" href="#">
                                <span class="icon icon_Share"></span> 
                                <span class="line"></span> 
                                <span class="text">Share</span>
                            </a>
                        </div>
                        <div class="social">
                            <h1>Share</h1>
                            <a href="#" class="close">x</a>
                            <ul>
                                <li><a id="facebook" class="icon icon_Facebook" href="#"><div class="left">Share</div></a></li>
                                <li><a id="twitter" class="icon icon_Twitter" href="#"><div class="left">Tweet</div></a></li>
                                <li><a id="linkedin" class="icon icon_LinkedIn" href="#"></a></li>
                                <li><a id="email" class="icon icon_Email" href="#"></a></li>
                            </ul>
                        </div>
                    <?php } elseif ( in_category( '5' ) ) { ?>
                        <?php _mbbasetheme_people_social(); ?>
                    <?php } else { ?>
                    <?php } ?>
                </div>
            </div>
    </a>    
</article>

Here is the _mbbasetheme_get_category_loop():

/**
 * Get categories from a post and render on the post loop
 */
if ( ! function_exists( '_mbbasetheme_get_category_loop' ) ) :
function _mbbasetheme_get_category_loop() {
global $post;
$categories = get_the_category($post->ID);
//var_dump($categories);
foreach($categories as $category) {
        echo '<div class="cat"><a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a></div>';
    }
}
endif;

Here is the _mbbasetheme_people_social() function:

/**
 * People social links
 */
if ( ! function_exists( '_mbbasetheme_people_social' ) ) :
function _mbbasetheme_people_social() {
    $facebookPeople = get_field('profile_facebook');
    $twitterPeople = get_field('profile_twitter');
    $linkedInPeople =  get_field('profile_linkedin');
    if ($facebookPeople) {
            echo '<ul id="social-area"><li><a target="_blank" href="' . $facebookPeople . '" class="icon icon_Facebook"></a></li>';
    }
    if ($twitterPeople) {
            echo '<li><a target="_blank" href="' . $twitterPeople . '" class="icon icon_Twitter"></a></li>';
    }
    if ($linkedInPeople) {
            echo '<li><a target="_blank" href="' . $linkedInPeople . '" class="icon icon_LinkedIn"></a></li></ul>';
    }
}
endif;

It only seems to work when I delete term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.' out of _mbbasetheme_get_category_loop() function.

Does anyone know what this could be? When I view source it works fine so it actually wraps it around the div just when viewing on browser it wont work.

Thanks

Read more here: Why is my WordPress post loop auto closing anchor tags and not wrapping the element with it?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , , , ,

Wordpress related questions and answers: