PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 8, 2022

[FIXED] How to customize wordpress function: the tags?

 January 08, 2022     css, php, post, tags, wordpress     No comments   

Issue

In my wordpress post I have included tags with using wordpress function

<?php the_tags( $before, $sep, $after ); ?> 

My actual Css :

.postclass{
  margin:10px 0px 10px 0px;
  }

.posttag{
  font-size:10px;
  float:left;
  color:#212121;
  margin-right:15px;
  padding:5px;
  border-radius:2px;
  background:black;
}

In my template:

<div class="postclass">
     <?php the_tags( '<p class="posttag">', ',', '</p>' ); ?>
</div>

This gives me all tags in same black background .How can I get each tag text with black background each separated by comma?


Solution

Following an example from here: http://codex.wordpress.org/Function_Reference/get_the_tag_list

<div class="postclass">
     <?php the_tags( '<p class="posttag">', '</p><p class="posttag">', '</p>' ); ?>
</div>

This will wrap all tags individually in <p class="posttag">[link]</p>.

Something closer to your jsfiddle:

PHP

<?php the_tags( '<ul class="postclass"><li>', ',</li><li>', '</li></ul>' ); ?>

CSS

ul.postclass li {
    float: left;
}
ul.postclass li a {
    padding: 5px;
    background-color: black;
}

With the_tags() you cannot customize the <a>-tag itself as in your jsfiddle. You can only wrap it. For achieving this you'll have to work with get_the_terms() which will return an array of tag-objects you can post-process.



Answered By - HenningCash
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing