Site logo

Archived topic

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

13 replies · Started by Cristiana on February 21, 2023

Viewing posts 1–14 of 14

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!

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.

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.

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

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.

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?

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?

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".

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 :)

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.

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

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

This archived topic is closed to new replies.