最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - WordPress template file if else issue

programmeradmin3浏览0评论

I'm trying to show information on a template page I made in WordPress. I am trying to show posts with GPS data if they don't have a tag that says no-gps. I want to check which pages are missing the GPS data. Is there an easy way to do that? I'm thinking of using an if else statement to add a mark so that I can do a search for the pages in WordPress and manually add the missing GPS data. Any ideas are greatly appreciated though. How do I put the extra if else statement into the current if statement? Here's my code:

<?php if(!has_tag('no-gps')){
//the_tags();
echo '<span id="topgps"><strong>GPS</strong>: '; 
the_field("GPS");
echo '</span>';
} ?>

I want to write:

If there is a page that doesn't have the no-gps tag, with GPS data, show the value. This works now.

New bit: But if the GPS value is missing (no value at all) on a page that doesn't have the no-gps tag show a star ★ instead.

I'm trying to show information on a template page I made in WordPress. I am trying to show posts with GPS data if they don't have a tag that says no-gps. I want to check which pages are missing the GPS data. Is there an easy way to do that? I'm thinking of using an if else statement to add a mark so that I can do a search for the pages in WordPress and manually add the missing GPS data. Any ideas are greatly appreciated though. How do I put the extra if else statement into the current if statement? Here's my code:

<?php if(!has_tag('no-gps')){
//the_tags();
echo '<span id="topgps"><strong>GPS</strong>: '; 
the_field("GPS");
echo '</span>';
} ?>

I want to write:

If there is a page that doesn't have the no-gps tag, with GPS data, show the value. This works now.

New bit: But if the GPS value is missing (no value at all) on a page that doesn't have the no-gps tag show a star ★ instead.

Share Improve this question asked Feb 23, 2022 at 7:45 Glen Charles RowellGlen Charles Rowell 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Try changing the code for the line with the_field("GPS"); to:

$gps = get_field("GPS");
echo ($gps == '') ? '*' : $gps;
发布评论

评论列表(0)

  1. 暂无评论