• I received an answer yesterday from MichaelH on how to query a post and search only certain keywords that I specify. Everything works great except if it doesn’t return any posts, it still echos out that it’s trying to display it:

    <?php
    // display post title for any post that has both $findtext1 and $findtext2 in the post content
    $findtext1 = 'Welcome';
    $findtext2 = 'first';
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'orderby' => 'date',
      'order' => 'DESC',
      'showposts' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts containing "'.$findtext1.'" and "'.$findtext2.'"';
      while ($my_query->have_posts()) : $my_query->the_post();
        if ( (strpos($post->post_content, $findtext1)!== false) && (strpos($post->post_content, $findtext2)!== false)) {   ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
          <?php
        } //if (strpos
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    This part is what I need help on. It’s still showing this echo statement even when there is no query results.

    if( $my_query->have_posts() ) {
      echo 'List of Posts containing "'.$findtext1.'" and "'.$findtext2.'"';

    Any ideas are welcome and much appreciated!

Viewing 11 replies - 46 through 56 (of 56 total)
  • Thread Starter fusiongt

    (@fusiongt)

    The right column is this:

    <?php
    if( in_category(‘browse-series’) ) {
    include( TEMPLATEPATH . ‘/series.php’ );
    }

    It gets series.php – was that / always there before? I forget. Something’s happening where it’s not displaying the series.php side bar which has important information.

    Check your email going to send you something

    It’ll display if the post being view is in category browse-series, i see it on some pages. All includes are the ones that were in the original code.

    There’s still this lingering error on alot of the pages.

    header.php line 101, do you want some help fixing that?

    I tried the login information you sent but it’s just giving me invalid username/password errors.

    EDIT: Think i see the problem, lol, i’ll try the https://FTP.. ??

    Any comment regarding the post meta(custom fields)?

    I hope you don’t mind, but i’ve added in meta filtering in the posts page so i can get a better idea of how the posts relate.

    If you want to remove it at any time (would appreciate at least a few mins to look at the information though), then just remove the functions.php i’ve created in your theme folder.

    Thread Starter fusiongt

    (@fusiongt)

    No problem I’m at work and can’t touch the code but will be interested in seeing what you did once I’m at home =)

    Ok, i’m just looking over your posts, and it really seems like an inefficient way to relate posts (checking the post title, the current method)..

    One thing i’ve noticed is that you are tagging your volumes for example all with the same tag. We can query posts based on tag, this would be more fool proof.

    Meta filtering isn’t anything fancy, but it does give you that little bit of extra info, that you might find handy.

    I’ll have a play around with the code, you’ve always got a backup if i mess something up (unlikely, your old code is back on page 1 of this thread anyway if need be).

    Managed to figure out why i can’t scroll down the page, one of the javascripts you’re loading is preventing scrollbars or overflows.

    This is also the source of the sidebar problem, as soon as i disabled Javascript in the browser and refresh, the sidebar (right column) then appears.

    Specifically (just tested), it’s this code causing a problem (in header.php).

    <script type="text/javascript">
      FB_RequireFeatures(["CanvasUtil"], function(){
        FB.XdComm.Server.init("/xd_receiver.htm");
        FB.CanvasClient.startTimerToSizeToContent();
    ... * rest of code trimmed

    Getting there, have got the right posts being selected on these pages, just need sorting..

    https://manga.lyght.net/series/berserk.html
    https://manga.lyght.net/browse/ykk.html

    Playing around with a few ideas right now, but i think you should have a re-think on how you relate your posts, i’m pretty sure you could make this a whole lot easier by re-thinking how you’re laying out your posts.

    Both category and tag archives could deal with what it is you’re doing if i understand correctly how you want to relate posts to one another.. Taxonomies would be great here, they support pretty permalinks off the bat, so no additional work.. but it would mean assigning new taxonomies to each post, and learning how they work (so maybe a bit too much at this point).

    I’ll keep playing with it, but welcome any input you have about post relationships, as right now that’s the one thing that’s confusing me still (just the way you’re using tagging and categories).

    Thread Starter fusiongt

    (@fusiongt)

    Yea I agree there might be some redundancy on how I set things up. But there’s a reason I did it the way I did… there are some things you can’t necessarily see that easily…

    About that Javascript that you said is effecting the code – I added it because this is actually going to be a Facebook app, https://apps.facebook.com/mangalyght/

    One thing that has broke is if you view the source, you’ll see this:

    <link rel="image_src" href="https://manga.lyght.net/images/.jpg." />

    It should have the image there which might be why I made it so complicated. The code originally was this in the header.php

    <?php
    global $post;
    foreach(get_the_tags($post->ID) as $tag) {
    $imgtitle = $tag->slug;
    }
    ?>
    
    <?php $image = get_post_meta($post->ID, 'img', true); ?>
    
    <?php if(empty($image)) { $image = "https://manga.lyght.net/images/$imgtitle.jpg"; } ?>
    
    <fb:share-button class="meta">
    <meta name="title" content="Manga Lyght">
    <link rel="target_url" href="<?php the_permalink() ?>"/>
    <link rel="image_src" href="<?php echo $image; ?>" />
    </fb:share-button>

    So that code says if the post has custom field img to use that as the image, but if not then to use the slug and add .jpg to the end of it.

    The categories and tags were set the way they were because I found it very easy to use something like

    if (in_category('browse-series')) {
    include (TEMPLATEPATH . '/series.php');
    }

    On the other hand, tags were used because I needed an easy way to have a breadcrumb back to my series pages. For example (though it’s broke now): https://manga.lyght.net/series/20th-century-boys-volume-03.html – The bread crumb goes Browsea Manga (spelling error, did you accidentally put that) >> Seinen >> 20th Century Boys. That link to 20th Century Boys used to go to the correct https://manga.lyght.net/browse/20th-century-boys.html but now it’s going to the https://manga.lyght.net/tag/20th-century-boys . That would be confusing to a user because a breadcrumb would allow them to go back where they came from, not to somewhere different.

    So my weird setup of categories with tags is indeed weird but I did it for a reason – there’s probably room for improvement of course but things were working fairly well. I just had problems querying “Series Volumes” and “Series Chapters” correctly.

    Tag link and spelling error are both me, playing around..

    You know, if you have a read of the article i linked to by justin tadlock you might like the idea of using some custom taxonomies.

    Example, you could have a series taxonomy.. which would allow you to have URLs like..

    site.com/series/name

    ..for showing posts that belong to a particlar series..

    I’ve been having a think about how you could refine the management of your posts (using taxonomies or not), to make it easier on yourself, but i’m still working out the nuts and bolts of how things relate. Of course i’m sure the articles make perfect sense to you, so you understand the relationships better etc.. ??

    How’d you like the meta filtering? different?

    p.s. fixed the header error, it’s your foreach loop that has the problem, and i’d suspect it’s the problem you mentioned with the image. I’ve commented in files i’ve touched where possible.

    Thread Starter fusiongt

    (@fusiongt)

    One of the problems I was having was getting everything to be in a similar category like /series/genre/series-name-here

    The problem I had (and I’m not a WordPress expert so this could definitely be possible, it’s just I didn’t know how to do it) was to basically have 2 different types of pages.

    Series Pages (ideally /series/genre/series-name.html) would have the list of Volumes and Chapters and the right side would have some good information like about series, and small image of the series, and a vote category.

    Viewing Pages (ideally /series/genre/series-volume-or-chapter-##.html) would be the actual viewing page. I call on this now within the post (I use some script that looks for a certain folder and volume on my server and then displays the images within there).

    The thing I couldn’t figure out was how to have those Volumes/Chapters listed on the series pages and not the viewing pages since I mostly use those <? if in this_category then… ?> statements.

    This is why I broke them up into different categories.

    Gah, I’ve only been working on this thing for a week and it’s really confusing!

    Regarding the current changes you’ve made. I’m a visual person so when I see debugging info and problems like that I can’t really ignore it. Here’s problems I see so far and I’m just listing them down (I’m not complaining because I know this isn’t done yet and I really appreciate your work!)

    • Volumes and Chapters aren’t seperated
    • Some series don’t return anything like +Anima (https://manga.lyght.net/browse/anima.html) – I don’t know how it’s setup (I haven’t viewed the code) so I don’t know if it can be easily fixed if I change a tag or something. I’m sure the + is messing things up.
    • The “last volume” image and navigation is in the series pages at the bottom
    • The series.php is not showing on the right side. I suspect it’s because that “last volume” image and navigation is showing it thinks its in a different category. It has to be in the category browse-series otherwise that right side won’t show up which has the About Series and Vote on Series.

    I’ll have to look into it more. I really like the speed of the query results – from where it was earlier this week (at 5+ seconds per series page) down to less than 1-2 seconds is great! Going to have dinner and I’ll check more after.

    Dropped you a reply to the email sent this morning.. ??

Viewing 11 replies - 46 through 56 (of 56 total)
  • The topic ‘Need help hiding text if a query has no posts’ is closed to new replies.