• Resolved geekgirl

    (@geekgirl)


    Hi everyone…

    I am trying to add a tag cloud to my sidebar using the following code

    <?php if ( function_exists('wp_tag_cloud') ) : ?>
    <?php wp_tag_cloud('smallest=8&largest=22'); ?>
    </ul>
    </li>
    <?php endif; ?>

    The cloud shows up but it’s causing validation errors with the “li” and “ul” tags..I’ve tried playing around with it for days and can’t figure it out…Because I don’t understand the code. The following link shows my original sidebar code https://wordpress.pastebin.ca/807114. I want to add the tag cloud under this code that is on line 52 <h2 class="sidebartitle"><img src="https://lovelatoya.com/wp-content/uploads/2007/11/cat.gif" alt="categories"/></h2>
    Could someone please tell me the correct way to do this so that my code will validate?

Viewing 8 replies - 1 through 8 (of 8 total)
  • <?php if ( function_exists('wp_tag_cloud') ) : ?>
    <?php wp_tag_cloud('smallest=8&largest=22'); ?>
    <?php endif; ?>

    No need for ul etc. as by default there are none.

    If want ul etc. then use

    <?php if ( function_exists('wp_tag_cloud') ) : ?>
    <?php wp_tag_cloud('smallest=8&largest=22&format=list'); ?>
    <?php endif; ?>

    Again, no need to manually add in ul li etc. Look in source code and see what’s been churned out, then use that to style it.

    ??

    Thread Starter geekgirl

    (@geekgirl)

    Thanks for your response…but that does not solve my issue. The problem is I don’t understand the “li” and “ul” tags very well…so when I add this code

    <?php if ( function_exists('wp_tag_cloud') ) : ?>
    <?php wp_tag_cloud('smallest=8&largest=22&format=list'); ?>
    <?php endif; ?>

    to my sidebar…I get 8 validation errors concerning the “li” and “ul” tags which can be found here
    https://validator.w3.org/check?uri=http%3A%2F%2Flovelatoya.com&charset=%28detect+automatically%29&doctype=Inline&group=0

    I know that the tag cloud code I’m adding is correct…I just don’t know how to add it to my existing code so that it will still validate. Any suggestions?

    Thread Starter geekgirl

    (@geekgirl)

    anyone?

    Have you taken the tag cloud out for good now? Can’t see it on that page, and the page validates.

    Copy the relevant HTML and paste it here if you still want to get it to work.

    Thread Starter geekgirl

    (@geekgirl)

    Yes I took the tag cloud out because I couldn’t figure it out. Now I have just added the following code back to my sidebar

    <?php if ( function_exists('wp_tag_cloud') ) : ?>
    <?php wp_tag_cloud('smallest=8&largest=22'); ?>
    <?php endif; ?>

    and I am getting 2 validation errors.

    https://validator.w3.org/check?uri=http%3A%2F%2Flovelatoya.com&charset=%28detect+automatically%29&doctype=Inline&group=0
    Here is my sidebar code now…
    https://wordpress.pastebin.ca/809567

    Thanks for responding

    What you have is this:

    <ul class="list-cat">
    <?php if ( function_exists('wp_tag_cloud') ) : ?>
    <?php wp_tag_cloud('smallest=8&largest=22'); ?>
    <?php endif; ?>
    </ul>
    </li>
    </ul>

    What you need is this:

    <?php if ( function_exists('wp_tag_cloud') ) : ?>
    <?php wp_tag_cloud('smallest=8&largest=22'); ?>
    <?php endif; ?>

    That will produce something like this:

    <a href='https://www.mysite.com/?tag=oranges' class='tag-link-14' title='1 topics' style='font-size: 8pt;'>oranges</a>
    <a href='https://www.mysite.com/?tag=plums' class='tag-link-7' title='2 topics' style='font-size: 15pt;'>plums</a>
    <a href='https://www.mysite.com/?tag=peaches' class='tag-link-8' title='3 topics' style='font-size: 22pt;'>peaches</a>

    In other words, you don’t need

    <ul>
    <li> </li>
     </ul>
    
    If you DO want
    <ul>
    <li> </li>
     </ul>

    elements, it will be done automatically by using this:

    <?php if ( function_exists('wp_tag_cloud') ) : ?>
    <?php wp_tag_cloud('smallest=8&largest=22&format=list'); ?>
    <?php endif; ?>

    Which will produce something like this:

    <ul class='wp-tag-cloud'>
    	<li><a href='https://www.mysite.com/?tag=oranges' class='tag-link-14' title='1 topics' style='font-size: 8pt;'>oranges</a></li>
    	<li><a href='https://www.mysite.com/?tag=plums' class='tag-link-7' title='2 topics' style='font-size: 15pt;'>plums</a></li>
    	<li><a href='https://www.mysite.com/?tag=peaches' class='tag-link-8' title='3 topics' style='font-size: 22pt;'>peaches</a></li>
    </ul>

    Note that NO

    <ul> or
    <li>

    elements were added – WordPress did it automatically, producing an unordered list with a class of wp-tag-cloud which you can style from inside your style.css e.g. ul.wp-tag-cloud {font-style:normal;}

    ??

    Thread Starter geekgirl

    (@geekgirl)

    Ok, so I followed your advice and added

    <?php if ( function_exists('wp_tag_cloud') ) : ?>
    <?php wp_tag_cloud('smallest=8&largest=22'); ?>
    <?php endif; ?>

    and now I have 6 more errors than I did before. Here is my sidebar code now. Did i do something wrong?
    https://wordpress.pastebin.ca/810622

    Thread Starter geekgirl

    (@geekgirl)

    Thank u so much Richard for all your help..It is valid now..The problem was that I needed to add the </li></ul> before adding the tag cloud code. Thank u again!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Help adding wp tag cloud’ is closed to new replies.