{"id":1961,"date":"2022-11-08T11:21:08","date_gmt":"2022-11-08T18:21:08","guid":{"rendered":"https:\/\/dimitrakarakou.gr\/digitalmedia\/?p=1961"},"modified":"2022-11-30T02:18:05","modified_gmt":"2022-11-30T09:18:05","slug":"digital-cat-footprints","status":"publish","type":"post","link":"https:\/\/dimitrakarakou.gr\/digitalmedia\/digital-cat-footprints\/","title":{"rendered":"my digital Cat footprints&#8230;"},"content":{"rendered":"<p>I have just finished my new portfolio (dimirakarakou.gr), for my blog I have just added an animated gif next to the &#8216;Read more&#8217; text. I like this FamilyM theme, it is simple and serves its purpose of blogging.<\/p>\n<p>This blog\u2019s Homepage, archive, and search pages display shorten blog post entries, and at the end of every blog post entry, a &#8216;Take a further walk&#8230;&#8217; link is added<\/p>\n<p><strong>My goal<br \/>\n<\/strong>When the user\u2019s mouse &#8216;mouses over&#8217; a \u2018Read more\u2019 link, an animated cat\u2019s footprints gif appears next to the hovered text.<br \/>\nWhen the user\u2019s mouse &#8216;moves out&#8217; from a \u2018Read more\u2019 text no image is displayed.<br \/>\nWhen the user\u2019s mouse hovers again a \u2018Read more&#8217; link, the cat\u2019s footprints will be animated next to the hovered current text.<br \/>\nThe gif file is animated only once.<\/p>\n<p><strong>Example.<\/strong><\/p>\n<div class=\"catfootsprint\">\n<table>\n<tbody>\n<tr>\n<td>\n<div class=\"entry-content\">\n<p>You are welcomed! Once upon a time \u2026<\/p>\n<p><a class=\"more-link1961 \" href=\"#https:\/\/dimitrakarakou.gr\/digitalmedia\/digital-cat-footprints\/\"><span style=\"font-weight: 900; color: #000; font-family: 'Delius Swash Caps', cursive;\">Take a further walk\u2026<\/span> <img class=\"catFootprints1961\" alt=\"\" \/><\/a><\/p>\n<\/div>\n<p><!-- .entry-content --><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>I used a jQuery script to perform this action the<strong> moreText.js<\/strong> script that I will discuss later on.<\/p>\n<p><strong>Initial thoughts<br \/>\n<\/strong>Where is the &#8216;Read more text?<br \/>\nI use the <strong>WordPress<\/strong> platform for this blog with the <strong>Family theme (child) <\/strong>that is based on the <strong>Omega theme\u00a0(parent)\u00a0<\/strong>.<\/p>\n<p><strong>Step 1: The structure of \u2018Read more<\/strong><\/p>\n<p>The &#8216;Take a further walk&#8230;&#8217; (\u2018Read more\u2026\u2019 is its default\u00a0 name) link\u00a0 text is built on the <strong>hooks.php<\/strong> file in <strong>omega_excerpt_more( $more ) function<\/strong>. The hooks.php file is inside <strong>the lib folder<\/strong> of the <strong>Omega theme<\/strong> (parent)<\/p>\n<h6>The default\u00a0omega_excerpt_more( $more\u00a0) function<\/h6>\n<pre>function omega_excerpt_more( $more ) {\r\n  return ' ... &lt;a class=\"more-link\" href=\"'. get_permalink( get_the_ID() ) . '\"&gt;' . omega_get_setting( 'content_archive_more' ) . '&lt;\/a&gt;';\r\n}<\/pre>\n<p>Two class attributes &lt;a and &lt;img are needed to apply the jQuery script on these elements.<br \/>\nThe img element was added, for the cat footprints gif image file, next to the link text.<br \/>\nThe class names attributes of &lt;a and &lt;img must be different and unique for every blog post entry.<br \/>\nThe GIF must be displayed in the right position next to the current hovered text thus these names would be <strong>built dynamically<\/strong> inside the <strong>omega_excerpt_more( $more )<\/strong> function.<\/p>\n<p>&lt;a class=&#8221;more-link&#8221;<br \/>\nwas change to<br \/>\n<strong>&lt;a class=&#8221;more-link&#8217;. strval(get_the_ID()) . &#8216;&#8221;<\/strong><br \/>\n<strong>\u00a0 <\/strong>and<br \/>\n<strong>&#8216;&lt;img class=&#8221;catFootprints&#8217; . strval(get_the_ID()) . &#8216;<\/strong> was added<\/p>\n<p>The strval(get_the_ID()) holds post Id<\/p>\n<h6>the final\u00a0 omega_excerpt_more( $more ) function<\/h6>\n<pre>function omega_excerpt_more( $more ) {\r\n\u00a0\u00a0 \u00a0return ' ... &lt;a class=\"more-link'. strval(get_the_ID()) . ' \" href=\"'. get_permalink( get_the_ID() ) . '\"&gt;&lt;span style=\"font-weight: 900; color: #000; font-family: \\'Delius Swash Caps\\', cursive;\"&gt;' . omega_get_setting( 'content_archive_more' ) . \r\n\u00a0\u00a0 \u00a0'&lt;\/span&gt;\u00a0 &lt;img class=\"catFootprints' . strval(get_the_ID()) . '\" src=\"\"&gt;&lt;\/a&gt;';\r\n}\r\n<\/pre>\n<h6 style=\"font-size: x-small;\">Note: &lt;span is used to style the &#8216;Take a further walk&#8230;&#8217;\u00a0 text, which is held in \u00a0omega_get_setting( &#8216;content_archive_more&#8217; ) and this value was changed from &#8216;Read more&#8217;\u00a0\u00a0 to &#8216;Take a further walk&#8217; text<br \/>\nfrom the WordPress Dashboard&#8211;&gt;Themes &#8211;&gt; (Family theme) Theme Details &#8211;&gt; Theme Settings<\/h6>\n<p>&nbsp;<\/p>\n<p><strong>Step. 2 Load moreText.js to WordPress&#8217; Omega theme<\/strong><\/p>\n<p>In the Omega theme directory, I create a js folder to hold moreTexr.js<br \/>\nthis script has to be loaded in this theme through the Omega theme&#8217;s\u00a0<strong>functions.php<\/strong> file.<br \/>\nAs I mentioned above I used the parent theme (Omega) to add my script.<br \/>\nSo I have to used the <strong>get_template_directory_uri<\/strong> function instead of the\u00a0<strong>get_stylesheet_directory_uri,<\/strong> that is use for child themes :<\/p>\n<p class=\"fl-heading\"><strong>Step. 3 <span class=\"fl-heading-text\">Passing Variables between PHP and jQuery<\/span><\/strong><\/p>\n<p>When a mouse hovers over a \u2018Take a further walk\u2019 link the <strong>post id value<\/strong> of the\u00a0this blog must be passed to the mo reText.js to run the gif in the appropriate position, next to the hovered\u00a0 \u2018Take a further walk\u2019 link<\/p>\n<p>In order to pass data from php file to js, the<strong> wp_localize_script()<\/strong> must be used.<\/p>\n<pre>function load_moreText(){ \r\n  wp_enqueue_script('moreText', get_template_directory_uri() . '\/js\/moreText.js', array('jquery'), false, true);\r\n  global $post;\r\n\r\n  $posts =get_posts(array(\r\n  'fields' =&gt; 'ids', \/\/ Only get post IDs\r\n  'posts_per_page' =&gt; -1\r\n  ));\r\n wp_localize_script( 'moreText', 'blogs_post_ids', $posts );\r\n}\r\nadd_action( 'wp_enqueue_scripts', 'load_moreText' );<\/pre>\n<p><strong>wp_localize_script()<\/strong> passes the <strong>$pos<\/strong>t array that holds the<span style=\"text-decoration: underline;\">\u00a0post ids<\/span>\u00a0to<strong> &#8216;blogs_post_id&#8217;<\/strong> object<\/p>\n<p>The <strong>&#8216;<strong>blogs_post_id<\/strong>&#8216;<\/strong> is available in the <strong>moreText.js<\/strong> script.<\/p>\n<p><strong>Step. 4\u00a0 The moreText.js script<\/strong><\/p>\n<pre>jQuery(document).ready(function ($) {\r\n   $.each(blogs_post_ids, function(idxArray, valArray) {\r\n   var moreLink = \".more-link\" + valArray;\r\n   var catFootprints = \".catFootprints\" + valArray;\r\n   $(moreLink).hover(function () { \r\n     $(catFootprints).show().attr('src', 'localhost:8888\/digitalmedia\/wp-content\/uploads\/2022\/09\/cat_footprints.gif?rnd=' +Math.random()+'');\r\n   }, function () {\r\n   $(catFootprints).hide().attr('src', '');\r\n   });\r\n }); \r\n});\r\n<\/pre>\n<p>The <strong>blogs_post_ids<\/strong> holds the post ids of my blog<br \/>\nThe <strong>valArray<\/strong> has the post-id value of the &#8216;blogs_post_ids&#8217; elements.<br \/>\nThe valArray value is used to construct of the names of &lt;img and &lt;a,\u00a0<strong>selector1<\/strong> and <strong>selector2<\/strong><\/p>\n<p><strong>Final thoughts<\/strong><br \/>\nA website has a lot of elements grouped together and styled,<br \/>\nIts DOM allows capturing browser events e.g a user hovers over a \u2018Take a further walk\u2019\u00a0link.<br \/>\nif you make right-click on this blog&#8217;s homepage and select &#8216;View page resource&#8217;, you will see\u00a0its html code<\/p>\n<p>A very short part of this:<\/p>\n<p><strong>The html code<\/strong>.<\/p>\n<pre>&lt;div class=\"entry-meta\"&gt;\r\n    Posted on ........\r\n        &lt;div class=\"entry-content\"&gt;        \r\n            &lt;p&gt; Welcome to my 4th #GreekDinner ..............\r\n&lt;a class=\"more-link1306\" href=\"#https:\/\/dimitrakarakou.gr\/digitalmedia\/4th-greek-dinner\/?p=1306\"&gt;&lt;span class=\"more-link-id\" style=\"font-weight: 900; color: #000; font-family: 'Delius Swash Caps', cursive;\"&gt;Take a further walk&amp;#1306; &lt;span?&gt;\r\n&lt;img class=\"footprints-img1306\" src=\"\"&gt;&lt;\/a&gt;&lt;\/p&gt;\r\n        &lt;\/div&gt;&lt;!-- .entry-content --&gt;\r\n<\/pre>\n<p><strong>The result, what you see.<\/strong><\/p>\n<div class=\"catfootsprint\">\n<table>\n<tbody>\n<tr>\n<td>\n<div class=\"entry-meta\">\n<p>Posted on &#8230;&#8230;&#8230;.<\/p>\n<div class=\"entry-content\">\n<p>Welcome to my 4th #GreekDinner&#8230;&#8230;&#8230;&#8230;..<br \/>\n<a class=\"more-link1306 \" href=\"#https:\/\/dimitrakarakou.gr\/digitalmedia\/4th-greek-dinner\/\"><span style=\"font-weight: 900; color: #000; font-family: 'Delius Swash Caps', cursive;\">Take a further walk\u2026 <\/span><img class=\"catFootprints1306\" alt=\"\" \/><\/a><\/p>\n<\/div>\n<p><!-- .entry-content --><\/p>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>The post-id of the above example is = 1306.<br \/>\n&#8212; link element node represents the &#8216;Take further walk link&#8217;<br \/>\n&#8212;-with\u00a0class attribute = <strong>more-link1306<\/strong><br \/>\n&#8212; image element node represents the cat footprints image<br \/>\n&#8212;-with class attribute =\u00a0<strong>catFootprints1306<\/strong><\/p>\n<p>My blog&#8217;s DOM is ready to accept events: user&#8217;s mouse hover a\u00a0&#8216;Take further walk&#8230;&#8217; link<\/p>\n<p>The github repository for this project is available <a href=\"https:\/\/github.com\/dimitrakarakou\/digital_cat_footprints\" target=\"_blank\" rel=\"noopener\">here<\/a><\/p>\n<p>Thank you \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have just finished my new portfolio (dimirakarakou.gr), for my blog I have just added an animated gif next to the &#8216;Read more&#8217; text. I like this FamilyM theme, it is simple and serves its purpose of blogging. This blog\u2019s Homepage, archive, and search pages display shorten blog post entries, and at the end of &#8230; <a class=\"more-link1961 \" href=\"https:\/\/dimitrakarakou.gr\/digitalmedia\/digital-cat-footprints\/\"><span style=\"font-weight: 900; color: #000; font-family: 'Delius Swash Caps', cursive;\">Take a further walk&#8230;<\/span>  <img decoding=\"async\" class=\"catFootprints1961\" src=\"\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":2003,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[78],"tags":[23,80,28,79],"_links":{"self":[{"href":"https:\/\/dimitrakarakou.gr\/digitalmedia\/wp-json\/wp\/v2\/posts\/1961"}],"collection":[{"href":"https:\/\/dimitrakarakou.gr\/digitalmedia\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dimitrakarakou.gr\/digitalmedia\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dimitrakarakou.gr\/digitalmedia\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dimitrakarakou.gr\/digitalmedia\/wp-json\/wp\/v2\/comments?post=1961"}],"version-history":[{"count":64,"href":"https:\/\/dimitrakarakou.gr\/digitalmedia\/wp-json\/wp\/v2\/posts\/1961\/revisions"}],"predecessor-version":[{"id":2168,"href":"https:\/\/dimitrakarakou.gr\/digitalmedia\/wp-json\/wp\/v2\/posts\/1961\/revisions\/2168"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dimitrakarakou.gr\/digitalmedia\/wp-json\/wp\/v2\/media\/2003"}],"wp:attachment":[{"href":"https:\/\/dimitrakarakou.gr\/digitalmedia\/wp-json\/wp\/v2\/media?parent=1961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dimitrakarakou.gr\/digitalmedia\/wp-json\/wp\/v2\/categories?post=1961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dimitrakarakou.gr\/digitalmedia\/wp-json\/wp\/v2\/tags?post=1961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}