Site logo

[Support request] filter php to show blog post by category without header, navigation and footer

Home Forums Support [Support request] filter php to show blog post by category without header, navigation and footer

Home Forums Support filter php to show blog post by category without header, navigation and footer

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #2540988
    Cristiana

    Hey there! 🙂
    I need to create a category filter that only shows posts from that category with no header, navigation bar or footer.

    This is the result to be obtained.
    https://magazine.dooid.it/vicinanze/toscana/

    Other than that.. I need to create a filter that recall a specific post through the post id. Also without showing header, navigation bar or footer.

    this is the example.
    https://magazine.dooid.it/segnalazione/36126/

    Thank you for the time and the help!

    #2541073
    David
    Staff
    Customer Support

    Hi there,

    does it have to be a PHP Snippet?
    As you can do it with the GP layout element:

    https://docs.generatepress.com/article/layout-element-overview/

    Let me know.

    #2541189
    Cristiana

    I think that this isn’t the right solution for me.
    I need the filter only when I go to invoke it in the url. I don’t want this to be a general rule and always present on my site.

    #2541229
    David
    Staff
    Customer Support

    What would be special about that URL? eg. a URL Parameter.

    If so, then you could:

    1. create the Layout Element, and use that to disable the header etc.
    2. But DO NOT set the Display Rules
    3. Then use the generate_element_display filter to display that element when a custom condition is met, such as checking for a URL param:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 99 === $element_id && isset( $_GET['your-url-param'] ) ) {
            $display = true;
        }
    
        return $display;
    }, 10, 2 );

    Let me know.

    #2543002
    Cristiana

    Thanks for your answer.
    I’ll try to explain better the situation.

    The special thing about the link https://magazine.dooid.it/vicinanze/toscana/ is that by inserting the parameter “vicinanze” and changing “toscana” which is a category, it shows the category archive without header and footer.
    By clicking on the articles shown in this list, they are presented without header and footer,too.

    ————-
    2nd necessity

    In the link https://magazine.dooid.it/segnalazione/36126/
    we have more or less the same functioning.

    “Segnalazione” is the parameter that allows you to see a certain article without foot and head.
    “36126” instead is the post ID directly of the article.

    As I said I don’t need this rule to display on the whole site, but only when clicking on these links.

    Thanks

    #2543409
    Fernando
    Customer Support

    Hi Cristiana,

    It’s the same concept. The parameter is just added after.

    In this way, no extra code is needed.

    So, the example link would now be something like this with David’s code: https://magazine.dooid.it/toscana/?your-url-param

    You can replace your-url-param with anything you prefer.

    #2543703
    Cristiana

    thanks for your patience and help.
    I’m a beginner with these things.
    I created the layout element as David suggested.
    but where should i put the code?

    #2543958
    David
    Staff
    Customer Support

    The code is a PHP Snippet, this doc explains:

    https://docs.generatepress.com/article/adding-php/

    #2544190
    Cristiana

    Unfortunately I don’t understand what I have to do.

    I had already read the guide you sent me, but I can’t apply it on the site.

    Is it possible to organize a video call with screen sharing?

    #2544756
    Fernando
    Customer Support

    Sorry, we don’t offer video calls or screen sharing for our support service.

    What exact step did you take to add it?

    If you haven’t tried, can you install the plugin Code Snippets: https://wordpress.org/plugins/code-snippets/

    1. In your Admin dashboard, go to Snippets > Add new.

    2. Add your code and set it to “Run snippet everywhere”.

    3. Click on “Save changes and activate”.

    #2545385
    Cristiana

    Ok fine.
    I downloaded the plugin as you told me, did the following steps you mentioned and added the code david suggested.

    and then?

    thanks for your patience and help 🙂

    #2545434
    David
    Staff
    Customer Support

    1. Edit your Layout Element, and in the browser URL bar you will see the url, it will look something like this:

    yourdomain.com/wp-admin/post.php?post=202&action=edit

    The 202 is the ID, look for the ID of your Element and make a note of it.

    Then in the code snippet – for reference:

    
    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 99 === $element_id && isset( $_GET['your-url-param'] ) ) {
            $display = true;
        }
    
        return $display;
    }, 10, 2 );

    Where there is the 99 replace that with Element ID.

    Then where it says: $_GET['your-url-param'] change the your-url-param for the parameter you want to use to activate the layout.

    #2550198
    Cristiana

    Thank you for the guide step by step.
    I’ve just done these things. And now?

    #2550396
    David
    Staff
    Customer Support

    You should now be able to use the link with the URL Param to make that work.

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