0

Hello i create an archive.php custom for category-id (category-id.php) and use this code

    <?php
/**
* A Simple Category Template
*/
 
get_header(); ?> 
 
<section id="primary" class="site-content">
<div id="content" role="main">
 
<?php 
// Check if there are any posts to display
if ( have_posts() ) : ?>
 
<header class="archive-header">

</header>




 <?php
// The Loop
while ( have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
 <div><p>
     <?php if( get_field('telefono') ): ?>Telefono: <?php the_field('telefono'); ?>      
     <?php endif; ?>
     
     <?php if( get_field('email') ): ?> Email <?php the_field('email'); ?>    
     <br />
     <?php endif; ?>
     <?php if( get_field('indirizzo') ): ?> Indirizzo: <?php the_field('indirizzo'); ?> 
     <br /> 
     <?php endif; ?>
     <?php if( get_field('link_mappa') ): ?>
     <a href="<?php the_field('link_mappa'); ?>" target="_blank" rel="noopener noreferrer"> <img src="https://www.mondosup.it/wp-content/uploads/link_mappa_scuole_sup.png" width="250" /></a>
     <?php endif; ?>
</p>
</div>
 
<?php endwhile; 
 
else: ?>
<p>Sorry, no posts matched your criteria.</p>
 
 
<?php endif; ?>
</div>
</section>
 
 
<?php get_sidebar(); ?>
<?php get_footer(); ?>

I display under title ACF field. Now i'd like to put link on single post only if the post have content.

I try with some code but i cant'do that..is possibile?

1 Answer 1

0

Based on this question

Probably the easiest way would be:

<?php
// The Loop
while (have_posts()) : the_post(); ?>

    <?php if ('' !== get_post()->post_content): ?>
        <h2><a href="<?php the_permalink() ?>" rel="bookmark"
               title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php else: ?>
        <h2><?php the_title(); ?></h2>
    <?php endif; ?>
    <div><p>
            <?php if (get_field('telefono')): ?>Telefono: <?php the_field('telefono'); ?>
            <?php endif; ?>

            <?php if (get_field('email')): ?> Email <?php the_field('email'); ?>
                <br/>
            <?php endif; ?>
            <?php if (get_field('indirizzo')): ?> Indirizzo: <?php the_field('indirizzo'); ?>
                <br/>
            <?php endif; ?>
            <?php if (get_field('link_mappa')): ?>
                <a href="<?php the_field('link_mappa'); ?>" target="_blank" rel="noopener noreferrer"> <img
                            src="https://www.mondosup.it/wp-content/uploads/link_mappa_scuole_sup.png" width="250"/></a>
            <?php endif; ?>
        </p>
    </div>

<?php endwhile;

else: ?>
    <p>Sorry, no posts matched your criteria.</p>


<?php endif; ?>
    </div>
    </section>


<?php get_sidebar(); ?>
<?php get_footer(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.