We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37693
    • 47 Posts
    Hi

    Using (the fantastic) Articles, I can't find a way to change the title of the page when a user clicks on a tag or an archived month. Currently, (rather deceptively) it always just says 'Blog' whether they are at /blog/ or /blog/tags/articles/ or /blog/2012/01/

    Previously, I used a snippet for tags:

    //-- Get all request string key/value pairs
    $s = $_REQUEST;
      
    if($s['key'] == 'tags'){
      return $s['tag'];
    } else {
     return false;
    }

    To display a tag as the page title call the snippet with appropriate input/output filters. e.g:
    <h1>[[!dyntagtitle:notempty=`Posts Tagged with "[[!dyntagtitle]]"`:empty=`[[*longtitle:empty=`[[*pagetitle]]`]]`]]</h1>

    The snippet no longer works sad

    Before Articles, I would have a separate template for archive listings meaning I could change the appropriate text in there.

    Anyone have a solution?
      • 37693
      • 47 Posts
      Tried to use input and output filters to get the Archives Page title behaving as desired:
      <h1>[[+arc_year:notempty=`[[+arc_month_name]] [[+arc_year]]`:empty=`[[*longtitle:empty=`[[*pagetitle]]`]]</h1>


      Unfortunately
      [[+arc_year]]
      didn't seem to like I/O filters applied to it. Tried calling it cached and uncached.
        • 39501
        • 163 Posts
        Bump - Still looking for a solution if anybody can help!
          • 19328
          • 433 Posts
          I would like to know this as well.. [[+arc_year]] and [[+arc_month_name]] is not working for me at all, where should I place this?
          I'm using friendly URL's, archive url looks like this: www.mysite.nl/blog/2012/05
          I'm trying to display the title 'Archive may 2012'.
          Thanks for any help!
            • 37131
            • 111 Posts
            How you have managed to get archive url look like www.mysite.nl/blog/2012/05 ?!
            I've tried even with clean install of MODX - there is always www.mysite.nl/2012/05 and of course they are not working.
              ---
              Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. Martin Golding
              • 34109
              • 119 Posts
              I've just come up with one solution - may not be the best way to go about it but it works!

              On the articles container template, include this (or similar) snippet:

              <?php
              $output='';
              $get = $modx->sanitize($_GET);
              if (ISSET($get['tag'])){
              	$tag=urldecode($get['tag']);
              	$output='Articles tagged \''.$tag.'\'';
              }
              if (ISSET($get['arc_year'])){
              	$output='Articles posted during '.date( 'F', mktime(0, 0, 0, $get['arc_month'])).' '.$get['arc_year'];
              }
              if ($output!=''){
              	$modx->setPlaceholder('extratitle',' - '.$output);
              	$modx->setPlaceholder('extradescription',' '.$output);
              	$modx->setPlaceholder('extrah1','<h1>'.$output.'</h1>');
              }
              


              This gives you placeholders to add into your title & description tags as well as a new H1 placeholder.
                Studio Republic
                http://www.studiorepublic.com
                0845 226 3205
                @christodhunter
                • 34109
                • 119 Posts
                Quick update to show a page number in the tags:

                <?php
                $output='';
                $get = $modx->sanitize($_GET);
                if (ISSET($get['tag'])){
                	$tag=urldecode($get['tag']);
                	$output='Articles tagged \''.$tag.'\'';
                }
                if (ISSET($get['arc_year'])){
                	$output='Articles posted during '.date( 'F', mktime(0, 0, 0, $get['arc_month'])).' '.$get['arc_year'];
                }
                if (ISSET($get['page'])){
                	$output.=' - page '.$get['page'];
                }
                if ($output!=''){
                	$modx->setPlaceholder('extratitle',' - '.$output);
                	$modx->setPlaceholder('extradescription',' '.$output);
                	$modx->setPlaceholder('extrah1','<h1>'.$output.'</h1>');
                }
                
                  Studio Republic
                  http://www.studiorepublic.com
                  0845 226 3205
                  @christodhunter
                  • 37693
                  • 47 Posts
                  Late thanks to Chris.

                  I've adjusted the code so the pagetitle displays if nothing is set:

                  <?php
                  $output='';
                  $pagetitle = $modx->resource->get('pagetitle');
                  $get = $modx->sanitize($_GET);
                  if (ISSET($get['tag'])){
                      $tag=urldecode($get['tag']);
                      $output=$tag;
                  }
                  if (ISSET($get['arc_year'])){
                      $output='Articles posted during '.date( 'F', mktime(0, 0, 0, $get['arc_month'])).' '.$get['arc_year'];
                  }
                  if ($output!=''){
                      $modx->setPlaceholder('blogTitlePlain',' '.$output);
                  }
                  else {
                    	$output = $pagetitle;
                  	$modx->setPlaceholder('blogTitlePlain',' '.$output);
                  }
                  

                  Also, if anyone doesn't know. To call the snippet you must add
                  [[blogTitle]]
                  (or whatever you called it) to your page and then add the placeholder where you want it to appear – in this instance I called it
                  [[+blogTitlePlain]]

                  Alternatively, you could just 'return $output;' at the end of the snippet which would output wherever you placed the snippet in your template.
                    • 41072
                    • 4 Posts
                    Pity you can't add Kudos here - but Kudos to both Chris and Shaun for a great thread!

                    I use the *description field on my blog, as the subheading under the main site title. I updated the code to use that, and all was well - except when I went into the post itself, the subheading would disappear.

                    So I added a new line at 3:

                    $default='My subheading goes here';
                    


                    and then at 16 change
                    $pagetitle
                    for
                    $default
                    - and this also worked just as I wanted.

                    For anyone interested, I then updated my template and where I would have the [[*description]] I replaced with [[+blogTitlePlain]] and at the top of each article, I called the snippet [[!blogTitle]].


                    The only question is:
                    When I click on a year, I get 'Articles posted in December 2012' rather than just 'Articles posted in 2012'. Clicking on the month is fine, I it works as expected, just not the year bit.


                    I'm guessing line 10 needs a mod to account for the year only.... I don't know enough PHP to figure this out yet, does anyone else?


                      • 41072
                      • 4 Posts
                      Well, whaddya know!!
                      I figured it out - quite simple really!!

                      $default='My continuing adventures in astro-imaging, and astronomy in general';
                      $output='';
                      $pagetitle = $modx->resource->get('description');
                      $get = $modx->sanitize($_GET);
                      if (ISSET($get['tag'])){
                          $tag=urldecode($get['tag']);
                          $output='Articles posted with ' . $tag;
                      }
                      if (ISSET($get['arc_year'])){
                         $output='Articles posted in '.$get['arc_year'];
                      }
                      if (ISSET($get['arc_month'])){
                          $output='Articles posted during '.date( 'F', mktime(0, 0, 0, $get['arc_month'])).' '.$get['arc_year'];
                      }
                      if ($output!=''){
                          $modx->setPlaceholder('blogTitlePlain',' '.$output);
                      }
                      else {
                          $output = $default;
                          $modx->setPlaceholder('blogTitlePlain',' '.$output);
                      }


                      Hope someone finds this useful