• Resolved inula

    (@janetb)


    Hi,

    In my template I would like to know if connection is in a specific category.
    This gives me all categories:
    $entry->getCategoryBlock(array( 'separator' => ', ' ));

    I thought $entry is a string so I can use:

    if (strpos($entry, 'categoryname') !== false) {
        echo 'true';
    }

    But that doesn’t work.
    What am I doing wrong?

    • This topic was modified 8 years, 1 month ago by inula.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Steven

    (@shazahm1hotmailcom)

    @ Inula

    The $entry->getCategoryBlock() function return an HTML block. I recommend using the $entry->getCategory() function. This will return an array of categories attached to the entry. You can search that array for the category you are looking for and then output what ever you want if it is found.

    Hope that helps!

    Thread Starter inula

    (@janetb)

    Hi Steven,

    Thanks so much for your answer, but I don’t quite understand what the code has to be.

    $entry->getCategory(array( ));
    if (strpos($entry, 'Self') !== false) { echo 'true';}

    I want to see if there is a category ID=4 or categoryname containing “Self”.
    Now all the connections say true. And I know they aren’t ??

    • This reply was modified 8 years, 1 month ago by inula.
    • This reply was modified 8 years, 1 month ago by inula.
    Plugin Author Steven

    (@shazahm1hotmailcom)

    @ Inula

    No, you would do something like this…

    $categories = $entry->getCategory();
    
    foreach ( $categories as $category ) {
        if ( 'Self' === $category->name ) echo 'true';
        if ( 4 === $category->term_id ) echo 'true';
    }
    Thread Starter inula

    (@janetb)

    Hi Steven,

    Thanks a lot!!
    You made my day (uhhh…night ?? )

    Plugin Author Steven

    (@shazahm1hotmailcom)

    @ @ Inula

    Great to hear!

    If you have a moment, I would truly appreciate if you could leave a review as they really do make a difference. Many thanks in advance

    https://www.ads-software.com/support/plugin/connections/reviews/

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Connection in specific category’ is closed to new replies.