I have the following code:
<div class="carousel-caption">
<div class="carousel-caption-inner">
<p class="carousel-caption-title" data-postid="<?php the_ID(); ?>" data-excerpt="<?php echo esc_html( get_the_excerpt() ); ?>" data-published="<?php echo get_the_date(); ?>"><?php the_title(); ?></p>
<p class="carousel-caption-category"><?php echo get_the_category_list( ', ' ); ?></p>
</div>
</div>
This ( with some more PHP lines ) turns out into this :
What I need is to have that white box clickable and it should send to the post link/article.
I tried adding
<div onclick="window.open('newurl.html','mywindow');" style="cursor: pointer;"> </div>
but it didn't work, or I did something wrong.
Any suggestions?
You can wrap the inner div in an anchor element to turn it into a link, and remove the anchor that's currently wrapping the title.
This is valid in HTML5.
<div class="carousel-caption">
<a href="<?php the_permalink(); ?>">
<div class="carousel-caption-inner">
<p class="carousel-caption-title" data-postid="<?php the_ID(); ?>" data-excerpt="<?php echo esc_html( get_the_excerpt() ); ?>" data-published="<?php echo get_the_date(); ?>">
<?php the_title(); ?>
</p>
<p class="carousel-caption-category"><?php echo get_the_category_list( ', ' ); ?></p>
</div>
</a>
</div>
I was able to fix it myself.
This is how I solved it. ( i found this method somewhere, I did not invent it :D )
<div class="carousel-caption container1">
<span class="link-spanner"></span>
<div class="carousel-caption-inner">
<p class="carousel-caption-title" data-postid="<?php the_ID(); ?>" data-excerpt="<?php echo esc_html( get_the_excerpt() ); ?>" data-published="<?php echo get_the_date(); ?>"><?php the_title(); ?></p>
<p class="carousel-caption-category"><?php echo get_the_category_list( ', ' ); ?></p>
</div>
</div>
As you can see, I added this code below the div I wanted to make it clickable
<span class="link-spanner"></span>
Then using this CSS:
.container1{
position:absolute;
}
.link-spanner {
position:absolute;
width:100%;
height:100%;
top:0;
left: 0;
z-index: 1;
}
It made my white area become clickable and it takes me to the post link.
Thanks!
Related
The images are not showing in front-end. ACF settings screenshot
<?php
if( have_rows('how_it_works_functions') ):
$counter = 0;
while( have_rows('how_it_works_functions') ) : the_row();
$counter++;
?>
<div class="step<?php echo $counter; ?>">
<div class="row section-content">
<?php if($counter == 2) { ?>
<div class="col-md-8 image">
<img class="skip-lazy" src="<?php get_sub_field('how_it_works_functions_image')['url']; ?>" alt="<?php get_sub_field('how_it_works_functions_image')['alt']; ?>">
</div>
<div class="col-md-4 text">
<h3 data-aos="fade-left" data-aos-offset="300" data-aos-duration="1000"><?php the_sub_field('how_it_works_functions_name'); ?></h3>
<p data-aos="fade-up" data-aos-offset="100" data-aos-duration="1000"><?php the_sub_field('how_it_works_functions_description'); ?></p>
</div>
<?php } else { ?>
<div class="col-md-4 text">
<h3 data-aos="fade-right" data-aos-offset="300" data-aos-duration="1000"><?php the_sub_field('how_it_works_functions_name'); ?></h3>
<p data-aos="fade-up" data-aos-offset="100" data-aos-duration="1000"><?php the_sub_field('how_it_works_functions_description'); ?></p>
</div>
<div class="col-md-8 image">
<img class="skip-lazy" src="<?php get_sub_field('how_it_works_functions_image')['url']; ?>" alt="<?php get_sub_field('how_it_works_functions_image')['alt']; ?>">
</div>
<?php } ?>
</div>
</div>
<?php
endwhile;
endif;
?>
I already check the var_dump and it is getting the correct url but I still have broken image in front-end.
You need to echo that field.
Like this based on your code:
<img class="skip-lazy" src="<?php echo get_sub_field( 'how_it_works_functions_image' )['url']; ?>" alt="<?php echo get_sub_field( 'how_it_works_functions_image' )['alt']; ?>">
Alternative effective way:
<?php
$image = get_sub_field( 'how_it_works_functions_image' );
?>
<img class="skip-lazy" src="<?php echo esc_attr( $image['url'] ); ?>" alt="<?php echo esc_attr( $image['alt'] ); ?>">
Try out the above solution and let me know if it works or not.
I'd like to display titles and thumbnails of my posts using this code snippet, which I'm unable to do so.
How do I solve this problem?
Code
<div class="row">
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
<div class="col-md-4">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="<?php the_post_thumbnail('thumbnail');?>
</div>
echo '<h5 class=" card-title ">'.get_the_title().'</h5 >';?>
<p class="card-text "><?php echo get_the_excerpt(); ?></p>
<a href="<?php the_permalink();?>" class="btn btn-primary"> Continue Reading »
</a>
</div>
<?php
endwhile;
else :
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;?>
</div>
It seems you might have PHP codes in your HTML. Maybe, try this:
<div class="row">
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post(); $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); ?>
<div class="col-md-4">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="<?php the_post_thumbnail('thumbnail'); ?>
</div>
<?php echo '<h5 class=" card-title ">' . get_the_title() . '</h5 >'; ?>
<p class="card-text"><?php echo get_the_excerpt(); ?></p>
Continue Reading »
</div>
<?php endwhile;
else :
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
?>
</div>
If it did not solve your problem, maybe look into your syntax errors/warnings.
You might consider indenting your codes, it would help you find errors without looking into error logs.
How can I move the logo before the Site Title in WordPress?
I have this code so far:
function smartline_display_site_title() { ?>
<div class='my-logo'>
<img src="<?php bloginfo('template_directory');?>/images/AA.gif">
</div>
<a href="<?php echo esc_url(home_url('/')); ?>"
title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"
rel="home">
<h1 class="site-title"><?php bloginfo('name'); ?></h1>
</a>
<?php
}
Set or Add display: inline-block to .my-logo and .site-title
.my-logo{
display: inline-block;
}
.site-title{
display: inline-block;
}
Based on your website you can move your image to the left
<img src="http://abraham-accountants.co.uk/wp-content/themes/smartline-lite/images/AA.gif" style="float: left;">
DEMO HERE
Navigate to Smartline Lite: header.php file and change the below given code.
Let me know if it works ....
<div id="logo" class="clearfix">
<?php do_action('smartline_site_title'); ?>
<img src="image location" alt="alt title" height="auto" width="auto">
<?php // Display Tagline on header if activated
if ( isset($theme_options['header_tagline']) and $theme_options['header_tagline'] == true ) : ?>
<h2 class="site-description"><?php echo bloginfo('description'); ?></h2>
<?php endif; ?>
</div>
<div id="header-content" class="clearfix">
<?php get_template_part('inc/header-content'); ?>
</div>
</header>
I'm having a very strange issue that I can't figure out. I'm working on a custom theme in wordpress and I've got a div with an image and another icon image inside.
I'm trying to make both the whole image and the icon image within it a link.
The issue is that when I try to put a link around the whole div, Wordpress closed the link prematurely and then adds a second link - neither of which are actually enclosing my div.
If I change the div to a span, it will let me wrap it in a link. Why?! What is going on and how and I turn off this 'feature'?
Here is the selected code in my template file:
<a href="<?php the_permalink(); ?>">
<div class="img">
<?php if (has_post_thumbnail()): ?>
<img style="display: none;" src="<?php echo $image_attributes[0]; ?>" alt="<?php echo strip_tags(get_the_title()); ?>">
<span class="zoom hide-ie"><i class="fa fa-search"></i></span>
<?php endif; ?>
<?php if ($categories): ?>
<?php echo $categories[0]->cat_name?>
<?php endif; ?>
<div class="background" style="background-image: url('<?php echo $image_attributes[0]; ?>');"></div>
</div>
</a>
However, this is the code that is being outputted to the browser:
<a href="http:somelink">
</a>
<div class="img">
<a href="http:somelink">
<img style="display: none;" src="imagelink.jpg" alt="This isn’t our beautiful contest – how did we get here?">
<span class="zoom hide-ie"><i class="fa fa-search"></i></span>
</a>
Agency Mojo
<div class="background" style="background-image: url('http://imagelink.jpg');"></div>
</div>
So as you can see, it's closing the link immediately, and then adding another link inside of the `
Any help would be amazing as I've seen this question asked but not answered in a few other places including here on this site
I generally try to avoid nesting anchor tags. Perhaps something like this would work better.
<div class="img">
<?php if ( has_post_thumbnail() ): ?>
<a href="<?php the_permalink(); ?>">
<img style="display: none;" src="<?php echo $image_attributes[0]; ?>" alt="<?php echo strip_tags(get_the_title()); ?>" />
<span class="zoom hide-ie"><i class="fa fa-search"></i></span>
</a>
<?php endif; ?>
<?php if ($categories): ?>
<a href="<?php echo get_category_link($categories[0]-> term_id ); ?>" class="category-link">
<?php echo $categories[0]->cat_name; ?>
</a>
<?php endif; ?>
<a href="<?php the_permalink(); ?>">
<div class="background" style="background-image: url('<?php echo $image_attributes[0]; ?>');"></div>
</a>
</div>
I want to show only the articles from current category, where I am at the moment. I wrote code for a look of every post. I use plugin Advanced Custom Fields, which can create more fields for new post in administration.
Now I have this code:
<?php $the_query = new WP_Query( 'cat=' ); ?>
<div id="category-window">
<div id="others" style="width:<?php echo $wp_query->post_count*400?>px">
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="other-box">
<div id="other-name"><?php the_title(); ?></div>
<div id="other-left"><?php the_field(misto); ?><br><?php the_field(rok); ?></div>
<div id="other-right"><?php foreach((get_the_category()) as $category) {echo $category->cat_name . '<br>';} ?></div>
<div id="other-line"></div>
<div id="other-about"><?php the_field(dej); ?></div>
<div id="other-gallery">
<a class="other-photo fancybox" rel="<?php the_title(); ?>" href="<?php the_field(obrazek1); ?>">
<img src="<?php the_field(obrazek1); ?>" style="width: 85px; height: 50px;">
</a>
<a class="other-photo fancybox" rel="<?php the_title(); ?>" href="<?php the_field(obrazek2); ?>">
<img src="<?php the_field(obrazek2); ?>" style="width: 85px; height: 50px;">
</a>
<a class="other-photo fancybox" rel="<?php the_title(); ?>" href="<?php the_field(obrazek3); ?>">
<img src="<?php the_field(obrazek3); ?>" style="width: 85px; height: 50px;">
</a>
</div>
</div><?php endwhile; ?>
</div>
</div>
And the problem is just in the first line, I have no idea, what to write behind "cat=", when I want to do it automatically. For example when I am in category "cars", it automatically show only the articles from this category.
Thank you for every help :)
Something like this should work :
<?php
$postid = get_the_ID();
$catid = get_the_category( $postid );
?>
That should get you the cat id.