• I have around 700 posts (each for a product line) spread over about 15 categories. I also have an external PDF with product links. I want to make the hyperlinks in the PDF point directly to the posts (Don’t want much, do I ??)

    I don’t really want to have use the admin screen mouseover each link to see the page ID, and copy the title / post ID to a text file; must be a programmatical way of doing it. So is there a plugin – or looping PHP code I can use once only – to ‘interogate’ the database and display/write text file to display /create this data?

    If “push comes to shove”, I could export the post data, and iterate through that file to find the data – that may only be only option, but thought I’d enquire here first.

Viewing 1 replies (of 1 total)
  • Thread Starter cristofayre

    (@cristofayre)

    It’s OK folks, solved it. Did it as proposed at the end. If anyone needs to do the same sort of thing, here’s the code for how I did it:

    `#!/usr/bin/perl
    use CGI qw/:standard/;
    print “content-type: text/html\n\n”;
    use CGI::Carp qw( fatalsToBrowser );

    open (WIKI, “<../../wikaniko/greenproducts.wordpress.2015-05-25.xml”); # The file containing all the posts
    @wiki=<WIKI>;
    close(WIKI);
    $count=0;

    for ($x=0; $x<@wiki; $x++){
    $line=$wiki[$x];
    if($line =~ m|<title>(.*?)</title>|igs){ # Locates title, link and category of post
    $title=$1;
    }
    if($line =~ m|<link>(.*?)</link>|igs){
    $link=$1;
    }
    if($line =~ m|<category domain=”category” nicename=”(.*?)”>(.*?)</category>|igs){
    $cat=$1;
    $outText[$count]=”$cat|$title|$link”.”\n”; # Creates a single line. Save to array
    $count++;
    }
    }

    @outText = sort { lc($a) cmp lc($b) } @outText; # Sort the array alphabetically so all category entries are together
    open (WIKI, “>../../wikaniko/PDF_link_data.txt”);
    print WIKI @outText;
    close(WIKI);

    print “All done”;

Viewing 1 replies (of 1 total)
  • The topic ‘Find all page titles / post ID’ is closed to new replies.