Forum Replies Created

Viewing 15 replies - 1 through 15 (of 30 total)
  • Thread Starter Galaxy_High

    (@galaxy_high)

    Yep, I’ve got so far and don’t understand why I can’t pass an array containing strings to a variable using a loop. That’s why I’m asking for help.
    You might as well said, “The answers are here: google.com

    Thread Starter Galaxy_High

    (@galaxy_high)

    I haven’t coded for a few years and it’s taking longer than anticipated to get back on the ball.

    Here’s my function:

    
    function tags(){ 
     if (is_page('tag')){$tags = get_tags();}
     else{$tags = get_the_tags();}
     
     if (!$tags){echo "";}
     else{
      $html = '<ul class="tags">' . "\r\n\t" . '<li>Tags: </li>' . "\r\n\t" . '';
      foreach ($tags as $tag){
       $tag_link = get_tag_link($tag->term_id);
    
       global $post;
       
       //get tag_group_ids
       $tag_group_ids = get_option('tag_group_ids', array());
        $i = array_search($tag->term_group, $tag_group_ids);
       
       //get tag_group_labels and change to lowercase
       $tag_group_labels = get_option('tag_group_labels', array());
        $lower = array_map('strtolower', $tag_group_labels);
       
       //get tag description and change ascii
       $description = str_replace('"', "''", $tag->description);
        $tagdescription = str_replace("=", "\n", $description);
       
       //get post excerpt relating to tag slug - CURRENTLY TESTING
       $tagslug = $tag->slug;
        $args = array('name' => $tagslug);
         $excerpt = get_posts($args);
          $output = $excerpt[0]->post_excerpt;
          
       echo '<pre>';
       var_dump ($excerpt);
       echo '</pre>';
       
       $outputreplace = str_replace('"', "''", $output);
        $postexcerpt = str_replace("=", "\n", $outputreplace);
            
       //change speechmarks for $tag->name
       $tagname = str_replace('"', "''", $tag->name); 
    
       //CURRENTLY TESTING
       $the_slug = 'uk';
       $the_slug = $tag->slug;
       $argz = array('name' => $the_slug);
       $my_posts = get_posts($argz);
        $html .= '<b>ID: </b>' . $my_posts[0]->ID . "\n\n";
        $html .= '<b>Name: </b>' . $my_posts[0]->post_name . "\n\n";
        $html .= '<b>Excerpt: </b>' . $my_posts[0]->post_excerpt . "\n\n";
        $html .= '<b>Slug: </b>' . $tag->slug ."\n\r\n\r";
    
       echo '<pre>';
       print_r($tag->slug);
       echo '</pre>';
      
       //output
       $html .= '<li class="' . $lower[$i] . ' ' . $tag->slug . ' tag">' . "\n\t";
       $html .= '<a href="' . $tag_link . '"';
       $html .= ' title="' . $tagname . "\n\n";
       if (!empty($postexcerpt)){
        $html .= $postexcerpt . "\n\n";
        }
       elseif (!empty($tagdescription)){
        $html .= $tagdescription . "\n\n";
        }
       else{
        $html .= "No tag description or post excerpt yet." . "\n\n";
        }
       $html .= 'Tagged in ' . $tag->count . ' posts' . "\n\n";
       $html .= 'Catergory: ' . $tag_group_labels[$i] . "\n" . '">';
       
       $html .= $tag->name;
       $html .= ' <sup>[' . $tag->count . ']';
       if (!empty($outputreplace)||($description)){
        $html .= '[D]';
        }
       $html .= '</sup></a></li> '. "\n\n\t";
       }
      $html .= '</ul>';
      echo $html;
      echo "\r\n";
      }
     }
    Thread Starter Galaxy_High

    (@galaxy_high)

    Thanx for getting back to me.

    I want my tag descriptions to automatically pull in the excerpt from posts with the same name.
    i.e.
    I have a post called UK, with a populated excerpt – permalink: mysite.com/uk
    I have a tag called UK but I’d like to have the description use the post excerpt

    $tag->slug populates all the relevant variables when var_dumped but wont produce the required result.

    $the_slug = 'the_slug_or_permalink'; //this works as standalone
    $the_slug = $tag->slug;               //this doesn't work but shows all the correct variables when dumped
    $args = array('name' => $the_slug);
    $my_posts = get_posts($args);
     $html .= '<b>ID: </b>' . $my_posts[0]->ID . "\n\n";
     $html .= '<b>Name: </b>' . $my_posts[0]->post_name . "\n\n";
     $html .= '<b>Excerpt: </b>' . $my_posts[0]->post_excerpt . "\n\n";
     $html .= '<b>Slug: </b>' . $tag->slug ."\n\n";

    I’ll try and neaten up my function and paste it here.

    Thanx again.

    • This reply was modified 6 years, 3 months ago by Galaxy_High.
    Thread Starter Galaxy_High

    (@galaxy_high)

    Posted this in the wrong section, sorry.

    Please delete.

    Thread Starter Galaxy_High

    (@galaxy_high)

    It’s what you predictided; I broke my theme somehow.

    Started from scratch and everything seems to be working fine.

    Thanks for all your help.

    Regards,
    Sam

    Thread Starter Galaxy_High

    (@galaxy_high)

    This is gold!

    Thank you. I’ll try these suggestions tomorrow when I have some spare time. Think I’m going to install the 20 16 theme and step through each point as you suggest.

    Really appreciate you taking time to help me out.

    Thanx again.

    Thread Starter Galaxy_High

    (@galaxy_high)

    …and here’s how I’m calling it in the loop…

    $cats = array(
    'corporations',//2
    'events',//3 
    'media',//4
    'operations',//5
    'organisations',//6
    'people',//7
    'places',//8
    'products',//9
    'projects',//10
    'recent-enteries');//3685
    
    foreach ($cats as $c){
    $posts = query_posts( $query_string . '&orderby=' . $_SESSION['selection'] . '&order=' . $_SESSION['order'] . '&cat=' . $c );
    
    if( $posts ) : while (have_posts()) : the_post();
    
    echo '<article>' . "\n";
    	title();
    	thumbnail();
    	echo '<div class="content_container">';
    		echo '<div class="excerpt">' . the_excerpt() . '</div>' . "\n";
    		if(strpos($post->post_content, '<!--nextpage-->')){
    			echo '<p class="postcount">This post contains multiple pages: ';
    			single_link_pages();
    			echo '</p>';
    			}
    		echo '<div class="post_footer">';
    			if (function_exists(posted)){posted();}
    			if (function_exists(updated)){updated();}
    			if (function_exists(wordcount)){wordcount();}
    			echo '</div><!--end post_footer-->';
    		echo '</div><!--end content_container-->';
    	<strong>tags();</strong>
    	echo '</article>' . "\n\n";
    endwhile;
    endif;
    }

    Thanks for getting back to me. I’ve hit a wall and struggling to understand.

    Thread Starter Galaxy_High

    (@galaxy_high)

    Here’s my tag function…

    function tags(){
    
    if (is_page('tag')){$tags = get_tags();}
    else{$tags = get_the_tags();}		
    if (! $tags){echo "";}
    else{
    $html = '<ul class="tags">' . "\r\n\t" . '<li>Tags: </li>' . "\r\n\t" . '';
    foreach ($tags as $tag){
    	$tag_link = get_tag_link($tag->term_id);
    
    	$tag_group_labels = get_option('tag_group_labels', array());
    	$tag_group_ids = get_option('tag_group_ids', array() );
    	$i = array_search($tag->term_group, $tag_group_ids);
    	$lower = array_map('strtolower', $tag_group_labels);
    	$description = str_replace('"', "''", $tag->description);
    	global $post;
    
    	//testing variables
    	$tagslug = $tag->slug;
    	$args = array('name' => $tagslug);
    	$excerpt = get_posts($args);
    	$output = $excerpt[0]->post_excerpt;
    	
    	$html .= '<li class="' . $lower[$i] . ' ' . $tag->slug . ' tag">' . "\n\t";
    	$html .= '<a href="' . $tag_link . '"';
    	$html .= ' title="' . $tag->name . "\n\n";
    	
    	//testing variables
    	$html .= 'tag slug: ' . $tag->slug . "\n\n";
    	$html .= 'post name: ' . $post->post_name . "\n\n";
    	$html .= 'post id: ' . get_the_ID() . "\n\n";
    	$html .= 'tag id: ' . $tag->term_id . "\n\n";
    	$html .= 'tag description: ' . $description . "\n\n";
    	$html .= 'post excerpt: ' . $post->post_excerpt . "\n\n";
    	$html .= 'relative excerpt to tag: ' . $output . "\n\n";			
    	
    	$html .= 'Tagged in ' . $tag->count . ' posts' . "\n\n";
    	$html .= 'Catergory: ' . $tag_group_labels[$i] . "\n" . '">';
    	$html .= $tag->name;
    	$html .= '</a></li> '. "\n\n\t";
    	}
    $html .= '</ul>';
    echo $html;
    echo "\r\n";
    }
    }
    Thread Starter Galaxy_High

    (@galaxy_high)

    I do want it to get the excerpt from the post with the slug the same name as the tag and use it as the tag description but I’m doing something wrong.

    The code works when the post slug and tag slug are equal.

    • post apples
      excerpt
      tag: apples (returns post apples excerpt as description)
      tag: banana (returns nothing)
    • post banana
      excerpt
      tag: apples (returns nothing)
      tag: banana (returns post banana excerpt as description)

    The problem is me not explaining it very well.

    Thanks again.

    • This reply was modified 7 years, 8 months ago by Galaxy_High. Reason: formatting
    Thread Starter Galaxy_High

    (@galaxy_high)

    Hello again,

    I’m not sure I’m implementing the code correctly.

    I’ve declared my variables and called [0] from the array.

    foreach ( $tags as $tag ){
    ...
    $tagslug = $tag->slug;
    $args = array('name' => $tagslug);
    $excerpt = get_posts($args);
    $output = $excerpt[0]->post_excerpt;
    ...
    $html .= 'relative excerpt to tag: ' . $output . "\n\n";
    }

    The tag description is generating from the excerpt but only if it matches the post it’s nested in, if that makes sense?

    My foo tag is pulling in the foo post excerpt when the foo tag is in the foo post but it doesn’t pull in any of the other tag’s relative excerpts.

    What am I doing wrong?

    Thanks again for your help,
    Sam

    Thread Starter Galaxy_High

    (@galaxy_high)

    Sorry for the late reply, alert went to my spam folder.

    Thanx for getting back to me. I’ll report how it goes on Monday.

    Regards,
    Sam

    Thread Starter Galaxy_High

    (@galaxy_high)

    Brilliant!

    Thanks for the explanation regarding $tag / $term.

    Been out of the loop, so to speak, regarding wordpress. It’s slowly coming back to me.

    Thanks again,
    Sam

    Forum: Plugins
    In reply to: PHP and forms
    Thread Starter Galaxy_High

    (@galaxy_high)

    Fixed. I needed to change Descending and Ascending to desc and asc, respectively, to coincide with &order= in my query.

    Thanks for looking.

    Forum: Plugins
    In reply to: PHP and forms
    Thread Starter Galaxy_High

    (@galaxy_high)

    I got my page to remember which &order= to remember by creating a cookie session. Still struggling with the &orderby= cookie.

    Any takers?

    <?php
    echo '<div id="refine">';
    echo '<p>Sorted ';
    
    switch ($_POST['selection']) {
    
    case 'title':
    echo $_POST['title'] . ' <strong>alphabetically</strong>';
    $orderby = "title";
    break;
    
    case 'date':
    echo $_POST['date'] . ' by <strong>date posted</strong>';
    $orderby = "date";
    break;
    
    case 'modified':
    echo $_POST['modified'] . ' by <strong>date modified</strong>';
    $orderby = "modified";
    break;
    
    case 'rand':
    echo $_POST['rand'] . ' <strong>randomly</strong>';
    $orderby = "rand";
    break;
    
    case 'comment_count':
    echo $_POST['comment_count'] . ' by <strong>popularity</strong>';
    $orderby = "comment_count";
    break;
    
    default:
    echo ' <strong>alphabetically</strong>';
    break;
    
    }
    
    echo ' in <strong>';
    
    switch ($_POST['order']) {
    
    case 'Ascending':
    echo $_POST['Ascending'] . 'ascending';
    break;
    
    case 'Descending':
    echo $_POST['Descending'] . 'descending';
    break;
    
    default:
    echo 'ascending';
    break;
    
    }
    
    echo '</strong> order</p>';
    
    if ($_SERVER["REQUEST_METHOD"] == "POST"){
    	if ($_POST['order'] == "Ascending"){$order = "asc";}
    	elseif ($_POST['order'] == "Descending"){$order = "desc";}
    	}
    ?>
    
    <form id="selection" action="" method="post">
    <select name="selection">
    <option name="title" value="title">Alphabetic</option>
    <option name="date" value="date">Posted</option>
    <option name="modified" value="modified">Modified</option>
    <option name="rand" value="rand">Random</option>
    <option name="comment_count" value="comment_count">Popularity</option>
    </select>
    <input type="submit" name="order" value="Ascending" title="Ascending">
    <input type="submit" name="order" value="Descending" title="Descending">
    </form>
    
    <?php
    session_start();
    if (isset($_POST['order'])){
    	$_SESSION['selection'] = $_POST['selection'];
    	$_SESSION['order'] = $_POST['order'];}
    
    echo $_SESSION['order'] . "\n";
    echo $_SESSION['selection'];
    echo '</div><!--end refine-->';
    ?>
    
    $cats = array(2, 3, 4, 5, 6 ,7, 8, 9, 10);
    foreach ($cats as $c){
    $posts = query_posts( $query_string . '&orderby=' . $_SESSION['selection'] . '&order=' . $_SESSION['order'] . '&cat=' . $c );
    
    if( $posts ) :
    	while (have_posts()) :
    		the_post();
    ?>
    
    [html content]

    Thanks for looking,
    Sam

    Thread Starter Galaxy_High

    (@galaxy_high)

    Last time now, I promise.

    If image is smaller (width or/and height) than option then option will not show.

    Regards,
    Sam

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