Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter sheva29

    (@sheva29)

    Found a Solution but still not working. Reading from this post

    Apparently, when the excerpt doesn’t have any content, it runs wp_trim_excerpt() and truncates the text to 55 words. wp_trim_exceprt() only takes empty text as a parameter. So basically every time you have text in your Exceprt field in the CMS wp_trim_exceprt() doesn’t run. The person who posted in the forum added this snippet of code which I modified to show read more at the end like this:

    function rw_trim_excerpt( $text='' )
    {
        global $post;
        $text = strip_shortcodes( $text );
        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]>', $text);
        $excerpt_length = apply_filters('excerpt_length', 55);
        $excerpt_more = apply_filters('excerpt_more', ' ' . '<a href="'. get_permalink($post->ID) . '">Read All ...</a>');
        return wp_trim_words( $text, $excerpt_length, $excerpt_more );
    }
    add_filter('wp_trim_excerpt', 'rw_trim_excerpt');

    This seems to work for me, now when I add this to limit the number of words in my excerpt it works:

    function wpdocs_custom_excerpt_length( $length ) {
        return 50;
    }
    add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );

    I’m happy it works but I wonder if there’s something I’m still missing. I started this template from scratch, so there shouldn’t be any reason why I’m modifying the_exceprt() somewhere else.

    Once again, If anyone could elaborate on this I will really appreciate it.

    Thanks!

    Thread Starter sheva29

    (@sheva29)

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

    add ‘post_id’, with the value of the current post, to the parameters

    Michael, thanks so much for your reply. I did some digging and your solution was perfect. I actually tried it before using arguments in the array without luck by having this:

    $comments = get_comments(array( 'post_id' => the_ID()));

    That was interestingly injecting the post ID number to the page, so I figured it was partially working. I switched it to this and it worked like a charm:

    $comments = get_comments(array( 'post_id' => get_the_ID()));

    Thanks again!

    Thread Starter sheva29

    (@sheva29)

    It worked! Thanks so much!

    Could you ellaborate on the $tag ‘template_redirect’. So if in the future I want to use two separete functions. I use ‘template_redirect’ instead of ‘wp_enqueue_script’. I noticed in the API section for plugins that there are a bunch of them.

    Best,

    Mauricio

    Thread Starter sheva29

    (@sheva29)

    This:

    //This two functions follow the same
    function mauricio_bootstrap_script_jquery() {
    
    //Includes bootstrap jQuery
    wp_register_script( 'custom-script', get_template_directory_uri().'/mauricio_bootstrap/js/bootstrap.js', array( 'jquery' ) );
    
    //This enqueus  the script
    
    wp_enqueue_script( 'custom-script' );
    }
    // Adds the new bootstrap function to the wp_enqueue_scripts
     add_action( 'wp_enqueue_scripts', 'mauricio_bootstrap_script_jquery' );
    
    function mauricio_bootstrap_script_carousel() {
    
    wp_register_script( 'myscript', get_template_directory_uri().'/mauricio_bootstrap/js/bootstrap-carousel.js', array( 'jquery' ) );
    
    wp_enqueue_script( 'myscript' );
    }
    
    add_action( 'wp_enqueue_script', 'mauricio_bootstrap_script_carousel' );

    I completely got rid of the first function

    Thread Starter sheva29

    (@sheva29)

    I did, but the boostrap-carousel.js still does not load :(. Only bootstrap.js

    Thread Starter sheva29

    (@sheva29)

    As I said I heard that it causes less conflicts when loading scripts of your own.

    Thread Starter sheva29

    (@sheva29)

    Thanks esmi.

    I did it because I want to load the one from the snippets. I read that it causes less trouble. But that still does not solve my problem with the last function.

    Thread Starter sheva29

    (@sheva29)

    Hey Mika,

    Thanks for the reply. I started asking around and reading more and I realized I have two options to approach it. I will use the post to query my different projects through categories. And also have a category called blog for the post I want to show in my blog page.

    The other option is to have a wordpress within a wordpress. But I’m not very fond of this one.

    For the first one. The only thing that I’m still trying to figure out is if I can customized also the different categories in how they are displayed. Meaning I don’t want the post for my projects to be displayed in the same fashion as the post for my blog.

    M

Viewing 8 replies - 1 through 8 (of 8 total)