Home N-13 News Forums Help Search
RegisterForgot password?
How to add image to post necklacesdiscou
Known bugs - 4.0.3 necklacesdiscou

Latest N-13 News 4.0.3

What is N-13 News?
Where can I get help?
Known bugs

Forums How To Adding Search Functionality
Sallyc
Posted on 28 Feb 2011, 00:42:35

Access: Member
Total Posts: 61
Joined: 2011-02-25

I'm learning from reading the forums and online documentation that it's possible to add Search functionality using $search=true; and other code options.

What I'm wondering is if it's possible to do this using a Search form. For example

Code:
<?php 
<div class="search">
        <
form id="form" name="form" method="post" action="http://domain.com/blog.php?goto=search">
          <
span>
          <
input name="q" type="text" class="keywords" id="textfield" maxlength="50" value="Search..." />
          </
span>
          <
input name="b" type="image" src="images/search.gif" class="button" />
          
        </
form>
?>


brings up blog.php with a Search form but nothing else - no results or the news, even though the news script is included in the page. I can use that S

I'm sure my lack of coding ability is causing me difficulty in understanding how to put this all together, but is it possible to incorporate the Search feature into a form I've made or alternatively to have it display on the blog.php page along with the news?

Thank you.
#3259
Rayc
Posted on 28 Feb 2011, 15:50:36

Access: Member
Total Posts: 74
Joined: 2010-06-13

I'm not much of a coder, so I won't comment on your approach. You can easily pull up a search box using the following...

If your news page is at:
http://www.mydomain.com/newspage.php

then this will bring up a search box, and display the results upon completion:
http://www.mydomain.com/newspage.php?goto=search

What I normally do is, on my news page, place a link with the above URL to pull up the search box.

HTH
#3260
Sallyc
Posted on 28 Feb 2011, 18:30:47

Access: Member
Total Posts: 61
Joined: 2011-02-25

Thanks for your response, Ray.

What you are doing gives me a page with just a Search box, and if I put in a Search query, the results with the Search box. What I want is either 1)a Search Form that is part of the overall site's layout or 2)have the Search box be at the top of my news page with the news below it.

I have tried making my blog's(where my news is)menu link be:
Code:
<?php 
<li><a href="blog.php?goto=search">Blog</a></li>
?>


and have also tried having the blog page include be:
Code:
<?php 
<?php
$search
=true;
include 
'news/index.php';
?>
?>


but both codes result in a page with only the search box being displayed - no news. I even tried adding the ?goto=search to the include 'news/index.php'; but that just gave me an error.

That's why I'm puzzling about how to incorporate it. Ideally I'd like to use the Search form since I can have that on the top right of every page and maybe even modify it to search various categories only but right now I'd like to find anything that allowed me to use it on a page.

I'm sure this can be done. But I'm not able to figure out how. If you (or anyone) have any other ideas, I'd love to try them out.

Thanks.
#3261
Sallyc
Posted on 01 Mar 2011, 01:29:25

Access: Member
Total Posts: 61
Joined: 2011-02-25

Okay, I finally realize this is more complicated than I thought. So for those who may come across this thread wanting to do this, my advice would be to create a nice little "Search" graphic and then link it to http://mydomain.com/mypage.php?goto=search where visitors can do their search. Fortunately Chris has a search feature in N-13 or I'd really be out of luck! (Thanks, Chris!)
#3262
Rayc
Posted on 01 Mar 2011, 12:37:42

Access: Member
Total Posts: 74
Joined: 2010-06-13

Yes, I can see where it would be more efficient to have the search box displayed on the news page.

No doubt Chris will have some elegant solution :ermm: but in the meantime you might look at using Multiple Includes. Check the Wiki here.
You could have one regular include, and one for the search form. The catch is one of the two includes must be "static" (whatever that means :blushing:). I'm not sure if the search form can be static, but it might be worth a shot.
#3263
Sallyc
Posted on 01 Mar 2011, 14:26:13

Access: Member
Total Posts: 61
Joined: 2011-02-25

That's interesting, Ray. I tried using
Code:
<?php 
<?php
$static 
= 'true'; #this is the important part
include 'news/index.php';
?>
</div>
?>
in a <div> on a side column and if I included just the page it worked fine. But if I changed the include to
Code:
<?php 
include 'news/index?goto=search.php';
?>
I get a "No such file or directory" error on the page.

But that's still interesting to know. I'm working on adding a script that will show show you all the categories, how many articles are in them, and then display them when you click on the category. It's going to be on a side column <div> so this might be a good way to use that.

I don't know what static means either. I'm still pretty new to this though and have a lot to learn.:new_huh: I'm delighted to find a program that offers flexibility and room to grown and learn with though! And user forums that people can actually get answers on. So thank you for your reply and thoughts!
#3265
Rayc
Posted on 01 Mar 2011, 16:31:05

Access: Member
Total Posts: 74
Joined: 2010-06-13

Looking at the Integration Section of the Wiki, I see the method for calling up the search function is a little different than when I last used it. Rather than the "?goto" parameter, it shows:

Code:
<?php 
$search 
= true;
include 
'news/index.php';
?>


May amount to the same thing, and it could be that the search function cannot work in a static include, but may be worth a shot.
#3268
Sallyc
Posted on 01 Mar 2011, 16:43:03

Access: Member
Total Posts: 61
Joined: 2011-02-25

That was much more fruitful! On my sidebar nav it didn't work so well because it produces the results in the sidebar. But I added this to the top of news page

Code:

<div>
<?php
$static 
= 'true'; #this is the important part
$search = true;
include 
'news/index.php';
?>
</div>


And voila! A working search form!

Thanks, Ray!
#3269
Rayc
Posted on 01 Mar 2011, 20:30:27

Access: Member
Total Posts: 74
Joined: 2010-06-13

Waitaminnit... are you now using only one include? If so, that contradicts what the Wiki says, which is that "...the search form will show instead of the news articles."

If it is a single include, it probably does notneed to be static.

I'm going to try this out when I get a chance. Much more elegant to have the search box on the page with the news.

Glad to have you as the guinea pig. :happy:
#3270
Sallyc
Posted on 01 Mar 2011, 20:47:04

Access: Member
Total Posts: 61
Joined: 2011-02-25

haha - no I'm using two includes. I just put the one for the search page in my message to show how it was written. The second include is the
Code:
<?php 
include 'news/index.php';
?>
one. I hadn't cut & pasted that part of my page because it would only confuse someone looking at this thread. Right now it has some other code prefacing the include since my son (bless him - he knows how to write code!:new_grin:) is helping me with something that requires it to be modified.

The Wiki documentation has the code to Display Categories with Article Count but it's not hyperlinked to actually display them. I wanted them to be clickable to display the articles in those categories. I found a post on here about that topic, but it wasn't clear to me how to actually put together the examples they talked about.

Anyway, I thought it would be confusing to show it so I left it out but I am using two includes.

It looks real nice too. Thanks again!
#3271
Network-13.com © 2013