• Resolved Willem 2

    (@willem-2)


    Hi Andrea,

    You helped me with showing the total amount of posts in the dropdown box of your plugin. It works very nice. Now I’m trying to put the code <?php echo count($pbytax_posts); ?> on one of my pages.

    I’m using the plugin ‘easy code placement’ to make a shortcode of the php code. When I do this, it shows a zero. So it looks like the plugin ‘easy code placement’ does what it promises but it doesn’t show the right amount of posts.

    I think I need another php code. Can you help me?

    Willem

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author piccart

    (@piccart)

    Hello Willem!

    that string of code works only inside my widget. You won’t have the variable $pbytax_posts if you are outside my widget..

    Where exactly do you want to display the post counter?

    this is not related to my plugin, but I will give you an hand if I can. ??

    Thread Starter Willem 2

    (@willem-2)

    Hi Andrea,

    I’m glad that you want to help me. I want to display the post counter on: https://www.razenberg.nl/categorieen/

    I hope you can help me.

    Willem

    Plugin Author piccart

    (@piccart)

    ok I see.

    that is a single page where you are displaying a list of categories.
    where do you want to display the counter exactly?

    next to each of the categories in the list?
    and if it’s there that you want it, how did you built that list? is it made with a plugin?

    Thread Starter Willem 2

    (@willem-2)

    Hi Andrea,

    I want to display the counter in the text between ‘alle’ and ‘columns’ in the sentence: ‘Je vindt in de rechterkolom ook een dropdown box met de titels van alle ….. columns.’

    I don’t want to display it in the list with categories which is made with the plugin ‘table of contents plus’.

    Willem

    Plugin Author piccart

    (@piccart)

    ok I see now.

    the only thing I’m not sure about is what count do you want to display (sorry but I don’t know german..).

    do you want to display the counter of the total posts in your entire website?

    Plugin Author piccart

    (@piccart)

    anyways, wordpress has this simple function to get the total posts

    
    
    $count_posts = wp_count_posts();
    $published_posts = $count_posts->publish;
    echo $published_posts;
    
    
    • This reply was modified 8 years, 5 months ago by piccart.
    • This reply was modified 8 years, 5 months ago by piccart.
    Thread Starter Willem 2

    (@willem-2)

    Hij Andrea,

    I want to display the counter on two pages and maybe in a text widget.

    I tried to put the code in the plugin ‘easy code placement’. This didn’t work.

    Willem

    Plugin Author piccart

    (@piccart)

    hi willem,

    I’ve just tested the code into a template file and it works.
    I don’t know exactly how this easy code placement works, but probably there is something you are doing wrong..

    maybe try to return the number instead of echoing

    
    $count_posts = wp_count_posts();
    $published_posts = $count_posts->publish;
    return $published_posts;
    

    because that’s how a shortcode would expect to get the output.

    then I don’t know if you also need to wrap the code into php tags

    <?php 
    code
    ?>

    also, you might want to paste the code into notepad or any other basic text editor, and then copy it from there and paste it where you want. many times when you copy and paste from a web page you also copy hidden characters which then break the code

    @piccart

    Hi piccart,

    the Code you′ve posted above works fine with my Plugin.

    <?php
    $count_posts = wp_count_posts();
    $published_posts = $count_posts->publish;
    echo $published_posts;
    ?>

    Willem said that the code <?php echo count($pbytax_posts); ?> doesn′t work – that′s correct. It only outputs a “0”. That′s the reason i′ve said to him that he should contact you – the Plugin Author. ??

    @willem

    Hi Willem,

    the Code above works fine. Do you tried the Tips from piccart?

    Thread Starter Willem 2

    (@willem-2)

    Hi Andrea,

    Like you suggested, this is the solution:

    <?php
    $count_posts = wp_count_posts();
    $published_posts = $count_posts->publish;
    echo $published_posts;
    ?>

    Do you know how I can make the font size bigger within this code?

    Willem

    • This reply was modified 8 years, 5 months ago by Willem 2.
    Plugin Author piccart

    (@piccart)

    ok great! ??

    Willem, the output code seems to contain the html tag for code.. that’s why it is displayed smaller: it is styled as a code block.
    I guess this might be caused by the fact that you have copied and pasted my code from here, and in this way you also pasted some hidden html into the “easy code placement” box.

    could you try to delete what you have and type it again manually instead of copy&paste?

    Thread Starter Willem 2

    (@willem-2)

    Hi Andrea,

    I followed your suggestion to type the code instead of copy and paste it. The size is still too small.

    Willem

    Plugin Author piccart

    (@piccart)

    Hello Willem,

    I’ve installed that plugin and did a test and I think I understood what’s the problem.

    if you copy and paste the shortcode from the table in the main plugin page, it will copy the html around the shortcode too!
    so when you paste it, it will paste it as well, and that’s why then the output of the code is wrapped into that html.

    try typing the shortcode manually, or you can click on the icon “paste as text” in the post content editor, before you actually paste it:
    paste as text screenshot

    this is something you should use as a general rule when you copy and paste into the post editor.
    and in general try to avoid copy&paste I’ve seen so many issues caused by copy&paste that is always one of the first things I check when debugging a problem.. ??

    what I do is to always paste into a basic text editor like notepad, which will then strip out all the extra html markup because it doesn’t understand it. then I click to copy again from the notepad and I paste the code where I need it. ??

    cheers!

    • This reply was modified 8 years, 5 months ago by piccart.
    Thread Starter Willem 2

    (@willem-2)

    Hi Andrea,

    Yes, that was the problem! It’s resolved now. Thank you very very much!!!

    I shall warn the developer of the plugin ‘easy code replacer’.

    Willem

    Plugin Author piccart

    (@piccart)

    perfect!

    though that’s not actually an error nor a fault of the plugin developer.. it is just normal behaviour when you copy and paste code from a web page or from a complex editor (like windows’ Word). in many cases the copy will copy the hidden html too.

    it is more about knowing that copy&paste could do this kind of things, and paying attention when you copy&paste. ??

    cheers!

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘php code’ is closed to new replies.