Black Friday Sale! Get up to $30 off GP Premium! Learn more ➝

[Resolved] Hi Tom, help needed again please

Home Forums Support [Resolved] Hi Tom, help needed again please

Home Forums Support Hi Tom, help needed again please

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #221894
    itg

    Hi Top you helped me recentley with showing different banners in different categories, the problem was solved with this code

    ======================
    <?php
    /**
    * All of your custom PHP can go in this file below this commented area
    * Caution: Be sure to have access to your server via File Manager or FTP in case an error occurs
    * Happy editing!
    */
    add_filter( ‘generate_logo’, ‘generate_category_logo’ );
    function generate_category_logo()
    {
    if ( is_category( ‘565’ ) || in_category( ‘565’ ) ) {
    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo2.jpg&#8217;;
    }

    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo.jpg&#8217;;
    }
    =================================================

    I am trying to add another new logo to another new category, how can i have a different logo for each new category, do i just keep repeating the code and changing the url to the new banner, i tried this and got white screen of death, sorry to be such a pain…. Many thanks In advance…

    #221980
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Any chance you can paste the code that’s giving you the error?

    Paste it into the editor here, highlight it and click the “code” button in the editor controls.

    That will make it easier for me to see what’s going on 🙂

    #222046
    itg

    `<?php
    /**
    * All of your custom PHP can go in this file below this commented area
    * Caution: Be sure to have access to your server via File Manager or FTP in case an error occurs
    * Happy editing!
    */
    add_filter( ‘generate_logo’, ‘generate_category_logo’ );
    function generate_category_logo()
    {
    if ( is_category( ‘565’ ) || in_category( ‘565’ ) ) {
    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo2.jpg’;
    }

    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo.jpg’;
    }

    add_filter( ‘generate_logo’, ‘generate_category_logo’ );
    function generate_category_logo()
    {
    if ( is_category( ‘23’ ) || in_category( ‘23’ ) ) {
    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo3.jpg’;
    }

    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo.jpg’;
    }

    #222047
    Neil

    You don’t need to repeat the code Irv, tthis is what you want to do I think. So you can multiple conditions set to activate if found to be true, otherwise the else bit is the default which happens if none of the conditions are true

    if (condition) {
    code to be executed if this condition is true;
    } elseif (condition) {
    code to be executed if this condition is true;
    } else {
    code to be executed if all conditions are false;
    }

    #222050
    itg

    Sorry, you lost me, i am useless with code

    So what would be the whole code i would use, thank you

    #222051
    Neil

    You should check with Tom that the following is correct, but I believe this is how you would write it.

    <?php
    add_filter( ‘generate_logo’, ‘generate_category_logo’ );
    function generate_category_logo()
    {
    if ( is_category( ‘565’ ) || in_category( ‘565’ ) ) {
    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo2.jpg’;
    }
    elseif ( is_category( ‘23’ ) || in_category( ‘23’ ) ) {
    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo3.jpg’;
    }
    else {
    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo.jpg’;
    }
    }
    ?>
    #222053
    itg

    i used this code and got white screen

    <?php
    add_filter( ‘generate_logo’, ‘generate_category_logo’ );
    function generate_category_logo()
    {
    if ( is_category( ‘1’ ) || in_category( ‘1’ ) ) {
    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo1.jpg’;
    }
    elseif ( is_category( ‘2’ ) || in_category( ‘2’ ) ) {
    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo2.jpg’;
    }
    else {
    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo.jpg’;
    }
    }
    ?>

    #222105
    Neil

    I was assuming your original code worked? Anyway you had single quotes for the urls for the logo, they should be wrapped in “url to logo” and not ‘url to logo’

    Where are you putting this code?

    #222129
    itg

    I was simply copying your code neil, the code i am using is working 100% here it is

    <?php
    /**
    * All of your custom PHP can go in this file below this commented area
    * Caution: Be sure to have access to your server via File Manager or FTP in case an error occurs
    * Happy editing!
    */
    add_filter( ‘generate_logo’, ‘generate_category_logo’ );
    function generate_category_logo()
    {
    if ( is_category( ‘565’ ) || in_category( ‘565’ ) ) {
    return ‘http://www.mywebsite/wp-content/uploads/2016/08/logo2.jpg&#8217;;
    }

    return ‘http://www.mywebsite.com/wp-content/uploads/2016/08/logo.jpg&#8217;;
    }

    I am using the code in simple php plugin downloaded form the generatepress website, thank you

    #222145
    Neil

    Sorry not been able to help Irv, I’ll have another look and see if I can figure it out

    #222174
    Neil

    This is absolutely working Irv. I am running this on a localhost and the images are on a test site so will not always be there in case anyone is looking at this later.

    You would just need to edit the if and ifelse conditions etc to suit your categories as before, as well as your own image urls of course.

    As far as I can see to do what you want to, you need the first ‘if’ and then the ‘elseif’ but does not seem to work unless you have the ‘else’ at the end.

    If you want to test it before adding your category conditions just change the first ‘if’ to an existing page on your site, the ‘elseif’ is any single post page, and any other page should show the ‘else’ image.

    Hope that helps you sort it out. You can of course add further ‘elseif’ as needed.

    add_filter( 'generate_logo', 'generate_category_logo' ); 
    function generate_category_logo() {
        if ( is_page('sample-page')) {
            return 'http://gwwtest.com/gk/wp-content/uploads/2013/02/cropped-galwaykennels_header6001.jpg';
        }
    elseif (is_single()) {
        return 'http://gwwtest.com/gk/wp-content/uploads/2011/07/Teas-up.jpg';
    }
    else {
        return 'http://gwwtest.com/gk/wp-content/uploads/2013/02/galwaykennels_header6001.jpg';
    }
    }
    #222177
    Neil

    Just to add, this is working for me. Try it as I suggest without the categories, keeping it simple first, then try adding in the category conditionals as there may be a problem with those as coded so far?

    #222180
    Ramesh Srinivasan

    My 2 cents:

    And beware of those curly quotes.. You may have to replace it with normal quotes, as in Neil’s latest reply.

    Not an expert in PHP but those special quotes can cause problems in any scripting/programming language in general.

    #222192
    Neil

    You know what? There was a syntax error in there somewhere, the ‘category number’, the apostrophes were not right somehow, I retyped those after adding a couple of sample categories and it is working with those now for me.

    add_filter( 'generate_logo', 'generate_category_logo' ); 
    function generate_category_logo() {
        if ( is_category( '2' ) || in_category( '2' ) ) {
            return 'http://gwwtest.com/gk/wp-content/uploads/2013/02/cropped-galwaykennels_header6001.jpg';
        }
    elseif ( is_category( '3' ) || in_category( '3' ) ) {
        return 'http://gwwtest.com/gk/wp-content/uploads/2011/07/Teas-up.jpg';
    }
    else {
        return 'http://gwwtest.com/gk/wp-content/uploads/2013/02/galwaykennels_header6001.jpg';
    }
    }
    #222193
    Neil

    As Ramesh mentioned and found here

    Works – <?php echo ‘<p>Hello World</p>’; ?>

    Doesn’t work – <?php echo ‘<p>Hello World</p>’; ?>

    The latter comes from a normal text editor, so that was the issue all along, one or several ‘slanty’ quotes got involved and broke the code. Which was then repeated by copying the original error.

Viewing 15 posts - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.