Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Condition to home page (index)
#1
hello,

I'm creating a theme which precio that the file template.php has a condition that appears only on the home page (index.php). Can anyone help me what command to use if?

The condition is for some includes, the pages that will create the CMS.

Thanks
Reply
#2
Code:
<?php
if (return_page_slug()=='index') {
// your code here ...
}
?>
Reply
#3
Carlos Wrote:
Code:
<?php
if (return_page_slug()=='index') {
// your code here ...
}
?>


Ok. Thanks Carlos.

I put the proposed code for you but could not, within the content of the condition is not rendering.

my code looks like this:
Code:
<?php
    if (return_page_slug()=='index') {
        <div class="coda-slider preload" id="coda-slider-1">

             <?php include("index.php");?>

          <?php include("index.php?id=page2");?>

          <?php include("index.php?id=page3");?>
    }
    else {
      get_page_content();
    }
    ?>

Any other tips to make it work?
Reply
#4
alvares Wrote:
Carlos Wrote:
Code:
<?php
if (return_page_slug()=='index') {
// your code here ...
}
?>


Ok. Thanks Carlos.

I put the proposed code for you but could not, within the content of the condition is not rendering.

my code looks like this:
Code:
<?php
    if (return_page_slug()=='index') {
        <div class="coda-slider preload" id="coda-slider-1">

             <?php include("index.php");?>

          <?php include("index.php?id=page2");?>

          <?php include("index.php?id=page3");?>
    }
    else {
      get_page_content();
    }
    ?>

Any other tips to make it work?


try like this :

Code:
<?php
    if (return_page_slug()=='index') {
        echo '<div class="coda-slider preload" id="coda-slider-1">';

          include("index.php");

          include("index.php?id=page2");

          include("index.php?id=page3");
    }
    else {
      get_page_content();
    }
    ?>
Reply
#5
Excuse me,
my code actually looks like this:
Code:
<div class="coda-slider preload" id="coda-slider-1">
<?php
    if (return_page_slug()=='index') {
          include("index.php");
          include("index.php?id=page2");
          include("index.php?id=page3");
    }
    else {
      get_page_content();
    }
    ?>
</div>

Note that I want to do is to include unique content only for home.
As there is no way to put the includes in the content of dynamic pages, I need them in template.php
Reply
#6
Instead of using include, that inserts the whole rendered page in your current page (BTW that might do an infinite loop) you should use some function that inserts only pages' contents.

There are some examples in the forum, also some plugins like SimplePageContent, I18N and others. (In GS 3.1 - beta right now- there's the getPageContent() function)
Reply




Users browsing this thread: 2 Guest(s)