Viewing 10 replies - 1 through 10 (of 10 total)
  • try to work with a conditional statement using in_category() in single.php

    https://codex.www.ads-software.com/Function_Reference/in_category

    Thread Starter klo-wp

    (@klo-wp)

    Thanks alchymyth for reply,

    I know should work with category tag, to add “else if” but don’t know what exactly should do.

    Can you suggest please?

    Thanks

    Thread Starter klo-wp

    (@klo-wp)

    alchymyth ,

    <?php
    if ( in_category( 'wordpress-theme' )) {
    	<a href="test"></a>
    ?>

    this doesn’t work!!! what I’m doing wrong?

    you need to switch from php to html and back (i.e. close and open the php tags accordingly), and close the brackets of the if code:

    try:

    <?php
    if ( in_category( 'wordpress-theme' )) { ?>
    	<a href="test"></a>
    <?php } ?>

    if you want to continue to customize your theme, you will sooner or later need to learn a few basics of php and html and css;

    for instance:
    https://www.w3schools.com/

    Thread Starter klo-wp

    (@klo-wp)

    got this error
    Parse error: syntax error, unexpected ‘<‘
    Parse error: syntax error, unexpected ‘}’

    I’m adding the code to single.php

    the last suggested snippet of code should not generate an error, however this might depend on where you’ve inserted it.

    please paste the full code of single.php into a https://pastebin.com/ and post the link to it here – see https://codex.www.ads-software.com/Forum_Welcome#Posting_Code

    Thread Starter klo-wp

    (@klo-wp)

    thanks for taking time to help me, i appreciate.

    when i add this code

    <?php
    if ( in_category( 'wordpress-theme' )) {
    	// They have long trunks...
    } ?>

    i don’t get any error, but dont see the text “// They have long trunks…” on post page

    these // are indicating that the rest of the line is a php comment, i.e. will not get shown.

    try:

    <?php
    if ( in_category( 'wordpress-theme' )) {
    	echo 'They have long trunks...';
    } ?>
    Thread Starter klo-wp

    (@klo-wp)

    Yes thats worked ??

    thanks alchymyth, this my second thread solved from you.

    wish u the best.

    Thread Starter klo-wp

    (@klo-wp)

    one more question

    echo '<a href="https://...../<?php the_title(); ?>/"></a>';

    this seems not work, “<?php the_title(); ?>” how to get title to work?

    thanks

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to show code only selective category’ is closed to new replies.