• krzysiekkcn

    (@krzysiekkcn)


    Hi!,
    I would like to modify my search results on my blog.

    In pages section I have templates like: smaller, fullwidth and show.
    In side them I have some content. In smaller and fullwidth templates I have casual text, but the SHOW templates including my tags like:
    [readthis]blablabla[/readthis] or others – inside the templates file, I’m using some php code to show it specialy. It’s required to use this code.

    But when I’m serching something my results looks horrible.
    smaller and fullwidth are ok, but show template is displaing my tags πŸ˜‰

    I would like to hide content when in search results is page with show template, or show just the [show] tag.

    I do not know how to check if the query in my while loop is using SHOW template.

    Thanks in advance,
    I’m waiting forward for your reply.
    Greetings

Viewing 8 replies - 1 through 8 (of 8 total)
  • David Choi

    (@wpthemes777)

    Thread Starter krzysiekkcn

    (@krzysiekkcn)

    Thanks, I think, that I would youse what-template-file-am-i-viewing.

    But one more question, how would you do that? I’m asking because, wordpress is quite new thing for me. I have looked at search.php, and I don’t exactly know how to integrate into the WHILE. How to check post by post?

    I know, that would be stupid questions – it’s just learning, sorry πŸ˜‰

    Moderator bcworkz

    (@bcworkz)

    Not a stupid question, it’s not so obvious. I understand you want to suppress the display of any pages in search results which use a particular tag or template. You may have figured out you need to put a conditional in the search results template to check for these things and if found skip to the next page.

    How to check for these things. For tags, use wp_get_post_tags(). It’s possible to get only a list of tag IDs, see the Codex for an example. You can then use in_array() to check for that one tag.

    How to find the page template used is rather obscure. It is stored in postmeta under the key ‘_wp_page_template’.

    Thread Starter krzysiekkcn

    (@krzysiekkcn)

    Hmm, actually I do not using tags like that ;/ Firstly I thought that a few pages like that would be faster to do with simple php scripts in template, so I do. In template I have script that is looking for predefinied tags take the data into some Jquery events.

    I that case, I don’t think so that wp_get_post_tgas() will show my tags πŸ˜‰

    The problem is that I do not want to hide the whole post, I just want do this thing:
    if template is pr_show then display normal title and description <- and this is the default way.

    And I would like to modify it to work like that (it’s work just with the description).

    when displaing description, look for text between [top_text]here is my simple text[/top_text]. DISPLAY text between tags.

    or if it is imposible,
    when template is pr_show, display title, and my predefinied content.

    Huh, I hope that is clearly and you would understand my problem πŸ˜‰

    Moderator bcworkz

    (@bcworkz)

    If you are not using conventional post tags, then yes, wp_get_post_tags() would not work. But still there must be a way to check which tags are assigned to each post, except I will not be able to tell how to do that.

    Perhaps getting the template used from post meta would still work for a conditional check in an if() else structure. If the template is a match then handle output as you describe, else handle output as is done normally.

    Thread Starter krzysiekkcn

    (@krzysiekkcn)

    Hi!
    Sorry that I didn’t write, but I had a lot of things to do πŸ˜‰

    I was trying to do that, and it is almost complete, but I need you help πŸ˜‰

    The simplies way to do that would be modify the standard.php template from includes/post-formats.

    I think that the simplies way would be to check if in the content is string like “[tekst_” <- is my prefix of all my tags. So I tried it, with a simple function:

    function StrContains($haystack, $needle)
    {
       return(strpos($haystack,$needle)!==false);
    }

    and I checked

    if(StrContains($content, "[tekst_"))
    {
       //my content
    echo '<p> blaablabal</p>
    }
    else
    {
       //normal display
    // there is code from if(has_exrept()
    }

    But the problem is that, I have to have some loop, I had error:
    cannot redeclare strcontains()

    I have placed there some counter, but It didn’t count, so HERE IS QUESTION for your. How to check in this way, if I don’t have a loop?

    I hope you will understand me πŸ˜›
    Greetings,

    — HERE IS MY ORGINAL standard.php part where the content is displaying —

    <div class="post-content">
    					<?php $post_excerpt = of_get_option('post_excerpt'); ?>
    					<?php if ($post_excerpt=='true' || $post_excerpt=='') { ?>
    
    						<div class="excerpt">
    
    						<?php
    						$content = get_the_content();
    						$excerpt = get_the_excerpt();
    
    						if (has_excerpt()) {
    
    								the_excerpt();
    
    						} else {
    
    								if(!is_search()) {
    
    								echo my_string_limit_words($content,85);
    
    								} else {
    
    								echo my_string_limit_words($excerpt,85);
    
    								}
    
    						}
    
    						?>
    
    						</div>
    
    					<?php } ?>
    					<a>" class="button"><?php _e('Czytaj wiΔ™cej', 'theme1669'); ?></a>
    				</div>

    Moderator bcworkz

    (@bcworkz)

    You have chosen a workable method, the only problem is the redeclare error. This is either caused because the function definition is inside of your loop or another strcontains() function has been defined somewhere else in your code. Either move the definition outside of the loop or rename the function.

    Other than that you are close to a working solution.

    Thread Starter krzysiekkcn

    (@krzysiekkcn)

    Oh, your great ;P
    Finally done.
    I wonder if somewhere is a prestashop community like for wordpress ;P

    Thank you veyr much.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Modyfing wordpress searcher’ is closed to new replies.