Forum Replies Created

Viewing 15 replies - 1 through 15 (of 35 total)
  • Thread Starter nagomitaro

    (@nagomitaro)

    The previous attempt created the following:

    <a target="blank" data-pin-custom="true" data-pin-log="button_pinit" data-pin-href="https://uk.pinterest.com/pin/create/button?guid=GfGfseSwDJxv-1&url=http%3A%2F%2Flocalhost%2Fmywebsite%2Findex.php%2F2017%2F04%2F16%2Fhello-world%2F&media=&description=Hello%20world!"><i class="icon-pinterest"></i></a>

    Is the pinit.js “taking over” my custom button ?

    I have my own class called icon-pinterest that is the pinterest icon i would like to use it in my already existing footer anchor. Since I am not really creating a button, rather a link, I have then replaced the already posted attempt with the following:

        <?php $pinterestimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
        
            <a href="https://pinterest.com/pin/create/link/?url=<?php echo urlencode(get_permalink($post->ID)); ?>&media=<?php echo $pinterestimage[0]; ?>&description=<?php the_title(); ?>"

    data-pin-custom=”true” target=”blank”><i class=”icon-pinterest”></i>

    The functionality does not work in this case and i am returned with this new page that opens blank:

    https://www.pinterest.com/pin/create/link/?url=http%3A%2F%2Flocalhost%2Fmywebsite%2Findex.php%2F2017%2F04%2F16%2Fhello-world%2F&media=&description=Hello%20world!

    I need to use my custom button, so I thought that using the icon-pinterest with a link would have worked.

    Can you please help? What am I missing?

    Thanks

    Thread Starter nagomitaro

    (@nagomitaro)

    So, I have ended up with these that puts the right meta tags:

    function my_twitter_cards() {
        if (is_singular()) {
            global $post;
    	$twitter_user = str_replace('@', '', get_the_author_meta('twitter'));
    	$twitter_url = get_permalink();
    	$twitter_title = get_the_title();
    	$twitter_excerpt = get_the_excerpt();
    	$twittercard_image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
    	$twittercard_thumb = $twittercard_image[0];
    	if ($twitter_user) {
    	    echo '<meta name="twitter:creator" content="@' . esc_attr($twitter_user) . '" />' . "\n";
    	}
    	echo '<meta name="twitter:card" content="summary" />' . "\n";
    	echo '<meta name="twitter:url" content="' . esc_url($twitter_url) . '" />' . "\n";
    	echo '<meta name="twitter:title" content="' . esc_attr($twitter_title) . '" />' . "\n";
    	echo '<meta name="twitter:description" content="' . esc_attr($twitter_excerpt) . '" />' . "\n";
    	echo '<meta name="twitter:image" content="' . esc_url($twittercard_thumb) . '" />' . "\n";
        }
    }
    add_action('wp_head', 'my_twitter_cards');

    Still same message, although I am validating the link by passing username and password of the staging instance. Any idea why it is not working?

    Cheers,

    • This reply was modified 8 years ago by nagomitaro.
    Thread Starter nagomitaro

    (@nagomitaro)

    Hi again and thank you for putting up with this ?? So much appreciated. So, I am now testing on a staging environment, but it is password protected so strictly speaking not publicly available and I am returned with WARN: no metatags available (although the page is successfully fetched). I believe if a password protected env would be an issue in term of testing, correct? (as much as localhost)

    As per the use of get_queried_object(), is this what you are suggesting:

    add_action( 'wp_head', 'wpse_add_twitter_metadata' );
    function wpse_add_twitter_metadata() {
      	$post = $wp_query->get_queried_object();
        printf(
            '<meta name="twitter:card" content="summary" />
            <meta name="twitter:title" content="%s" />
            <meta name="twitter:description" content="%s" />
            <meta name="twitter:image" content="%s" />',
            get_the_title( $post ),
            get_the_excerpt( $post ),
            get_the_post_thumbnail_url($post)
        );
    }

    Thank you!

    Thread Starter nagomitaro

    (@nagomitaro)

    Hi,
    thanks for your reply, much appreciated. I have a social anchor at the bottom of my article’s page and it currently shares the post’s url via Twitter intent. You can use YOAST to add meta tags by enabling that feature, but then it looks like you need to go into each post to add the meta tags (I have also a current restriction on using YOAST, so for now it is not a viable option). Can you provide an example? I have seen an example like this:

    add_action( 'wp_head', 'wpse_add_twitter_metadata' );
    function wpse_add_twitter_metadata() {
        global $post;
        printf(
            '<meta name="twitter:card" content="summary" />
            <meta name="twitter:title" content="%s" />
            <meta name="twitter:description" content="%s" />
            <meta name="twitter:image" content="%s" />',
            get_the_title( $post ),
            get_the_excerpt( $post ),
            get_the_post_thumbnail_url($post)
        );
    }

    But when implemented locally, it did not seem to work.

    Thank you.

    Thread Starter nagomitaro

    (@nagomitaro)

    Brilliant, thank you so much for your help!

    Thread Starter nagomitaro

    (@nagomitaro)

    Hi,

    Thank you so much, it works fine. This is what I have ended up with:

    <nav class="my-nav-menu">
      <div class="myclass">
        <ul role="navigation" class="mymenuentries">
          <li class="col-clas">
             <a class="myotherclass" href="<?php $cat_slug = 'Amazing';
    $taxonomy = 'category';
    $cat_link = get_term_link( $cat_slug, $taxonomy );
    
    if ( is_wp_error( $cat_link ) ) {
       echo $cat_link->get_error_message();
    } else {
        echo $cat_link;
    }?>">AmazingCategory.</a>
          </li>
       </ul>
      </div>
    </nav>

    I have one additional question, in case I have more than one category, how can I make that more generic?

    Thank you

    Thread Starter nagomitaro

    (@nagomitaro)

    Just realised that I only need to call $cat_link inside href. I have tried this:

    <li class="col-clas">
                <a class="myotherclass" href='{$cat_link}'>News.</a>
              </li>

    But that is not correct. Should I include the php code inside a function?

    Thank you

    Thread Starter nagomitaro

    (@nagomitaro)

    Hi,
    Thank you for your reply. This is a good shout and tried it already, but I wanted to have a more dynamic way to retrieve the category ID rather than encoding it again via its ID. I have this:

    $cat_slug = 'Amazing';
    $taxonomy = 'category';
    $cat_link = get_term_link( $cat_slug, $taxonomy );
    
    if ( is_wp_error( $cat_link ) ) {
       echo $cat_link->get_error_message();
    } else {
        echo $cat_link;
    }

    and I am trying to do something like this:

    <nav class="my-nav-menu">
      <div class="myclass">
        <ul role="navigation" class="mymenuentries">
          <li class="col-clas">
             <a class="myotherclass" href=". get_term_link($cat_link) . "'>AmazingCategory</a>
          </li>
       </ul>
      </div>
    </nav>

    But I cannot get it to work. Where do I call the php code? Just before the nav class? is the get_term_link usage correct?

    Thank you

    Thread Starter nagomitaro

    (@nagomitaro)

    I have actually had a play around and emojii from 4.2 onwards are supported everywhere including categories. The important element is to be running a MySQL version higher than 5.5.3 in order to be able to support the required character set (utf8mb4)

    Thanks

    Thread Starter nagomitaro

    (@nagomitaro)

    Hi, I have managed to resolve the issue with both tags and categories on the sidebar by using get_term_link, as follows (this is an example for categories):

    <div class='categories-container'>
                      <strong><a href='". get_term_link( $sectionSlug) . "'>{$section}</a></strong>
                    </div>

    Thanks

    Thread Starter nagomitaro

    (@nagomitaro)

    The maintenance page is automatically triggered as the update kicks off. The only precautionary measure is to be taken in case your WordPress instance gets stuck in a maintenance mode. If that happens, the .maintenance.php can be deleted from the root folder.

    Cheers

    Thread Starter nagomitaro

    (@nagomitaro)

    Hi again,

    I am trying to get the categories work first, then the tags. I have tried this:

    <div class='categories-container'>
                      <strong><a href='". home_url() ."/category/?cat=". $cat_ID."'>{$section}</a></strong>
                    </div>

    In order to get the format as “home_url/category/?cat=123”, but cat_ID does not return the ugly permalinks. What I am doing wrong? Based on the code, is there the right place where I need making the changes?

    Thank you

    Thread Starter nagomitaro

    (@nagomitaro)

    Michael, thank you so much for your reply. This is the full code for my sidebar:

        <div class="row sidebar">
          <h2 class="myclass" id="sidebarMainTitle">SideBar Title</h2>
          <ul class="col" id="sideBar">
    
        <?php
    
         $numSuggestion = 4;
         $GLOBALS['currentSuggestion'] = 0;
         $GLOBALS['$alreadySuggested'] = [];
    
         $args = array(
           //Limit for the number of suggestions for the page
          'posts_per_page' => $numSuggestion,
          //Posts with tags that will be displayed
          'tag' => implode(",", getTags(get_the_tags(get_the_ID()))),
          'orderby' => 'date',
          'order' => 'DESC'
         );
    
         $posts = get_posts( $args );
         getPosts($posts, $numSuggestion);
    
         if($currentSuggestion<$numSuggestion){
           $args = array(
             //Limit for the number of suggestions for the page
            'posts_per_page' => $numSuggestion,
            'category' => get_the_category(get_the_ID())[0]->cat_ID,
            'orderby' => 'date',
            'order' => 'DESC'
           );
    
            $posts = get_posts( $args );
            getPosts($posts, $numSuggestion);
         }
    
        if($currentSuggestion<$numSuggestion){
          $args = array(
            //Limit for the number of suggestions for the page
           'posts_per_page' => $numSuggestion,
           'orderby' => 'date',
           'order' => 'DESC'
          );
    
           $posts = get_posts( $args );
           getPosts($posts, $numSuggestion);
        }
    
        function getPosts($posts, $numSuggestion){
    
          foreach ( $posts as $post ) {
             if ($post->ID!=get_the_ID() &&  $GLOBALS['currentSuggestion']<$numSuggestion && !in_array($post->ID, $GLOBALS['$alreadySuggested'])){
                $imageUrl = wp_get_attachment_url( get_post_thumbnail_id($post->ID));
    
                if ($imageUrl == false){
                  $imageUrl = getDefaultImage();
                }
                newSuggestion($post->post_title, get_the_category($post->ID)[0]->slug, get_the_category($post->ID)[0]->name, $imageUrl, get_permalink($post->ID), get_the_tags($post->ID));
                $GLOBALS['currentSuggestion']++;
                array_push($GLOBALS['$alreadySuggested'], $post->ID);
              }
          }
        }
    
        function getTags($tagData){
            $tagArray = [];
            //Check to see if tags are returned
            if($tagData!=false){
              foreach ($tagData as $i){
                array_push($tagArray, $i->name);
              }
            }
            return $tagArray;
        }
    
        function getDefaultImage(){
          return get_bloginfo('template_directory') . "/images/default_image.jpg";
        }
    
    function newSuggestion($itemTitle, $sectionSlug, $section, $image, $url, $tags){
            echo "<li class='row class'>
                    <div class='col item'>
                      <div class='row img-container'>
                        <div class='col'>
                          <a href='{$url}'><img src='{$image}' alt='No Image'/></a>
                        </div>
                      </div>
                      <div class='row anotherclass'>
                        <div class='categories-container'>
                          <strong><a href='". home_url() ."/category/". $sectionSlug."'>{$section}</a></strong>
                        </div>
                        <div class='tags-container'>
                          <ul class='tags'>". printTags($tags) ."</ul>
                        </div>
                      </div>
                      <div class='row title-container'>
                        <h2 class='h3'><a href='{$url}'>{$itemTitle}</a></h2>
                      </div>
                    </div>
                  </li>";
        }
    
        function printTags($tags){
            //Check to see if tags are provided
            if ($tags!=false) {
              $return = '';
              foreach ($tags as $i){
                $return .= '<li><a href="' . home_url() . "/tag/" . $i->slug . '">' . $i->name . '</a></li>';
              }
              return $return;
            }
        }
    
        ?>
        </ul>
        </div>

    Where are you suggesting to make use of get_category_link and get_tag_link?

    The theme has always been used with pretty permalinks and always worked. I have had to revert back to ugly permalinks (for some reasons rather convoluted) and noticed that the sidebar tags and categories have never worked.

    Thank you for your help,

    • This reply was modified 8 years ago by nagomitaro.
    Thread Starter nagomitaro

    (@nagomitaro)

    Hi,
    I am not sure I have understood correctly. In my index.php and home.php I have my shortcode, something along this line:

    
    <?php echo do_shortcode('[ajax_load_more post_type="post" offset="9" posts_per_page="10" pause="true"
          scroll="false" button_label="Show me more." transition_container="false"  transition="none"]'); ?>

    I am using Masonry and I have some additional call backs after more posts are loaded. Is that what you mean by “function from which your ajax request is generating”? I am using Ajax Load More in a very standard way, other than for the extra bit in Masonry. Can you provide an example, please?

    Thank you

    Thread Starter nagomitaro

    (@nagomitaro)

    Hi,
    I am not sure why I am using a Get and how should I change it to a Post in my code? Really sorry, but I would you integrate the wp ajax nopri in the already existing function? I feel they are very advanced concepts for me still very new WP and I am not sure how to go about it.

    Thank you so much

Viewing 15 replies - 1 through 15 (of 35 total)