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>
]]>Any advice is appreciated!
wp_get_archives( array( 'type' => 'monthly', 'format' => 'html', 'show_post_count' => 0, 'post_type' => 'news' ) );
function news_post_type() {
$labels = array(
'name' => _x( 'Posts', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Post', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'News', 'text_domain' ),
'name_admin_bar' => __( 'Posts', 'text_domain' ),
'archives' => __( 'Post Archives', 'text_domain' ),
'parent_item_colon' => __( 'Parent News:', 'text_domain' ),
'all_items' => __( 'All Posts', 'text_domain' ),
'add_new_item' => __( 'Add Post', 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'new_item' => __( 'New Post', 'text_domain' ),
'edit_item' => __( 'Edit Post', 'text_domain' ),
'update_item' => __( 'Update Post', 'text_domain' ),
'view_item' => __( 'View Post', 'text_domain' ),
'search_items' => __( 'Search Posts', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into item', 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
'items_list' => __( 'Posts list', 'text_domain' ),
'items_list_navigation' => __( 'Post list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter items list', 'text_domain' ),
);
$rewrite = array(
'slug' => 'our-stories/post',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => __( 'Posts', 'text_domain' ),
'description' => __( 'Post Type Description', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'comments' ),
//'taxonomies' => array( 'news_category' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-megaphone',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => 'our-stories',
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'page',
);
register_post_type( 'news', $args );
}
add_action( 'init', 'news_post_type', 0 );
]]>$args = array(
'type' => 'yearly',
'limit' => '',
'format' => 'custom',
'before' => '<div class="arch-single"><span class="btn arch-toggle">',
'after' => '</span></div>',
'show_post_count' => false,
'echo' => 1,
'order' => 'DESC',
'post_type' => $post_type
);
wp_get_archives( $args );
is generating this html:
<span class="btn arch-toggle"><a href='https://site.com/2017/'>2017</a></span>
<span class="btn arch-toggle"><a href='https://site.com/2016/'>2016</a></span>
While those date based root links do show the archives, things like pagination appear to not work, and $wp_query->max_num_pages returns 1 page even when there should be more. However, the correctly structured links, https://site.com/blog/2017/, allow pagination and $wp_query->max_num_pages to return the correct results. Is there a parameter to add in a url prefix for the archives? Shouldn’t it be automatically adding the /blog/ to the url, since that is the posts page?
-Michael
]]>I am using wp_get_archives to get monthly post,
wp_get_archives( array( ‘type’ => ‘monthly’, ‘format’ => ‘html’, ‘show_post_count’ => 1 ) );
when counting ,it count all posts according to date,but i want to count the post that have content ,blank post should not be count.
thanks and regards.
]]><ul>
<li>
<a href="https://localhost/eager/2016/03/">2016年三月</a>
</li>
</ul>
but l wanna use bootstrap,so l need to change that html;like this :
<ul class="blog_archieve">
<li>
<a href="#">
<i class="fa fa-angle-double-right"></i>
2016年三月
<span class="pull-right">(count)</span>
</a>
</li>
</ul>
how?l find a hook “get_archives_link”,use in add_filter.but sorry my php,l don’t know how to add the count of post.anybody can help me?
]]>What do i have to do in order to get: <a class="archive_link" href...>
instead of: <a href...>
from the wp_get_archives function for an aside widget?
In functions.php i have this:
function sxo_widgets_init() {
register_sidebar( array(
'name' => __( 'Primary Widget Area', 'sabercomer' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>'
) );
}
add_action( 'widgets_init', 'sxo_widgets_init' );
And in aside.php template i have:
...
<ul>
<?php wp_get_archives( array( 'type' => 'monthly') ); ?>
</ul>
...
Thanks in advance!
]]>What do i have to do in order to get <a>class="archive_link" ...>
instead of <a ...>
from the wp_get_archives function for an aside widget?
In functions.php i have this:
function sxo_widgets_init() {
register_sidebar( array(
'name' => __( 'Primary Widget Area', 'sabercomer' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>'
) );
add_action( 'widgets_init', 'sxo_widgets_init' );
And in aside.php template i have:
...
<ul>
<?php wp_get_archives( array( 'type' => 'monthly') ); ?>
</ul>
...
thanks in advance,
snor512
[Moderator Note: No bumping, thank you.]
]]>This is the code I have:
HTML
<div class="date">
<div class="date-text"><?php the_date('y.m.d'); ?></div>
<div class="arc"><?php wp_get_archives('type=alpha'); ?></div>
</div>
CSS
.date-text {
display: none;
}
.date:hover .date-text {
display: inline;
}
.date:hover .arc {
display: none;
}
But instead of having all posts in the archive listed as separate <li>
in the same <div>
, I figure I need each post go inside a separate <div>
for the HTML to work properly.
So my question is, can I do this with wp_get_archives
or is there a better way to do it?
Either way, please show some example code, since I’m a complete beginner and couldn’t figure out how to write all the code myself.
And here‘s the page with an example of what I get with the current code.
]]>