• Resolved Indent

    (@indent)


    Hi,
    I’m not much of a PHP wizard so I was wondering if something like this is possible?

    In the single.php, after the loop, I want to display a link to the blogpage, but only if there’s more than let’s say 3 posts total. How to check this?

    Appreciate any help on this.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Michael

    (@alchymyth)

    https://codex.www.ads-software.com/Function_Reference/wp_count_posts

    for instance:

    <?php
    $count_posts = wp_count_posts();
    $published_posts = $count_posts->publish;
    if( $published_posts >= 3 ) {
    echo '<a href="' . get_option('home') . '/">' . get_bloginfo('name') . '</a>'; }
    ?>
    Thread Starter Indent

    (@indent)

    Thank you so much.
    I knew there would be a PHP wiz out there.

    Thanks a lot! You made my day.

    Thread Starter Indent

    (@indent)

    @alchymyth;

    One problem:
    get_option('home')
    displays my static front page.

    Can’t find anything on how to make it display my blog page / page for posts.
    I would really appreciate it if you could help. Thanks.

    Michael

    (@alchymyth)

    not sure what your blog page is – maybe this answers the question:
    https://www.ads-software.com/support/topic/how-to-link-to-blog-from-static-page?replies=19

    Thread Starter Indent

    (@indent)

    What I mean is that in WP admin/Reading Settings one can set at static front page and a posts page, which I have done.

    As I understand the conditional tag is_home always refers to the posts page, while get_option('home') refers to whatever the front page is; static or latest posts.

    I just thought it might be a tag for the selected posts page as it is for the front page eg. get_option('home').

    Hope this can help you help me. Thanks for your time.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘If blog has more than x posts display link’ is closed to new replies.