• Resolved SolidSnake2003

    (@solidsnake2003)


    I am trying to add a custom front page that displays the latest 8 posts on the front page. I’ve got the loop setup, and the posts show up, but the button I’ve created for linking to the full post links to the front page. I’ve got this same code for the posts page, and it works perfectly. Is there something wrong with the loop for the front page?

    Here is the code for the…
    [Extremely large code dump removed by moderator per forum rules. Please use Pastebin or a Gist for all large code excerpts, they work better anyway.]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    @solidsnake2003 — There’s no need to post entire code files that could be remotely related. Just the relevant code, like how you are getting the single post links is all that’s necessary. Please re-post only the pertinent code. If you mention pertinent details about your installation, like the theme you are using, we can find supporting code ourselves.

    One small nitpick. Please correctly use HTML comments. There is no final ‘!’ in comments. Correct syntax: <!-- Comment here. --> The space before or after -- is part of the correct syntax. The only reason I ask is the trailing ! confuses my syntax highlighter, making your code all that much more difficult to read. Browsers tend to be forgiving about syntax errors, my code editor is not.

    Due to the highlighting issue, I could not locate the button you refer to. A link to the page in question would have helped.

    Thread Starter SolidSnake2003

    (@solidsnake2003)

    My website is currently in production. Im finalizing the code for launching. Here is the code for the loop that is causing the problem.

    <?php $latest = new WP_Query( array(
                    'post_type' => 'post',
                    'posts_per_page' => 8
                ) );
    
    	    if ($latest->have_posts()) :
                while ($latest->have_posts()) : $latest->the_post(); ?>
    <!-- Begin Latest Haley News/Website Post --!>
    <tr>
    <td width="0700px" align="left" valign="top">
    <table cellpadding="0" cellspacing="0" width="0700px" background="<?php bloginfo('template_directory'); ?>/images/layout/multiple/content/post-short/content_post-short01.jpg" style="background-repeat: repeat-y;" id="post-<?php the_ID(); ?>" border="0">
    <tbody>
    <tr>
    <td width="0700px" height="0060px" align="left" valign="top">
    <table cellpadding="0" cellspacing="0" width="0700px" height="0060px" border="0">
    <tbody>
    <tr>
    <td width="0060px" height="0060px" background="<?php bloginfo('template_directory'); ?>/images/layout/multiple/content/post-short/content_post-short02.jpg" style="background-repeat: no-repeat;" align="left" valign="middle">
    <img src="https://www.haley-osment.net/images/content/multiple/icons/title/content_multiple_icons_title_news.png" title="" alt="" width="0060px" height="0060px" border="0" class="img" hspace="0" vspace="0" /></td>
    <td width="0640px" height="0060px" background="<?php bloginfo('template_directory'); ?>/images/layout/multiple/content/post-short/content_post-short03.jpg" style="background-repeat: no-repeat;" align="left" valign="middle">
    <div class="content-title">
    <a href="<?php the_permalink(); ?>" rel="nofollow" target="_blank">
    <h1><?php the_title(); ?></h1></a></div></td></tr></tbody></table></td></tr>
    <tr>
    <td width="0700px" align="left" valign="top">
    <table cellpadding="0" cellspacing="0" width="0700px" border="0">
    <tbody>
    <tr>
    <td width="0200px" align="left" valign="top">
    <table cellpadding="0" cellspacing="0" width="0200px" border="0">
    <tbody>
    <tr>
    <td width="0200px" height="0200px" background="<?php bloginfo('template_directory'); ?>/images/layout/multiple/content/post-short/content_post-short04.jpg" style="background-repeat: no-repeat;" align="left" valign="top">
    <a href="<?php the_field('main_title_image_link'); ?>" title="<?php the_title(); ?>" target="_blank">
    <img src="<?php the_field('main_title_image_short'); ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" width="0200px" height="0200px" border="0" class="img" hspace="0" vspace="0" /></a></td></tr>
    <tr>
    <td width="0200px" height="0010px" align="left" valign="top"></td></tr>
    <tr>
    <td width="0200px" align="left" valign="top">
    <center>
    <div class="post-info-box">
    <span class="post-info post-info-date" title="Date Posted"><span class="post-info-icon"><i class="fa fa-calendar"></i></span> <?php the_time( 'M d, Y' ) ?></span>
    <span class="post-info post-info-author" title="Author"><span class="post-info-icon"><i class="fa fa-user"></i></span> <?php the_author(); ?></span>
    <span class="post-info post-info-comments" title="Comments"><span class="post-info-icon"><i class="fa fa-comments"></i></span> <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
    <span class="post-info post-info-views" title="Views"><span class="post-info-icon"><i class="fa fa-pie-chart"></i></span> <?php echo_views(get_the_ID()); ?></span></div></center></td></tr>
    <tr>
    <td width="0200px" height="0010px" align="left" valign="top"></td></tr></tbody></table></td>
    <td width="0500px" align="left" valign="top">
    <table cellpadding="0" cellspacing="0" width="0500px" border="0">
    <tbody>
    <tr>
    <td width="0500px" height="0010px" align="left" valign="top"></td></tr>
    <tr>
    <td width="0500px" align="left" valign="top">
    <center>
    <table cellpadding="0" cellspacing="0" width="0480px" border="0">
    <tbody>
    <tr>
    <td width="0480px" align="left" valign="top">
    <div class="content-short">
    <?php the_excerpt(); ?></div></td></tr>
    <tr>
    <td width="0480px" height="0010px" align="left" valign="top"></td></tr>
    <tr>
    <td width="0480px" height="0060px" class="content-short-button" align="left" valign="top">
    <center>
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" target="_blank">
    <div class="buttons_full_news" title="Read Full Article">
     </div></a></center></td></tr></tbody></table></center></td></tr>
    <tr>
    <td width="0500px" height="0010px" align="left" valign="top"></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><!-- End Latest Haley News/Website Post --!>

    The link for the h1 links to the post, but the one for the buttons_full_news class just links to the home page.

    Moderator bcworkz

    (@bcworkz)

    For the permalink() to work in one place and not another, something must be altering the global $post object behind the scenes. Any PHP call can result in other code being executed from just about anywhere. To narrow down the source, deactivate all of your plugins. Clear your browser cache and reload the page. If the link still does not work properly, the fault is in your theme somewhere, not necessarily your code but something hooked into it. If the link works, reactivate your plugins, one at a time. Test the link after each activation. When the link fails again, the last activated plugin is at fault.

    Thread Starter SolidSnake2003

    (@solidsnake2003)

    Thank you, it solved the problem. Marking as solved.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Front Page Loop Not Working Properly’ is closed to new replies.