• Hello everyone,

    I’ve created a bikini girls blog at https://bikinigirlsgalore.com and I’m having a problem with the homepage.

    You see, I’ve used the wp_get_archives() function at the bottom to list the months of the year and a post count in brackets. The output can be seen at the bottom in the links section underneath the homepage thumbnails.

    The problem is that when I click on the month which is currently April(6). I’m having two problems actually.

    1. The thumbnails on the landing page no longer link correctl to the posts pages.

    2. The number of thumbnails that show up is only 5 but in actuality I have 6 confirmed posts with status published.

    please help anyone,

    below is my code.

    sidebar.php

    <div class="row">
      <div class="col-sm-6"><nav class="navbar navbar-expand-sm bg-light">
      <!-- Links -->
      <?php $args = array(
    	'type'            => 'monthly',
    	'limit'           => '',
    	'format'          => 'custom', 
    	'before'          => '<li class="nav-item">',
    	'after'           => '</li>',
    	'show_post_count' => true,
    	'echo'            => 1,
    	'order'           => 'ASC',
            'post_type'     => 'post'
    );
    	  echo '<ul class="navbar-nav">';
    	  wp_get_archives($args);
    	  echo '</ul>';
    ?>
      <?php //wp_get_archives( 'type=monthly' ); ?>
      <?php //the_author_meta( 'description' ); ?>
      
    </nav>
     </div>
      <div class="col-sm-6"><nav class="navbar navbar-expand-sm bg-light">
      <!-- Links -->
      <?php wp_list_pages( '&title_li=' ); ?>
    </nav>
    </div>
    </div>
Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter FalsAlarm

    (@falsalarm)

    I forgot to mention that my permalinks setting is currently set to post name but the urls on the generated page when click on the month is set to be 02/01/post name

    which is a problem, how do i fix?

    does your theme have an archive.php or date.php template file?

    if yes, what are the codes?
    how are you creating the (perma)links for the thumbnails?

    if no, how are you creating the links for the thumbnails in index.php?

    Thread Starter FalsAlarm

    (@falsalarm)

    below is a copy of my index.php file.

    
    <?php get_header(); ?>
    
     </div> 
      <!-- A grey horizontal navbar that becomes vertical on small screens -->
     
      
    
    <?php
    //include the database file
    //include 'database.php';
    
    //$query = "SELECT * FROM wp_mnqhposts WHERE post_type='post'";
    
    //echo $query;
    
    //$result = mysqli_query($con, $query);
    
    //if (mysqli_num_rows($result) > 0) {
    //	while($row = mysqli_fetch_assoc($result)) {
    //		//echo "post_title: " . $row['post_title'] . "<br>";
    //		//echo "post_title: " . $row['post_title'] . "<br>";
    //	}
    // } else {
    //	//echo "0 results";
    // }
    //mysqli_close($con);
    
    //$fivesdrafts = $wpdb->get_results( 
    //	"SELECT * FROM $wpdb->posts	WHERE id <= 60 && post_type='post' && post_title!='Auto Draft'"
    //);        
    //
    //echo '<div class="row">';
    //foreach ( $fivesdrafts as $fivesdraft )
    //{
    //	echo '<div class="col-sm-3" style="text-align:center;">';
    //	//echo "<br>".print_r($fivesdraft);
    //	echo '<h2><a href='.$fivesdraft->post_name.'>'.$fivesdraft->post_title.'</a></h2>';
    //	//echo "<br><a href='.$fivesdraft->post_title.'>".$fivesdraft->post_title."</a>";
    //	echo "<p>".$fivesdraft->post_content . "</p>";
    //	echo wpautop( $fivesdraft->post_content );
    //	echo '</div>';
    //} 
    //echo '</div>';
    //?>
    <?php
    $args = array(
    	'posts_per_page'   => -1,
    	'orderby'          => 'date',
    	'order'            => 'ASC',
    );
    
    	//$args = array($args);
    	$posts_array = get_posts($args);
    	echo '<div class="row">';
    	//echo "<p>Found, " . count($posts_array) . "</p>";
    	foreach($posts_array as $post)
    	{
    		echo '<div class="col-sm-3 border" style="text-align:center;">';
    		echo "<h3 class='headers'><a href='" . $post->post_name ."'>" . $post->post_title . "</h3>";
    		echo "<p>" . $post->post_content . "</p></a>";
    		echo "</div>";
    	}
    echo '</div>';
    
    ?>
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>
    
     
    </body>
    </html>

    I couldn’t find a way to seperate the and the text from the content of the post so I did a little hack of wrapping it all up in an tag.

    Furthermore, I did create my own custom theme but I did not specify a archive.php file at all. Am I supposed to do that?

    Thread Starter FalsAlarm

    (@falsalarm)

    Also, I resolved the issue of why not all of my posts were showing up on the homepage.

    I created an archive.php file for my theme just now. Below is the contents of that file.

    <?php
    /*
    Template Name: Archives
    */
    get_header(); ?>
    
    <?php
    $args = array(
    	'posts_per_page'   => -1,
    	'orderby'          => 'date',
    	'order'            => 'ASC',
    );
    
    	//$args = array($args);
    	$posts_array = get_posts($args);
    	echo '<div class="row">';
    	//echo "<p>Found, " . count($posts_array) . "</p>";
    	foreach($posts_array as $post)
    	{
    		echo '<div class="col-sm-3 border" style="text-align:center;">';
    		echo "<h3 class='headers'><a href='" . $post->post_name ."'>" . $post->post_title . "</h3>";
    		echo "<p>" . $post->post_content . "</p></a>";
    		echo "</div>";
    	}
    echo '</div>';
    
    ?>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    After creating this file, whenever I click on the month it takes me correctly to the new archive.php where it now shows up all 6 of my posts which is awesome.

    However, I notice that the links differ from the links on the homepage. The links include the month and day before the post title for some odd reason.

    Hopefully, you can help me fix this issue, please and thanks.

    Thread Starter FalsAlarm

    (@falsalarm)

    Also, I tried creating a date.php file and copying the contents of my archive.php file to it, but that doesn’t seem to help the link structure of the anchors at all. ??

    Moderator bcworkz

    (@bcworkz)

    Permalinks including dates is just what wp_get_archives() does. It does not even try to conform to your permalinks settings. As long as the date correctly reflects the post date, there is no problem with such links.

    If having the date in the generated links bothers you, you can hook the ‘get_archives_link’ filter and strip out the date portion.

    FYI, your theme does not require an archive.php template. If one does not exist, WP will use the theme’s index.php instead. Of course, if you want archive lists to appear differently than index.php, you need a different template.

    Thread Starter FalsAlarm

    (@falsalarm)

    please tell me how I can hook the ‘get_archives_link’ filter and strip out the date portion.

    Thread Starter FalsAlarm

    (@falsalarm)

    also, in case you didn’t notice on my blog on the archives page, the links don’t actually work with the date included so it does matter.

    PS: correcting the messed-up code from my last reply:

    change this line:

    		echo "<h3 class='headers'><a href='" . $post->post_name ."'>" . $post->post_title . "</h3>";
    

    to:

    		echo "<h3 class='headers'><a href='" . get_permalink( $post->ID ) ."'>" . $post->post_title . "</a></h3>";
    
    Thread Starter FalsAlarm

    (@falsalarm)

    sweet thanks bro, that resolved the issues I was having.. ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How to fix wordpress wp_get_archives() function problem’ is closed to new replies.