I am working on changing how posts in slider on this website ( https://otwartakultura.org/ ) are linked. Now they can link only to post, but I would like to have possibility to link to other pages.
I have created a new field in ACF ('link'). I wrote if statement - when the 'link' field is not empty, use 'link' value; else: use post permalink. It works for 'link" value, but for "else" it shows homepage url not post url.
Current working code:
<article<?php
if (has_post_thumbnail()) {
?> style="background-image: url('<?php echo the_post_thumbnail_url('full'); ?>');"<?php
} ?>>
<a href="<?php echo get_permalink() ?>">
<header>
<div class="title-box">
<h1><?php echo get_the_title(); ?></h1>
<span class="read-more">czytaj więcej ></span>
</div></header></a>
</article>
Code I have tried to use:
<article<?php
if (has_post_thumbnail()) {
?> style="background-image: url('<?php echo the_post_thumbnail_url('full'); ?>');"<?php
} ?>>
<a href="<?php
if (get_field( 'link' ) !==0) {
echo get_field( 'link' ); }
else {
echo get_the_permalink();
} ?>">
<header>
<div class="title-box">
<h1><?php echo get_title(); ?></h1>
<span class="read-more">czytaj więcej ></span>
</div></header></a>
</article>
Please help:)
Above this:
<?php
while ( have_posts() ) {
the_post(); ?>
<article <?php
if (has_post_thumbnail()) {
?> style="background-image: url('<?php echo the_post_thumbnail_url('full'); ?>');"<?php
} ?>>
<a href="<?php echo get_permalink() ?>">
<header>
<div class="title-box">
<h1><?php echo get_the_title(); ?></h1>
<span class="read-more">czytaj więcej ></span>
</div></header></a>
</article>
<?php
} ?>
Paste this:
<article style="background-image: url('ADD_SOME_URL');">
<a href="google.com">
<header>
<div class="title-box">
<h1>Some title</h1>
<span class="read-more">czytaj więcej ></span>
</div></header></a>
</article>
So all Together will look like this:
<?php
if ( have_posts() ) {
?><div id="promobox"><div id="news" class="cycle-slideshow"
data-cycle-slides="> article"
data-cycle-pager-template="<span></span>">
<div class="cycle-pager"></div>
<article style="background-image: url('ADD_SOME_URL');">
<a href="google.com">
<header>
<div class="title-box">
<h1>Some title</h1>
<span class="read-more">czytaj więcej ></span>
</div></header></a>
</article>
<?php
while ( have_posts() ) {
the_post(); ?>
<article <?php
if (has_post_thumbnail()) {
?> style="background-image: url('<?php echo the_post_thumbnail_url('full'); ?>');"<?php
} ?>>
<a href="<?php echo get_permalink() ?>">
<header>
<div class="title-box">
<h1><?php echo get_the_title(); ?></h1>
<span class="read-more">czytaj więcej ></span>
</div></header></a>
</article>
<?php
} ?>
</div>
<a id="archive" href="/archiwum/">archiwum aktualności</a>
</div>
<?php
}
?>
Comment answer if some thing is not ok and edit hard coded article set background-image: url()
and title in <h1>
tag.
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.