• I’ve made a custom design for wordpress posts, and everything works except the last part where I have a “block” that’s showing the category the post was published in.

    <div class="post">
    	<h4><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h4>
    	<span class="postinfo">Publisert <?php the_date(); ?></span>
    	<div class="utdrag">
    		<?php the_excerpt(); ?>
    	</div>
    
    	<a href="#" class="block"><?php the_category( $id ); ?></a>
    </div>

    I’ve had this problem before, that the class won’t work together with a wordpress php code. What should I do?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Can you post a link to a site that shows the issue?

    Thread Starter Phoenix39

    (@phoenix39)

    Sorry, it’s on XAMPP (localhost)…

    i’ve made a css code for class=”block” that works perfectly by itself, but with the php code in the example above, the text shows up outside the box… first, the box shows up, then the text below.

    Ah, I see what the issue is. the_category() returns an <a> tag as part of its output, so your code outputs two <a></a> tag pairs next to each other. You could try either filtering the output of the_category() or try some code like this:

    <?php
    $categories = get_the_category();
    foreach ( $categories as $category ) {
      printf( '<a href="#" class="block">%1$s</a>', $category->name);
    };
    ?>
    Thread Starter Phoenix39

    (@phoenix39)

    That seems to work, thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Link class doesn't work?’ is closed to new replies.