if post title is this then require this include, elseif do this, else nothing.
-
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!
- The topic ‘if post title is this then require this include, elseif do this, else nothing.’ is closed to new replies.