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

taxonomy - Adding Advanced Custom Fields to posts without hyperlinks

programmeradmin0浏览0评论

I'm trying to display custom fields on my post like this:

<ul>
                    <li><?php the_field('name_of_placement'); ?></li>
                    <?php
                            $terms = get_the_terms( get_the_ID(), 'country' );
                            $names = array();

                            foreach ( $terms as $term ) {
                                $names[] = $term->name;
                            }

                            echo '<li>' . implode( ', ', $names ) . '<li>';
                    ?>
                    <?php
                            $terms = get_the_terms( get_the_ID(), 'timeframe' );
                            $names = array();

                            foreach ( $terms as $term ) {
                                $names[] = $term->name;
                            }

                            echo '<li>' . implode( ', ', $names ) . '<li>';
                    ?>
                    <li><?php the_terms( get_the_ID(), 'types_of_healthcare_placement' ); ?></li>

                </ul>

The problem is like this form creates an extra blank <li> item after each field.

/

How can i fix it?

I'm trying to display custom fields on my post like this:

<ul>
                    <li><?php the_field('name_of_placement'); ?></li>
                    <?php
                            $terms = get_the_terms( get_the_ID(), 'country' );
                            $names = array();

                            foreach ( $terms as $term ) {
                                $names[] = $term->name;
                            }

                            echo '<li>' . implode( ', ', $names ) . '<li>';
                    ?>
                    <?php
                            $terms = get_the_terms( get_the_ID(), 'timeframe' );
                            $names = array();

                            foreach ( $terms as $term ) {
                                $names[] = $term->name;
                            }

                            echo '<li>' . implode( ', ', $names ) . '<li>';
                    ?>
                    <li><?php the_terms( get_the_ID(), 'types_of_healthcare_placement' ); ?></li>

                </ul>

The problem is like this form creates an extra blank <li> item after each field.

http://electives-abroad/custom-field-test/

How can i fix it?

Share Improve this question edited Apr 29, 2019 at 13:08 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Apr 29, 2019 at 12:33 Draws Ren GundamDraws Ren Gundam 251 gold badge2 silver badges6 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

The code seems to be good to me, may be try to correct this line :

echo '<li>' . implode( ', ', $names ) . '<li>';

To :

echo '<li>' . implode( ', ', $names ) . '</li>';

You forget to close the li tag.

Same thing here :

echo '<li>' . implode( ', ', $names ) . '</li>';
发布评论

评论列表(0)

  1. 暂无评论