Forum Replies Created

Viewing 15 replies - 1 through 15 (of 19 total)
  • Thread Starter hyacinthus

    (@hyacinthus)

    Cancel. I found my stupid mistake already.

    Thread Starter hyacinthus

    (@hyacinthus)

    Thanks for your help and for pointing out Query Overview. I like to understand what I’m doing. Yeah, I’ve found much source code hard sledding especially since a lot of it is not commented. I really appreciate the forum for that reason.

    Thread Starter hyacinthus

    (@hyacinthus)

    Using setup_postdata($post); did not help things. But I did get it working by changing the href in the link. Here’s what I ended up with

    <?php
    if(have_posts()){
        foreach($posts as $post){
            setup_postdata($post);
            $category = get_the_category();
            $cats = $category[0]->cat_ID;
            //$cats = array_flip($cats); ?>
    
    <!--  set up to display in boxes --> 
    <div class="item">
             
        <header>
           
            <h2><?php $my_link = get_category_link($cats);
                       $my_cat = get_the_category_by_ID($cats); ?>
                
                <a href="<?php echo get_category_link($cats); ?>">
        <?php echo get_the_category_by_id($cats); ?> </a>
            </h2>
        </header>
        
            <?php if(has_post_thumbnail()){ 
            $image_url = wp_get_attachment_image_src(get_post_thumbnail_id()
            ,'medium',true);   
            $image = $image_url[0];?>
                <a href="<?php echo esc_url($my_link); ?> "
                   >
                    <img src ="<?php echo esc_url( $image ); ?>" alt="table">
                   </a> 
            <?php } ?>
      </div> <!-- class=item -->
    <!-- end set display boxes -->
    <?php } //end foreach
     } //end if have posts  

    Using
    href="<?php echo esc_url($my_link); ?> "
    `seemed to be the trick although I’m not sure why. If you know please explain.
    you wrote

    Most template tags that rely only on $post will work fine, but others that rely on other globals set by the_post() will not work. The loop mostly works but not reliably so. It’s an insidious problem if you are unaware.

    I agree that is an insidious problem. I keep wishing there was a good book that goes into detail on the innards of WP. The only one I know of is Smashing WordPress and it gives me lots of information but only goes so far. I keep thinking that I need to bite the bullet and study how to access the data base and make my own loops. Been too busy trying to get my basic theme going, but I’m getting very close.

    Thread Starter hyacinthus

    (@hyacinthus)

    I understand what you’re saying, I think. But I am getting the correct information such as the link for the category, and ( I did find a spelling error where I had spelled image as imgage) even when I used
    <img src ="<?php echo esc_url( $image ); ?>" alt="table">
    I got the correct image, but the link when I hover over the image is still incorrect. As far as I can tell from looking at documentation on W3schools my html is correct for specifying the link as localhost/wordpress/ironwork/tables (I’m working on my computer using Xampp) but the link remains localhost/wordpress and I end up back in index.php.
    I am asking first
    if(have_posts()) and everything works as I desire except that the link for the pic is wrong and I can’t see why that would be. I’m able to debug and set breakpoints, step through and look at variables, so I know I’m getting information such as I should or think I should.

    Thread Starter hyacinthus

    (@hyacinthus)

    Thanks for the extra clarification. I can see that it’s going to take some time to get up to speed on how WordPress works. But I’m getting there.

    Thread Starter hyacinthus

    (@hyacinthus)

    I think I’m getting closer to having it work. I think I had the wrong href in my link on the front page.
    But if I need special category handling on single type templates, would I then create a single-tables.php file? And then maybe do my own loop there? Sometimes I get confused by what has to be done within the loop and what can be done outside. Any tutorials lurking around for that?

    Thread Starter hyacinthus

    (@hyacinthus)

    Well, I tried it but it didn’t work. I have a category called ‘tables’ and I have a file called category-tables.php, but when I clicked on the post falling under the category ‘tables’ I still ended up in index.php. What could I be doing wrong?

    So when I set a breakpoint in Template-Loader and it goes through all those elseif’s to find the template, it ends up with

    else :
    		$template = get_index_template();
    	endif;

    The only flag I can see being set is $single which is set to 1 at that time. But I don’t have a single-tables.php file.

    • This reply was modified 9 years, 3 months ago by hyacinthus. Reason: a bit more information
    Thread Starter hyacinthus

    (@hyacinthus)

    Thanks. I had missed that by_ID uses the category ID. Using the get_the_category works for me now.

    Thread Starter hyacinthus

    (@hyacinthus)

    I think I finally figured out what my problem is. I keep forgetting that everything runs through the database. This has to be since users should be able to create menus in the admin interface. This means that functions like wp_nav_menu pull those menu items from the database. So ‘primary’ has no real meaning other than being a label. It could be called ‘february’ and it wouldn’t matter as long as you use it consistently. Where the menu gets located has nothing to do with template_location. The location on the web page depends on where you use wp_nav_menu and the styling depends on whatever styling is in effect at the time. Have I got this correct? If not, please clarify.
    Sure wish somebody would clarify this explicitly in the codex.

    Thread Starter hyacinthus

    (@hyacinthus)

    Okay. Here’s the function from TwentyThirteen. I look in these things to try to understand.

    // This theme uses wp_nav_menu() in one location.
    	register_nav_menu( 'primary', __( 'Navigation Menu', 'twentythirteen' ) );

    Where is ‘primary’ defined? Where is ‘Navigation Menu’ defined? I am used to looking up functions in Microsoft’s library for Windows Apps and finding all the parameters I can pass to a given function and finding them defined so I know how to use them. I’m finding WP very frustrating in this regard. The codex lists the arguments but it’s not clear what each means or its useage. theme_location is a prime example.

    • This reply was modified 9 years, 3 months ago by hyacinthus. Reason: found more information
    Thread Starter hyacinthus

    (@hyacinthus)

    I had already looked at the Function_Reference/register_nav_menus. It doesn’t help. I am working on my own theme. I have yet to find anything that helps understanding of how these things are defined. I have looked at the appearance->menus on the themes I’m currently running on my two websites and under the Manage Locations tab it says the current theme only supports one menu location but doesn’t give a clue to what it’s called. Would these things be defined in a .css file somewhere?

    Thread Starter hyacinthus

    (@hyacinthus)

    Many thanks for your help. I’ve got a lot to chew on and study for a while.

    Thread Starter hyacinthus

    (@hyacinthus)

    Thanks for the direction. I would have looked a long time before finding that info. The article at humanshell.net was extremely helpful.
    What I understand about hooks is that it is a way to connect events within WP to functions. I’ve worked a lot with event driven programming but the way these things are connected in WP is new to me. How does one know when certain events will fire?
    I won’t belabor the point about the assignment statement in the if clause. My goal is to understand WP, not to be a troll. But if I had done that at my old day job, my boss would have given me a very stern lecture and made me fix it. πŸ˜‰

    Thread Starter hyacinthus

    (@hyacinthus)

    Does it matter where the following occurs?
    add_action( 'after_setup_theme', 'portfoliopress_setup' );
    Reason I ask is that it currently follows the function inside function.php and I haven’t yet discovered when function.php is loaded.

    Thread Starter hyacinthus

    (@hyacinthus)

    well, yes and no. Now I understand a bit better what “hooks” are. Some of the terminology is baffling. But I’ve tracked the beginning of portfolio-press to template_loader.php and it seems it includes the portfolio-press index.php directly by the following.

    if ( $template = apply_filters( 'template_include', $template ) ) {
    		include( $template );
    	} elseif ( current_user_can( 'switch_themes' ) ) {
    		$theme = wp_get_theme();
    		if ( $theme->errors() ) {
    			wp_die( $theme->errors() );
    		}
    	}

    Why is there an assignment statement within the if() clause? This is a WordPress file, not part of the theme itself. At this point the $template variable is set to portfolio-press/index.php and things go from there.

Viewing 15 replies - 1 through 15 (of 19 total)