0

I have a div block that I only want to display on the first page. I mean, if the user is on

http://mywebsite.com/

it displays the div. But if he navigates to the second page of the posts

http://mywebsite.com/page/2

it hides that div. I am using Datalife Engine.

Div example:

<div class="example"> This is a test </div>

Can this be done?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Pedro Lino
  • 601
  • 1
  • 9
  • 18
  • You say you're using Datalife, right? That wouldn't happen to have anything to do with www2.datalife.com, would it? – Mr Lister Feb 07 '14 at 20:53
  • @MrLister nah. It's a russian plataform. :) I don't have any HTML files. Template files are .TPL and .CSS – Pedro Lino Feb 07 '14 at 20:59

2 Answers2

1

follow this and all be worked fine.

  <head>

  <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>


  <script type="text/javascript">

     $(document).ready(function(){


        if( $('#mainPage').length > 0 ) {

           $("#hideMe").css({"display": "block"});

        } else {

           $("#hideMe").css({"display": "none"});

        }


      });//end doc ready function 


  </script>


  </head>

  <body>

     <div id="mainPage">  </div>


      <div id="hideMe">lorem ipsum</div>

  </body>

hope it helps you

example http://jsfiddle.net/viktorino/56ea5/

Victorino
  • 1,623
  • 11
  • 22
  • I php files on datalife engine are a litle bit diferent. :) I am not using wordpress – Pedro Lino Feb 07 '14 at 21:11
  • this use is not only in wordpress. you can use it where you want – Victorino Feb 07 '14 at 21:13
  • But my "looks" are defined by tpl files, not php. I have my div on tpl files :) – Pedro Lino Feb 07 '14 at 21:14
  • then do this with jquery. check on what page you and if it main page set the div with display block – Victorino Feb 07 '14 at 21:16
  • Sorry, can you help with the jquery code? Don't know much about it :P – Pedro Lino Feb 07 '14 at 21:18
  • i change my unswer check it – Victorino Feb 07 '14 at 21:24
  • Hmm, or i'm using it wrong or it's not working. This is what i've done http://jsfiddle.net/B6AZ3/ I only changed displayed the js in the js tags on the template files. It doesn't do nothing when changing pages. – Pedro Lino Feb 07 '14 at 21:37
  • `$("#Myblock")` not `$("Myblock")` – Victorino Feb 07 '14 at 22:00
  • an dont forget load jquery library 2.1.0 it is work i checked it . if it help you mark my answer . change id of your navigation div in html and you see that div is hide. – Victorino Feb 07 '14 at 22:06
  • Still doesn't work. And as i've said before, i don't have HTML files...i've included Jquery library and tried... – Pedro Lino Feb 07 '14 at 22:47
  • look up on my answer. i have made changes. that you can understand it now – Victorino Feb 07 '14 at 23:01
  • What is suposed the "$('#mainPage').length" measure? I'm still missing something. Or it hides everytime or it shows everytime depending on the ID i put in there. content is called with {content} tag on the template files(.tpl files). just this. I could send you the link maybe. I can't start a chat :S – Pedro Lino Feb 07 '14 at 23:14
  • my english not so good but i try excplane you `$('#mainPage').length` measure is that exists. if is exists the length is 1 and when it's not the length is 0. mark up my answer with code. it is important to me. you need to put your div with content that you want to hide on both of pages with display:none; in css as default and then on main page put my code of answer. with your selectors. – Victorino Feb 07 '14 at 23:39
  • Ok, but the problem is, that i don't want to know if exists or not. What i mean is, you go to the mainpage, you navigate to the 2º page on the navbar... Since there's allways a post there, it will allways be 1... – Pedro Lino Feb 08 '14 at 00:16
  • you want to display this div only on main page. you don't need to now if he exist or not. he exists allways ,you just hide him on both of pages with the code that i write you. – Victorino Feb 08 '14 at 00:56
  • Viktorino, that's the problem. I want that to show on the mainpage, but just the page number 1! If i go to page number two, it hides the content. I don't want to display in one page and hide on other, that's not the problem – Pedro Lino Feb 08 '14 at 02:31
0

For datalife engine, display just on the first page we use:

[page-count=1]Content goes here[/page-count]
tshepang
  • 12,111
  • 21
  • 91
  • 136
Pedro Lino
  • 601
  • 1
  • 9
  • 18