WordPress.org

Ready to get started?Download WordPress

Forums

How to use WordPress Conditions in pages / static content? (1 post)

  1. faeronsayn
    Member
    Posted 1 year ago #

    Well, I've got a theme that has a layout builder, it's able to put any static content like "pages" into sidebars and such.

    So I've got a common layout for all posts, that includes custom post types. I can't seem to figure out a way to have different layouts for different posts for that specific theme.

    So now I'm trying to figure out how I can have conditions within pages. Meaning I have some content in a page, but I wrap it around a wordpress conditional like if ( 'book' == get_post_type()) then display some content. Else display some other content. So the page would essentially be a little dynamic, in the sense that it will display different content depending on the post type the user is currently on.

    All i'm wondering is how I can get this done on a page, instead of doing template edits, since my theme uses a layout builder it's increasingly difficult to figure out the sidebar and manipulate it. If I am somehow able to just use conditionals in pages it'll be great. Another problem is that I've tried some of those Allow PHP in pages, the problem is I can't wrap the code with the conditional since it's a short code.

    So I can't do this <?php if('book' == get_post_type()) { [shortcode] } else { [another-shortcode] } ?>

    I obviously can't have shortcodes inside PHP, so I'm wondering how this can be done, or if there are other ways to implement conditionals into pages.

Topic Closed

This topic has been closed to new replies.

About this Topic