• Resolved rw1

    (@rw1)


    hello,

    i have a front page slideshow that displays the most recent posts.

    i am wanting the associated ‘Read More’ link on each slide to open a lightbox that has content that is unique to that slide.

    the content contains script and cannot be called by shortcode which is why i am looking at creating a dynamic structure where:

    if the posts title (of the current slide) is this

    then require this include.php which contains custom content

    elseif the posts title is something else

    then require this different include.php which contains custom content

    otherwise do nothing

    so i have tried a few methods (see below) but am still learning php and wordpress and not sure of the correct syntax and calls to make, for example:

    1.

    <?php
    // If the post title is Title 1
    if ($post->post_title('Title 1')) {
    //Then grab this
    require("includes1.php");
    //Or if the post title is Title 2
    } elseif ($post->post_title('Title 2')) {
    //Then grab this
    require("includes2.php");
    //Otherwise do nothing
    } else
    echo "";
    ?>

    2.

    <?php
    // If the post title is Title 1
    if ($post->post_title = 'Title 1') {
    //Then grab this
    require("includes1.php");
    // Or If the post title is Title 2
    } elseif ($post->post_title = 'Title 2') {
    //Then grab this
    require("includes2.php");
    //Otherwise do nothing
    } else
    echo "";
    ?>

    3. i also tried defining the post title as a variable:

    <?php
    $post_title_name = "get_the_title();"
    ?>
    <?php
    // If the post title is Title 1
    if ($post_title_name == "Title 1") {
    //Then grab this
    require("includes1.php");
    //Or if the post title is Title 2
    } elseif ($post_title_name == "Title 2") {
    //Then grab this
    require("includes2.php");
    //Otherwise do nothing
    } else
    echo "";
    ?>

    i’ve been referring to a few different sources but particuarly this article on $post object’s and this post which deals with the post title as a variable.

    if anyone could post a solution that achieves what i have been trying to get that would be much appreciated.

    thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter rw1

    (@rw1)

    Can anyone tell me which of the above approaches is close to being correct (if any) and if so where i can make changes so that the syntax is correct.

    thanks!

    Thread Starter rw1

    (@rw1)

    i *think* i’m getting closer – the code below is working, the source code shows all the right custom values, but i still have the issue where the custom values are not being passed on to the lightbox ie whatever ‘Read More’ link i click on opens up the contents assigned to the first slide ie Title 1.

    <?php
    //Set up the variable
    $post_title = get_the_title();
    // If the post title is Title 1
    if ($post_title == 'Title 1') {
    //Then grab this
    require($_SERVER['DOCUMENT_ROOT'] . '/sub-folder/wp-content/themes/theme_name/includes/includes1.php');
    // If the post title is Title 2
    } elseif ($post_title == 'Title 2') {
    //Then grab this
    require($_SERVER['DOCUMENT_ROOT'] . '/sub-folder/wp-content/themes/theme_name/includes/includes2.php');
    } else
    echo "";
    ?>
    Thread Starter rw1

    (@rw1)

    i figured it out, the above code was correct, i had to:

    – add this to the top of each includes:

    <?php
    echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://www.pathtotheme.com/wp-content/themes/theme_name/style.css\" />";
    ?>

    – add the ‘Read More’ link in each include, rather than outside of it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘if post title is this then require this include, elseif do this, else nothing.’ is closed to new replies.